登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

Code@Pig Home

喜欢背着一袋Code傻笑的Pig .. 忧美.欢笑.记忆.忘却 .之. 角落

 
 
 

日志

 
 

[wx] Hello World, again!  

2010-07-22 22:03:33|  分类: gui_wxWidgets |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
弄一个有 menu, status bar 的最简单的 window 出来。
wx 实在和 mfc 很像,呵呵。

DECLARE_APP(MyApp), IMPLEMENT_APP(MyApp) 会弄出这么个全局函数:
MyApp& wxGetApp();

MyApp 就是全局数据存放地,MyApp::OnInit() 就是 program entry。
MyFrame 就是一个 window,MyFrame 退出了,进程就退出了。

程序link需要:Comctl32.lib wxbase28u.lib wxmsw28u_core.lib

---------------------------------------------------------------
// MyApp.h
#ifndef MY_APP_H
#define MY_APP_H

#include <wx/wx.h>

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

DECLARE_APP(MyApp);

#endif
---------------------------------------------------------------
// MyApp.cpp
#include "MyApp.h"
#include "MyFrame.h"

bool MyApp::OnInit()
{
    MyFrame *frame = new MyFrame(wxT("Mini wx app"));
    frame->Show(true);
    return true;
}

IMPLEMENT_APP(MyApp);
---------------------------------------------------------------
// MyFrame.h
#ifndef MY_FRAME_H
#define MY_FRAME_H

#include <wx/wx.h>

class MyFrame : public wxFrame
{
public:
    MyFrame(const wxString& title);

    void OnQuit(wxCommandEvent& event);
    void OnAbout(wxCommandEvent& event);

private:
    DECLARE_EVENT_TABLE();
};

#endif
---------------------------------------------------------------
// MyFrame.cpp
#include "MyFrame.h"

BEGIN_EVENT_TABLE(MyFrame, wxFrame)
    EVT_MENU(wxID_ABOUT, MyFrame::OnAbout)
    EVT_MENU(wxID_EXIT, MyFrame::OnQuit)
END_EVENT_TABLE()

MyFrame::MyFrame(const wxString &title) : wxFrame(NULL, wxID_ANY, title)
{
    wxMenu *menuFile = new wxMenu;

    menuFile->Append( wxID_ABOUT, _("&About...") );
    menuFile->AppendSeparator();
    menuFile->Append( wxID_EXIT, _("E&xit") );

    wxMenuBar *menuBar = new wxMenuBar;
    menuBar->Append( menuFile, _("&File") );

    SetMenuBar( menuBar );

    CreateStatusBar();
    SetStatusText( _("Welcome to wxWidgets!") );
}

void MyFrame::OnAbout(wxCommandEvent& event)
{
    wxString msg;
    msg.Printf(wxT("Hello and welcome to %s"), wxVERSION_STRING);
    wxMessageBox(msg, wxT("About Mini"), wxOK | wxICON_INFORMATION, this);
}

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

[wx] Hello World, again! - kasicass - Code@Pig Home

还是图片比较好看,其中代 icon 的 menu button 很好做,如下:
    // [File] => [Open]
    item = new wxMenuItem(menuFile, wxID_OPEN, _("&Open\tCtrl+O"));
    item->SetBitmap(open_xpm);
    menuFile->Append(item);
xpm 格式就是一个数组数据,很方便,哈哈。
  评论这张
 
阅读(938)| 评论(0)

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2018