Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
ER - only allow the app to run once
Message
General information
Forum:
Visual FoxPro
Category:
The Mere Mortals Framework
Miscellaneous
Thread ID:
00688594
Message ID:
00688654
Views:
36
Hi Paul,

good suggestion! This is something many people need. But there's one problem with the code: What happens, if the application changes the Screen's caption at runtime (yes, I do that < g >).

FindWindow will find the first instance if you keep the old caption and append some text after to it (Original Screen Caption - CurrentFormName). But if you have that in different order (CurrentFormName - Original Screen Caption) just like all the MS products do it, FindWindow will not be able to find the first instance.

Christof Lange once wrote a routine called "IsAppRun" that creates an invisible "semaphor" window. The application checks for the window on startup. This works regardless of the Screen's caption. You can find the code in "1001 Things you wanted to know about VFP" on pages 12/13. Kevin might check out if he is allowed to put that code into the framework.

What do you think about that?

Regards,
Armin


>It is possible for users to start up every MM's app. as many times as they'd like. For advanced users, this is OK. For MOST users, especially if they're not particularly computer literate, this is a problem. It's not uncommon to find that they have opened the app a dozen times because they don't realize it is already running. It would be nice if the framework would allow us to keep this from happening.
>
>I've added a IsRunning() method to my goApp object:
>
>
>#DEFINE SW_MAXIMIZE		   3
>
>LOCAL llRunning, ;
>      lcCaption, ;
>      lnHWnd
>
>llRunning = .F.
>
>* Temporarily rename the caption of
>* the screen, we don't want to find
>* ourselves.
>
>lcCaption = _SCREEN.Caption
>
>_SCREEN.Caption = [_] + lcCaption
>
>lnHWnd = FindWin(lcCaption)
>
>IF lnHWnd <> 0
>
>   DECLARE INTEGER ShowWindow in user32 ;
>           INTEGER hwnd, ;
>           INTEGER nCmdShow
>
>   ShowWindow(lnHWnd, SW_MAXIMIZE)
>   llRunning = .T.
>ENDIF
>
>_SCREEN.Caption = lcCaption
>
>RETURN llRunning
>
>
>I've also modified the Setup.PRG and added the code:
>
>
>		*---------------------------------------------------
>		*-- Check to see if the app. is already running. If
>		*-- it is, and it's only meant to be run once, let's
>		*-- exit. The running app. will automatically be
>		*-- brought to the front, maximized.
>		*---------------------------------------------------
>		* PCM - 8/9/2002		
>		IF goApp.lOnlyOneInstance
>                   IF goApp.IsRunning()
>                      QUIT
>                   ENDIF
>                ENDIF
>
>
>This code is put right after creating goApp (after the RELEASE code and before the *--- Support for Steven Black's INTL) line.

Armin Neudert
Regional Director (Stuttgart) of German FoxPro User Group dFPUG

MCP for Visual FoxPro

Expert/Editor of the VFP section in the German Codezone community portal
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform