2012년 5월 17일 목요일

wxWidgets튜토리얼03-2 버튼 만들기

1-단순한 창 띄우기
main.h
#include<wx/wx.h>

class MyApp: public wxApp
{
    public:
        virtual bool OnInit();
};

main.cpp
#include"main.h"
#include"CMainFrame.h"

IMPLEMENT_APP(MyApp)

bool MyApp::OnInit()
{
    CMainFrame *MainFrame = new CMainFrame(wxT("My First Program"));
    MainFrame->Show(true);
    return true;
}

CMainFrame.h

#include<wx/wx.h>

class CMainFrame:public wxFrame
{
    public:
        CMainFrame(const wxString& title);
//기본 프로그램에서 추가된 함수
        void OnButton(wxCommandEvent & Event);
};

CMainFrame.cpp

#include"CMainFrame.h"

CMainFrame::CMainFrame(const wxString & title)
 : wxFrame(NULL,wxID_ANY,title,wxDefaultPosition,wxSize(640,480))
{
    wxPanel * Panel = new wxPanel(this,wxID_ANY);
    wxButton * Button = new wxButton(Panel , wxID_OK , wxT("This is a button") , wxPoint(20,20) );
    Connect(wxID_OK , wxEVT_COMMAND_BUTTON_CLICKED,wxCommandEventHandler
   (CMainFrame::OnButton));
    Centre();
}
void CMainFrame::OnButton(wxCommandEvent & WXUNUESED( Event ) )
{
    wxMessageBox(wxT("You click a button"),wxT("Info"),wxOK);
}

댓글 없음:

댓글 쓰기