整理了一下在linux下,codeblocks中用widgets来创建窗口的大致步骤,直接看图片。

1.wx01Main.cpp

/**************************************************************** Name:      wx01Main.cpp* Purpose:   Code for Application Frame* Author:    Gary (garyao@126.com)* Created:   2022-07-30* Copyright: Gary ()* License:**************************************************************/
//预编译
#ifdef WX_PRECOMP
#include "wx_pch.h"
#endif#ifdef __BORLANDC__
#pragma hdrstop
#endif //__BORLANDC__#include "wx01Main.h"//helper functions
enum wxbuildinfoformat {short_f, long_f };wxString wxbuildinfo(wxbuildinfoformat format)
{wxString wxbuild(wxVERSION_STRING);if (format == long_f ){
#if defined(__WXMSW__)wxbuild << _T("-Windows");
#elif defined(__WXMAC__)wxbuild << _T("-Mac");
#elif defined(__UNIX__)wxbuild << _T("-Linux");
#endif#if wxUSE_UNICODEwxbuild << _T("-Unicode build");
#elsewxbuild << _T("-ANSI build");
#endif // wxUSE_UNICODE}return wxbuild;
}wx01Dialog::wx01Dialog(wxDialog *dlg): GUIDialog(dlg)
{
}wx01Dialog::~wx01Dialog()
{
}
//8. 绑定的事件
void wx01Dialog::OnClose(wxCloseEvent &event)
{Destroy();
}void wx01Dialog::OnQuit(wxCommandEvent &event)
{Destroy();
}void wx01Dialog::OnAbout(wxCommandEvent &event)
{wxString msg = wxbuildinfo(long_f);wxMessageBox(msg, _("Welcome to..."));
}

2. wxMain.h

/**************************************************************** Name:      wx01Main.h* Purpose:   Defines Application Frame* Author:    Gary (garyao@126.com)* Created:   2022-07-30* Copyright: Gary ()* License:**************************************************************/#ifndef WX01MAIN_H
#define WX01MAIN_H#include "wx01App.h"#include "GUIDialog.h"class wx01Dialog: public GUIDialog
{public:wx01Dialog(wxDialog *dlg);~wx01Dialog();private://7. 虚拟事件,在主程序里重写virtual void OnClose(wxCloseEvent& event);virtual void OnQuit(wxCommandEvent& event);virtual void OnAbout(wxCommandEvent& event);
};
#endif // WX01MAIN_H

3. wx01App.h

/**************************************************************** Name:      wx01App.h* Purpose:   Defines Application Class* Author:    Gary (garyao@126.com)* Created:   2022-07-30* Copyright: Gary ()* License:**************************************************************/#ifndef WX01APP_H
#define WX01APP_H
//1.首先,需要继承wxApp
#include <wx/app.h>class wx01App : public wxApp
{public:virtual bool OnInit();
};#endif // WX01APP_H

4. wx01App.cpp

/**************************************************************** Name:      wx01App.cpp* Purpose:   Code for Application Class* Author:    Gary (garyao@126.com)* Created:   2022-07-30* Copyright: Gary ()* License:**************************************************************/#ifdef WX_PRECOMP
#include "wx_pch.h"
#endif#ifdef __BORLANDC__
#pragma hdrstop
#endif //__BORLANDC__#include "wx01App.h"
#include "wx01Main.h"
//3. 主函数表明程序的执行
IMPLEMENT_APP(wx01App);
//4. 程序初始化
bool wx01App::OnInit()
{wx01Dialog* dlg = new wx01Dialog(0L);dlg->Show();return true;
}

5. GUIDialog.h

///
// C++ code generated with wxFormBuilder (version Feb 17 2007)
// http://www.wxformbuilder.org/
//
// PLEASE DO "NOT" EDIT THIS FILE!
///#ifndef __GUIDialog__
#define __GUIDialog__// Define WX_GCH in order to support precompiled headers with GCC compiler.
// You have to create the header "wx_pch.h" and include all files needed
// for compile your gui inside it.
// Then, compile it and place the file "wx_pch.h.gch" into the same
// directory that "wx_pch.h".
#ifdef WX_GCH
#include <wx_pch.h>
#else
#include <wx/wx.h>
#endif#include <wx/button.h>
#include <wx/statline.h>//2.其次,需要一个继承与wxDialog或wxFrame的类
//////
/// Class GUIDialog
///
class GUIDialog : public wxDialog
{DECLARE_EVENT_TABLE()private://6. 事件绑定// Private event handlersvoid _wxFB_OnClose( wxCloseEvent& event ){ OnClose( event ); }void _wxFB_OnAbout( wxCommandEvent& event ){ OnAbout( event ); }void _wxFB_OnQuit( wxCommandEvent& event ){ OnQuit( event ); }protected:enum{idBtnAbout = 1000,idBtnQuit,};wxStaticText* m_staticText1;wxButton* BtnAbout;wxStaticLine* m_staticline1;wxButton* BtnQuit;// Virtual event handlers, overide them in your derived classvirtual void OnClose( wxCloseEvent& event ){ event.Skip(); }virtual void OnAbout( wxCommandEvent& event ){ event.Skip(); }virtual void OnQuit( wxCommandEvent& event ){ event.Skip(); }public:GUIDialog( wxWindow* parent, int id = wxID_ANY, wxString title = wxT("wxWidgets Application Template"), wxPoint pos = wxDefaultPosition, wxSize size = wxDefaultSize, int style = wxDEFAULT_DIALOG_STYLE );};#endif //__GUIDialog__

6. GUIDialog.cpp

///
// C++ code generated with wxFormBuilder (version Feb 17 2007)
// http://www.wxformbuilder.org/
//
// PLEASE DO "NOT" EDIT THIS FILE!
///#include "wx/wxprec.h"#ifdef __BORLANDC__
#pragma hdrstop
#endif //__BORLANDC__#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif //WX_PRECOMP#include "GUIDialog.h"///
BEGIN_EVENT_TABLE( GUIDialog, wxDialog )EVT_CLOSE( GUIDialog::_wxFB_OnClose )EVT_BUTTON( idBtnAbout, GUIDialog::_wxFB_OnAbout )EVT_BUTTON( idBtnQuit, GUIDialog::_wxFB_OnQuit )
END_EVENT_TABLE()
//5. 构建窗口
GUIDialog::GUIDialog( wxWindow* parent, int id, wxString title, wxPoint pos, wxSize size, int style ) : wxDialog( parent, id, title, pos, size, style )
{this->SetSizeHints( wxDefaultSize, wxDefaultSize );wxBoxSizer* bSizer1;bSizer1 = new wxBoxSizer( wxHORIZONTAL );m_staticText1 = new wxStaticText( this, wxID_ANY, wxT("Welcome To\nwxWidgets"), wxDefaultPosition, wxDefaultSize, 0 );m_staticText1->SetFont( wxFont( 20, 74, 90, 90, false, wxT("Arial") ) );bSizer1->Add( m_staticText1, 0, wxALL|wxEXPAND, 5 );wxBoxSizer* bSizer2;bSizer2 = new wxBoxSizer( wxVERTICAL );BtnAbout = new wxButton( this, idBtnAbout, wxT("&About"), wxDefaultPosition, wxDefaultSize, 0 );bSizer2->Add( BtnAbout, 0, wxALL, 5 );m_staticline1 = new wxStaticLine( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL );bSizer2->Add( m_staticline1, 0, wxALL|wxEXPAND, 5 );BtnQuit = new wxButton( this, idBtnQuit, wxT("&Quit"), wxDefaultPosition, wxDefaultSize, 0 );bSizer2->Add( BtnQuit, 0, wxALL, 5 );bSizer1->Add( bSizer2, 1, wxEXPAND, 5 );this->SetSizer( bSizer1 );this->Layout();bSizer1->Fit( this );
}

7. 最后还有一个文件:

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<wxFormBuilder_Project><FileVersion major="1" minor="5" /><object class="Project" expanded="1"><property name="bitmaps"></property><property name="code_generation">C++</property><property name="encoding">UTF-8</property><property name="file">GUIDialog</property><property name="first_id">1000</property><property name="icons"></property><property name="internationalize">0</property><property name="name">MyProject</property><property name="path">.</property><property name="precompiled_header">wx/wxprec.h</property><property name="relative_path">1</property><property name="use_enum">1</property><property name="use_microsoft_bom">0</property><object class="Dialog" expanded="1"><property name="bg"></property><property name="center"></property><property name="enabled">1</property><property name="extra_style"></property><property name="fg"></property><property name="font"></property><property name="hidden">0</property><property name="id">wxID_ANY</property><property name="maximum_size"></property><property name="minimum_size"></property><property name="name">GUIDialog</property><property name="pos"></property><property name="size"></property><property name="style">wxDEFAULT_DIALOG_STYLE</property><property name="subclass"></property><property name="title">wxWidgets Application Template</property><property name="tooltip"></property><property name="window_extra_style"></property><property name="window_style"></property><event name="OnClose">OnClose</event><event name="OnSize"></event><object class="wxBoxSizer" expanded="1"><property name="minimum_size"></property><property name="name">bSizer1</property><property name="orient">wxHORIZONTAL</property><object class="sizeritem" expanded="1"><property name="border">5</property><property name="flag">wxALL|wxEXPAND</property><property name="proportion">0</property><object class="wxStaticText" expanded="1"><property name="bg"></property><property name="enabled">1</property><property name="fg"></property><property name="font">Arial,90,90,20</property><property name="hidden">0</property><property name="id">wxID_ANY</property><property name="label">Welcome To
wxWidgets</property><property name="maximum_size"></property><property name="minimum_size"></property><property name="name">m_staticText1</property><property name="permission">protected</property><property name="pos"></property><property name="size"></property><property name="style"></property><property name="subclass"></property><property name="tooltip"></property><property name="window_extra_style"></property><property name="window_style"></property></object></object><object class="sizeritem" expanded="1"><property name="border">5</property><property name="flag">wxEXPAND</property><property name="proportion">1</property><object class="wxBoxSizer" expanded="1"><property name="minimum_size"></property><property name="name">bSizer2</property><property name="orient">wxVERTICAL</property><object class="sizeritem" expanded="1"><property name="border">5</property><property name="flag">wxALL</property><property name="proportion">0</property><object class="wxButton" expanded="1"><property name="bg"></property><property name="enabled">1</property><property name="fg"></property><property name="font"></property><property name="hidden">0</property><property name="id">idBtnAbout</property><property name="label">&amp;About</property><property name="maximum_size"></property><property name="minimum_size"></property><property name="name">BtnAbout</property><property name="permission">protected</property><property name="pos"></property><property name="size"></property><property name="style"></property><property name="subclass"></property><property name="tooltip"></property><property name="window_extra_style"></property><property name="window_style"></property><event name="OnButtonClick">OnAbout</event></object></object><object class="sizeritem" expanded="1"><property name="border">5</property><property name="flag">wxALL|wxEXPAND</property><property name="proportion">0</property><object class="wxStaticLine" expanded="1"><property name="bg"></property><property name="enabled">1</property><property name="fg"></property><property name="font"></property><property name="hidden">0</property><property name="id">wxID_ANY</property><property name="maximum_size"></property><property name="minimum_size"></property><property name="name">m_staticline1</property><property name="permission">protected</property><property name="pos"></property><property name="size"></property><property name="style">wxLI_HORIZONTAL</property><property name="subclass"></property><property name="tooltip"></property><property name="window_extra_style"></property><property name="window_style"></property></object></object><object class="sizeritem" expanded="1"><property name="border">5</property><property name="flag">wxALL</property><property name="proportion">0</property><object class="wxButton" expanded="1"><property name="bg"></property><property name="enabled">1</property><property name="fg"></property><property name="font"></property><property name="hidden">0</property><property name="id">idBtnQuit</property><property name="label">&amp;Quit</property><property name="maximum_size"></property><property name="minimum_size"></property><property name="name">BtnQuit</property><property name="permission">protected</property><property name="pos"></property><property name="size"></property><property name="style"></property><property name="subclass"></property><property name="tooltip"></property><property name="window_extra_style"></property><property name="window_style"></property><event name="OnButtonClick">OnQuit</event></object></object></object></object></object></object></object>
</wxFormBuilder_Project>

Codeblocks + Widgets 创建窗口代码分析相关推荐

