wxWidgets+CodeBlocks搭建环境


版本的选择

1、CodeBlocks要下载带mingw编译器的安装程序codeblocks-*.**mingw-setup.exe

2、wxWidgets可以下载2.8.* 或3.0.*版本的

 

注意事项

1、配置mingw的环境变量:在path变量里添加路径为C:/Program Files/CodeBlocks/MinGW/bin(根据你的情况修改)

2、wxWidgets是需要编译的(根据你的情况修改)

进入目录到c:/wxwidgets/build/msw;
mingw32-make -f makefile.gcc BUILD=release SHARED=1 MONOLITHIC=1 UNICODE=1 (注:如果想数据库操作类wxodbc,在编译前需要到C:/wxWidgets/include/wx/msw里setup.h的#define USE_ODBC  1)

3、wx/platform.h  文件里关于setup.h的路径错了,应该改为   #include "wx/msw/setup.h",否则报错

4、找不到libwxmsw30ud.a这种文件是因为没有做2,做了会生成C:\wxWidgets\lib\gcc_dll

5、菜单Project->Build options...,在选项卡Linker settings中,加入C:\wxWidgets\lib\gcc_dll文件夹中的所有.a文件

6、在C:\wxWidgets\lib\gcc_dll中找到那wxmsw30ud_gcc_custom.dll文件,将其拷贝到项目所在文件夹

 

测试代码如下

 

#include <wx/wxprec.h>
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
class MyApp: public wxApp
{
public:
    virtual bool OnInit();
};
class MyFrame: public wxFrame
{
public:
    MyFrame();
private:
    void OnHello(wxCommandEvent& event);
    void OnExit(wxCommandEvent& event);
    void OnAbout(wxCommandEvent& event);
};
enum
{
    ID_Hello = 1
};
wxIMPLEMENT_APP(MyApp);
bool MyApp::OnInit()
{
    MyFrame *frame = new MyFrame();
    frame->Show( true );
    return true;
}
MyFrame::MyFrame()
    : wxFrame(NULL, wxID_ANY, "Hello World")
{
    wxMenu *menuFile = new wxMenu;
    menuFile->Append(ID_Hello, "&Hello...\tCtrl-H",
                     "Help string shown in status bar for this menu item");
    menuFile->AppendSeparator();
    menuFile->Append(wxID_EXIT);
    wxMenu *menuHelp = new wxMenu;
    menuHelp->Append(wxID_ABOUT);
    wxMenuBar *menuBar = new wxMenuBar;
    menuBar->Append( menuFile, "&File" );
    menuBar->Append( menuHelp, "&Help" );
    SetMenuBar( menuBar );
    CreateStatusBar();
    SetStatusText( "Welcome to wxWidgets!" );
    Bind(wxEVT_MENU, &MyFrame::OnHello, this, ID_Hello);
    Bind(wxEVT_MENU, &MyFrame::OnAbout, this, wxID_ABOUT);
    Bind(wxEVT_MENU, &MyFrame::OnExit, this, wxID_EXIT);
}
void MyFrame::OnExit(wxCommandEvent& event)
{
    Close( true );
}
void MyFrame::OnAbout(wxCommandEvent& event)
{
    wxMessageBox( "This is a wxWidgets' Hello world sample",
                  "About Hello World", wxOK | wxICON_INFORMATION );
}
void MyFrame::OnHello(wxCommandEvent& event)
{
    wxLogMessage("Hello world from wxWidgets!");
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值