# wxWidgets 설치

# 개요

C++ 프로젝트의 UI에서 사용할 wxWidgets 라이브러리의 기본적인 사용 예제입니다.

# 준비 사항

# 설치 및 설정

# Windows Desktop Application 생성

  • 비주얼 스튜디오에서 새로운 프로젝트를 생성합니다.

# 프로젝트 설정 변경

  • Project의 Properties에서
    • Configuration Properties → C / C++ → Preprocessor 선택
    • Preprocessor Definitions에 "WXUSINGDLL" 추가

# 폼 빌더를 이용하여 화면 디자인

  • 폼 빌더를 사용하여 원하는 모양대로 폼을 디자인 합니다.

# 자동 생성 코드 사용

  • 폴 빌더에서 자동으로 생성된 코드를 비주얼 스튜디오의 소스 복사하여 실행합니다.

# 실행결과

# 자동 생성 코드

#include <wx/wxprec.h>
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif

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

class FormMain : public wxFrame
{
private:
protected:
	wxButton* bt_hello;

	void on_click(wxMouseEvent& event) 
	{  
		// TODO:
	}
public:
	FormMain(wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxEmptyString, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize(500, 300), long style = wxDEFAULT_FRAME_STYLE | wxTAB_TRAVERSAL);
	~FormMain();
};

wxIMPLEMENT_APP(MyApp);

bool MyApp::OnInit()
{
	FormMain* frame = new FormMain(NULL, 0, "Hi", wxPoint(50, 50), wxSize(450, 340), wxDEFAULT_FRAME_STYLE | wxTAB_TRAVERSAL);
	frame->Show(true);
	return true;
}

FormMain::FormMain(wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style) : wxFrame(parent, id, title, pos, size, style)
{
	this->SetSizeHints(wxDefaultSize, wxDefaultSize);

	wxBoxSizer* bSizer1;
	bSizer1 = new wxBoxSizer(wxVERTICAL);

	bt_hello = new wxButton(this, wxID_ANY, wxT("MyButton"), wxDefaultPosition, wxDefaultSize, 0);
	bSizer1->Add(bt_hello, 0, wxALL, 5);


	this->SetSizer(bSizer1);
	this->Layout();

	this->Centre(wxBOTH);

	// Connect Events
	bt_hello->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(FormMain::on_click), NULL, this);
}

FormMain::~FormMain()
{
	// Disconnect Events
	bt_hello->Disconnect(wxEVT_LEFT_DOWN, wxMouseEventHandler(FormMain::on_click), NULL, this);
}
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