Kbase P122501: How to avoid having multiple copies of a Windows Application running?
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  27/02/2007 |
|
Status: Unverified
GOAL:
How to avoid having multiple copies of a Windows Application running?
FACT(s) (Environment):
Windows 32 Intel
FIX:
The following code uses the Windows API function: FindWindowA to prevent the user from running a new instance of a given Windows Application from running if another copy is already running. The code assumes that the Window Title of the application is "myApplication Window Title" and that the procedure name is "myApplication.w":
Run FindWindowA (0, "myApplication Window Title", OUTPUT TheWindowHandle).
IF TheWindowHandle NE 0 THEN DO:
MESSAGE "The program is already running"
VIEW-AS ALERT-BOX INFO BUTTONS OK.
QUIT.
END.
ELSE
RUN myApplication.w.
PROCEDURE FindWindowA EXTERNAL "USER32.DLL":
DEFINE INPUT PARAMETER LpClassName AS LONG NO-UNDO.
DEFINE INPUT PARAMETER LpCaption AS CHARACTER NO-UNDO.
DEFINE RETURN PARAMETER LpHandle AS LONG NO-UNDO.
END PROCEDURE.:
DEFINE VARIABLE TheWindowHandle AS INTEGER NO-UNDO.
Run FindWindowA (0, "myApplication Window Title", OUTPUT TheWindowHandle).
IF TheWindowHandle NE 0 THEN DO:
MESSAGE "The program is already running"
VIEW-AS ALERT-BOX INFO BUTTONS OK.
QUIT.
END.
ELSE
RUN myApplication.w.
PROCEDURE FindWindowA EXTERNAL "USER32.DLL":
DEFINE INPUT PARAMETER LpClassName AS LONG NO-UNDO.
DEFINE INPUT PARAMETER LpCaption AS CHARACTER NO-UNDO.
DEFINE RETURN PARAMETER LpHandle AS LONG NO-UNDO.
END PROCEDURE.