MyWindow.h | class MyWindow : public wxFrame { public: MyWindow(wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxDEFAULT_FRAME_STYLE, const wxString& name = "Draw") : wxFrame(parent, id, title, pos, size, style, name) { }; }; |
AppMain.cpp | #include "wx\wx.h" #include "MyWindow.h" class MyApp : public wxApp { public: virtual bool OnInit(); }; IMPLEMENT_APP(MyApp) bool MyApp::OnInit() { // ウィンドウを生成 MyWindow* pWnd = new MyWindow(NULL, -1, wxT("wxWidgets Button")); // 表示 pWnd->Show(TRUE); // トップウィンドウに設定 SetTopWindow(pWnd); // 成功を通知 return TRUE; } |
MyWindow.cpp | MyWindow::MyWindow(wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style, const wxString& name) : wxFrame(parent, id, title, pos, size, style, name) { new wxButton( this, //wxWindow* parent -1, //wxWindowID id wxT("Button"), //const wxString& label wxPoint(100, 100) //const wxPoint& pos //const wxSize& size = wxDefaultSize //long style = 0 //const wxValidator& validator //const wxString& name = "button" ); }; |
メモリーリークしないだろう コード |
bool MyApp::OnInit() { MyDialog dlg; dlg.ShowModal(); return false; } |
メモリーリークするかも しれないコード |
bool MyApp::OnInit() { MyDialog* pDlg = new MyDialog(); pDlg->ShowModal(); return false; } |
デストラクタで、 メッセージボックスを出す。 |
MyDialog::~MyDialog() { wxMessageBox(wxT("~MyDialog")); } |
クラス定義 (*.h) |
class MyWindow : public wxFrame { .... private: void OnButtonClicked(wxCommandEvent& event); DECLARE_EVENT_TABLE() }; |
イベントテーブル (*.cpp) |
BEGIN_EVENT_TABLE(MyWindow, wxFrame) EVT_BUTTON(-1, MyWindow::OnButtonClicked) END_EVENT_TABLE() |
実装(*.cpp) | void MyWindow::OnButtonClicked(wxCommandEvent& event) { m_pCheckBox->SetValue( !m_pCheckBox->GetValue() ); } |