Ticket #40931: hw_wx_hack.cpp

File hw_wx_hack.cpp, 1.5 KB (added by jxy (Xiao-Yong), 10 years ago)

Minimum working code.

Line 
1#include <wx/wx.h>
2#ifdef __WXMAC__
3#include <Carbon/Carbon.h>
4extern "C" { void CPSEnableForegroundOperation(ProcessSerialNumber* psn); }
5#endif
6
7class MyApp : public wxApp
8{
9  virtual bool OnInit();
10};
11
12// IMPLEMENT_APP(MyApp)
13
14int main(int argc, char**argv)
15{
16    wxApp::SetInstance( new MyApp() );
17    wxEntryStart( argc, argv );
18#ifdef __WXMAC__
19    ProcessSerialNumber psn;
20    GetCurrentProcess( &psn );
21    CPSEnableForegroundOperation( &psn );
22    SetFrontProcess( &psn );
23#endif
24    wxTheApp->OnInit();
25    wxTheApp->OnRun();
26    wxTheApp->OnExit();
27    wxEntryCleanup();
28
29    return 0;
30}
31
32class MyFrame : public wxFrame
33{
34public:
35  MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size);
36  void OnQuit(wxCommandEvent& event);
37};
38
39enum
40  {
41    ID_Quit=1
42  };
43
44
45bool MyApp::OnInit()
46{
47  MyFrame *frame = new MyFrame( _("Hello World"), wxPoint(50, 50),
48                                wxSize(450, 350));
49
50  frame->Connect( ID_Quit, wxEVT_COMMAND_MENU_SELECTED,
51                  (wxObjectEventFunction) &MyFrame::OnQuit );
52
53  frame->Show(true);
54  SetTopWindow(frame);
55  return true;
56}
57
58MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
59  : wxFrame( NULL, -1, title, pos, size )
60{
61  wxMenuBar *menuBar = new wxMenuBar;
62  wxMenu *menuFile = new wxMenu;
63
64  menuFile->Append( ID_Quit, _("E&xit") );
65  menuBar->Append(menuFile, _("&File") );
66  SetMenuBar(menuBar);
67
68  CreateStatusBar();
69  SetStatusText( _("Welcome to wxWidgets!") );
70}
71
72void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
73{
74  Close(true);
75}