wxWindows 第一个Frame程序

wxWindows  第一个Frame程序

联系我,请发邮件至 huyoo353{at}126{dot}com

前几天给出了一个最简单的Hello World 程序, 由于这几天我还在学习wxWindows, 所以把今天做的第一个Frame框架程序写出来,给大家分享.

1. 新建一个Win32 Application,名字为Frame,然后选择Empty Project,点Finish完成.
2. Insert 一个Class, Class Type为Generic Class,名字为 CMyApp ,基类信息中Deviced From 填入wxApp,类别为Public(默认),弹出对话框点OK.
3. 按照和上面同样的步骤插入一个新类 CMyFrame, 基类为wxFrame, Public 继承.
4. 在ClassView中双击CMyApp的构造函数CMyApp(),在MyApp.cpp中加入#include "wx/wx.h"
5. 同样在MyFrame.cpp中加入#include "wx/wx.h"
6. 在ClassView中右键单击CMyApp,选择添加成员函数,加入一个Public的virtual bool OnInit()成员函数.
7. 在ClassView中右键单击CMyFrame,选择添加成员函数,加入一个Public的MyFrame(const wxChar *title,int xpos,int ypos,int width,int height)的构造函数(无类型的).
8. 修改MyFrame(const wxChar *title,int xpos,int ypos,int width,int height)如下:

MyFrame::MyFrame(const wxChar *title,int xpos,int ypos,int width,int height)
:wxFrame((wxFrame*)NULL,-1,title,wxPoint(xpos,ypos),wxSize(width,height))
{
 // 创建状态栏
 CreateStatusBar();
 SetStatusText("状态栏就绪");
}
9. 修改CMyApp的OnInit()如下
bool CMyApp::OnInit()
{
 MyFrame* frame=new MyFrame("我的第一个框架窗口",100,100,400,300);
 frame->Show(TRUE);
 return true;
}
10. 在MyApp.cpp头部加入#include "MyFrame.h"
在CMyApp:CMyApp(){}前面加入IMPLEMENT_APP(CMyApp),看下面:
IMPLEMENT_APP(CMyApp)
CMyApp::CMyApp()
{

}
10.5 这个时候你如果点编译按钮的话,会出现一个致命错误(Fatal Error)
fatal error C1083: Cannot open include file: 'wx/setup.h': No such file or directory
怎么解决?看下面
11. 设置好Settings
win32 Debug配置
C++选项卡
预处理定义为: _DEBUG,WIN32,_WINDOWS,_MT,WINVER=0x400,_wxUSE_GUI,__WXDEBUG__,WXDEBUG=1
额外包含头文件目录为: $(WXWIN)/lib/mswd
预编译头文件选择 Automatic use of precompiled headers
Code Generation 中的Use Runtime library 选择 Debug MultiThreaded DLL
Link选项卡
在对象代码模块最后,添加comctl32.lib rpcrt4.lib wsock32.lib wxmswd.lib , 这4个库

编译完成,执行程序如下图:

Frame



//源文件附在后面
//
// MyApp.h: interface for the CMyApp class.
//
//

#if !defined(AFX_MYAPP_H__08DC4B2E_BCC2_48EC_A02A_D82513125055__INCLUDED_)
#define AFX_MYAPP_H__08DC4B2E_BCC2_48EC_A02A_D82513125055__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

class CMyApp : public wxApp 
{
public:
 virtual bool OnInit();
 CMyApp();
 virtual ~CMyApp();

};

#endif // !defined(AFX_MYAPP_H__08DC4B2E_BCC2_48EC_A02A_D82513125055__INCLUDED_)
//-------------------------------------------------------------------------
// MyApp.cpp: implementation of the CMyApp class.
//
//
#include "wx/wx.h"
#include "MyApp.h"
#include "MyFrame.h"

//
// Construction/Destruction
//
IMPLEMENT_APP(CMyApp)
CMyApp::CMyApp()
{

}

CMyApp::~CMyApp()
{

}

bool CMyApp::OnInit()
{
 MyFrame* frame=new MyFrame("我的第一个框架窗口",100,100,400,300);
 frame->Show(TRUE);
 return true;
}
//============================================
// MyFrame.h: interface for the MyFrame class.
//
//

#if !defined(AFX_MYFRAME_H__6DA98C02_589A_44A9_B65A_F0C1941E3AFA__INCLUDED_)
#define AFX_MYFRAME_H__6DA98C02_589A_44A9_B65A_F0C1941E3AFA__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

class MyFrame : public wxFrame 
{
public:
 MyFrame(const wxChar *title,int xpos,int ypos,int width,int height);

 MyFrame();
 virtual ~MyFrame();
};

#endif // !defined(AFX_MYFRAME_H__6DA98C02_589A_44A9_B65A_F0C1941E3AFA__INCLUDED_)
//-----------------------------------------------------
// MyFrame.cpp: implementation of the MyFrame class.
//
//
#include "wx/wx.h"
#include "MyFrame.h"

//
// Construction/Destruction
//

MyFrame::MyFrame()
{

}

MyFrame::~MyFrame()
{

}

MyFrame::MyFrame(const wxChar *title,int xpos,int ypos,int width,int height)
:wxFrame((wxFrame*)NULL,-1,title,wxPoint(xpos,ypos),wxSize(width,height))
{
 // 创建状态栏
 CreateStatusBar();
 SetStatusText("状态栏就绪");
}
//=================================================

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值