parent
dbcf539616
commit
5271aca526
@ -32,6 +32,9 @@ wxIMPLEMENT_APP(ZRColaApp);
|
||||
|
||||
ZRColaApp::ZRColaApp() :
|
||||
m_mainWnd(NULL),
|
||||
#ifdef __WXMSW__
|
||||
m_running(NULL),
|
||||
#endif
|
||||
wxApp()
|
||||
{
|
||||
}
|
||||
@ -66,6 +69,25 @@ bool ZRColaApp::OnInit()
|
||||
wxVERIFY(m_locale.AddCatalog(wxT("ZRCola-zrcdb")));
|
||||
}
|
||||
|
||||
#ifdef __WXMSW__
|
||||
// Create global event.
|
||||
m_running = ::CreateEvent(NULL, FALSE, FALSE, _T(ZRCOLA_CFG_APPLICATION) _T("{BBDE7AAD-29B6-4B83-ADA1-92AFA81A0883}"));
|
||||
wxASSERT(m_running);
|
||||
if (::GetLastError() == ERROR_ALREADY_EXISTS) {
|
||||
// ZRCola is already running. Find its window.
|
||||
HWND okno = ::FindWindow(_T("wxWindowNR"), _("ZRCola"));
|
||||
if (okno) {
|
||||
if (::IsIconic(okno))
|
||||
::SendMessage(okno, WM_SYSCOMMAND, SC_RESTORE, 0);
|
||||
::SetActiveWindow(okno);
|
||||
::SetForegroundWindow(okno);
|
||||
|
||||
// Not an error condition actually; Just nothing else to do...
|
||||
return false;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
std::fstream dat((LPCTSTR)GetDatabasePath(), std::ios_base::in | std::ios_base::binary);
|
||||
if (dat.good()) {
|
||||
if (stdex::idrec::find<ZRCola::recordid_t, ZRCola::recordsize_t, ZRCOLA_RECORD_ALIGN>(dat, ZRCOLA_DB_ID, sizeof(ZRCola::recordid_t))) {
|
||||
@ -145,3 +167,18 @@ bool ZRColaApp::OnInit()
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
int ZRColaApp::OnExit()
|
||||
{
|
||||
int res = wxApp::OnExit();
|
||||
|
||||
#ifdef __WXMSW__
|
||||
if (m_running) {
|
||||
wxVERIFY(::CloseHandle(m_running));
|
||||
m_running = NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
return res;
|
||||
}
|
||||
|
@ -52,6 +52,12 @@ public:
|
||||
///
|
||||
virtual bool OnInit();
|
||||
|
||||
///
|
||||
/// Called when application uninitializes.
|
||||
///
|
||||
/// \returns Result code to return to OS
|
||||
///
|
||||
virtual int OnExit();
|
||||
|
||||
///
|
||||
/// \returns Path to ZRCola.zrcdb file
|
||||
@ -70,6 +76,9 @@ public:
|
||||
|
||||
protected:
|
||||
wxLocale m_locale; ///< Current locale
|
||||
#ifdef __WXMSW__
|
||||
HANDLE m_running; ///< Global Win32 event to determine if another instance of ZRCola is already running
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user