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