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