The first example we will develop is minimal: a “micro” blogging application. It is stripped down so that all it can do is display an About box, but it will show you the principles of building a wxErlang application. In the next section, you’ll see how to add the blogging functionality.
Our program is given in one file, microblog.erl, which begins like this:
%% A micro-blog, which sets up a frame with menus, and allows an %% "about" box to be displayed. -module(microblog). -compile(export_all). -include_lib("wx/include/wx.hrl"). -define(ABOUT,?wxID_ABOUT). -define(EXIT,?wxID_EXIT)
This shows the inclusion of the wx.hrl header file (located in an
installation-specific position) that contains definitions of the standard
identifiers and types. The local macro definitions of
EXIT link these to the standard
wx identifiers for these menu items. This will
allow the application to handle them in a platform-specific way.
The top-level function for our example is
%% Top-level function: create the wx-server, the graphical objects, %% show the application, process and clean up on termination. start() -> wx:new(), Frame = wxFrame:new(wx:null(), ?wxID_ANY, "MicroBlog"), setup(Frame), wxFrame:show(Frame), loop(Frame), wx:destroy().
This function first creates an instance of the
wx-server, and before termination ensures that
it is destroyed and memory is reclaimed. The principal graphical object is
wxFrame, created with no parent