1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
|
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif
#include <wx/dcbuffer.h>
#include <wx/image.h>
#define MNU_QUIT 10200
class MyApp : public wxApp
{
public:
virtual bool OnInit();
};
class MyFrame : public wxFrame
{
DECLARE_EVENT_TABLE()
public:
MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size,
long style = wxDEFAULT_FRAME_STYLE);
protected:
void CreateControls();
void OnQuit(wxCommandEvent& event);
void OnSize(wxSizeEvent& event);
void OnPaint(wxPaintEvent& event);
void OnEraseBackground(wxEraseEvent& event);
private:
wxImage m_Image;
};
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_MENU(MNU_QUIT, MyFrame::OnQuit)
EVT_PAINT(MyFrame::OnPaint)
EVT_ERASE_BACKGROUND(MyFrame::OnEraseBackground)
EVT_SIZE(MyFrame::OnSize)
END_EVENT_TABLE()
IMPLEMENT_APP(MyApp)
bool MyApp::OnInit()
{
wxImage::AddHandler(new wxPNGHandler);
MyFrame *frame = new MyFrame(_T("Minimal wxWindows App"),
wxPoint(50, 50), wxSize(450, 340));
frame->Show(TRUE);
return TRUE;
}
MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size,
long style) : wxFrame(NULL, -1, title, pos, size, style)
{
wxMenu *menuFile = new wxMenu;
menuFile->Append(MNU_QUIT, _T("E&xit\tAlt-X"), _T("Quit this program"));
wxMenuBar *menuBar = new wxMenuBar();
menuBar->Append(menuFile, _T("&File"));
SetMenuBar(menuBar);
m_Image = wxImage(_T("backgrnd.png"), wxBITMAP_TYPE_PNG);
CreateControls();
CreateStatusBar(2);
SetStatusText(_T("Welcome to wxWindows!"));
}
void MyFrame::CreateControls()
{
wxStaticText* staticText;
wxTextCtrl* textCtrl;
staticText = new wxStaticText(this, wxID_STATIC, _("Static text"),
wxPoint(50, 50), wxDefaultSize, 0);
textCtrl = new wxTextCtrl(this, 100, wxEmptyString, wxPoint(150, 45),
wxDefaultSize, 0);
staticText = new wxStaticText(this, wxID_STATIC, _("Static text"),
wxPoint(50, 100), wxDefaultSize, 0);
textCtrl = new wxTextCtrl(this, 110, wxEmptyString, wxPoint(150, 95),
wxDefaultSize, 0);
}
void MyFrame::OnSize(wxSizeEvent& event)
{
#if defined(__WXUNIVERSAL__)
// this is also necessary to update the context on some platforms
wxFrame::OnSize(event);
#endif
event.Skip();
Refresh();
}
void MyFrame::OnPaint(wxPaintEvent& event)
{
wxRect rect(GetClientSize());
wxBufferedPaintDC dcPaint(this);
wxBitmap bitmap(m_Image.Scale(rect.GetWidth(), rect.GetHeight()));
dcPaint.DrawBitmap(bitmap, rect.x, rect.y, false);
}
void MyFrame::OnEraseBackground(wxEraseEvent& event) { /* Do nothing */ }
void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event)){Close(TRUE);} |
Partager