/*************************************************************** * Name: autostopMain.cpp * Purpose: Code for Application Frame * Author: multi (multikty@gmail.com) * Created: 2008-04-17 * Copyright: multi () * License: **************************************************************/ #include "autostopMain.h" #include //(*InternalHeaders(autostopFrame) #include #include //*) //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(autostopFrame) const long autostopFrame::ID_STATICBOX1 = wxNewId(); const long autostopFrame::ID_STATICBOX2 = wxNewId(); const long autostopFrame::ID_STATICBOX3 = wxNewId(); const long autostopFrame::ID_BUTTON1 = wxNewId(); const long autostopFrame::ID_BUTTON2 = wxNewId(); const long autostopFrame::ID_BUTTON3 = wxNewId(); const long autostopFrame::ID_STATICTEXT1 = wxNewId(); const long autostopFrame::ID_STATICTEXT2 = wxNewId(); const long autostopFrame::ID_STATICTEXT3 = wxNewId(); const long autostopFrame::ID_DATEPICKERCTRL1 = wxNewId(); const long autostopFrame::ID_STATICTEXT4 = wxNewId(); const long autostopFrame::ID_STATICTEXT5 = wxNewId(); const long autostopFrame::ID_STATICTEXT6 = wxNewId(); const long autostopFrame::ID_COMBOBOX1 = wxNewId(); const long autostopFrame::ID_COMBOBOX2 = wxNewId(); const long autostopFrame::ID_COMBOBOX3 = wxNewId(); const long autostopFrame::ID_STATICTEXT7 = wxNewId(); const long autostopFrame::ID_STATICTEXT8 = wxNewId(); const long autostopFrame::ID_STATICTEXT9 = wxNewId(); const long autostopFrame::ID_COMBOBOX4 = wxNewId(); const long autostopFrame::ID_PANEL1 = wxNewId(); const long autostopFrame::idMenuQuit = wxNewId(); const long autostopFrame::idMenuAbout = wxNewId(); const long autostopFrame::ID_STATUSBAR1 = wxNewId(); const long autostopFrame::ID_TIMER1 = wxNewId(); const long autostopFrame::ID_TIMER2 = wxNewId(); //*) BEGIN_EVENT_TABLE(autostopFrame,wxFrame) //(*EventTable(autostopFrame) //*) END_EVENT_TABLE() autostopFrame::autostopFrame(wxWindow* parent,wxWindowID id) { //(*Initialize(autostopFrame) wxMenuItem* MenuItem2; wxMenuItem* MenuItem1; wxMenu* Menu1; wxMenuBar* MenuBar1; wxMenu* Menu2; Create(parent, id, _("오토스탑"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE|wxMINIMIZE_BOX, _T("id")); SetClientSize(wxSize(320,400)); Panel1 = new wxPanel(this, ID_PANEL1, wxPoint(376,216), wxDefaultSize, wxTAB_TRAVERSAL, _T("ID_PANEL1")); StaticBox1 = new wxStaticBox(Panel1, ID_STATICBOX1, _("날짜 설정"), wxPoint(16,8), wxSize(288,88), 0, _T("ID_STATICBOX1")); StaticBox2 = new wxStaticBox(Panel1, ID_STATICBOX2, _("시간 설정"), wxPoint(16,104), wxSize(288,80), 0, _T("ID_STATICBOX2")); StaticBox3 = new wxStaticBox(Panel1, ID_STATICBOX3, _("작업 설정"), wxPoint(16,192), wxSize(288,80), 0, _T("ID_STATICBOX3")); btnStart = new wxButton(Panel1, ID_BUTTON1, _("시 작"), wxPoint(16,288), wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON1")); btnStop = new wxButton(Panel1, ID_BUTTON2, _("중 지"), wxPoint(120,288), wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON2")); btnStop->Disable(); cmbQuit = new wxButton(Panel1, ID_BUTTON3, _("종 료"), wxPoint(232,288), wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON3")); StaticText1 = new wxStaticText(Panel1, ID_STATICTEXT1, _("오늘 날짜 :"), wxPoint(32,32), wxDefaultSize, 0, _T("ID_STATICTEXT1")); StaticText2 = new wxStaticText(Panel1, ID_STATICTEXT2, _("예약 날짜 :"), wxPoint(32,56), wxDefaultSize, 0, _T("ID_STATICTEXT2")); nowDate = new wxStaticText(Panel1, ID_STATICTEXT3, _("nowDate"), wxPoint(104,32), wxDefaultSize, 0, _T("ID_STATICTEXT3")); datePicker = new wxDatePickerCtrl(Panel1, ID_DATEPICKERCTRL1, wxDefaultDateTime, wxPoint(104,56), wxDefaultSize, wxDP_DEFAULT|wxDP_SHOWCENTURY, wxDefaultValidator, _T("ID_DATEPICKERCTRL1")); StaticText3 = new wxStaticText(Panel1, ID_STATICTEXT4, _("현재 시간 :"), wxPoint(32,128), wxDefaultSize, 0, _T("ID_STATICTEXT4")); StaticText4 = new wxStaticText(Panel1, ID_STATICTEXT5, _("예약 시간 :"), wxPoint(32,152), wxDefaultSize, 0, _T("ID_STATICTEXT5")); nowTime = new wxStaticText(Panel1, ID_STATICTEXT6, _("nowTime"), wxPoint(104,128), wxDefaultSize, 0, _T("ID_STATICTEXT6")); cmbHour = new wxComboBox(Panel1, ID_COMBOBOX1, wxEmptyString, wxPoint(104,152), wxSize(40,22), 0, 0, 0, wxDefaultValidator, _T("ID_COMBOBOX1")); cmbHour->SetSelection( cmbHour->Append(_("00")) ); cmbHour->Append(_("01")); cmbHour->Append(_("02")); cmbHour->Append(_("03")); cmbHour->Append(_("04")); cmbHour->Append(_("05")); cmbHour->Append(_("06")); cmbHour->Append(_("07")); cmbHour->Append(_("08")); cmbHour->Append(_("09")); cmbHour->Append(_("10")); cmbHour->Append(_("11")); cmbHour->Append(_("12")); cmbHour->Append(_("13")); cmbHour->Append(_("14")); cmbHour->Append(_("15")); cmbHour->Append(_("16")); cmbHour->Append(_("17")); cmbHour->Append(_("18")); cmbHour->Append(_("19")); cmbHour->Append(_("20")); cmbHour->Append(_("21")); cmbHour->Append(_("22")); cmbHour->Append(_("23")); cmbMinute = new wxComboBox(Panel1, ID_COMBOBOX2, wxEmptyString, wxPoint(168,152), wxSize(40,22), 0, 0, 0, wxDefaultValidator, _T("ID_COMBOBOX2")); cmbMinute->SetSelection( cmbMinute->Append(_("00")) ); cmbMinute->Append(_("01")); cmbMinute->Append(_("02")); cmbMinute->Append(_("03")); cmbMinute->Append(_("04")); cmbMinute->Append(_("05")); cmbMinute->Append(_("06")); cmbMinute->Append(_("07")); cmbMinute->Append(_("08")); cmbMinute->Append(_("09")); cmbMinute->Append(_("10")); cmbMinute->Append(_("11")); cmbMinute->Append(_("12")); cmbMinute->Append(_("13")); cmbMinute->Append(_("14")); cmbMinute->Append(_("15")); cmbMinute->Append(_("16")); cmbMinute->Append(_("17")); cmbMinute->Append(_("18")); cmbMinute->Append(_("19")); cmbMinute->Append(_("20")); cmbMinute->Append(_("21")); cmbMinute->Append(_("22")); cmbMinute->Append(_("23")); cmbMinute->Append(_("24")); cmbMinute->Append(_("25")); cmbMinute->Append(_("26")); cmbMinute->Append(_("27")); cmbMinute->Append(_("28")); cmbMinute->Append(_("29")); cmbMinute->Append(_("30")); cmbMinute->Append(_("31")); cmbMinute->Append(_("32")); cmbMinute->Append(_("33")); cmbMinute->Append(_("34")); cmbMinute->Append(_("35")); cmbMinute->Append(_("36")); cmbMinute->Append(_("37")); cmbMinute->Append(_("38")); cmbMinute->Append(_("39")); cmbMinute->Append(_("40")); cmbMinute->Append(_("41")); cmbMinute->Append(_("42")); cmbMinute->Append(_("43")); cmbMinute->Append(_("44")); cmbMinute->Append(_("45")); cmbMinute->Append(_("46")); cmbMinute->Append(_("47")); cmbMinute->Append(_("48")); cmbMinute->Append(_("49")); cmbMinute->Append(_("50")); cmbMinute->Append(_("51")); cmbMinute->Append(_("52")); cmbMinute->Append(_("53")); cmbMinute->Append(_("54")); cmbMinute->Append(_("55")); cmbMinute->Append(_("56")); cmbMinute->Append(_("57")); cmbMinute->Append(_("58")); cmbMinute->Append(_("59")); cmbSecond = new wxComboBox(Panel1, ID_COMBOBOX3, wxEmptyString, wxPoint(232,152), wxSize(40,22), 0, 0, 0, wxDefaultValidator, _T("ID_COMBOBOX3")); cmbSecond->SetSelection( cmbSecond->Append(_("00")) ); cmbSecond->Append(_("01")); cmbSecond->Append(_("02")); cmbSecond->Append(_("03")); cmbSecond->Append(_("04")); cmbSecond->Append(_("05")); cmbSecond->Append(_("06")); cmbSecond->Append(_("07")); cmbSecond->Append(_("08")); cmbSecond->Append(_("09")); cmbSecond->Append(_("10")); cmbSecond->Append(_("11")); cmbSecond->Append(_("12")); cmbSecond->Append(_("13")); cmbSecond->Append(_("14")); cmbSecond->Append(_("15")); cmbSecond->Append(_("16")); cmbSecond->Append(_("17")); cmbSecond->Append(_("18")); cmbSecond->Append(_("19")); cmbSecond->Append(_("20")); cmbSecond->Append(_("21")); cmbSecond->Append(_("22")); cmbSecond->Append(_("23")); cmbSecond->Append(_("24")); cmbSecond->Append(_("25")); cmbSecond->Append(_("26")); cmbSecond->Append(_("27")); cmbSecond->Append(_("28")); cmbSecond->Append(_("29")); cmbSecond->Append(_("30")); cmbSecond->Append(_("31")); cmbSecond->Append(_("32")); cmbSecond->Append(_("33")); cmbSecond->Append(_("34")); cmbSecond->Append(_("35")); cmbSecond->Append(_("36")); cmbSecond->Append(_("37")); cmbSecond->Append(_("38")); cmbSecond->Append(_("39")); cmbSecond->Append(_("40")); cmbSecond->Append(_("41")); cmbSecond->Append(_("42")); cmbSecond->Append(_("43")); cmbSecond->Append(_("44")); cmbSecond->Append(_("45")); cmbSecond->Append(_("46")); cmbSecond->Append(_("47")); cmbSecond->Append(_("48")); cmbSecond->Append(_("49")); cmbSecond->Append(_("50")); cmbSecond->Append(_("51")); cmbSecond->Append(_("52")); cmbSecond->Append(_("53")); cmbSecond->Append(_("54")); cmbSecond->Append(_("55")); cmbSecond->Append(_("56")); cmbSecond->Append(_("57")); cmbSecond->Append(_("58")); cmbSecond->Append(_("59")); StaticText5 = new wxStaticText(Panel1, ID_STATICTEXT7, _("시"), wxPoint(144,160), wxDefaultSize, 0, _T("ID_STATICTEXT7")); StaticText6 = new wxStaticText(Panel1, ID_STATICTEXT8, _("분"), wxPoint(208,160), wxDefaultSize, 0, _T("ID_STATICTEXT8")); StaticText7 = new wxStaticText(Panel1, ID_STATICTEXT9, _("초"), wxPoint(272,160), wxDefaultSize, 0, _T("ID_STATICTEXT9")); cmbAction = new wxComboBox(Panel1, ID_COMBOBOX4, wxEmptyString, wxPoint(32,224), wxDefaultSize, 0, 0, 0, wxDefaultValidator, _T("ID_COMBOBOX4")); cmbAction->SetSelection( cmbAction->Append(_("작업을 선택하세요!")) ); cmbAction->Append(_("컴퓨터 종료")); cmbAction->Append(_("컴퓨터 재부팅")); MenuBar1 = new wxMenuBar(); Menu1 = new wxMenu(); MenuItem1 = new wxMenuItem(Menu1, idMenuQuit, _("종료\tAlt-F4"), _("Quit the application"), wxITEM_NORMAL); Menu1->Append(MenuItem1); MenuBar1->Append(Menu1, _("파일 (&F)")); Menu2 = new wxMenu(); MenuItem2 = new wxMenuItem(Menu2, idMenuAbout, _("대하여\tF1"), _("Show info about this application"), wxITEM_NORMAL); Menu2->Append(MenuItem2); MenuBar1->Append(Menu2, _("도움말")); SetMenuBar(MenuBar1); StatusBar1 = new wxStatusBar(this, ID_STATUSBAR1, 0, _T("ID_STATUSBAR1")); int __wxStatusBarWidths_1[1] = { -1 }; int __wxStatusBarStyles_1[1] = { wxSB_NORMAL }; StatusBar1->SetFieldsCount(1,__wxStatusBarWidths_1); StatusBar1->SetStatusStyles(1,__wxStatusBarStyles_1); SetStatusBar(StatusBar1); Timer1.SetOwner(this, ID_TIMER1); Timer1.Start(1000, false); Timer2.SetOwner(this, ID_TIMER2); Center(); Connect(ID_BUTTON1,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&autostopFrame::OnbtnStartClick); Connect(ID_BUTTON2,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&autostopFrame::OnbtnStopClick); Connect(ID_BUTTON3,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&autostopFrame::OncmbQuitClick); Connect(idMenuQuit,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&autostopFrame::OnQuit); Connect(idMenuAbout,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&autostopFrame::OnAbout); Connect(ID_TIMER1,wxEVT_TIMER,(wxObjectEventFunction)&autostopFrame::OnTimer1Trigger); Connect(ID_TIMER2,wxEVT_TIMER,(wxObjectEventFunction)&autostopFrame::OnTimer2Trigger); //*) wxDateTime tt = wxDateTime::Now(); wxString d1 = tt.Format(wxT("%Y")); wxString d2 = tt.Format(wxT("%m")); wxString d3 = tt.Format(wxT("%d")); wxString hh = tt.Format(wxT("%H")); wxString mm = tt.Format(wxT("%M")); wxString ss = tt.Format(wxT("%S")); cmbHour->SetValue(hh); cmbMinute->SetValue(mm); cmbSecond->SetValue(ss); nowDate->SetLabel(d1 + wxT("년 ") + d2 + wxT("월 ") + d3 + wxT("일")); nowTime->SetLabel(hh + wxT("시 ")+ mm +wxT("분 ") + ss + wxT("초") ); } autostopFrame::~autostopFrame() { //(*Destroy(autostopFrame) //*) } void autostopFrame::OnQuit(wxCommandEvent& event) { Close(); } void autostopFrame::OnAbout(wxCommandEvent& event) { //wxString msg = wxbuildinfo(long_f); wxString msg = _("본 프로그램은 g++와 wxWidgets로 만들어진 예제입니다.\n\n도서명 : 김태용의 C++ 기초 입문 :: gcc로 공부하는 C++와 wxWidgets"); wxMessageBox(msg, _("오토스탑 정보")); } void autostopFrame::OnTimer1Trigger(wxTimerEvent& event) { wxDateTime tt = wxDateTime::Now(); wxString hh = tt.Format(wxT("%H")); wxString mm = tt.Format(wxT("%M")); wxString ss = tt.Format(wxT("%S")); nowTime->SetLabel(hh + wxT("시 ")+ mm +wxT("분 ") + ss + wxT("초") ); } void autostopFrame::OnTimer2Trigger(wxTimerEvent& event) { wxDateTime tt = wxDateTime::Now(); wxDateTime tt1 = datePicker->GetValue(); wxString hh1 = cmbHour->GetLabel(); wxString mm1 = cmbMinute->GetLabel(); wxString ss1 = cmbSecond->GetLabel(); wxTimeSpan setT(wxAtoi(hh1), wxAtoi(mm1), wxAtoi(ss1), 0); wxDateTime tt2 = tt1 + setT; if (tt == tt2) { int selectAction = cmbAction->GetSelection(); switch(selectAction){ case 1: wxShutdown(wxSHUTDOWN_POWEROFF); break; case 2: wxShutdown(wxSHUTDOWN_REBOOT); break; default: break; } } } void autostopFrame::OnbtnStartClick(wxCommandEvent& event) { autostopFrame::Timer2.Start(1000); btnStart->Enable(false); btnStop->Enable(true); } void autostopFrame::OnbtnStopClick(wxCommandEvent& event) { autostopFrame::Timer2.Stop(); btnStart->Enable(true); btnStop->Enable(false); } void autostopFrame::OncmbQuitClick(wxCommandEvent& event) { Close(); }