You cannot, therefore, hard code the handle number in your code, but must use other API functions to give you the handle you need. Handles are allocated dynamically by Windows and are unlikely to be the same between sessions. A handle is simply a pointer to an area of memory that contains information about the object being pointed to (in this case, a window). The first parameter of the GetWindowRect function is shown as hwnd, and it represents a handle to a window. The UDT definitions for most of the common structures are also included in the API Viewer. Left As Long Top As Long Right As Long Bottom As Long End Type This can be converted to a VBA UDT using the same data-type conversion shown in the previous section, giving: The RECT structure is defined on MSDN (at library/en-us/gdi/rectangl_6cqa.asp)as: The lpRect parameter is a RECT structure that is filled in by the GetWindowRect function with the window's dimensions. For example, the GetWindowRect function is used to return the size of a window, and is defined as:ĭeclare Function GetWindowRect Lib "user32" Many of the Windows API functions pass information using structures, which is the C term for a user-defined type (UDT). MsgBox "Screen resolution is " & lScreenX & "x" & lScreenY End Sub 'Get the screen's dimensions lScreenX = GetSystemMetrics(SM_CXSCREEN) Private Declare Function GetSystemMetrics Lib "user32" _ (ByVal nIndex As Long) As Long There are more than 80 constants for GetSystemMetrics, including SM_CXSCREEN and SM_CYSCREEN to retrieve the screen's dimensions:Ĭonst SM_CXSCREEN As Long = 0 'Screen width Const SM_CYSCREEN As Long = 1 'Screen height The API Viewer also contains most of the constants that you are likely to need. The applicable constants are listed in the MSDN documentation, with their corresponding values in many cases. The value that you pass in the nIndex argument tells the function which metric you want to be given, and must be one of a specific set of constants that the function knows about. For example, to get information about the operating system's capabilities, you can use the GetSystemMetrics function:ĭeclare Function GetSystemMetrics Lib "user32" ( _ ByVal nIndex As Long) As Long Most of the API functions include arguments that accept a limited set of predefined constants.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |