campo-sirio/xvaga/xvapp.cpp
guy 526ec34d8a Migliorata gestione istanze multiple
git-svn-id: svn://10.65.10.50/branches/R_10_00@22927 c028cbd2-c16b-5b4b-a496-9718f37d4682
2014-03-07 14:41:44 +00:00

62 lines
1.3 KiB
C++
Executable File

#include "../xvaga/wxinc.h"
#include "xvt.h"
#include <wx/filename.h>
#include <wx/snglinst.h>
extern int xvt_main(int argc, char** argv);
class TMainApp : public wxApp
{
wxSingleInstanceChecker* m_sic;
protected:
virtual bool OnInit();
virtual int OnExit();
void OnTimer(wxTimerEvent& evt);
DECLARE_EVENT_TABLE()
DECLARE_DYNAMIC_CLASS(TMainApp);
};
IMPLEMENT_DYNAMIC_CLASS(TMainApp, wxApp)
IMPLEMENT_APP(TMainApp)
#define TIMER_ID 883
BEGIN_EVENT_TABLE(TMainApp, wxApp)
EVT_TIMER(TIMER_ID, TMainApp::OnTimer)
END_EVENT_TABLE()
void TMainApp::OnTimer(wxTimerEvent& evt)
{
xvt_app_pre_create();
xvt_main(argc, argv);
}
bool TMainApp::OnInit()
{
wxFileName strWrk = argv[0];
//const wxString strApp = strWrk.GetName().Lower();
strWrk.MakeAbsolute();
wxString strApp = strWrk.GetFullPath().Lower();
strApp.Replace("\\", "_"); strApp.Replace("/", "_"); strApp.Replace(":", "_");
m_sic = new wxSingleInstanceChecker(strApp);
xvt_vobj_set_attr(NULL_WIN, ATTR_APPL_ALREADY_RUNNING, m_sic->IsAnotherRunning());
// Non eseguo direttamente xvt_main per dar modo al main event loop di partire
wxTimerEvent evt(TIMER_ID);
AddPendingEvent(evt);
return true;
}
int TMainApp::OnExit()
{
delete m_sic;
m_sic = NULL;
return wxApp::OnExit();
}