]> git.saurik.com Git - wxWidgets.git/blob - samples/dll/wx_exe.cpp
put both versions of wxGetMousePosition in one place so they can use one implementation
[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 #ifndef __WINDOWS__
35 #error "This sample is Windows-only"
36 #endif
37
38 #ifdef WXUSINGDLL
39 #error "This sample doesn't work with DLL build of wxWidgets"
40 #endif
41
42 // ----------------------------------------------------------------------------
43 // GUI classes
44 // ----------------------------------------------------------------------------
45
46 static const int ID_RUN_DLL = wxNewId();
47
48 class MainFrame : public wxFrame
49 {
50 public:
51 MainFrame();
52
53 void OnRunDLL(wxCommandEvent& event);
54
55 DECLARE_EVENT_TABLE()
56 };
57
58
59 class MainApp : public wxApp
60 {
61 public:
62 virtual bool OnInit();
63 virtual int OnExit();
64 };
65
66
67 // ============================================================================
68 // implementation
69 // ============================================================================
70
71 // ----------------------------------------------------------------------------
72 // MainFrame
73 // ----------------------------------------------------------------------------
74
75 BEGIN_EVENT_TABLE(MainFrame, wxFrame)
76 EVT_BUTTON(ID_RUN_DLL, MainFrame::OnRunDLL)
77 END_EVENT_TABLE()
78
79 MainFrame::MainFrame()
80 : wxFrame(NULL, wxID_ANY, "Main wx app",
81 wxDefaultPosition, wxSize(400, 300))
82 {
83 wxPanel *p = new wxPanel(this, wxID_ANY);
84 wxSizer *sizer = new wxBoxSizer(wxVERTICAL);
85
86 sizer->Add
87 (
88 new wxStaticText
89 (
90 p, wxID_ANY,
91 wxString::Format
92 (
93 "Main wxApp instance is %p (%s),\n"
94 "thread ID %ld.\n",
95 wxApp::GetInstance(),
96 wxVERSION_STRING,
97 wxThread::GetCurrentId()
98 )
99 ),
100 wxSizerFlags(1).Expand().Border(wxALL, 10)
101 );
102
103 sizer->Add
104 (
105 new wxButton(p, ID_RUN_DLL, "Run GUI from DLL"),
106 wxSizerFlags(0).Right().Border(wxALL, 10)
107 );
108
109 p->SetSizerAndFit(sizer);
110
111 wxSizer *fsizer = new wxBoxSizer(wxVERTICAL);
112 fsizer->Add(p, wxSizerFlags(1).Expand());
113 SetSizerAndFit(fsizer);
114 }
115
116 void MainFrame::OnRunDLL(wxCommandEvent& WXUNUSED(event))
117 {
118 run_wx_gui_from_dll("child instance");
119 }
120
121
122 // ----------------------------------------------------------------------------
123 // MainApp
124 // ----------------------------------------------------------------------------
125
126 bool MainApp::OnInit()
127 {
128 if ( !wxApp::OnInit() )
129 return false;
130
131 wxFrame *f = new MainFrame();
132 f->Show(true);
133
134 return true;
135 }
136
137 int MainApp::OnExit()
138 {
139 wx_dll_cleanup();
140 return wxApp::OnExit();
141 }
142
143
144 IMPLEMENT_APP(MainApp)