Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As Any, ByVal lpWindowName As Any) As Long
FindWindow searches all windows for one which matches the window class name and/or window name. The function's searching mechanism is not case-sensitive. If you do not wish to specify either a class name or window name, you must pass a 0 for that parameter -- passing merely an empty string does not work.
If an error occured or a matching window could not be found, the function returns 0 (use GetLastError to get the error code). If successful, the function returns a handle to the window which it found.
When explicitly passing a 0 as either parameter, you must use the CLng function on it to explicitly make the parameter a Long. Visual Basic does not allow ordinary numeric literals to be passed as Any data type.
' Search for a window called Minesweeper and flash its title bar
' once. We don't need to know the name of that window's class in order to
' find it, but we could include it if we wanted.
Dim hwnd As Long ' receives handle to the found window
Dim retval As Long ' generic return value
' Attempt to locate a window called Minesweeper. Note how the CLng function
' must be used to force 0 as a Long data type.
hwnd = FindWindow(CLng(0), "Minesweeper") ' look for the window
If hwnd = 0 Then ' could not find the window
Debug.Print "Minesweeper is not currently running." ' if it were, there'd be a window!
Else
' Flash the window's title bar on and off once.
retval = FlashWindow(hwnd, 1)
Sleep 500 ' pause for half a second
retval = FlashWindow(hwnd, 0)
End If
Last Modified: October 11, 1999
This page is copyright © 1999 Paul Kuliniewicz. Copyright Information