C++ で書かれた wxTutorial by Franky Braem の例を wxHaskell に置き換えながら wxWidgets と wxHaskell の学習をしようと思います。
まず、C++のソースです。
- HelloWorldApp.h
// http://wiki.wxwidgets.org/Hello_World #ifndef INCLUDED_HELLOWORLDAPP_H #define INCLUDED_HELLOWORLDAPP_H // The HelloWorldApp class. This class shows a window // containing a statusbar with the text "Hello World" class HelloWorldApp : public wxApp { public: virtual bool OnInit(); }; DECLARE_APP(HelloWorldApp) #endif // INCLUDED_HELLOWORLDAPP_H
- HelloWorldApp.cpp
// For compilers that don't support precompilation, include "wx/wx.h" #include "wx/wxprec.h" #ifndef WX_PRECOMP # include "wx/wx.h" #endif #include "HelloWorldApp.h" IMPLEMENT_APP(HelloWorldApp) // This is executed upon startup, like 'main()' in non-wxWidgets programs. bool HelloWorldApp::OnInit() { wxFrame *frame = new wxFrame((wxFrame*) NULL, -1, _T("こんにちは wxWidgets の世界")); frame->CreateStatusBar(); frame->SetStatusText(_T("StatusBar:こんにちは世界。")); frame->Show(true); SetTopWindow(frame); return true; }
g++ HelloWorldApp.cpp `wx-config --libs` `wx-config --cxxflags` -o HelloWorldApp
コンパイルして実行すると最初に示した画像が表示されます。
http://wxhaskell.sourceforge.net/ ドメインから "statusBar" をキーワード検索すると Graphics.UI.WX.Menu が見つかりましたので、ベースの Hello world in wxHaskell を修正してみます。
module Main where import Graphics.UI.WX main :: IO () main = start hello hello :: IO () hello = do f <- frame [text := "こんにちは wxWidgets の世界"] field <- statusField [text := "StatusBar:こんにちは世界。"] set f [statusBar := [field]]
ghc -package wx wxhello.hs -o wxhello
C++ も wxHaskell も同じ動作をします。wxHaskellは簡潔!