]>
git.saurik.com Git - wxWidgets.git/blob - samples/resource/resource.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Dialog resource sample
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
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 "This sample can't be compiled in Unicode mode."
29 #endif // wxUSE_UNICODE
31 #include "wx/resource.h"
36 // If we wanted to demonstrate total platform independence,
37 // then we'd use the dynamic file loading form for all platforms.
38 // But this shows how to embed the wxWindows resources
39 // in the program code/executable for UNIX and Windows
42 // In order to get the ID of the controls defined in the
43 // dialog, we include the header automatically generated
48 // If you have a Windows compiler that can cope with long strings,
49 // then you can always use the #include form for simplicity.
51 // NOTE: Borland's brc32.exe resource compiler doesn't recognize
52 // the TEXT resource, for some reason, so either run-time file loading
53 // or file inclusion should be used.
55 #if defined(__WXMSW__)
56 // Under Windows, some compilers can't include
57 // a whole .wxr file. So we use a .rc user-defined resource
58 // instead. dialog1 will point to the whole .wxr 'file'.
59 static wxChar
*dialog1
= NULL
;
60 static wxChar
*menu1
= NULL
;
62 // Other platforms should have sensible compilers that
63 // cope with long strings.
64 #include "dialog1.wxr"
69 MyFrame
*frame
= (MyFrame
*) NULL
;
73 // Testing of ressources
78 // The `main program' equivalent, creating the windows and returning the
80 bool MyApp::OnInit(void)
82 #if defined(__WXMSW__)
83 // Load the .wxr 'file' from a .rc resource, under Windows.
84 dialog1
= wxLoadUserResource(wxT("dialog1"), wxT("WXRDATA"));
85 menu1
= wxLoadUserResource(wxT("menu1"), wxT("WXRDATA"));
86 // All resources in the file (only one in this case) get parsed
88 wxResourceParseString(dialog1
);
89 wxResourceParseString(menu1
);
91 // Simply parse the data pointed to by the variable dialog1.
92 // If there were several resources, there would be several
93 // variables, and this would need to be called several times.
94 wxResourceParseData(dialog1
);
95 wxResourceParseData(menu1
);
98 // Create the main frame window
99 frame
= new MyFrame( (wxFrame
*) NULL
, -1,
100 (char *) "wxWindows Resource Sample",
101 wxPoint(-1, -1), wxSize(300, 250) );
103 // Give it a status line
104 frame
->CreateStatusBar(2);
106 wxMenuBar
*menu_bar
= wxResourceCreateMenuBar("menu1");
108 // Associate the menu bar with the frame
109 frame
->SetMenuBar(menu_bar
);
112 frame
->panel
= new MyPanel( frame
, -1, wxPoint(0, 0), wxSize(400, 400),
123 #if defined(__WXMSW__)
129 BEGIN_EVENT_TABLE(MyPanel
, wxPanel
)
130 EVT_LEFT_DOWN( MyPanel::OnClick
)
135 wxWindow
*parent
, wxWindowID id
, const wxPoint
& pos
,
137 int style
, const wxString
&name
138 ) : wxPanel( parent
, id
, pos
, size
, style
, name
)
142 void MyPanel::OnClick( wxMouseEvent
&WXUNUSED(event2
) )
144 MyFrame
*frame
= (MyFrame
*)(wxTheApp
->GetTopWindow());
145 wxCommandEvent event
;
146 frame
->OnTestDialog( event
);
150 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
151 EVT_MENU(RESOURCE_ABOUT
, MyFrame::OnAbout
)
152 EVT_MENU(RESOURCE_QUIT
, MyFrame::OnQuit
)
153 EVT_MENU(RESOURCE_TESTDIALOG
, MyFrame::OnTestDialog
)
156 // Define my frame constructor
159 wxWindow
*parent
, const wxWindowID id
,
160 const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
161 ) : wxFrame(parent
, id
, title
, pos
, size
)
163 panel
= (wxWindow
*) NULL
;
166 void MyFrame::OnAbout( wxCommandEvent
& WXUNUSED(event
) )
168 wxMessageBox("wxWindows resource sample.\n"
169 "(c) Julian Smart", "About wxWindows sample",
170 wxICON_INFORMATION
| wxOK
);
173 void MyFrame::OnQuit( wxCommandEvent
& WXUNUSED(event
) )
178 void MyFrame::OnTestDialog(wxCommandEvent
& WXUNUSED(event
) )
180 MyDialog
*dialog
= new MyDialog
;
182 if (dialog
->LoadFromResource(this, "dialog1"))
184 wxTextCtrl
*text
= (wxTextCtrl
*)wxFindWindowByName("multitext3", dialog
);
187 text
->SetValue("wxWindows resource demo");
196 BEGIN_EVENT_TABLE(MyDialog
, wxDialog
)
197 //EVT_BUTTON(RESOURCE_OK, MyDialog::OnOk)
198 EVT_BUTTON(ID_BUTTON109
, MyDialog::OnCancel
)
202 void MyDialog::OnOk(wxCommandEvent
& WXUNUSED(event
) )
204 // EndModal(RESOURCE_OK);
207 void MyDialog::OnCancel(wxCommandEvent
& WXUNUSED(event
) )
209 EndModal(ID_BUTTON109
);