0
|
1 // Filename : main.cpp
|
|
2 // Last Change: 20-Jul-2013.
|
|
3 //
|
|
4 #include "main.h"
|
|
5 #include "myframe.h"
|
|
6
|
|
7 IMPLEMENT_APP(MyApp)
|
|
8
|
|
9 IMPLEMENT_CLASS( MyApp, wxApp )
|
|
10
|
|
11 MyApp::MyApp()
|
|
12 {
|
|
13 }
|
|
14 MyApp::~MyApp()
|
|
15 {
|
|
16 }
|
|
17
|
|
18 bool MyApp::OnInit()
|
|
19 {
|
|
20 if ( !wxApp::OnInit() ) return false;
|
|
21
|
|
22 wxImage::AddHandler( new wxJPEGHandler );
|
|
23 wxImage::AddHandler( new wxPNGHandler );
|
|
24
|
|
25 InitLog();
|
|
26 InitSetting();
|
|
27
|
|
28 MyFrame *mainframe = new MyFrame( NULL, ID_MAIN, wxT("Searcher 03"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE );
|
|
29 mainframe->SetSize( rect );
|
|
30 mainframe->Show(true);
|
|
31
|
|
32 return true;
|
|
33 }
|
|
34
|
|
35 int MyApp::OnExit()
|
|
36 {
|
|
37 SaveSetting();
|
|
38 return 0;
|
|
39 }
|
|
40
|
|
41 void MyApp::InitSetting()
|
|
42 {
|
|
43 conf_file = wxGetCwd() + wxFILE_SEP_PATH + wxT("app.conf");
|
|
44 config = new wxFileConfig( wxT("MyApp"), wxT("T.Mutoh"), conf_file, wxEmptyString, wxCONFIG_USE_LOCAL_FILE );
|
|
45
|
|
46 config->SetPath( wxT("/Geometry") );
|
|
47 config->Read( wxT("x"), &rect.x );
|
|
48 config->Read( wxT("y"), &rect.y );
|
|
49 config->Read( wxT("w"), &rect.width );
|
|
50 config->Read( wxT("h"), &rect.height );
|
|
51
|
|
52 WriteLog( wxT("Setting Parameters read.") );
|
|
53 }
|
|
54
|
|
55 void MyApp::SaveSetting()
|
|
56 {
|
|
57 config->SetPath( wxT("/Geometry") );
|
|
58 config->Write( wxT("x"), rect.x );
|
|
59 config->Write( wxT("y"), rect.y );
|
|
60 config->Write( wxT("w"), rect.width );
|
|
61 config->Write( wxT("h"), rect.height );
|
|
62 delete config;
|
|
63
|
|
64 WriteLog( wxT("Setting Parameters saved.") );
|
|
65 }
|
|
66
|
|
67 void MyApp::InitLog()
|
|
68 {
|
|
69 log_file = wxGetCwd() + wxFILE_SEP_PATH + wxT("log") + wxFILE_SEP_PATH + wxT("log");
|
|
70 wxTextFile file( log_file );
|
|
71
|
|
72 if ( file.Exists() ) {
|
|
73 wxString log_bak = log_file + wxT(".bak");
|
|
74 wxRenameFile( log_file, log_bak, true );
|
|
75 }
|
|
76
|
|
77 file.Create();
|
|
78 WriteLog( wxT("[Application start...]") );
|
|
79 }
|
|
80
|
|
81 void MyApp::WriteLog( wxString msg )
|
|
82 {
|
|
83 wxDateTime now = wxDateTime::Now();
|
|
84 wxTextFile logfile;
|
|
85 logfile.Open( log_file );
|
|
86 logfile.AddLine( now.Format(wxT("%Y-%m-%d %H:%M:%S ")) + msg );
|
|
87 logfile.Write();
|
|
88 logfile.Close();
|
|
89 }
|
|
90
|