]>
git.saurik.com Git - wxWidgets.git/blob - samples/resource/resource.cpp
807c387fa13dcb1e93be5b2f2e834428e3535b86
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 // In order to get the ID of the controls defined in the
39 // dialog, we include the header automatically generated
44 // If you have a Windows compiler that can cope with long strings,
45 // then you can always use the #include form for simplicity.
47 // NOTE: Borland's brc32.exe resource compiler doesn't recognize
48 // the TEXT resource, for some reason, so either run-time file loading
49 // or file inclusion should be used.
51 #if defined(__WXMSW__)
52 // Under Windows, some compilers can't include
53 // a whole .wxr file. So we use a .rc user-defined resource
54 // instead. dialog1 will point to the whole .wxr 'file'.
55 static char *dialog1
= NULL
;
56 static char *menu1
= NULL
;
58 // Other platforms should have sensible compilers that
59 // cope with long strings.
60 #include "dialog1.wxr"
65 MyFrame
*frame
= (MyFrame
*) NULL
;
69 // Testing of ressources
74 // The `main program' equivalent, creating the windows and returning the
76 bool MyApp::OnInit(void)
78 #if defined(__WXMSW__)
79 // Load the .wxr 'file' from a .rc resource, under Windows.
80 dialog1
= wxLoadUserResource("dialog1", "WXRDATA");
81 menu1
= wxLoadUserResource("menu1", "WXRDATA");
82 // All resources in the file (only one in this case) get parsed
84 wxResourceParseString(dialog1
);
85 wxResourceParseString(menu1
);
87 // Simply parse the data pointed to by the variable dialog1.
88 // If there were several resources, there would be several
89 // variables, and this would need to be called several times.
90 wxResourceParseData(dialog1
);
91 wxResourceParseData(menu1
);
94 // Create the main frame window
95 frame
= new MyFrame((wxFrame
*) NULL
, -1, (char *) "wxWindows Resource Sample", wxPoint(-1, -1), wxSize(300, 250));
97 // Give it a status line
98 frame
->CreateStatusBar(2);
100 wxMenuBar
*menu_bar
= wxResourceCreateMenuBar("menu1");
102 // Associate the menu bar with the frame
103 frame
->SetMenuBar(menu_bar
);
106 frame
->panel
= new MyPanel(frame
, -1, wxPoint(0, 0), wxSize(400, 400), 0, "MyMainFrame");
116 #if defined(__WXMSW__)
122 BEGIN_EVENT_TABLE(MyPanel
, wxPanel
)
123 EVT_LEFT_DOWN( MyPanel::OnClick
)
126 MyPanel::MyPanel( wxWindow
*parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
,
127 int style
, const wxString
&name
) :
128 wxPanel( parent
, id
, pos
, size
, style
, name
)
132 void MyPanel::OnClick( wxMouseEvent
&WXUNUSED(event2
) )
134 MyFrame
*frame
= (MyFrame
*)(wxTheApp
->GetTopWindow());
135 wxCommandEvent event
;
136 frame
->OnTestDialog( event
);
140 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
141 EVT_MENU(RESOURCE_ABOUT
, MyFrame::OnAbout
)
142 EVT_MENU(RESOURCE_QUIT
, MyFrame::OnQuit
)
143 EVT_MENU(RESOURCE_TESTDIALOG
, MyFrame::OnTestDialog
)
146 // Define my frame constructor
147 MyFrame::MyFrame(wxWindow
*parent
, const wxWindowID id
, const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
):
148 wxFrame(parent
, id
, title
, pos
, size
)
150 panel
= (wxWindow
*) NULL
;
153 void MyFrame::OnAbout( wxCommandEvent
& WXUNUSED(event
) )
155 wxMessageBox("wxWindows resource sample.\n"
156 "(c) Julian Smart", "About wxWindows sample",
157 wxICON_INFORMATION
| wxOK
);
160 void MyFrame::OnQuit( wxCommandEvent
& WXUNUSED(event
) )
165 void MyFrame::OnTestDialog(wxCommandEvent
& WXUNUSED(event
) )
167 MyDialog
*dialog
= new MyDialog
;
168 if (dialog
->LoadFromResource(this, "dialog1"))
170 wxTextCtrl
*text
= (wxTextCtrl
*)wxFindWindowByName("multitext3", dialog
);
172 text
->SetValue("wxWindows resource demo");
178 BEGIN_EVENT_TABLE(MyDialog
, wxDialog
)
179 //EVT_BUTTON(RESOURCE_OK, MyDialog::OnOk)
180 EVT_BUTTON(ID_BUTTON109
, MyDialog::OnCancel
)
184 void MyDialog::OnOk(wxCommandEvent
& WXUNUSED(event
) )
186 // EndModal(RESOURCE_OK);
189 void MyDialog::OnCancel(wxCommandEvent
& WXUNUSED(event
) )
191 EndModal(ID_BUTTON109
);