Microsoft Office 2000/Visual Basic Programmer's Guide |
A function may require that you pass a constant to indicate what information you want the function to return. For example, the GetSystemMetrics function takes any one of 75 constants, each specifying a different aspect of the operating system. The information returned by the function depends on which constant you passed to it. To call GetSystemMetrics, you don't need to include all 75 constants — you can simply include the ones you're going to use.
Note It's a good idea to define constants rather than simply passing in the values that they represent. Microsoft ensures that the constants will remain the same in future versions, but there are no guarantees for the constant values themselves.
The constants required by a DLL function are often cryptic in nature, so you'll need to consult documentation for the function to determine what constant to pass in order to return a particular value.
The following example includes the Declare statement for the GetSystemMetrics function and two of the constants that it can take, then shows how to call GetSystemMetrics from within property procedures to return the height of the screen in pixels:
Declare Function GetSystemMetrics Lib "User32" (ByVal nIndex As Long) As Long
Const SM_CXSCREEN As Long = 0
Const SM_CYSCREEN As Long = 1
Public Property Get ScreenHeight() As Long
' Return screen height in pixels.
ScreenHeight = GetSystemMetrics(SM_CYSCREEN)
End Property
Public Property Get ScreenWidth() As Long
' Return screen width in pixels.
ScreenWidth = GetSystemMetrics(SM_CXSCREEN)
End Property
These procedures are available in the System class module in System.xls, available in the ODETools\V9\Samples\OPG\Samples\CH10 folder on the Office 2000 Developer CD-ROM.