A rough guide for wxWidgets programming
从最基本的概念开始,一个wxWidgets程序需要从wxApp继承一个应用程序类并且该程序还必须有一个top-level的窗口(继承自wxFrame或者wxDialog)。这样就组成了一个最下化的应用程序实例,剩下的就是基于你设计的界面添加和逻辑部分。在Frame/Dialog之上,有wxPanel,wxSplitterWindow或者其他的窗口控件可供使用,在上一篇的Sizer/Frame/Panel关系的文章中大家已经看到如何利用这些元素组织和设计程序界面。
To set a wxWidgets application going, you will need to derive a wxApp class and override wxApp::OnInit.
An application must have a top-level wxFrame or wxDialog window. Each frame may contain one or more instances of classes such as wxPanel, wxSplitterWindow or other windows and controls.
A frame can have a wxMenuBar, a wxToolBar, a status line, and a wxIcon for when the frame is iconized.
A wxPanel is used to place controls (classes derived from wxControl) which are used for user interaction. Examples of controls are wxButton, wxCheckBox, wxChoice, wxListBox, wxRadioBox, wxSlider.
Instances of wxDialog can also be used for controls and they have the advantage of not requiring a separate frame.
最短的wxWidgets程序(网上流传):
#include"wx/wx.h"
class Plot3DApp:public wxApp{
public:
virtual bool OnInit();
};
IMPLEMENT_APP(Plot3DApp)
bool Plot3DApp::OnInit(){
wxFrame *frame=new wxFrame(NULL,wxID_ANY,wxT("Plot3D"));
frame->Show(true);
return true;
}
Instead of creating a dialog box and populating it with items, it is possible to choose one of the convenient common dialog classes, such as wxMessageDialog and wxFileDialog.
You never draw directly onto a window - you use a device context (DC). wxDC is the base for wxClientDC, wxPaintDC, wxMemoryDC, wxPostScriptDC, wxMemoryDC, wxMetafileDC and wxPrinterDC. If your drawing functions have wxDC as a parameter, you can pass any of these DCs to the function, and thus use the same code to draw to several different devices. You can draw using the member functions of wxDC, such as wxDC::DrawLine and wxDC::DrawText. Control colour on a window (wxColour) with brushes (wxBrush) and pens (wxPen).
To intercept events, you add a DECLARE_EVENT_TABLE macro to the window class declaration, and put a BEGIN_EVENT_TABLE … END_EVENT_TABLE block in the implementation file. Between these macros, you add event macros which map the event (such as a mouse click) to a member function. These might override predefined event handlers such as for wxKeyEvent and wxMouseEvent.
Most modern applications will have an on-line, hypertext help system; for this, you need wxHelp and the wxHelpController class to control wxHelp.
GUI applications aren’t all graphical wizardry. List and hash table needs are catered for by wxList and wxHashMap. You will undoubtedly need some platform-independent file functions, and you may find it handy to maintain and search a list of paths using wxPathList. There’s a miscellany of operating system and other functions.
See also Classes by Category for a list of classes.
以上链接可以直接访问参考。
Related posts:
- wxWidgets Programming: Sizer, Frame and Panel
- Using XRC in wxWidgets based Application for UI design
- Book: Cross-Platform GUI Programming with wxWidgets (Bruce Perens)(含中英文版本下载地址)
- wxWidget Layout Algorithm Demo - BoxPlanner
- CodeLite Initializaion analysis - 初始化流程分析(1)
- Python Programming – Sqlite for data persistence
- Python programming- List extend() and append()
- Core Python Programming(1) - Basic
- 关于wxSmith与其他RAD之间的比较














