]> git.saurik.com Git - wxWidgets.git/blob - samples/dll/wx_exe.cpp
Add a very simple example of a Win32 application using wx DLL.
[wxWidgets.git] / samples / dll / wx_exe.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx_exe.cpp
3 // Purpose: Sample showing how to use wx from a DLL
4 // Author: Vaclav Slavik
5 // Created: 2009-12-03
6 // RCS-ID: $Id$
7 // Copyright: (c) 2009 Vaclav Slavik
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 // ============================================================================
12 // declarations
13 // ============================================================================
14
15 // ----------------------------------------------------------------------------
16 // headers
17 // ----------------------------------------------------------------------------
18
19 #include "wx/wxprec.h"
20
21 #ifdef __BORLANDC__
22 #pragma hdrstop
23 #endif
24
25 #include "my_dll.h"
26
27 #include "wx/app.h"
28 #include "wx/frame.h"
29 #include "wx/panel.h"
30 #include "wx/sizer.h"
31 #include "wx/stattext.h"
32 #include "wx/button.h"
33
34
35 // ----------------------------------------------------------------------------
36 // GUI classes
37 // ----------------------------------------------------------------------------
38
39 static const int ID_RUN_DLL = wxNewId();
40
41 class MainFrame : public wxFrame
42 {
43 public:
44 MainFrame();
45
46 void OnRunDLL(wxCommandEvent& event);
47
48 DECLARE_EVENT_TABLE()
49 };
50
51
52 class MainApp : public wxApp
53 {
54 public:
55 virtual bool OnInit();
56 virtual int OnExit();
57 };
58
59
60 // ============================================================================
61 // implementation
62 // ============================================================================
63
64 // ----------------------------------------------------------------------------
65 // MainFrame
66 // ----------------------------------------------------------------------------
67
68 BEGIN_EVENT_TABLE(MainFrame, wxFrame)
69 EVT_BUTTON(ID_RUN_DLL, MainFrame::OnRunDLL)
70 END_EVENT_TABLE()
71
72 MainFrame::MainFrame()
73 : wxFrame(NULL, wxID_ANY, "Main wx app",
74 wxDefaultPosition, wxSize(400, 300))
75 {
76 wxPanel *p = new wxPanel(this, wxID_ANY);
77 wxSizer *sizer = new wxBoxSizer(wxVERTICAL);
78
79 sizer->Add
80 (
81 new wxStaticText
82 (
83 p, wxID_ANY,
84 wxString::Format
85 (
86 "Main wxApp instance is %p (%s),\n"
87 "thread ID %ld.\n",
88 wxApp::GetInstance(),
89 wxVERSION_STRING,
90 wxThread::GetCurrentId()
91 )
92 ),
93 wxSizerFlags(1).Expand().Border(wxALL, 10)
94 );
95
96 sizer->Add
97 (
98 new wxButton(p, ID_RUN_DLL, "Run GUI from DLL"),
99 wxSizerFlags(0).Right().Border(wxALL, 10)
100 );
101
102 p->SetSizerAndFit(sizer);
103
104 wxSizer *fsizer = new wxBoxSizer(wxVERTICAL);
105 fsizer->Add(p, wxSizerFlags(1).Expand());
106 SetSizerAndFit(fsizer);
107 }
108
109 void MainFrame::OnRunDLL(wxCommandEvent& WXUNUSED(event))
110 {
111 run_wx_gui_from_dll("child instance");
112 }
113
114
115 // ----------------------------------------------------------------------------
116 // MainApp
117 // ----------------------------------------------------------------------------
118
119 bool MainApp::OnInit()
120 {
121 if ( !wxApp::OnInit() )
122 return false;
123
124 wxFrame *f = new MainFrame();
125 f->Show(true);
126
127 return true;
128 }
129
130 int MainApp::OnExit()
131 {
132 wx_dll_cleanup();
133 return wxApp::OnExit();
134 }
135
136
137 IMPLEMENT_APP(MainApp)