]>
git.saurik.com Git - wxWidgets.git/blob - contrib/samples/deprecated/resource/resource.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Dialog resource sample
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 // #pragma implementation
16 // For compilers that support precompilation, includes "wx/wx.h".
17 #include "wx/wxprec.h"
27 #include "wx/deprecated/setup.h"
29 #if !wxUSE_WX_RESOURCES
30 #error "You should set wxUSE_WX_RESOURCES to 1 to compile this sample"
34 // #error "This sample can't be compiled in Unicode mode."
35 #endif // wxUSE_UNICODE
37 #include "wx/deprecated/resource.h"
42 // If we wanted to demonstrate total platform independence,
43 // then we'd use the dynamic file loading form for all platforms.
44 // But this shows how to embed the wxWidgets resources
45 // in the program code/executable for UNIX and Windows
48 // In order to get the ID of the controls defined in the
49 // dialog, we include the header automatically generated
54 // If you have a Windows compiler that can cope with long strings,
55 // then you can always use the #include form for simplicity.
57 // NOTE: Borland's brc32.exe resource compiler doesn't recognize
58 // the TEXT resource, for some reason, so either run-time file loading
59 // or file inclusion should be used.
61 #if defined(__WXMSW__) && !wxUSE_UNICODE
62 // Under Windows, some compilers can't include
63 // a whole .wxr file. So we use a .rc user-defined resource
64 // instead. dialog1 will point to the whole .wxr 'file'.
65 static wxChar
*dialog1
= NULL
;
66 static wxChar
*menu1
= NULL
;
68 // Other platforms should have sensible compilers that
69 // cope with long strings.
70 #include "dialog1.wxr"
75 MyFrame
*frame
= (MyFrame
*) NULL
;
79 // Testing of ressources
84 // The `main program' equivalent, creating the windows and returning the
86 bool MyApp::OnInit(void)
88 #if defined(__WXMSW__) && !wxUSE_UNICODE
89 // Load the .wxr 'file' from a .rc resource, under Windows.
90 // note that the resource really is a char*, not a wxChar*!
91 dialog1
= wxLoadUserResource(wxT("dialog1"), wxT("WXRDATA"));
92 menu1
= wxLoadUserResource(wxT("menu1"), wxT("WXRDATA"));
93 // All resources in the file (only one in this case) get parsed
95 wxResourceParseString(dialog1
);
96 wxResourceParseString(menu1
);
98 // Simply parse the data pointed to by the variable dialog1.
99 // If there were several resources, there would be several
100 // variables, and this would need to be called several times.
101 wxResourceParseData(dialog1
);
102 wxResourceParseData(menu1
);
105 // Create the main frame window
106 frame
= new MyFrame( (wxFrame
*) NULL
, -1,
107 wxT("wxWidgets Resource Sample"),
108 wxPoint(-1, -1), wxSize(300, 250) );
110 // Give it a status line
111 frame
->CreateStatusBar(2);
113 wxMenuBar
*menu_bar
= wxResourceCreateMenuBar(wxT("menu1"));
115 // Associate the menu bar with the frame
116 frame
->SetMenuBar(menu_bar
);
119 frame
->panel
= new MyPanel( frame
, -1, wxPoint(0, 0), wxSize(400, 400),
120 0, wxT("MyMainFrame") );
130 #if defined(__WXMSW__) && !wxUSE_UNICODE
136 BEGIN_EVENT_TABLE(MyPanel
, wxPanel
)
137 EVT_LEFT_DOWN( MyPanel::OnClick
)
142 wxWindow
*parent
, wxWindowID id
, const wxPoint
& pos
,
144 int style
, const wxString
&name
145 ) : wxPanel( parent
, id
, pos
, size
, style
, name
)
149 void MyPanel::OnClick( wxMouseEvent
&WXUNUSED(event2
) )
151 MyFrame
*frame
= (MyFrame
*)(wxTheApp
->GetTopWindow());
152 wxCommandEvent event
;
153 frame
->OnTestDialog( event
);
157 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
158 EVT_MENU(RESOURCE_ABOUT
, MyFrame::OnAbout
)
159 EVT_MENU(RESOURCE_QUIT
, MyFrame::OnQuit
)
160 EVT_MENU(RESOURCE_TESTDIALOG
, MyFrame::OnTestDialog
)
163 // Define my frame constructor
166 wxWindow
*parent
, const wxWindowID id
,
167 const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
168 ) : wxFrame(parent
, id
, title
, pos
, size
)
170 panel
= (wxWindow
*) NULL
;
173 void MyFrame::OnAbout( wxCommandEvent
& WXUNUSED(event
) )
175 wxMessageBox(wxT("wxWidgets resource sample.\n")
176 wxT("(c) Julian Smart"), wxT("About wxWidgets sample"),
177 wxICON_INFORMATION
| wxOK
);
180 void MyFrame::OnQuit( wxCommandEvent
& WXUNUSED(event
) )
185 void MyFrame::OnTestDialog(wxCommandEvent
& WXUNUSED(event
) )
187 MyDialog
*dialog
= new MyDialog
;
189 if (wxLoadFromResource(dialog
, this, wxT("dialog1")))
191 wxTextCtrl
*text
= (wxTextCtrl
*)wxFindWindowByName(wxT("multitext3"), dialog
);
194 text
->SetValue(wxT("wxWidgets resource demo"));
203 BEGIN_EVENT_TABLE(MyDialog
, wxDialog
)
204 //EVT_BUTTON(RESOURCE_OK, MyDialog::OnOk)
205 EVT_BUTTON(ID_BUTTON109
, MyDialog::OnCancel
)
209 void MyDialog::OnOk(wxCommandEvent
& WXUNUSED(event
) )
211 // EndModal(RESOURCE_OK);
214 void MyDialog::OnCancel(wxCommandEvent
& WXUNUSED(event
) )
216 EndModal(ID_BUTTON109
);