]>
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"
28 #error "You should set wxUSE_RESOURCES to 1 to compile this sample"
32 // #error "This sample can't be compiled in Unicode mode."
33 #endif // wxUSE_UNICODE
35 #include "wx/resource.h"
40 // If we wanted to demonstrate total platform independence,
41 // then we'd use the dynamic file loading form for all platforms.
42 // But this shows how to embed the wxWindows resources
43 // in the program code/executable for UNIX and Windows
46 // In order to get the ID of the controls defined in the
47 // dialog, we include the header automatically generated
52 // If you have a Windows compiler that can cope with long strings,
53 // then you can always use the #include form for simplicity.
55 // NOTE: Borland's brc32.exe resource compiler doesn't recognize
56 // the TEXT resource, for some reason, so either run-time file loading
57 // or file inclusion should be used.
59 #if defined(__WXMSW__) && !wxUSE_UNICODE
60 // Under Windows, some compilers can't include
61 // a whole .wxr file. So we use a .rc user-defined resource
62 // instead. dialog1 will point to the whole .wxr 'file'.
63 static wxChar
*dialog1
= NULL
;
64 static wxChar
*menu1
= NULL
;
66 // Other platforms should have sensible compilers that
67 // cope with long strings.
68 #include "dialog1.wxr"
73 MyFrame
*frame
= (MyFrame
*) NULL
;
77 // Testing of ressources
82 // The `main program' equivalent, creating the windows and returning the
84 bool MyApp::OnInit(void)
86 #if defined(__WXMSW__) && !wxUSE_UNICODE
87 // Load the .wxr 'file' from a .rc resource, under Windows.
88 // note that the resource really is a char*, not a wxChar*!
89 dialog1
= wxLoadUserResource(wxT("dialog1"), wxT("WXRDATA"));
90 menu1
= wxLoadUserResource(wxT("menu1"), wxT("WXRDATA"));
91 // All resources in the file (only one in this case) get parsed
93 wxResourceParseString(dialog1
);
94 wxResourceParseString(menu1
);
96 // Simply parse the data pointed to by the variable dialog1.
97 // If there were several resources, there would be several
98 // variables, and this would need to be called several times.
99 wxResourceParseData(dialog1
);
100 wxResourceParseData(menu1
);
103 // Create the main frame window
104 frame
= new MyFrame( (wxFrame
*) NULL
, -1,
105 wxT("wxWindows Resource Sample"),
106 wxPoint(-1, -1), wxSize(300, 250) );
108 // Give it a status line
109 frame
->CreateStatusBar(2);
111 wxMenuBar
*menu_bar
= wxResourceCreateMenuBar(wxT("menu1"));
113 // Associate the menu bar with the frame
114 frame
->SetMenuBar(menu_bar
);
117 frame
->panel
= new MyPanel( frame
, -1, wxPoint(0, 0), wxSize(400, 400),
118 0, wxT("MyMainFrame") );
128 #if defined(__WXMSW__) && !wxUSE_UNICODE
134 BEGIN_EVENT_TABLE(MyPanel
, wxPanel
)
135 EVT_LEFT_DOWN( MyPanel::OnClick
)
140 wxWindow
*parent
, wxWindowID id
, const wxPoint
& pos
,
142 int style
, const wxString
&name
143 ) : wxPanel( parent
, id
, pos
, size
, style
, name
)
147 void MyPanel::OnClick( wxMouseEvent
&WXUNUSED(event2
) )
149 MyFrame
*frame
= (MyFrame
*)(wxTheApp
->GetTopWindow());
150 wxCommandEvent event
;
151 frame
->OnTestDialog( event
);
155 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
156 EVT_MENU(RESOURCE_ABOUT
, MyFrame::OnAbout
)
157 EVT_MENU(RESOURCE_QUIT
, MyFrame::OnQuit
)
158 EVT_MENU(RESOURCE_TESTDIALOG
, MyFrame::OnTestDialog
)
161 // Define my frame constructor
164 wxWindow
*parent
, const wxWindowID id
,
165 const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
166 ) : wxFrame(parent
, id
, title
, pos
, size
)
168 panel
= (wxWindow
*) NULL
;
171 void MyFrame::OnAbout( wxCommandEvent
& WXUNUSED(event
) )
173 wxMessageBox(wxT("wxWindows resource sample.\n")
174 wxT("(c) Julian Smart"), wxT("About wxWindows sample"),
175 wxICON_INFORMATION
| wxOK
);
178 void MyFrame::OnQuit( wxCommandEvent
& WXUNUSED(event
) )
183 void MyFrame::OnTestDialog(wxCommandEvent
& WXUNUSED(event
) )
185 MyDialog
*dialog
= new MyDialog
;
187 if (dialog
->LoadFromResource(this, wxT("dialog1")))
189 wxTextCtrl
*text
= (wxTextCtrl
*)wxFindWindowByName(wxT("multitext3"), dialog
);
192 text
->SetValue(wxT("wxWindows resource demo"));
201 BEGIN_EVENT_TABLE(MyDialog
, wxDialog
)
202 //EVT_BUTTON(RESOURCE_OK, MyDialog::OnOk)
203 EVT_BUTTON(ID_BUTTON109
, MyDialog::OnCancel
)
207 void MyDialog::OnOk(wxCommandEvent
& WXUNUSED(event
) )
209 // EndModal(RESOURCE_OK);
212 void MyDialog::OnCancel(wxCommandEvent
& WXUNUSED(event
) )
214 EndModal(ID_BUTTON109
);