HYPER MIKAN BOX
検索
最近の変更
メディアマネージャー
サイトマップ
文書の表示
以前のリビジョン
バックリンク
ログイン
トレース:
この文書は読取専用です。文書のソースを閲覧することは可能ですが、変更はできません。もし変更したい場合は管理者に連絡してください。
====== Hello World ====== {{:wxwidgets:wxwidgets_logo_title.svg?350|wxWidgets Logo}} ===== 前提 ===== [[install|インストールのページ]]に従い、wxWidget 3.2がインストール済みであることを前提とします。 ===== 作業ディレクトリの用意 ===== 作業ディレクトリは $HOME/code/wxwidgets/hello-wxwidgets とします。 <note> こういった名前やパスは、何かしら決めておかないと説明がしづらいので提示しているだけです。 同じ名前にする必要は全くありません。 ご自身の好みの場所に好きな名前で作成してください。 </note> まずディレクトリを作成して、そこに移動しておきます。 <cli> $ mkdir -p ~/code/wxwidgets/hello-wxwidgets $ cd $_ </cli> ===== プログラムのソースコード ===== 今回作成するプログラムのソースコードは、公式のドキュメントにあるHello Worldのサンプルをそのまま拝借します。 * https://docs.wxwidgets.org/latest/overview_helloworld.html ソースコードは1つのファイルのみで、名前はmain.cppとします。 __main.cpp__ <code cpp> /**************************************************************/ /* https://docs.wxwidgets.org/latest/overview_helloworld.html */ /**************************************************************/ // Start of wxWidgets "Hello World" Program #include <wx/wx.h> class MyApp : public wxApp { public: bool OnInit() override; }; wxIMPLEMENT_APP(MyApp); class MyFrame : public wxFrame { public: MyFrame(); private: void OnHello(wxCommandEvent &event); void OnExit(wxCommandEvent &event); void OnAbout(wxCommandEvent &event); }; enum { ID_Hello = 1 }; bool MyApp::OnInit() { MyFrame *frame = new MyFrame(); frame->Show(true); return true; } MyFrame::MyFrame() : wxFrame(nullptr, wxID_ANY, "Hello World") { wxMenu *menuFile = new wxMenu; menuFile->Append(ID_Hello, "&Hello...\tCtrl-H", "Help string shown in status bar for this menu item"); menuFile->AppendSeparator(); menuFile->Append(wxID_EXIT); wxMenu *menuHelp = new wxMenu; menuHelp->Append(wxID_ABOUT); wxMenuBar *menuBar = new wxMenuBar; menuBar->Append(menuFile, "&File"); menuBar->Append(menuHelp, "&Help"); SetMenuBar(menuBar); CreateStatusBar(); SetStatusText("Welcome to wxWidgets!"); Bind(wxEVT_MENU, &MyFrame::OnHello, this, ID_Hello); Bind(wxEVT_MENU, &MyFrame::OnAbout, this, wxID_ABOUT); Bind(wxEVT_MENU, &MyFrame::OnExit, this, wxID_EXIT); } void MyFrame::OnExit(wxCommandEvent &event) { Close(true); } void MyFrame::OnAbout(wxCommandEvent &event) { wxMessageBox("This is a wxWidgets Hello World example", "About Hello World", wxOK | wxICON_INFORMATION); } void MyFrame::OnHello(wxCommandEvent &event) { wxLogMessage("Hello world from wxWidgets!"); } </code> ===== コンパイル ===== <cli> $ g++ -c main.cpp `wx-config --cxxflags` </cli> ==== 結果の確認 ==== <cli> $ ls -l 合計 200 -rw-rw-r-- 1 freemikan freemikan 1597 5月 23 07:38 main.cpp -rw-rw-r-- 1 freemikan freemikan 197544 5月 23 07:38 main.o ←生成されたオブジェクトファイル </cli> ===== リンク ===== <cli> $ g++ -o hello-wxwidgets main.o `wx-config --libs` </cli> ==== 結果の確認 ==== <cli> $ ls -l 合計 348 -rwxrwxr-x 1 freemikan freemikan 151144 5月 23 07:41 hello-wxwidgets ←生成された実行可能バイナリファイル -rw-rw-r-- 1 freemikan freemikan 1597 5月 23 07:38 main.cpp -rw-rw-r-- 1 freemikan freemikan 197544 5月 23 07:38 main.o </cli> ===== 実行 ===== <cli> $ ./hello-wxwidgets </cli> {{ :wxwidgets:wxwidgets_hello.jpg |Hello wxWidgets}}
文書の先頭へ