Subject Re: prevent program opening twice
From Akshat Kapoor <akshat.kapoor@kapoorsons.in>
Date Mon, 23 Sep 2024 12:34:41 +0530
Newsgroups dbase.getting-started

Good Afternoon Charlie,

> There was a post here a couple of years with instructions of preventing a form (i think) from opening twice.  I can't seem to find it when searching.  Can anyone point me to it?  Thanks much.

Here is some code which I am using to check if window is running or not.

     if not type("GetSystemMetrics") == "FP"
          extern CINT GetSystemMetrics(CINT) user32 from "GetSystemMetrics"
       endif
       #define SM_CMONITORS 80
       if GetSystemMetrics(SM_CMONITORS) >1
          //If second monitor is there then display on that monitor.
          if type("SetFocus") # "FP"
             extern cHandle SetFocus( cHandle ) User32
          endif
          if type("SetForegroundWindow") # "FP"
             extern clogical SetForegroundWindow(chandle) user32
          endif
          if type("FindWindow") # "FP"
             extern cHandle FindWindow(CSTRING, CSTRING) User32 from
"FindWindowA"
          endif
          if type("ShowWindow") # "FP"
             extern CLOGICAL ShowWindow(cHandle, cInt) User32
          endif
          if type("UpdateWindow") # "FP"
             extern CLOGICAL UpdateWindow( CHANDLE ) USER32
          endif
          nH = FindWindow(0, [Kapoorsons ]) //MUST be EXACT i.e. it is
case sensitive
          if nH >0
             *do nothing we have window running
          else
             runhidden("display_invoice.exe")
           endif

This checks if the exe is running or not. If not running then run it.
It has some additional code to check number of monitors. That may not be
required in your case. It has been some time since I coded this after
help from the newsgroup.

I do not remember which command is for checking exe and which is for
checking 2nd monitor. You can leave it there or give a hit and try to
remove the extra code.

       #define SM_CMONITORS 80
       if GetSystemMetrics(SM_CMONITORS) >1
          //If second monitor is there then display on that monitor.

The above 3 should be deleted. I am not sure for the rest.

Regards
Akshat