Re: Win32lib dialogs within proc's
- Posted by Matthew Lewis <MatthewL at KAPCOUSA.COM> Mar 10, 2000
- 418 views
> From: Irv Mullins > > Ermm. I have dozens of such "user built dialogs" in my programs. > I just build a new window, place an edit text and/or checkboxes or > radio buttons as needed, and probably an "OK" button and a "cancel" > button, which when clicked transfer the info or do the task > called for, > then close the window. > > I'm trying to think of where something like this would be > needed. So far, > nothing comes to mind. > I seem to have solved my problem, but here's what I'm doing. I'm working on writing a game that's basically like Magic the Gathering (a fantasy card game--and actually the reason I started using Euphoria a couple of years ago). Each card has it's own special procedures for doing whatever the card's effects are in the game. For instance, when you cast a Lightning Bolt, you then choose a target, and the Lightning Bolt does some damage to whatever your target was. Well, I've got a ton of procedures that need to do such a thing. In order to find out what the target is, I need to open up the window, and once the window is done, go right back to the spot in the card's event code. If I simply open the window, it comes right back to the code, without giving the user a chance to respond. > > Actually, there shouldn't be many globals required. Perhaps > you need to > reconsider > how your program functions. In Windows, there's generally _not_ a main > flow - > just a state that is modified in response to events, and perhaps some > procedures that > are run on demand. (sort, print, etc) > I've definitely considered this, but I haven't come up with any satisfactory solutions yet. At least, not without completely rewriting the basic engine of the game... In any case, I hacked win32lib, and came up with something that seems to work. I created a procedure called EventLoop, which just runs an extra event loop on top of WinMain's (in fact, EventLoop is just WinMain modified). When you've finished with the Loop, you just set the last value of EventLoopExit to true, and it ends, and you continue. This should allow multiple nested loops, using EventLoopExit as a stack of flags. A definite caveat is that win32lib won't detect if you've closed down the main window (to exit the program) from within the event loop. global sequence EventLoopExit global procedure EventLoop( integer id, integer style ) -- main routine atom hWnd atom msg atom ele -- allocate a message buffer msg = allocate_struct(SIZEOF_MESSAGE) EventLoopExit &= 0 ele = length(EventLoopExit) openWindow( id, style ) -- message loop while c_func( xGetMessage, { msg, NULL, 0, 0 } ) and not EventLoopExit[ele] do c_proc( xTranslateMessage, { msg } ) c_proc( xDispatchMessage, { msg } ) end while EventLoopExit = EventLoopExit[1..ele-1] end procedure