Using the Windows API, you can extend testing abilities and add usability and flexibility to your function libraries. The Windows operating system provides a large number of functions to help you control and manage Windows operations. You can use these functions to obtain additional functionality.
The Windows API is documented in the Microsoft MSDN Web site, which can be found at: http://msdn2.microsoft.com/en-us/library/Aa383750
A reference to specific API functions can be found at: http://msdn2.microsoft.com/en-us/library/Aa383749
To use Windows API functions:
The following example declares a call to a function called GetForegroundWindow, located in user32.dll:
extern.declare micHwnd, "GetForegroundWindow", "user32.dll", "GetForegroundWindow"
In this example, the foreground window's handle is retrieved. You can enhance your function library if the foreground window is not in the object repository or cannot be determined beforehand (for example, a window with a dynamic title). You may want to use this handle as part of a programmatic description of the window, for example:
In some cases, you may have to use predefined constant values as function arguments. Since these constants are not defined in the context of your function, you need to find their numerical value to pass them to the called function. The numerical values of these constants are usually declared in the function's header file. A reference to header files can also be found in each function's documentation under the Header section. If you have Microsoft Visual Studio installed on your computer, you can typically find header files under X:\Program Files\Microsoft Visual Studio\VC98\Include.
For example, the GetWindow API function expects to receive a numerical value that represents the relationship between the specified window and the window whose handle is to be retrieved. In the MSDN documentation, you can find the constants: GW_CHILD, GW_ENABLEDPOPUP, GW_HWNDFIRST, GW_HWNDLAST, GW_HWNDNEXT, GW_HWNDPREV and GW_HWNDPREV. If you open the WINUSER.H file, mentioned in the GetWindow documentation, you will find the following flag values:
* GetWindow() Constants
#define GW_HWNDFIRST 0
#define GW_HWNDLAST 1
#define GW_HWNDNEXT 2
#define GW_HWNDPREV 3
#define GW_OWNER 4
#define GW_CHILD 5
#define GW_ENABLEDPOPUP 6
#define GW_MAX 6Example
The following example retrieves a specific menu item's value in the Notepad application.
' Constant Values:
const MF_BYPOSITION = 1024
' API Functions Declarations
hwin = Window("Notepad").GetROProperty ("hwnd")' Get Window's handle
' Use API Functions
men_hwnd = Extern.GetMenu(hwin)' Get window's main menu's handle
item_cnt = Extern.GetMenuItemCount(men_hwnd)
hSubm = Extern.GetSubMenu(men_hwnd,0)
rc = Extern.GetMenuString(hSubm,0,value,64 ,MF_BYPOSITION)
来自 “ ITPUB博客 ” ，链接：http://blog.itpub.net/16792402/viewspace-567255/，如需转载，请注明出处，否则将追究法律责任。