Contents Up Previous Next 原文へのリンク

wxWidgetsアプリケーションを書く:大雑把なガイド
  Writing a wxWidgets application: a rough guide

wxWidgetsアプリケーションを書き始めるには,wxAppを継承して wxApp::OnInitをオーバーライドする必要がある.

アプリケーションは必ずwxFramewxDialogの トップレベルウィンドウを持つ. 各フレームは幾つかのクラスのインスタンスを持つだろう.例えばwxPanel, wxSplitterWindow,その他のウィンドウやコントロール.

フレームはwxMenuBar,wxToolBar, ステータスライン, フレームがアイコン化されたときのアイコン(wxIcon)を 持つことが出来る.

wxPanelは,ユーザーと対話するためのコントロール (wxControlから継承されたクラス)を配置するのに使われる. コントロールにはwxButton,wxCheckBox, wxChoice, wxListBox, wxRadioBox, wxSlider等がある.

wxDialogのインスタンスもコントロールのために使われる.そしてダイアログ にはseparate frameを必要としないという利点がある.

誰かseparate frameが何か教えて by 思兼

ダイアログを作ってそこにいろいろ配置する変わりに,便利なコモンダイアログを利用する事が出来る. 例えばコモンダイアログには wxMessageDialogwxFileDialog等がある.

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.

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.

描画にはデバイスコンテキスト(DC)を用い,ウィンドウに直接描画はしない. wxDCwxClientDC, wxPaintDC, wxMemoryDC, wxPostScriptDC, wxMemoryDC, wxMetafileDC , wxPrinterDCの親クラスである. wxDCを引数に取るパラメータがあれば,これらのどのDCもその関数に渡せる. そして,幾つかの別のデバイスに描画するのに,同じコードを使える. wxDCのメンバ関数を使って描画する事が出来る.メンバ関数には wxDC::DrawLine , wxDC::DrawText 等がある. ブラシ(wxBrush)やペン(wxPen)で, 描画時の色(wxColour)を制御できる,

イベントを処理するために,DECLARE_EVENT_TABLE マクロをウィンドウクラスの宣言部分に書き, BEGIN_EVENT_TABLE から END_EVENT_TABLE までのブロックを実装ファイルに書く. そしてこのブロックの中に,イベント(例:マウスクリック)をメンバ関数にマップするマクロを書く. それらは,デフォルトの(wxKeyEventwxMouseEvent等のための)イベントハンドラをオーバーライドすることになる.

最近のアプリケーションは,オンラインでハイパーテキストを用いたヘルプシステムを持っている. これを実現するには,wxHelpと,wxHelpを制御するwxHelpControllerが 必要になる.

GUIアプリケーションも,グラフィック以外のこともしないといけない. リストやハッシュテーブルが欲しければ,wxList, wxStringList , wxHashMapがある.  マルチプラットフォームなファイルを扱う関数群file functionsが必用だろう.  パスのリストを保存し検索するのにはwxPathListが便利だ. 他のにも雑多な,OS関連やその他の関数がある.

Classes by Categoryにクラスの一覧がある.

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, wxStringList 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.