RE: [win32lib] Converting event-based system into procedural system.
- Posted by Mike <vulcan at win.co.nz> Dec 04, 2004
- 493 views
Patrick, Patrick Barnes wrote: > > > On Sat, 04 Dec 2004 01:18:05 -0800, Tommy Carlier > <guest at rapideuphoria.com> wrote: > > > > posted by: Tommy Carlier <tommy.carlier at telenet.be> > > > > Patrick Barnes wrote: > > > Well yes, I just want to keep the CPU load down... > > > > > > I'm thinking I'll try using openDialog with an invisible window... > > > > What you need is this typical WIN32 message loop (used in Win32Lib > > openDialog and also used as the main event loop): > > }}} <eucode> > > atom msg, result > > msg = w32acquire_mem(0, SIZEOF_MSG) > > while true do > > result = w32Func(xGetMessage, {msg, 0, 0, 0}) > > if result = 0 or result = -1 then exit end if > > > > w32Proc(xTranslateMessage, {msg}) > > w32Proc(xDispatchMessage, {msg}) > > > > -- do your stuff here > > end while > > w32release_mem(msg) > > </eucode> {{{ > > > > This loop keeps CPU load down, since the xGetMessage-function doesn't > > return if there are no messages for the application. > > I know of it, but I'd rather have something like a > GetMessageWithTimeout... > Unfortunately, the MSDN site just looks at me funny. > > -- > MrTrick You may be able to glean some ideas by studying the message loop in WinMain() in ARWEN. It makes a call to runIdle() which queries the windows message buffer for any pending messages. I use this process to perform background tasks that may or may not be triggered by actual events. If the "large procedure" you have in mind can be redesigned to perform its' processing in small incremental chunks then this suggestion might work for you. Mike