INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

API Functions

Only one instance of an application by mgagnon
Posted: 10 Apr 02 (Edited 24 Jan 05)

Here are two methods to do that. One using an API call and one using the Foxtools.fll library.
#1

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
  BringWindowToTop(m.lnHWND)
  ShowWindow(m.lnHWND,SW_MAXIMIZE)
  qUIT
ENDIF
ENDPROC

_________________________________________________________
#2

CODE

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.'

_________________________________________________________
#3

&& This is a variant of FAQ184-2442. Important. If the application closes normally, use GlobalDeleteAtom to remove the atom.


CODE

#Define AtomStrLength   512
Local lcAtomName
lcAtomName = "mon application"
Declare Integer GlobalAddAtom In win32api String
Declare Integer GlobalDeleteAtom In win32api Integer
Declare Integer GlobalGetAtomName In kernel32;
     INTEGER  nAtom,;
     STRING @ lpBuffer,;
     INTEGER  nSize
findAtom(lcAtomName)
Function findAtom(tcAtom)
Create Cursor cs (atom N(12), strlen N(5), Name C(100))
Index On Allt(Name) Tag Name
For nAtom = 49152 To 65535
     lpBuffer = Repli(Chr(0), AtomStrLength)
     lnResult = GlobalGetAtomName (nAtom, @lpBuffer, AtomStrLength)

     If lnResult > 0
          Insert Into cs Values (nAtom, lnResult, Left(lpBuffer, lnResult))
     Endif
Endfor
Select cs
If Seek(tcAtom)
     Messagebox("Application is already running")
     Quit
Else
     = GlobalAddAtom(tcAtom)
Endif


Mike Gagnon

Back to Microsoft: Visual FoxPro FAQ Index
Back to Microsoft: Visual FoxPro Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close