wxWidgets 初步学习(1)

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

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

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

 

第一篇, wxWidgets初步

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

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

 

ContractedBlock.gif ExpandedBlockStart.gif Code
ExpandedBlockStart.gifContractedBlock.gif/**//***********************
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
ExpandedBlockStart.gifContractedBlock.gif
{
public:
    
bool OnInit();
 MVFrame 
* GetFrame(void);
private:
 MVFrame 
* frame;
}
;
DECLARE_APP(MVApp);
#endif // #ifndef MV_APP_H

ExpandedBlockStart.gifContractedBlock.gif
/**//*************************************
MVApp.cpp
*************************************
*/

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

MVFrame 
* MVApp::GetFrame(void)
ExpandedBlockStart.gifContractedBlock.gif
{
 
return frame;
}


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

ExpandedBlockStart.gifContractedBlock.gif
/**//*************************************
MVFrame.h
*************************************
*/

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

ExpandedBlockStart.gifContractedBlock.gif
/**//*****************************************
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()
ExpandedBlockStart.gifContractedBlock.gif
/**//* 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)
ExpandedBlockStart.gifContractedBlock.gif
{
        CreateMenubar();
     
// Create a statubar 
 CreateStatusBar(2);
 SetStatusText(wxT(
"MyFEM"),0);

}


void MVFrame::CreateMenubar()
ExpandedBlockStart.gifContractedBlock.gif
{
    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);
}


ExpandedBlockStart.gifContractedBlock.gif
/**//* Intercept menu commands */

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


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

ExpandedBlockStart.gifContractedBlock.gif
/**//***************************************
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工程中,即可生成漂亮的程序界面

转载于:https://www.cnblogs.com/suerey/archive/2008/08/13/1267156.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值