Thank you a lot for you tip.
I was able to successfully use the wxTimerEvent.
I just have a problem because I tried to set a timeout on my second frame in order to reloads the first frame when there is no user action for more than 5 minutes.
It seems to work, but when it returns to the first frame, it reloads it again by opening another window, so it reloads the first frame for two times and I get two instances of the same program.
For example, if I set a timeout for t = 2 seconds, than the second frame reloads the first frame but after t=2 seconds the first frame load a new application instance and I can see two different programs. It keeps reloading both first frame and second frame each 2 seconds.
This is very weird to me. How can I solve it? And why this happens?
This is the code for the second frame:
Code: Select all
BEGIN_EVENT_TABLE(SecondPage,wxFrame)
//(*EventTable(SecondPage)
//*)
END_EVENT_TABLE()
//void SecondPage::SetPage(ProjectFrame* page)
void SecondPage::SetPage(ThirdPage* page)
{
int w = 1024, h = 768;
but_prev->SetPosition(wxPoint(w / 2 - 300, h / 2 - 150));
but_prev->SetSize(600, 300);
but_exit->SetPosition(wxPoint(w - 40, 0));
but_exit->SetSize(40, 40);
thirdpage = page;
thirdpage->Refresh();
thirdpage->Update();
}
SecondPage::SecondPage(wxWindow* parent,wxWindowID id)
{
//(*Initialize(SecondPage)
Create(parent, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE, _T("wxID_ANY"));
SetClientSize(wxSize(1314,769));
SetBackgroundColour(wxColour(175,253,202));
// .... several objects declared .... //
//
Connect(ID_BITMAPBUTTON7,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&SecondPage::OncancelClick);
//*)
m_reboot.Bind(wxEVT_TIMER, &SecondPage::Reboot, this);
m_reboot.StartOnce(2000); // <- I make the timer starts here
}
void SecondPage::Reboot(wxTimerEvent&){
printf("Reboot the whole system! Timeout!\n");
firstpage = new ProjectFrame(nullptr, 1);
firstpage ->SetClientSize(wxSize(1323,768));
firstpage->ShowFullScreen(true);
firstpage->Show(true); //show it
this->Destroy(); //and destroy page3
//then you do not need to modify destructors.
}
This is the code for the first frame:
Code: Select all
#include "ProjectMain.h"
#include <wx/msgdlg.h>
#include <wx/tokenzr.h>
#include <mysql++.h>
#include <stdlib.h>
#include <string.h>
//(*InternalHeaders(ProjectFrame)
#include <wx/font.h>
#include <wx/intl.h>
#include <wx/string.h>
//*)
using namespace mysqlpp;
//helper functions
enum wxbuildinfoformat {
short_f, long_f };
wxString wxbuildinfo(wxbuildinfoformat format)
{
wxString wxbuild(wxVERSION_STRING);
if (format == long_f )
{
#if defined(__WXMSW__)
wxbuild << _T("-Windows");
#elif defined(__UNIX__)
wxbuild << _T("-Linux");
#endif
#if wxUSE_UNICODE
wxbuild << _T("-Unicode build");
#else
wxbuild << _T("-ANSI build");
#endif // wxUSE_UNICODE
}
return wxbuild;
}
//(*IdInit(ProjectFrame)
const long ProjectFrame::ID_STATICTEXT8 = wxNewId();
//*)
void prova(){
printf("ciao\n");
}
BEGIN_EVENT_TABLE(ProjectFrame,wxFrame)
//(*EventTable(ProjectFrame)
//*)
END_EVENT_TABLE()
ProjectFrame::ProjectFrame(wxWindow* parent,wxWindowID id)
{
//(*Initialize(ProjectFrame)
Create(parent, wxID_ANY, _("Isola 01"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE, _T("wxID_ANY"));
SetClientSize(wxSize(1311,486));
SetBackgroundColour(wxColour(176,253,203));
// .. several text controls and buttons ...
m_clearDataTimer.Bind(wxEVT_TIMER, &ProjectFrame::OnClearData, this);
}
void ProjectFrame::SetPage(SecondPage* page)
{
int w = 1024, h = 768;
// icon_butt->SetPosition(wxPoint(w / 2 - 300, h / 2 - 150));
// icon_butt->SetSize(600, 300);
but_exit->SetPosition(wxPoint(w - 40, 0));
but_exit->SetSize(40, 40);
secondpage = page;
}
ProjectFrame::~ProjectFrame()
{
//(*Destroy(ProjectFrame)
//*)
}
void ProjectFrame::OnQuit(wxCommandEvent& event)
{
Close(true);
}