Kbase 16134: How to Avoid having Multiple Copies of a Program Running
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  10/05/1998 |
|
How to Avoid having Multiple Copies of a Program Running
INTRODUCTION:
=============
This knowledgebase entry describes how to use the FindWindow API (DLL)
call to determine if there is already a window open before opening/
starting another instance (copy) of the same window (program).
WHY YOU NEED TO KNOW THIS:
===========================
You may need to know this if your program does not allow your users to
double-click on the program's icon and start multiple instances of the
program on the same PC at the same time.
PROCEDURAL APPROACH:
====================
For V7 style applications, insert the code in the "Definitions"
section. This must be done so that the test is done before the
create window statement is executed.
For V8 style applications, insert the code in the "local-initialize"
procedure before the default behavior.
/* This Code Goes Into The Definitions Section */
DEFINE VARIABLE TheWindowHandle AS INTEGER NO-UNDO.
PROCEDURE FindWindow EXTERNAL "USER.EXE":
DEFINE INPUT PARAMETER LpClassName AS LONG NO-UNDO.
DEFINE INPUT PARAMETER LpCaption AS CHARACTER NO-UNDO.
DEFINE RETURN PARAMETER LpHandle AS SHORT NO-UNDO.
END PROCEDURE.
/* This Code Goes Into The "Main Block" or "local-initialize" */
RUN FindWindow (0, <Your Window Title>, OUTPUT TheWindowHandle).
IF TheWindowHandle NE 0 THEN
DO:
MESSAGE "Program is Already Running" VIEW-AS ALERT-BOX.
QUIT.
END.
NOTE: For version 8.2A you should change the external procedure
definition and RUN statement as follows:
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.
Run FindWindowA (0, <Your Window Title>, OUTPUT TheWindowHandle).
Progress Software Technical Support Note # 16134