Hi All,
I am doing some Forth exercises with Petzolds examples.
( Programming Windows: Chapter 5 - Random Rectangles )
I struggled with the Dispather
\ ===============================================
while (TRUE)
{
if (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE))
{
if (msg.message == WM_QUIT)
break ;
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
else
DrawRectangle (hwnd) ;
}
return msg.wParam ;
\ ==============================================
First I tried:
\ ==============================================
: Messageloop ( -- res )
begin winmsg 0 0 0 PM_REMOVE PeekMessage
if msg WM_QUIT <>
if winmsg TranslateMessage drop
winmsg DispatchMessage drop
then
else DrawRectangle
then
again ;
\ ==============================================
Although the program works, the Forth system hangs after closing the
Window.
Then I tried a more literal translation:
\ ==============================================
: Messageloop ( -- res )
true
begin
while winmsg 0 0 0 PM_REMOVE PeekMessage
if msg WM_QUIT =
if false
else winmsg TranslateMessage drop
winmsg DispatchMessage drop
true
then
else DrawRectangle
true
then
repeat winmsg 2 cells + @ ( wparam) ;
\ ==============================================
This version works fine, but now I am confused.
It seems to me that the Messageloop will only run the part between
WHILE and REPEAT until it recieves the WM_QUIT.
Obviously the two missing lines should be coded:
the first: TRUE
and the last after the REPEAT: winmsg 2 cells + @
I don't see how the last line is reached, and what sense makes the first?
Cees
.
Received on Sun May 21 2000 - 11:02:08 PDT
Subscribe to our e-mail list service. It's free for all SwiftForth and SwiftX users!
This archive was generated 08-Feb-2012. Archive updated nightly.