我们知道,在使用Win32或者是MFC的时候,最简单的Hello World程序就是用消息框蹦出来Hello World了. 下面我就用wxWindows同样来做一个,源代码如下:
// ============================== // filename xi.cpp // ============================== #ifndef _XI_CPP #define _XI_CPP#include "wx\wx.h" // ==================== // main application class. // ==================== class xiApp : public wxApp { public: // Init Event. virtual bool OnInit(); }; #endif IMPLEMENT_APP(xiApp) // ==================== // initialization. // ==================== bool xiApp::OnInit() { wxString msg; msg.Printf( _T("Hello World!\n") _T("Welcome to %s"), wxVERSION_STRING); wxMessageBox(msg, _T("Hello World Sample"), wxOK | wxICON_INFORMATION, NULL); return false; }
由于程序需要把Settings配置好,主要是链接库和头文件的目录的包含,所以初学者务必参看我写的安装. 取名为xiApp,是细程序的意思. 上面的IMPLEMENT_APP(xiApp) ,是把xiApp做为Entry Class的,就是程序的入口. xiApp::OnInit()是bool返回值的,如果初始化成功就返回ture,程序运行;返回false的话,初始化失败,程序就结束. 在上面,显示了一个消息框之后,我让它返回了false,程序就结束了,否则,由于我没有创建主框架窗口FrameWnd,程序会在后台运行的,但是没有办法和它交互,只有通过任务管理器结束它. 截图如下: 

|