]>
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"
27 #include "wx/resource.h"
32 // If we wanted to demonstrate total platform independence,
33 // then we'd use the dynamic file loading form for all platforms.
34 // But this shows how to embed the wxWindows resources
35 // in the program code/executable for UNIX and Windows
38 // If you have a Windows compiler that can cope with long strings,
39 // then you can always use the #include form for simplicity.
41 // NOTE: Borland's brc32.exe resource compiler doesn't recognize
42 // the TEXT resource, for some reason, so either run-time file loading
43 // or file inclusion should be used.
45 #if defined(__WXMSW__) && !defined(__BORLANDC__) && !defined(__GNUWIN32__)
46 // Under Windows, some compilers can't include
47 // a whole .wxr file. So we use a .rc user-defined resource
48 // instead. dialog1 will point to the whole .wxr 'file'.
49 static char *dialog1
= NULL
;
50 static char *menu1
= NULL
;
52 // Other platforms should have sensible compilers that
53 // cope with long strings.
54 #include "dialog1.wxr"
59 MyFrame
*frame
= NULL
;
63 // Testing of ressources
68 // The `main program' equivalent, creating the windows and returning the
70 bool MyApp::OnInit(void)
72 #if defined(__WXMSW__) && !defined(__BORLANDC__)
73 // Load the .wxr 'file' from a .rc resource, under Windows.
74 dialog1
= wxLoadUserResource("dialog1");
75 menu1
= wxLoadUserResource("menu1");
76 // All resources in the file (only one in this case) get parsed
78 wxResourceParseString(dialog1
);
79 wxResourceParseString(menu1
);
81 // Simply parse the data pointed to by the variable dialog1.
82 // If there were several resources, there would be several
83 // variables, and this would need to be called several times.
84 wxResourceParseData(dialog1
);
85 wxResourceParseData(menu1
);
88 // Create the main frame window
89 frame
= new MyFrame(NULL
, -1, "wxWindows Resource Sample", wxPoint(0, 0), wxSize(300, 250));
91 // Give it a status line
92 frame
->CreateStatusBar(2);
96 wxMenu *file_menu = new wxMenu;
98 file_menu->Append(RESOURCE_TEST1, "&Dialog box test", "Test dialog box resource");
99 file_menu->Append(RESOURCE_QUIT, "E&xit", "Quit program");
101 wxMenuBar *menu_bar = new wxMenuBar;
103 menu_bar->Append(file_menu, "&File");
106 wxMenuBar
*menu_bar
= wxResourceCreateMenuBar("menu1");
108 // Associate the menu bar with the frame
109 frame
->SetMenuBar(menu_bar
);
112 frame
->panel
= new wxWindow(frame
, -1, wxPoint(0, 0), wxSize(400, 400), 0, "MyMainFrame");
120 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
121 EVT_MENU(RESOURCE_QUIT
, MyFrame::OnQuit
)
122 EVT_MENU(RESOURCE_TEST1
, MyFrame::OnTest1
)
125 // Define my frame constructor
126 MyFrame::MyFrame(wxWindow
*parent
, const wxWindowID id
, const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
):
127 wxFrame(parent
, id
, title
, pos
, size
)
132 void MyFrame::OnQuit(wxCommandEvent
& event
)
137 void MyFrame::OnTest1(wxCommandEvent
& event
)
139 MyDialog
*dialog
= new MyDialog
;
140 if (dialog
->LoadFromResource(this, "dialog1"))
142 wxTextCtrl
*text
= (wxTextCtrl
*)wxFindWindowByName("multitext3", dialog
);
144 text
->SetValue("wxWindows resource demo");
145 dialog
->SetModal(TRUE
);
151 bool MyFrame::OnClose(void)
158 BEGIN_EVENT_TABLE(MyDialog
, wxDialog
)
159 EVT_BUTTON(RESOURCE_OK
, MyDialog::OnOk
)
160 EVT_BUTTON(RESOURCE_CANCEL
, MyDialog::OnCancel
)
164 void MyDialog::OnOk(wxCommandEvent
& event
)
166 EndModal(RESOURCE_OK
);
169 void MyDialog::OnCancel(wxCommandEvent
& event
)
171 EndModal(RESOURCE_CANCEL
);