1%% 2%% %CopyrightBegin% 3%% 4%% Copyright Ericsson AB 2009-2018. All Rights Reserved. 5%% 6%% Licensed under the Apache License, Version 2.0 (the "License"); 7%% you may not use this file except in compliance with the License. 8%% You may obtain a copy of the License at 9%% 10%% http://www.apache.org/licenses/LICENSE-2.0 11%% 12%% Unless required by applicable law or agreed to in writing, software 13%% distributed under the License is distributed on an "AS IS" BASIS, 14%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15%% See the License for the specific language governing permissions and 16%% limitations under the License. 17%% 18%% %CopyrightEnd% 19%% 20%%%------------------------------------------------------------------- 21%%% File : hello.erl 22%%% Author : Matthew Harrison <harryhuk at users.sourceforge.net> 23%%% Description : _really_ minimal example of a wxerlang app 24%%% 25%%% Created : 18 Sep 2008 by Matthew Harrison <harryhuk at users.sourceforge.net> 26%%%------------------------------------------------------------------- 27-module(hello). 28 29-include_lib("wx/include/wx.hrl"). 30 31-export([start/0]). 32 33start() -> 34 Wx = wx:new(), 35 Frame = wx:batch(fun() -> create_window(Wx) end), 36 wxWindow:show(Frame), 37 loop(Frame), 38 wx:destroy(), 39 ok. 40 41create_window(Wx) -> 42 Frame = wxFrame:new(Wx, 43 -1, % window id 44 "Hello World", % window title 45 [{size, {600,400}}]), 46 47 48 wxFrame:createStatusBar(Frame,[]), 49 50 %% if we don't handle this ourselves, wxwidgets will close the window 51 %% when the user clicks the frame's close button, but the event loop still runs 52 wxFrame:connect(Frame, close_window), 53 54 ok = wxFrame:setStatusText(Frame, "Hello World!",[]), 55 Frame. 56 57loop(Frame) -> 58 receive 59 #wx{event=#wxClose{}} -> 60 io:format("~p Closing window ~n",[self()]), 61 ok = wxFrame:setStatusText(Frame, "Closing...",[]), 62 wxWindow:destroy(Frame), 63 ok; 64 Msg -> 65 io:format("Got ~p ~n", [Msg]), 66 loop(Frame) 67 end. 68 69 70