Kbase 17252: How to Call WIN32 API Function: SetForegroundWindow
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  13/05/1998 |
|
How to Call WIN32 API Function: SetForegroundWindow
DISCLAIMER:
===========
The code example in this knowledgebase is for informational purposes
only. If you have specific questions about which API calls would be
best suited to your design goals, please consult your Microsoft
documentation.
INTRODUCTION:
=============
The following code sample 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.
This code has been tested on Windows NT 4.0 Workstation only.
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.
Progress Software Technical Support Note # 17252