Accessing the System VB Help

The API functions described in this section let you look at other running applications from within your Visual Basic application and obtain information about an application and ever i!s’parent window.

Querying Other Applications

To query an application, you must be able to tell your program which application to query. One way to do this is to place the mouse pointer over the other application’s window This is how the Query application (see Figure 13.8) works. This application demonstrates how to spy on other active applications and it uses the GetCursorPos() and SetWindowPos() functions, as well as a number of new functions which are discussed in the following section.

VB6 at Work: The Query Project

The window of the Query application displays information about the current active window and retrieves information about its parent window.

FIGURE 13.8

FIGURE 13.8

This program uses the following functions to retrieve information about any other window that happens to be open:

  1. SetWindowPos()
  2. GetCursorPos()
  3. WindowFromPoint()
  4. GetClassName()
  5. GetWindowText()
  6. GetParent()

SetWindowPos() The program keeps the window on top of other applications with the SetWindowPos() function call, The key element is the HWND_TOPMOST flag, which tells Windows to keep a particular window on top of the Z order, You .track the mouse to see which window the mouse is over and obtain information about the window. This is accomplished with the CetCursorPos() and the Window FromPoint() functions.

GetCursorPos() WindowFromPoint() The GetCursorPos() function returns the screen coordinates of the mouse pointer. These coordinates res are then used by the WindowFromPoint() function to retrieve the name of the, window that is visible at the pointer’s coordinates, The declaration of the WindowFromPoint() function is:

Declare Function WindowF~omPoint Lib’ “user32” (ByVal xPoint As_ Long, ByVal yPoint As Long) As Long

The arguments XPoint and yPoint are a pair of coordinates, The function.returns a Long Integer, which is the handle of the window at the specified location (the window that would be brought on top of the Z order if the user clicked the specific point)

GetClassName(), GetWindowText To spy on other applications, you can use the GetClassName() and GetWindowText() functions. The GetClassName() function obtains a window’s class name, and the GetWindowText() function retrieves the window’s title bar if there is one. If the window is a control, the text of the control is returned.

GetParent() This function gets the window’s parent window.

Posted on November 6, 2015 in The Windows API

Share the Story

Back to Top