]>
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) );
111 // Give it a status line
112 frame
->CreateStatusBar(2);
113 #endif // wxUSE_STATUSBAR
115 wxMenuBar
*menu_bar
= wxResourceCreateMenuBar(wxT("menu1"));
117 // Associate the menu bar with the frame
118 frame
->SetMenuBar(menu_bar
);
121 frame
->panel
= new MyPanel( frame
, -1, wxPoint(0, 0), wxSize(400, 400),
122 0, wxT("MyMainFrame") );
132 #if defined(__WXMSW__) && !wxUSE_UNICODE
138 BEGIN_EVENT_TABLE(MyPanel
, wxPanel
)
139 EVT_LEFT_DOWN( MyPanel::OnClick
)
144 wxWindow
*parent
, wxWindowID id
, const wxPoint
& pos
,
146 int style
, const wxString
&name
147 ) : wxPanel( parent
, id
, pos
, size
, style
, name
)
151 void MyPanel::OnClick( wxMouseEvent
&WXUNUSED(event2
) )
153 MyFrame
*frame
= (MyFrame
*)(wxTheApp
->GetTopWindow());
154 wxCommandEvent event
;
155 frame
->OnTestDialog( event
);
159 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
160 EVT_MENU(RESOURCE_ABOUT
, MyFrame::OnAbout
)
161 EVT_MENU(RESOURCE_QUIT
, MyFrame::OnQuit
)
162 EVT_MENU(RESOURCE_TESTDIALOG
, MyFrame::OnTestDialog
)
165 // Define my frame constructor
168 wxWindow
*parent
, const wxWindowID id
,
169 const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
170 ) : wxFrame(parent
, id
, title
, pos
, size
)
172 panel
= (wxWindow
*) NULL
;
175 void MyFrame::OnAbout( wxCommandEvent
& WXUNUSED(event
) )
177 wxMessageBox(wxT("wxWidgets resource sample.\n")
178 wxT("(c) Julian Smart"), wxT("About wxWidgets sample"),
179 wxICON_INFORMATION
| wxOK
);
182 void MyFrame::OnQuit( wxCommandEvent
& WXUNUSED(event
) )
187 void MyFrame::OnTestDialog(wxCommandEvent
& WXUNUSED(event
) )
189 MyDialog
*dialog
= new MyDialog
;
191 if (wxLoadFromResource(dialog
, this, wxT("dialog1")))
193 wxTextCtrl
*text
= (wxTextCtrl
*)wxFindWindowByName(wxT("multitext3"), dialog
);
196 text
->SetValue(wxT("wxWidgets resource demo"));
205 BEGIN_EVENT_TABLE(MyDialog
, wxDialog
)
206 //EVT_BUTTON(RESOURCE_OK, MyDialog::OnOk)
207 EVT_BUTTON(ID_BUTTON109
, MyDialog::OnCancel
)
211 void MyDialog::OnOk(wxCommandEvent
& WXUNUSED(event
) )
213 // EndModal(RESOURCE_OK);
216 void MyDialog::OnCancel(wxCommandEvent
& WXUNUSED(event
) )
218 EndModal(ID_BUTTON109
);