1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxSingleInstanceChecker can be used to restrict the number of
4 // simultaneously running copies of a program to one
5 // Author: Vadim Zeitlin
9 // Copyright: (c) 2001 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
10 // Licence: wxWindows licence
11 ///////////////////////////////////////////////////////////////////////////////
13 #ifndef _WX_SNGLINST_H_
14 #define _WX_SNGLINST_H_
17 #pragma interface "snglinst.h"
20 #if wxUSE_SNGLINST_CHECKER
22 // ----------------------------------------------------------------------------
23 // wxSingleInstanceChecker
24 // ----------------------------------------------------------------------------
26 class WXDLLEXPORT wxSingleInstanceChecker
29 // default ctor, use Create() after it
30 wxSingleInstanceChecker() { Init(); }
32 // like Create() but no error checking (dangerous!)
33 wxSingleInstanceChecker(const wxString
& name
,
34 const wxString
& path
= wxEmptyString
)
40 // name must be given and be as unique as possible, it is used as the mutex
41 // name under Win32 and the lock file name under Unix -
42 // wxTheApp->GetAppName() may be a good value for this parameter
44 // path is optional and is ignored under Win32 and used as the directory to
45 // create the lock file in under Unix (default is wxGetHomeDir())
47 // returns FALSE if initialization failed, it doesn't mean that another
48 // instance is running - use IsAnotherRunning() to check it
49 bool Create(const wxString
& name
, const wxString
& path
= wxEmptyString
);
51 // is another copy of this program already running?
52 bool IsAnotherRunning() const;
55 // Activates Previous Instance if a window whose Title contains the search string is found
56 bool ActivatePrevInstance(const wxString
& sSearch
);
58 // Activates Previous Instance and passes CommandLine to wxCommandLineEvent
59 // if a window with matching Title is found
60 bool PassCommandLineToPrevInstance(const wxString
& sSearch
, const wxString
& sCmdLine
);
63 // dtor is not virtual, this class is not meant to be used polymorphically
64 ~wxSingleInstanceChecker();
67 // common part of all ctors
68 void Init() { m_impl
= NULL
; }
70 // the implementation details (platform specific)
71 class WXDLLEXPORT wxSingleInstanceCheckerImpl
*m_impl
;
74 #endif // wxUSE_SNGLINST_CHECKER
76 #endif // _WX_SNGLINST_H_