Towards a native windows GUI
Joe Armstrong (AL/EAB)
Wed Aug 17 11:45:16 CEST 2005
Some random thoughts on a windows GUI:
About once every second year I get the same crazy thought - why not run
Erlang on windows - I hack for a bit and then give up and go back to *nix
So I started googeling and found some interesting stuff.
I have often toyed with the idea of using the win32 api to do graphics and *not*
use a library to hide the gory details - but how easy is this. Having made ex11
which has a raw X11 interface I thought that it might be nice to look at the
This is what I have learnt so far. (Actually I may be wrong here - so I'd be grateful if a real windows expert could fill me in on the details, and correct my mistakes)
I started by reading http://www.winprog.org/tutorial/
This was very interesting - what I learnt was:
A win32 applications is made up from windows. Inside a window you can place several
"controls" - a control is something like a button, a listbox, and editor, ...
Controls *are* windows.
You manipulate controls by sending them *messages*
There are two primitives that send Messages
PostMessage and SendMessage
PostMessage is asynchronous - SendMessage is like a remote procedure call.
It appears that a very large number of the routines in the winapi merely are wrappers
to SendMessage and PostMessage.
Thus interfacing Erlang to the windapi "merely" involves interfacing SendMessage
and PostMessage and a few small routines like CreateWindowEx.
<< I think you could get a lot of mileage from just interfacing CreateWindowEx, SendMessage and PostMessage - but this might be incorrect << can a real windows expert comment on this>> >>
Next problem - where are the arguments to PostMessage and SendMessage documented?
Not in the APIs and you can't read the source - BUT - I did find the following
Has a free program that actually makes windows useful - this stuff is *amazing*
I didn't realise you can automate any windows operation - this is very cool. There's
lots of documentaion on the arguments to the messages on this site.
Then I found polyML
The polyml distribution has all the answers
Writing a native window app in polyML is "easy" (TM)
Reproducing this in Erlang seems not unreasonable.
Then I thought to myself "can I write postMessage, sendMessage etc. as BIFs"
this requires compiling Erlang on windows :-(
I tried mingw - no success so I read the read me on "compiling for windows" -
So I thought "how do I write a port program for windows" - and we're back to
"interfacing Erlang to C" - triple yuck.
Now all the methods for interfacing Erlang to C suck greatly. Why can't you just
make a generic metacall from erlang to C - is this possible? - answer "possibly"
Then I found
Avcall is part of the ffcall package - now this looks hopeful and does compile
So now the plan is this:
Use avcall to write a generic interface to the win32api
Implement PostMessage SendMessage and CreatWindowEx using the generic interface
write a simple windows app with the above, then recode the polyML stuff in Erlang.
This is leading me into unexplored terratories - since I know *nothing*
about the problems of compiling C apps on windows - I'd like to end up with
rock solid native compiled winapi applications -
I really like some feedback here from a real windows expert - are my statements
about windows correct, is the API as simple as it appears to be?
The really interesting observation is that the underlying windows GUI architecture is
a pure message passing system - (Like X) - which should mean that it will interface
well with the Erlang process model (like the X11 ex11 code did).
Is this observation correct?
More information about the erlang-questions