• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
包子的BLOG
小包子的BLOG
博客园    首页    新随笔    联系   管理    订阅  订阅
wxWidgets 初步学习(1)

由于源程序使用了wxWidgets 2.4.2 ,所以要先学习下其中的结构是什么样子的。。。。。。安装就不用说了,网上大把大把的是。。。

这是初步介绍,转载过来先。。。咔咔

http://blog.programfan.com/blog.asp?blogid=3500&columnid=5587

 

第一篇, wxWidgets初步

开发交互软件首先必须有界面, wxWidgets是很不错的界面库,由于wxWidgets的教材很少,所以本篇先介绍如何分离wxWidgets基本框架的几个类,

首先,MVApp类是主应用程序类,

 

Code
/**//***********************
MVApp.h
***********************
*/

#ifndef MV_APP_H
#define MV_APP_H
#pragma warning (disable: 4018)
#include 
"wx_pch.h"
#include 
"MVFrame.h"
class MVApp: public wxApp
{
public:
    
bool OnInit();
 MVFrame 
* GetFrame(void);
private:
 MVFrame 
* frame;
}
;
DECLARE_APP(MVApp);
#endif // #ifndef MV_APP_H

/**//*************************************
MVApp.cpp
*************************************
*/

#include 
"MVApp.h"
IMPLEMENT_APP(MVApp)
//Main program (equivalent)
bool MVApp::OnInit()
{
    
// Create the main frame window
    frame = new MVFrame(NULL, wxT("MV Post"),wxDefaultPosition, wxSize(650, 600));
    
// Show the frame 
    frame->Show(true);
    
return true;
}

MVFrame 
* MVApp::GetFrame(void)
{
 
return frame;
}


MVFrame是主框架类,负责界面的构建,

/**//*************************************
MVFrame.h
*************************************
*/

#ifndef MV_FRAME_H
#define MV_FRAME_H
#pragma warning (disable: 4018)
#include 
"wx_pch.h"
class MVFrame: public wxFrame
{
public:
    MVFrame(wxFrame 
*frame, const wxString& title, const wxPoint& pos,
            
const wxSize& size, long style = wxDEFAULT_FRAME_STYLE);
 
void OnExit       (wxCommandEvent& WXUNUSED(event)) { Close(true); }
 
void OnAbout      (wxCommandEvent& WXUNUSED(event)); 
private:
    DECLARE_EVENT_TABLE()
}
;
#endif // #ifndef MV_FRAME_H

/**//*****************************************
MVFrame.cpp
*****************************************
*/

#include 
"MVFrame.h"
BEGIN_EVENT_TABLE(MVFrame, wxFrame)
 EVT_MENU(wxID_EXIT, MVFrame::OnExit)
 EVT_MENU(ID_ABOUT, MVFrame::OnAbout)
END_EVENT_TABLE()
/**//* My frame constructor */
MVFrame::MVFrame(wxFrame 
*frame, const wxString& title, const wxPoint& pos,
    
const wxSize& size, long style)
    : wxFrame(frame, wxID_ANY, title, pos, size, style)
{
        CreateMenubar();
     
// Create a statubar 
 CreateStatusBar(2);
 SetStatusText(wxT(
"MyFEM"),0);

}


void MVFrame::CreateMenubar()
{
    wxMenuBar 
*menuBar = new wxMenuBar;

    wxMenu 
*winMenu = new wxMenu;
    winMenu
->Append(wxID_EXIT, wxT("E&xit"));
    menuBar
->Append(winMenu, wxT("&File"));

    winMenu 
= new wxMenu;
    winMenu
->Append(ID_ABOUT, _T("About"));
    menuBar
->Append(winMenu, _T("&Help"));

    SetMenuBar(menuBar);
}


/**//* Intercept menu commands */

void MVFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
{
    (
void)wxMessageBox(_T("About MVPost"));
}


另外,头文件wx_pch.h里面设置基本的wxWidgets链接,

/**//***************************************
wx_pch.h
***************************************
*/

#ifndef WX_PCH_H_INCLUDED
#define WX_PCH_H_INCLUDED

#if ( defined(USE_PCH) && !defined(WX_PRECOMP) )
#define WX_PRECOMP
#endif // USE_PCH

// basic wxWidgets headers
#include <wx/wxprec.h>

// for use xrc files
#include <wx/xrc/xmlres.h>

#ifdef __BORLANDC__
#pragma hdrstop
#endif

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

#if !wxUSE_GLCANVAS
    
#error "OpenGL required: set wxUSE_GLCANVAS to 1 and rebuild the library"
#endif

#ifdef USE_PCH
// put here all your rarely-changing header files

#endif // USE_PCH

#endif // WX_PCH_H_INCLUDED

将以上5个文件添加到设置好wxWidgets环境的VC工程中,即可生成漂亮的程序界面

posted on 2008-08-13 17:23  流浪的菜包子  阅读(1050)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3