]>
git.saurik.com Git - wxWidgets.git/blob - samples/dll/wx_exe.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Sample showing how to use wx from a DLL
4 // Author: Vaclav Slavik
6 // Copyright: (c) 2009 Vaclav Slavik
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 // ============================================================================
12 // ============================================================================
14 // ----------------------------------------------------------------------------
16 // ----------------------------------------------------------------------------
18 #include "wx/wxprec.h"
30 #include "wx/stattext.h"
31 #include "wx/button.h"
34 #error "This sample is Windows-only"
38 #error "This sample doesn't work with DLL build of wxWidgets"
41 // ----------------------------------------------------------------------------
43 // ----------------------------------------------------------------------------
45 static const int ID_RUN_DLL
= wxNewId();
47 class MainFrame
: public wxFrame
52 void OnRunDLL(wxCommandEvent
& event
);
58 class MainApp
: public wxApp
61 virtual bool OnInit();
66 // ============================================================================
68 // ============================================================================
70 // ----------------------------------------------------------------------------
72 // ----------------------------------------------------------------------------
74 BEGIN_EVENT_TABLE(MainFrame
, wxFrame
)
75 EVT_BUTTON(ID_RUN_DLL
, MainFrame::OnRunDLL
)
78 MainFrame::MainFrame()
79 : wxFrame(NULL
, wxID_ANY
, "Main wx app",
80 wxDefaultPosition
, wxSize(400, 300))
82 wxPanel
*p
= new wxPanel(this, wxID_ANY
);
83 wxSizer
*sizer
= new wxBoxSizer(wxVERTICAL
);
92 "Main wxApp instance is %p (%s),\n"
96 wxThread::GetCurrentId()
99 wxSizerFlags(1).Expand().Border(wxALL
, 10)
104 new wxButton(p
, ID_RUN_DLL
, "Run GUI from DLL"),
105 wxSizerFlags(0).Right().Border(wxALL
, 10)
108 p
->SetSizerAndFit(sizer
);
110 wxSizer
*fsizer
= new wxBoxSizer(wxVERTICAL
);
111 fsizer
->Add(p
, wxSizerFlags(1).Expand());
112 SetSizerAndFit(fsizer
);
115 void MainFrame::OnRunDLL(wxCommandEvent
& WXUNUSED(event
))
117 run_wx_gui_from_dll("child instance");
121 // ----------------------------------------------------------------------------
123 // ----------------------------------------------------------------------------
125 bool MainApp::OnInit()
127 if ( !wxApp::OnInit() )
130 wxFrame
*f
= new MainFrame();
136 int MainApp::OnExit()
139 return wxApp::OnExit();
143 IMPLEMENT_APP(MainApp
)