整理了一下在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. ASP.NET Core 2 学习笔记(四)依赖注入
  2. java 自定义注解_两步实现Java自定义注解
  3. Spring Boot ApplicationContextRunner 测试指南
  4. 操作系统原理:页置换算法,FIFO,LRU,Clock,LFU,二次机会法
  5. leetcode 剑指 Offer 05. 替换空格
  6. 判断二叉树是否是完全二叉树c语言_完全二叉树的节点数,你真的会算吗?
  7. eclipse--eclipse(JavaEE版本)部署Tomcat工程(转)
  8. 7-3 方格取数 (15 分)
  9. android 开发问题集(一):SDK更新后 运行程序报错Location of the Android SDK has not been setup in the preferences
  10. ip代理服务器软件25探索云速捷_使用代理进行Web网页抓取的基础
  11. 再学 GDI+[67]: 路径画刷(7) - 画个五角星
  12. [BZOJ1999][codevs1167][Noip2007]Core树网的核
  13. android小应用帮美女更衣系列一(附源码)
  14. GB35114---聊聊SM2签名格式
  15. 莫烦 pytorch
  16. 双层PDFmaker
  17. 输出魔方矩阵(C语言实现)
  18. eclipse IED的优化(gc.log)
  19. CMS 常见问题分析和解决方案
  20. 李宏毅机器学习 02回归

热门文章

  1. Spring Boot实战【上】
  2. python 气泡图 聚类_可视化数据分析软件 气泡图
  3. 5种不同的仓储堆垛机哪个更好用,海格里斯告诉你!
  4. laravel爬坑日记No query results for model [App\Admin\Models\Capacity\ProductPrice] threeForm
  5. 资料打印不用再跑文印店,网上打印省时省力
  6. 手机上计算机功能,手机上有计算器的赶紧看看,这个功能不说很多人不知道,赶紧告诉身边人...
  7. 4 赫斯曼网管软件重新申请序列号
  8. 【河北工业大学】考研初试复试资料分享
  9. 智慧燃气解决方案-最新全套文件
  10. java 既然出现double类型×2的n次方的时候计算结果出现偏差