Mercurial > mercurial > hgweb_searcher03.cgi
diff src/main.cpp @ 0:0c0701a935f8
Start Development.
author | pyon@macmini |
---|---|
date | Sun, 21 Jul 2013 16:07:19 +0900 |
parents | |
children | 7b6dab24f4b8 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main.cpp Sun Jul 21 16:07:19 2013 +0900 @@ -0,0 +1,90 @@ +// Filename : main.cpp +// Last Change: 20-Jul-2013. +// +#include "main.h" +#include "myframe.h" + +IMPLEMENT_APP(MyApp) + +IMPLEMENT_CLASS( MyApp, wxApp ) + +MyApp::MyApp() +{ +} +MyApp::~MyApp() +{ +} + +bool MyApp::OnInit() +{ + if ( !wxApp::OnInit() ) return false; + + wxImage::AddHandler( new wxJPEGHandler ); + wxImage::AddHandler( new wxPNGHandler ); + + InitLog(); + InitSetting(); + + MyFrame *mainframe = new MyFrame( NULL, ID_MAIN, wxT("Searcher 03"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE ); + mainframe->SetSize( rect ); + mainframe->Show(true); + + return true; +} + +int MyApp::OnExit() +{ + SaveSetting(); + return 0; +} + +void MyApp::InitSetting() +{ + conf_file = wxGetCwd() + wxFILE_SEP_PATH + wxT("app.conf"); + config = new wxFileConfig( wxT("MyApp"), wxT("T.Mutoh"), conf_file, wxEmptyString, wxCONFIG_USE_LOCAL_FILE ); + + config->SetPath( wxT("/Geometry") ); + config->Read( wxT("x"), &rect.x ); + config->Read( wxT("y"), &rect.y ); + config->Read( wxT("w"), &rect.width ); + config->Read( wxT("h"), &rect.height ); + + WriteLog( wxT("Setting Parameters read.") ); +} + +void MyApp::SaveSetting() +{ + config->SetPath( wxT("/Geometry") ); + config->Write( wxT("x"), rect.x ); + config->Write( wxT("y"), rect.y ); + config->Write( wxT("w"), rect.width ); + config->Write( wxT("h"), rect.height ); + delete config; + + WriteLog( wxT("Setting Parameters saved.") ); +} + +void MyApp::InitLog() +{ + log_file = wxGetCwd() + wxFILE_SEP_PATH + wxT("log") + wxFILE_SEP_PATH + wxT("log"); + wxTextFile file( log_file ); + + if ( file.Exists() ) { + wxString log_bak = log_file + wxT(".bak"); + wxRenameFile( log_file, log_bak, true ); + } + + file.Create(); + WriteLog( wxT("[Application start...]") ); +} + +void MyApp::WriteLog( wxString msg ) +{ + wxDateTime now = wxDateTime::Now(); + wxTextFile logfile; + logfile.Open( log_file ); + logfile.AddLine( now.Format(wxT("%Y-%m-%d %H:%M:%S ")) + msg ); + logfile.Write(); + logfile.Close(); +} +