Declare Function SetForegroundWindow Lib "user32.dll" (ByVal hwnd As Long) As Long
Platforms: Win 95/98, Win NT
SetForegroundWindow makes the specified window the current foreground window and gives it the focus. This function should only be used with windows which your program owns. Of course this function should be used with caution, since the user usually doesn't expect the foreground window to change unexpectedly. The function tells Windows to somehow draw the user's attention to the window, such as by flashing its icon in the taskbar. The function returns 1 if successful, or 0 if an error occured.
Example:
' Make the window Form1 the current foreground window. The operating
' system will somehow draw the user to the window.
Dim retval As Long ' return value
retval = SetForegroundWindow(Form1.hWnd) ' set Form1 as the foreground window
Related Calls: GetForegroundWindow, SetActiveWindow
Category: Windows
Back to the index.