![]() |
||
| Home | SwiftForth Archive | SwiftX Archive | |

>From: "C.G.W. van Zeeland" <cees_van_zeeland_at_compuserve.com>
>
>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 ;
Cees,
Perhaps a better translation of the message loop is
: MSGLOOP ( -- res ) BEGIN
PAD 0 0 0 PM_REMOVE PeekMessage IF
PAD CELL+ @ WM_QUIT = IF
PAD 2 CELLS + @ EXIT
THEN
PAD TranslateMessage DROP
PAD DispatchMessage DROP
ELSE DrawRectangle THEN
AGAIN ;
Or, if you object to the exit in the middle:
: MSGLOOP ( -- res ) BEGIN
PAD 0 0 0 PM_REMOVE PeekMessage IF
PAD CELL+ @ WM_QUIT <> DUP IF
PAD TranslateMessage DROP
PAD DispatchMessage DROP
THEN 0=
ELSE DrawRectangle 0 THEN
UNTIL PAD 2 CELLS + @ ;
but I find the second variation harder to read because
it has to carry a flag around instead of acting immediately
when the exit condition is detected.
Hope this helps!
Rick VanNorman
.
Received on Sun May 21 2000 - 10:06:41 PDT
This archive was generated by hypermail 2.2.0 : Thu Nov 20 2008 - 03:04:28 PST