  1. 【DND图形库】三、创建窗口和绘制精灵

    三.创建窗口和绘制精灵与文本 (甲)创建窗口 代码如下,很简明,通过调用一系列SetWindow函数: virtual void _init() override {//初始化sys->SetW ...

  2. mybatis源码之执行insert代码分析

    系列文档: mybatis源码之创建SqlSessionFactory代码分析 mybatis源码之创建SqlSessionFactory代码分析 - mapper xml解析 mybatis源码之执 ...

  3. kernel 3.10代码分析--KVM相关--虚拟机创建\VCPU创建\虚拟机运行

    分三部分:一是KVM虚拟机创建.二是VCPU创建.三是KVM虚拟机运行 第一部分: 1.基本原理 如之前分析,kvm虚拟机通过对/dev/kvm字符设备的ioctl的System指令KVM_CREAT ...

  4. linux内存映射起始地址,内存初始化代码分析(三):创建系统内存地址映射

    内存初始化代码分析(三):创建系统内存地址映射 作者:linuxer 发布于:2016-11-24 12:08 分类:内存管理 一.前言 经过内存初始化代码分析(一)和内存初始化代码分析(二)的过渡, ...

  5. 关于《机器学习实战》中创建决策树的核心代码分析

       关于<机器学习实战>中创建决策树的核心代码分析                 SIAT  nyk          2017年10月21日星期六 一.源码内容 def create ...

  6. 6.面向对象,构造器,递归以及对象创建时内存分析(内含代码与练习)

    面向对象的概念以及特征 概念 实质上将 "数据" 与 "行为" 的过程, 以类的形式封装起来, 一切以 对象 为中心的 面向对象的程序设计过程中有两个重要概念: ...

  7. 基于Android T代码分析: 在freeform窗口的标题栏拖动时移动窗口流程和拖动freeform窗口边沿改变大小流程

    基于Android T代码分析: 在freeform窗口的标题栏拖动时移动窗口流程和拖动freeform窗口边沿改变大小流程在线看Android源代码网址: http://aospxref.com/a ...

  8. 用自定义代码分析来标准开发人员的开发规范

      代码分析(关于代码分析详见http://msdn.microsoft.com/zh-cn/library/3z0aeatx(VS.80).aspx),是visual studio开发工具中提供的一 ...

  9. 【OpenGL】七、桌面窗口搭建 ( 导入头文件 | 桌面程序入口函数 | 注册窗口 | 创建窗口 | 显示窗口 )

    文章目录 一.导入头文件 二.桌面程序入口函数 三.注册窗口 四.创建窗口 五.显示窗口 六.完整代码示例 七.相关资源 基于 [OpenGL]一.Visual Studio 2019 创建 Wind ...

最新文章

  1. ML之回归预测:利用十(xgboost,10-1)种机器学习算法对无人驾驶汽车系统参数(2017年的data,18+2)进行回归预测值VS真实值——bug调试记录
  2. 参赛作品介绍 | IM体感游戏、校园管家...这些创意颠覆你的想象!
  3. LeetCode 52. N-Queens II
  4. 今日发现的:一个类似Google Baidu的搜索引擎[C#]代码比较简单
  5. 外国人怎么看祖冲之量子计算机,我国“祖冲之号”量子计算机再次刷新纪录:1.2 小时完成超算 8 年计算量...
  6. Android系统启动过程详解
  7. Windows核心编程_FS段寄存器
  8. 服务器(Windows系统)自建filebrowser网盘服务器超详细教程
  9. Oracle 10G R2 让表常驻内存
  10. 尚学堂--面向对象2
  11. Android第二十课 解决Logcat无法输出调试信息
  12. linux cpu mysql_Linux 指定MySQL服务运行的CPU核心(数)
  13. 西电网络攻防大赛--渗透测试第一题
  14. 判断是否为字母 ctype
  15. 20182319《数据结构与面向对象程序设计》实验二报告
  16. 由动物启发的15个管理学定律
  17. u盘如何安装xp和linux,怎样从U盘安装Windows XP?
  18. 给IBM的黑科技跪了:量子计算机强势来袭!
  19. EnjoyToShare | 考研英语复试口语
  20. java多线程 占用内存_java线程池常驻线程占内存吗

热门文章

  1. H5申请谷歌分析 google analytics,以及使用谷歌分析进行网站、应用的数据分析
  2. Python 下载无水印的短视频
  3. 物理真机上LUKS结合TPM的测试 —— 使用随机数密钥
  4. 用C语言来实现五子棋小游戏
  5. greenplum安装(单机环境)
  6. 下载配置JDK开发环境,记事本编写Hello world
  7. 厌倦了大众字体?你可以用这个项目自创一款手写体
  8. insightface项目Retinaface训练方法
  9. Unity预制件Prefab的概念,创建与加载(包括动态加载)
  10. 【C语言】如何应用%.0f