Microsoft KB Archive/109059: Difference between revisions

From BetaArchive Wiki
(importing KB archive)
 
m (Text replacement - ">" to ">")
 
(2 intermediate revisions by the same user not shown)
Line 63: Line 63:
<span class="kbd userinput"> </span>
<span class="kbd userinput"> </span>


<pre class="codesample">  SET LIBRARY TO SYS(2004)+&quot;foxtools.fll&quot; ADDITIVE
<pre class="codesample">  SET LIBRARY TO SYS(2004)+"foxtools.fll" ADDITIVE
   * FindWindow() takes two parameters and returns the handle of the
   * FindWindow() takes two parameters and returns the handle of the
   * window, HWND, if it was found.
   * window, HWND, if it was found.
   GetWind = RegFn(&quot;FindWindow&quot;, &quot;CC&quot;, &quot;I&quot;)
   GetWind = RegFn("FindWindow", "CC", "I")
   *Set the first parameter of the call to getwind to 0, null.
   *Set the first parameter of the call to getwind to 0, null.
   wclass=0
   wclass=0
   winname=&quot;My Application&quot;
   winname="My Application"
   apphand=CallFn(GetWind,wclass ,winname)
   apphand=CallFn(GetWind,wclass ,winname)
   *If the call was successful, stop processing.
   *If the call was successful, stop processing.
   IF apphand&lt;&gt;0
   IF apphand<>0
       WAIT WINDOW ;
       WAIT WINDOW ;
         &quot;You cannot start another instance of the window 'My Application'!&quot;
         "You cannot start another instance of the window 'My Application'!"
       QUIT
       QUIT
   ENDIF
   ENDIF
   MODIFY WINDOW screen TITLE &quot;My Application&quot;
   MODIFY WINDOW screen TITLE "My Application"
   WAIT WINDOW ;
   WAIT WINDOW ;
     &quot;The first instance of the window 'My Application' is running.&quot;
     "The first instance of the window 'My Application' is running."
                         </pre>
                         </pre>


Line 89: Line 89:
== REFERENCES ==
== REFERENCES ==


Microsoft Windows Software Development Kit, &quot;Programmer's Reference, Volume 2: Functions,&quot; page 309<br />
Microsoft Windows Software Development Kit, "Programmer's Reference, Volume 2: Functions," page 309<br />
<br />
<br />
Foxtools.hlp, located in the C:\Vfp\Tools
Foxtools.hlp, located in the C:\Vfp\Tools

Latest revision as of 17:45, 20 July 2020

Knowledge Base


How To Prevent Multiple Instances of an Application

Article ID: 109059

Article Last Modified on 7/1/2004



APPLIES TO

  • Microsoft Visual FoxPro 3.0 Standard Edition
  • Microsoft Visual FoxPro 5.0 Standard Edition



This article was previously published under Q109059

SUMMARY

The program shown below demonstrates how to stop a second instance of the same FoxPro window from being started by using the Windows application programming interface (API) function FindWindow() to test if a given window name already exists. The FindWindow() function can be accessed by including FOXTOOLS.FLL, the library file that is supplied with FoxPro for Windows and documented in the Foxtools.hlp file.

NOTE: This method does not prevent multiple instances of FoxPro for Windows from starting.

MORE INFORMATION

NOTE: This works in Windows for Workgroups 3.00, Windows 95, and Windows NT.

Copy this code into a program file in FoxPro for windows. The first time you call the program, you will notice the main FoxPro window title change. The second time you run it, you will get the message that you cannot start another instance of the window.

NOTE: Set the window name after you check for its existence.

   SET LIBRARY TO SYS(2004)+"foxtools.fll" ADDITIVE
   * FindWindow() takes two parameters and returns the handle of the
   * window, HWND, if it was found.
   GetWind = RegFn("FindWindow", "CC", "I")
   *Set the first parameter of the call to getwind to 0, null.
   wclass=0
   winname="My Application"
   apphand=CallFn(GetWind,wclass ,winname)
   *If the call was successful, stop processing.
   IF apphand<>0
      WAIT WINDOW ;
        "You cannot start another instance of the window 'My Application'!"
      QUIT
   ENDIF
   MODIFY WINDOW screen TITLE "My Application"
   WAIT WINDOW ;
     "The first instance of the window 'My Application' is running."
                        

REFERENCES

Microsoft Windows Software Development Kit, "Programmer's Reference, Volume 2: Functions," page 309

Foxtools.hlp, located in the C:\Vfp\Tools


Additional query words: foxtools sdk fll api recursive recursion loaded twice

Keywords: kbhowto kbinterop kbcode KB109059