]>
git.saurik.com Git - wxWidgets.git/blob - interface/snglinst.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxSingleInstanceChecker
4 // Author: wxWidgets team
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
10 @class wxSingleInstanceChecker
13 wxSingleInstanceChecker class allows to check that only a single instance of a
14 program is running. To do it, you should create an object of this class. As
15 long as this object is alive, calls to
16 wxSingleInstanceChecker::IsAnotherRunning from
17 other processes will return @true.
19 As the object should have the life span as big as possible, it makes sense to
20 create it either as a global or in wxApp::OnInit. For
26 const wxString name = wxString::Format("MyApp-%s", wxGetUserId().c_str());
27 m_checker = new wxSingleInstanceChecker(name);
28 if ( m_checker-IsAnotherRunning() )
30 wxLogError(_("Another program instance is already running, aborting."));
32 delete m_checker; // OnExit() won't be called if we return @false
38 ... more initializations ...
51 Note using wxGetUserId() to construct the name: this
52 allows different user to run the application concurrently which is usually the
53 intended goal. If you don't use the user name in the wxSingleInstanceChecker
54 name, only one user would be able to run the application at a time.
56 This class is implemented for Win32 and Unix platforms (supporting @c fcntl()
57 system call, but almost all of modern Unix systems do) only.
62 class wxSingleInstanceChecker
66 Like Create() but without
69 wxSingleInstanceChecker(const wxString
& name
,
70 const wxString
& path
= wxEmptyString
);
73 Destructor frees the associated resources.
74 Note that it is not virtual, this class is not meant to be used polymorphically
76 ~wxSingleInstanceChecker();
79 Initialize the object if it had been created using the default constructor.
80 Note that you can't call Create() more than once, so calling it if the
81 @ref wxsingleinstancechecker() "non default ctor"
82 had been used is an error.
85 must be given and be as unique as possible. It is used as the
86 mutex name under Win32 and the lock file name under Unix.
87 GetAppName() and wxGetUserId()
88 are commonly used to construct this parameter.
90 is optional and is ignored under Win32 and used as the directory to
91 create the lock file in under Unix (default is
94 @return Returns @false if initialization failed, it doesn't mean that
95 another instance is running - use IsAnotherRunning()
98 bool Create(const wxString
& name
,
99 const wxString
& path
= wxEmptyString
);
102 Returns @true if another copy of this program is already running, @false
105 bool IsAnotherRunning() const;