]>
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
= (MyFrame
*) 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((wxFrame
*) NULL
, -1, (char *) "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 MyPanel(frame
, -1, wxPoint(0, 0), wxSize(400, 400), 0, "MyMainFrame");
120 BEGIN_EVENT_TABLE(MyPanel
, wxPanel
)
121 EVT_LEFT_DOWN( MyPanel::OnClick
)
124 MyPanel::MyPanel( wxWindow
*parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
,
125 int style
, const wxString
&name
) :
126 wxPanel( parent
, id
, pos
, size
, style
, name
)
130 void MyPanel::OnClick( wxMouseEvent
&WXUNUSED(event
) )
132 MyFrame
*frame
= (MyFrame
*)(wxTheApp
->GetTopWindow());
133 wxCommandEvent event
;
134 frame
->OnTest1( event
);
138 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
139 EVT_MENU(RESOURCE_QUIT
, MyFrame::OnQuit
)
140 EVT_MENU(RESOURCE_TEST1
, MyFrame::OnTest1
)
143 // Define my frame constructor
144 MyFrame::MyFrame(wxWindow
*parent
, const wxWindowID id
, const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
):
145 wxFrame(parent
, id
, title
, pos
, size
)
147 panel
= (wxWindow
*) NULL
;
150 void MyFrame::OnQuit( wxCommandEvent
& WXUNUSED(event
) )
155 void MyFrame::OnTest1(wxCommandEvent
& WXUNUSED(event
) )
157 MyDialog
*dialog
= new MyDialog
;
158 if (dialog
->LoadFromResource(this, "dialog1"))
160 wxTextCtrl
*text
= (wxTextCtrl
*)wxFindWindowByName("multitext3", dialog
);
162 text
->SetValue("wxWindows resource demo");
163 dialog
->SetModal(TRUE
);
169 bool MyFrame::OnClose(void)
176 BEGIN_EVENT_TABLE(MyDialog
, wxDialog
)
177 EVT_BUTTON(RESOURCE_OK
, MyDialog::OnOk
)
178 EVT_BUTTON(RESOURCE_CANCEL
, MyDialog::OnCancel
)
182 void MyDialog::OnOk(wxCommandEvent
& WXUNUSED(event
) )
184 EndModal(RESOURCE_OK
);
187 void MyDialog::OnCancel(wxCommandEvent
& WXUNUSED(event
) )
189 EndModal(RESOURCE_CANCEL
);