]> git.saurik.com Git - wxWidgets.git/blob - samples/nativdlg/nativdlg.cpp
Minor corrections to XRC format description.
[wxWidgets.git] / samples / nativdlg / nativdlg.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: samples/nativdlg/nativdlg.cpp
3 // Purpose: Native Windows dialog sample
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 04/01/98
7 // Copyright: (c) Julian Smart
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 // For compilers that support precompilation, includes "wx/wx.h".
12 #include "wx/wxprec.h"
13
14 #ifdef __BORLANDC__
15 #pragma hdrstop
16 #endif
17
18 #ifndef WX_PRECOMP
19 #include "wx/wx.h"
20 #endif
21
22 #ifndef __WXMSW__
23 #error Sorry, this sample is only appropriate under Windows.
24 #endif
25
26 #ifndef wxHAS_IMAGES_IN_RESOURCES
27 #include "../sample.xpm"
28 #endif
29
30 #include <ctype.h>
31 #include "nativdlg.h"
32 #include "resource.h"
33
34
35
36
37 IMPLEMENT_APP(MyApp)
38
39 bool MyApp::OnInit(void)
40 {
41 if ( !wxApp::OnInit() )
42 return false;
43
44 // Create the main frame window
45 MyFrame *frame = new MyFrame(NULL, wxID_ANY, wxT("wxWidgets Native Dialog Sample"), wxPoint(0, 0), wxSize(300, 250));
46
47 #if wxUSE_STATUSBAR
48 // Give it a status line
49 frame->CreateStatusBar(2);
50 #endif // wxUSE_STATUSBAR
51
52 // Make a menubar
53 wxMenu *file_menu = new wxMenu;
54
55 file_menu->Append(RESOURCE_TEST1, wxT("&Dialog box test"), wxT("Test dialog box resource"));
56 file_menu->Append(RESOURCE_QUIT, wxT("E&xit"), wxT("Quit program"));
57
58 wxMenuBar *menu_bar = new wxMenuBar;
59
60 menu_bar->Append(file_menu, wxT("&File"));
61
62 // Associate the menu bar with the frame
63 frame->SetMenuBar(menu_bar);
64
65 // Make a panel
66 frame->panel = new wxWindow(frame, wxID_ANY, wxPoint(0, 0), wxSize(400, 400), 0, wxT("MyMainFrame"));
67 frame->Show(true);
68
69 return true;
70 }
71
72 BEGIN_EVENT_TABLE(MyFrame, wxFrame)
73 EVT_MENU(RESOURCE_QUIT, MyFrame::OnQuit)
74 EVT_MENU(RESOURCE_TEST1, MyFrame::OnTest1)
75 END_EVENT_TABLE()
76
77 // Define my frame constructor
78 MyFrame::MyFrame(wxWindow *parent, const wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size):
79 wxFrame(parent, id, title, pos, size)
80 {
81 SetIcon(wxICON(sample));
82
83 panel = NULL;
84 }
85
86 void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
87 {
88 Close(true);
89 }
90
91 void MyFrame::OnTest1(wxCommandEvent& WXUNUSED(event))
92 {
93 #if ( defined(__WXPM__) || defined(__WXMSW__) ) && !defined(__WXUNIVERSAL__)
94 MyDialog dialog;
95 if (dialog.LoadNativeDialog(this, wxT("dialog1")))
96 {
97 dialog.ShowModal();
98 }
99 #else
100 wxMessageBox(wxT("No native dialog support"),wxT("Platform limitation"));
101 #endif
102 }
103
104 BEGIN_EVENT_TABLE(MyDialog, wxDialog)
105 EVT_BUTTON(wxID_OK, MyDialog::OnOk)
106 EVT_BUTTON(wxID_CANCEL, MyDialog::OnCancel)
107 END_EVENT_TABLE()
108
109
110 void MyDialog::OnOk(wxCommandEvent& WXUNUSED(event))
111 {
112 EndModal(wxID_OK);
113 }
114
115 void MyDialog::OnCancel(wxCommandEvent& WXUNUSED(event))
116 {
117 EndModal(wxID_CANCEL);
118 }