]>
Commit | Line | Data |
---|---|---|
61aba460 VS |
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 | |
61aba460 VS |
6 | // Copyright: (c) 2009 Vaclav Slavik |
7 | // Licence: wxWindows licence | |
8 | ///////////////////////////////////////////////////////////////////////////// | |
9 | ||
10 | // ============================================================================ | |
11 | // declarations | |
12 | // ============================================================================ | |
13 | ||
14 | // ---------------------------------------------------------------------------- | |
15 | // headers | |
16 | // ---------------------------------------------------------------------------- | |
17 | ||
18 | #include "wx/wxprec.h" | |
19 | ||
20 | #ifdef __BORLANDC__ | |
21 | #pragma hdrstop | |
22 | #endif | |
23 | ||
24 | #include "my_dll.h" | |
25 | ||
26 | #include "wx/app.h" | |
27 | #include "wx/frame.h" | |
28 | #include "wx/panel.h" | |
29 | #include "wx/sizer.h" | |
30 | #include "wx/stattext.h" | |
31 | #include "wx/button.h" | |
32 | ||
bb5a9514 VZ |
33 | #ifndef __WINDOWS__ |
34 | #error "This sample is Windows-only" | |
cfdcbf66 VS |
35 | #endif |
36 | ||
37 | #ifdef WXUSINGDLL | |
38 | #error "This sample doesn't work with DLL build of wxWidgets" | |
39 | #endif | |
61aba460 VS |
40 | |
41 | // ---------------------------------------------------------------------------- | |
42 | // GUI classes | |
43 | // ---------------------------------------------------------------------------- | |
44 | ||
45 | static const int ID_RUN_DLL = wxNewId(); | |
46 | ||
47 | class MainFrame : public wxFrame | |
48 | { | |
49 | public: | |
50 | MainFrame(); | |
51 | ||
52 | void OnRunDLL(wxCommandEvent& event); | |
53 | ||
54 | DECLARE_EVENT_TABLE() | |
55 | }; | |
56 | ||
57 | ||
58 | class MainApp : public wxApp | |
59 | { | |
60 | public: | |
61 | virtual bool OnInit(); | |
62 | virtual int OnExit(); | |
63 | }; | |
64 | ||
65 | ||
66 | // ============================================================================ | |
67 | // implementation | |
68 | // ============================================================================ | |
69 | ||
70 | // ---------------------------------------------------------------------------- | |
71 | // MainFrame | |
72 | // ---------------------------------------------------------------------------- | |
73 | ||
74 | BEGIN_EVENT_TABLE(MainFrame, wxFrame) | |
75 | EVT_BUTTON(ID_RUN_DLL, MainFrame::OnRunDLL) | |
76 | END_EVENT_TABLE() | |
77 | ||
78 | MainFrame::MainFrame() | |
79 | : wxFrame(NULL, wxID_ANY, "Main wx app", | |
80 | wxDefaultPosition, wxSize(400, 300)) | |
81 | { | |
82 | wxPanel *p = new wxPanel(this, wxID_ANY); | |
83 | wxSizer *sizer = new wxBoxSizer(wxVERTICAL); | |
84 | ||
85 | sizer->Add | |
86 | ( | |
87 | new wxStaticText | |
88 | ( | |
89 | p, wxID_ANY, | |
90 | wxString::Format | |
91 | ( | |
92 | "Main wxApp instance is %p (%s),\n" | |
93 | "thread ID %ld.\n", | |
94 | wxApp::GetInstance(), | |
95 | wxVERSION_STRING, | |
96 | wxThread::GetCurrentId() | |
97 | ) | |
98 | ), | |
99 | wxSizerFlags(1).Expand().Border(wxALL, 10) | |
100 | ); | |
101 | ||
102 | sizer->Add | |
103 | ( | |
104 | new wxButton(p, ID_RUN_DLL, "Run GUI from DLL"), | |
105 | wxSizerFlags(0).Right().Border(wxALL, 10) | |
106 | ); | |
107 | ||
108 | p->SetSizerAndFit(sizer); | |
109 | ||
110 | wxSizer *fsizer = new wxBoxSizer(wxVERTICAL); | |
111 | fsizer->Add(p, wxSizerFlags(1).Expand()); | |
112 | SetSizerAndFit(fsizer); | |
113 | } | |
114 | ||
115 | void MainFrame::OnRunDLL(wxCommandEvent& WXUNUSED(event)) | |
116 | { | |
117 | run_wx_gui_from_dll("child instance"); | |
118 | } | |
119 | ||
120 | ||
121 | // ---------------------------------------------------------------------------- | |
122 | // MainApp | |
123 | // ---------------------------------------------------------------------------- | |
124 | ||
125 | bool MainApp::OnInit() | |
126 | { | |
127 | if ( !wxApp::OnInit() ) | |
128 | return false; | |
129 | ||
130 | wxFrame *f = new MainFrame(); | |
131 | f->Show(true); | |
132 | ||
133 | return true; | |
134 | } | |
135 | ||
136 | int MainApp::OnExit() | |
137 | { | |
138 | wx_dll_cleanup(); | |
139 | return wxApp::OnExit(); | |
140 | } | |
141 | ||
142 | ||
143 | IMPLEMENT_APP(MainApp) |