差分

このページの2つのバージョン間の差分を表示します。

この比較画面へのリンク

両方とも前のリビジョン前のリビジョン
次のリビジョン
前のリビジョン
wxwidgets:helloworld [2025/05/23 09:36] freemikanwxwidgets:helloworld [2025/05/24 16:35] (現在) – [結果の確認] Mark out generated file freemikan
行 1: 行 1:
 ====== Hello World ====== ====== Hello World ======
 +{{:wxwidgets:wxwidgets_logo_title.svg?350|wxWidgets Logo}}
  
-{{:wxwidgets:wxwidgets_logo_blocks.svg?150|wxWidgets Logo}} 
  
-作業ディレク+===== 前提 ===== 
 +[[install|インスールのページ]]に従い、wxWidget 3.2がインストール済みであることを前提とします。
  
-$HOME/code/wxwidgets/hello-wxwidgets+ 
 +===== 作業ディレクトリの用意 ===== 
 +作業ディレクトリは $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__ __main.cpp__
行 16: 行 39:
 // Start of wxWidgets "Hello World" Program // Start of wxWidgets "Hello World" Program
 #include <wx/wx.h> #include <wx/wx.h>
-  + 
-class MyApp : public wxApp +class MyApp : public wxApp {
-{+
 public: public:
-    bool OnInit() override;+  bool OnInit() override;
 }; };
- +
 wxIMPLEMENT_APP(MyApp); wxIMPLEMENT_APP(MyApp);
-  + 
-class MyFrame : public wxFrame +class MyFrame : public wxFrame {
-{+
 public: public:
-    MyFrame(); +  MyFrame(); 
- +
 private: private:
-    void OnHello(wxCommandEvent& event); +  void OnHello(wxCommandEvent &event); 
-    void OnExit(wxCommandEvent& event); +  void OnExit(wxCommandEvent &event); 
-    void OnAbout(wxCommandEvent& event);+  void OnAbout(wxCommandEvent &event);
 }; };
-  + 
-enum +enum { ID_Hello = 1 }; 
-{ + 
-    ID_Hello = 1 +bool MyApp::OnInit() { 
-}; +  MyFrame *frame = new MyFrame(); 
-  +  frame->Show(true); 
-bool MyApp::OnInit() +  return true;
-+
-    MyFrame *frame = new MyFrame(); +
-    frame->Show(true); +
-    return true;+
 } }
-  + 
-MyFrame::MyFrame() +MyFrame::MyFrame() : wxFrame(nullptr, wxID_ANY, "Hello World") { 
-    : wxFrame(nullptr, wxID_ANY, "Hello World") +  wxMenu *menuFile = new wxMenu; 
-+  menuFile->Append(ID_Hello, "&Hello...\tCtrl-H", 
-    wxMenu *menuFile = new wxMenu; +                   "Help string shown in status bar for this menu item"); 
-    menuFile->Append(ID_Hello, "&Hello...\tCtrl-H", +  menuFile->AppendSeparator(); 
-                     "Help string shown in status bar for this menu item"); +  menuFile->Append(wxID_EXIT); 
-    menuFile->AppendSeparator(); + 
-    menuFile->Append(wxID_EXIT); +  wxMenu *menuHelp = new wxMenu; 
-  +  menuHelp->Append(wxID_ABOUT); 
-    wxMenu *menuHelp = new wxMenu; + 
-    menuHelp->Append(wxID_ABOUT); +  wxMenuBar *menuBar = new wxMenuBar; 
-  +  menuBar->Append(menuFile, "&File"); 
-    wxMenuBar *menuBar = new wxMenuBar; +  menuBar->Append(menuHelp, "&Help"); 
-    menuBar->Append(menuFile, "&File"); + 
-    menuBar->Append(menuHelp, "&Help"); +  SetMenuBar(menuBar); 
-  + 
-    SetMenuBar( menuBar ); +  CreateStatusBar(); 
-  +  SetStatusText("Welcome to wxWidgets!"); 
-    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::OnHello, this, ID_Hello); +  Bind(wxEVT_MENU, &MyFrame::OnExit, this, wxID_EXIT);
-    Bind(wxEVT_MENU, &MyFrame::OnAbout, this, wxID_ABOUT); +
-    Bind(wxEVT_MENU, &MyFrame::OnExit, this, wxID_EXIT);+
 } }
-  + 
-void MyFrame::OnExit(wxCommandEvent& event) +void MyFrame::OnExit(wxCommandEvent &event) { Close(true); } 
-{ + 
-    Close(true);+void MyFrame::OnAbout(wxCommandEvent &event) { 
 +  wxMessageBox("This is a wxWidgets Hello World example", "About Hello World", 
 +               wxOK | wxICON_INFORMATION);
 } }
-  + 
-void MyFrame::OnAbout(wxCommandEvent& event) +void MyFrame::OnHello(wxCommandEvent &event) { 
-+  wxLogMessage("Hello world from wxWidgets!");
-    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> </code>
  
-コンパイル+ 
 +===== コンパイル =====
  
 <cli> <cli>
行 97: 行 108:
 </cli> </cli>
  
-コンパイル結果の確認+==== 結果の確認 ====
  
 <cli> <cli>
行 103: 行 114:
 合計 200 合計 200
 -rw-rw-r-- 1 freemikan freemikan   1597  5月 23 07:38 main.cpp -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+-rw-rw-r-- 1 freemikan freemikan 197544  5月 23 07:38 main.o    ←生成されたオブジェクトファイル
 </cli> </cli>
  
-リンク+ 
 +===== リンク =====
  
 <cli> <cli>
行 112: 行 124:
 </cli> </cli>
  
-リンク結果の確認+ 
 +==== 結果の確認 ====
  
 <cli> <cli>
 $ ls -l $ ls -l
 合計 348 合計 348
--rwxrwxr-x 1 freemikan freemikan 151144  5月 23 07:41 hello-wxwidgets+-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   1597  5月 23 07:38 main.cpp
 -rw-rw-r-- 1 freemikan freemikan 197544  5月 23 07:38 main.o -rw-rw-r-- 1 freemikan freemikan 197544  5月 23 07:38 main.o
 </cli> </cli>
  
-実行+ 
 +===== 実行 =====
  
 <cli> <cli>
文書の先頭へ