Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to activate exe if attempt to run twice

Status
Not open for further replies.

vfpgolfer

Programmer
Oct 16, 2004
76
US
Is there a windows api that will let me activate a program that is already loaded if the operator tries to load second copy. We have code in our application that chks to see if form is already loaded (uses findwindow getwindow getwindowtext win 32 apis to chk) and if already loaded we display message already loaded.

I would like to change so that if already loaded, we activate or setfocus to that window. I guess this wouldn't just apply to VFP.
 
Here's a thread that will give you what you need...

I've been working on some code with
thread184-672388


boyd.gif

 
Here's some code I was advised of from this Forum (was it yours Craig?) that I've used and works perfectly. Put this at the start of your main PRG:
Code:
***********
DO DupStart
***********
Now put this near the end:
Code:
******************
PROCEDURE DupStart
******************

#DEFINE SW_NORMAL    1
#DEFINE SW_MAXIMIZE  3
#DEFINE SW_MINIMIZE  6

DECLARE Long FindWindow in user32 String, String
DECLARE Long BringWindowToTop in user32 Long
DECLARE Long ShowWindow in user32 Long, Long

LOCAL lnHWND,lcTitle
lcTitle = _screen.Caption
_SCREEN.Caption = Sys(3)
lnHWND = FindWindow(null,m.lcTitle)
_SCREEN.Caption = m.lcTitle
IF m.lnHWND >0
  =messagebox("This program is already running"+ ;
    space(10),0+64+0,"System Message")
  BringWindowToTop(m.lnHWND)
  ShowWindow(m.lnHWND,SW_MAXIMIZE)
  QUIT
ENDIF
ENDPROC

Hope it helps

Lee....

Visual FoxPro Versions: 6 & 9
Operating System: Windows XP
 
crewchiefpro6,

The above code does not work on EXEs (processes), but instead works with windows that have an HWND. However, I am not sure what would happen should you attempt to use the above code on a hidden window or on a control that has an HWND... my feeling is it would fail to give the desired results. Whether it would throw an exception, I don't know.

boyd.gif

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top