466 views
首页 > 技术心得 > Beginning with wxWidgets

Beginning with wxWidgets

2011年5月5日

1. 下载最近的稳定版 Current Stable Release: 2.8.12

http://sourceforge.net/projects/wxwindows/files/2.8.12

解压到 E:\wxWidgets-2.8.12\

2. 编译, 用 VS 2010 命令行.

e:
cd E:\wxWidgets-2.8.12

nmake -f makefile.vc BUILD=release UNICODE=0 RUNTIME_LIBS=static
nmake -f makefile.vc BUILD=release UNICODE=1 RUNTIME_LIBS=static
nmake -f makefile.vc BUILD=debug UNICODE=0 RUNTIME_LIBS=static
nmake -f makefile.vc BUILD=debug UNICODE=1 RUNTIME_LIBS=static

3. 设置 vs 2010 的路径

include : E:\wxWidgets-2.8.12\include
E:\wxWidgets-2.8.12\include\msvc

lib : E:\wxWidgets-2.8.12\lib\vc_lib

4. 例子

wxHello.zip

#include <wx/wx.h>

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

class MyFrame : public wxFrame
{
public:
	MyFrame(const wxString & title, const wxPoint & pos, const wxSize & size);
	void OnQuit(wxCommandEvent & event);
	void OnAbout(wxCommandEvent & event);

	DECLARE_EVENT_TABLE()
};

enum {
	ID_Quit = 1,
	ID_About,
};

BEGIN_EVENT_TABLE(MyFrame, wxFrame)
	EVT_MENU(ID_Quit, MyFrame::OnQuit)
	EVT_MENU(ID_About, MyFrame::OnAbout)
END_EVENT_TABLE()

IMPLEMENT_APP(MyApp)

bool MyApp::OnInit()
{
	MyFrame * frame = new MyFrame(_("Hello world"), wxPoint(50, 50), wxSize(450, 340));
	frame->Show(true);
	SetTopWindow(frame);
	return true;
}

MyFrame::MyFrame(const wxString & title, const wxPoint & pos, const wxSize & size)
	: wxFrame(NULL, -1, title, pos, size)
{
	wxMenu * menuFile = new wxMenu;
	menuFile->Append(ID_About, _("&About..."));
	menuFile->AppendSeparator();
	menuFile->Append(ID_Quit, _("E&xit"));
	wxMenuBar * menuBar = new wxMenuBar;
	menuBar->Append(menuFile, _("&File"));
	SetMenuBar(menuBar);
	CreateStatusBar();
	SetStatusText(_("Welcome to wxWidgets!"));
}

void MyFrame::OnQuit(wxCommandEvent & event)
{
	Close(true);
}

void MyFrame::OnAbout(wxCommandEvent & event)
{
	wxMessageBox(_("This is a wxWidgets Hello world sample"),
		_("About Hello World"),
		wxOK | wxICON_INFORMATION, this);
}

常规 -> 字符集 -> 使用 Unicode 字符集
编译设置 -> 代码生成 -> 多线程调试 (/MTd)
连接器 -> 系统 -> 子系统 -> 窗口 (/SUBSYSTEM:WINDOWS)
连接器 -> 输入 -> 附加依赖项 -> Rpcrt4.lib;Comctl32.lib;%(AdditionalDependencies)

5. 参考及教程
wxWidgets download
wxWidgets Documentation

技术心得 ,

  1. 目前还没有任何评论.
  1. 目前还没有任何 trackbacks 和 pingbacks.