1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Dynamic events wxWidgets sample
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 #if defined(__GNUG__) && !defined(__APPLE__)
13 #pragma implementation "dynamic.cpp"
14 #pragma interface "dynamic.cpp"
17 // For compilers that support precompilation, includes "wx/wx.h".
18 #include "wx/wxprec.h"
28 #if defined(__WXGTK__) || defined(__WXX11__) || defined(__WXMOTIF__) || defined(__WXMAC__) || defined(__WXMGL__) || defined(__WXCOCOA__)
29 #include "mondrian.xpm"
32 // Define a new application type
33 class MyApp
: public wxApp
38 // Define a new frame type
39 class MyFrame
: public wxFrame
41 MyFrame(wxFrame
*frame
, wxChar
*title
, int x
, int y
, int w
, int h
);
44 void OnQuit(wxCommandEvent
& event
);
45 void OnAbout(wxCommandEvent
& event
);
48 // ID for the menu commands
49 #define DYNAMIC_QUIT 1
50 #define DYNAMIC_TEXT 101
51 #define DYNAMIC_ABOUT 102
53 // Create a new application object
56 // `Main program' equivalent, creating windows and returning main app frame
57 bool MyApp::OnInit(void)
59 // Create the main frame window
60 MyFrame
*frame
= new MyFrame(NULL
, _T("Dynamic wxWidgets App"), 50, 50, 450, 340);
62 // You used to have to do some casting for param 4, but now there are type-safe handlers
63 frame
->Connect( DYNAMIC_QUIT
, wxID_ANY
,
64 wxEVT_COMMAND_MENU_SELECTED
, wxCommandEventHandler(MyFrame::OnQuit
) );
65 frame
->Connect( DYNAMIC_ABOUT
, wxID_ANY
,
66 wxEVT_COMMAND_MENU_SELECTED
, wxCommandEventHandler(MyFrame::OnAbout
) );
70 frame
->SetIcon(wxIcon(_T("mondrian")));
72 frame
->SetIcon(wxIcon(mondrian_xpm
));
76 wxMenu
*file_menu
= new wxMenu
;
78 file_menu
->Append(DYNAMIC_ABOUT
, _T("&About"));
79 file_menu
->Append(DYNAMIC_QUIT
, _T("E&xit"));
80 wxMenuBar
*menu_bar
= new wxMenuBar
;
81 menu_bar
->Append(file_menu
, _T("&File"));
82 frame
->SetMenuBar(menu_bar
);
84 // Make a panel with a message
85 wxPanel
*panel
= new wxPanel(frame
, wxID_ANY
, wxPoint(0, 0), wxSize(400, 200), wxTAB_TRAVERSAL
);
87 (void)new wxStaticText(panel
, 311, _T("Hello!"), wxPoint(10, 10), wxDefaultSize
, 0);
97 // My frame constructor
98 MyFrame::MyFrame(wxFrame
*frame
, wxChar
*title
, int x
, int y
, int w
, int h
):
99 wxFrame(frame
, wxID_ANY
, title
, wxPoint(x
, y
), wxSize(w
, h
))
102 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
) )
107 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
) )
109 wxMessageDialog
dialog(this, _T("This demonstrates dynamic event handling"),
110 _T("About Dynamic"), wxYES_NO
|wxCANCEL
);