Consultor Eletrônico



Kbase P24738: How to Call WIN32 API Function: SetForegroundWindow
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   10/16/2008
Status: Verified

GOAL:

How to bring the given window into the foreground?

GOAL:

How to call the Win32 API function called SetForegroundWindow?

GOAL:

How to activate the window giving it input focus?

FACT(s) (Environment):

Windows 32 Intel

FIX:

The following code shows how to call the Win32 API function called SetForegroundWindow. This function brings the thread that created the given window into the foreground and activates the window giving it input focus. Keyboard input will now be directed to the given window.

DEFINE VARIABLE intResult AS INTEGER NO-UNDO.
DEFINE VARIABLE intHwnd AS INTEGER NO-UNDO.


PROCEDURE SetForegroundWindow EXTERNAL "USER32.DLL":
DEFINE INPUT PARAMETER intHwnd AS LONG.
DEFINE RETURN PARAMETER intResult AS LONG.
END PROCEDURE.

PROCEDURE FindWindowA EXTERNAL "USER32.DLL":
DEFINE INPUT PARAMETER intClassName AS LONG.
DEFINE INPUT PARAMETER chrCaption AS CHARACTER.
DEFINE RETURN PARAMETER intHandle AS LONG.
END PROCEDURE.

RUN FindWindowA (0, "Some Window Title", OUTPUT intHwnd).


IF intHwnd <> 0 THEN
DO:
RUN SetForeGroundWindow(intHwnd, OUTPUT intResult).
IF intResult = 1 THEN
MESSAGE "Existing Window Given Focus" VIEW-AS ALERT-BOX.
ELSE
MESSAGE "Unable To Give Focus" VIEW-AS ALERT-BOX.
END.