Hi everybody,

to get this clear, this is a newbie question, but here it goes:
I'm writing a program that does some lengthy calculations as soon as the user presses a certain button. That means my program does something for a long time outside the event loop. But I want to give some progress report back to the GUI. I tried SetWindowText followed by UpdateWindow and it works partially. The text in my TextEdit control is updated as it should until a window of another application overlaps it, the screen saver starts or I simply move the window to a different position. Then all updating stops :-(
I tried an InvalidateRgn before the UpdateWindow but nothing worked. So the question is:

What is the proper way to update my window outside the eventloop ?

Many thanks,

Posted on 2002-08-22 03:37:08 by MrSmith
There is not really a simple (ie a way that those new to asm can pick up quickly) way to do this...

The best way to do what you want would be something along the lines of:
1) Spawn another thread to perform the calculation, this thread updates some globally accessable variable as to how far its got.

2) Also start a timer in your main thread.

3) On the timer even, check the globally accessable variable, and update accordingly.

This is not particularly nice if you've never done multi threading, or if you are new to assembler.

The only other option I suppose is if the calculation is inside some loop which is itterated many hundreds of times, use the timer again, and instead of running all through the loop, run small chunks on the timer event and update then. This way you will not give the entire thread over to the calculation, so it can then also service other messages in the queue. This is not so pretty a method, and is also not always possible (if your calculation doesn't break down into nice chunks).

Posted on 2002-08-22 04:52:19 by Mirno
Hi Mirno,

thanx for the quick reply. I understand both methods you are mentioning, it just seems quite a bit of work for a assembler newbie :-(

Do you by any chance know why my approach (UpdateWindow) worked partially, but stopped working under the described conditions ?

Anyway, many thanks for the help.

Posted on 2002-08-22 05:00:55 by MrSmith
At the moment (if you aren't using several threads) then you are occupying all the processes time, so it cannot process any messages waiting for it in the message queue. So all the messages sent to the window by the OS, such as recieving focus, or paint messages cannot be processed until the end of your big calculation.

Posted on 2002-08-22 05:15:14 by Mirno
I've just knocked this together (out of old washing machine parts, and some rubber bands).
Take a look at it, if you understand it feel free to use it!

Posted on 2002-08-22 05:36:03 by Mirno
Afternoon, MrSmith.

Add this proc to your proggy...

;-- CheckEvents -----------------------------------------------------------
;-- Allow processing of a waiting message ---------------------------------
CheckEvents PROC
invoke PeekMessage,ADDR msg, NULL, 0, 0, PM_REMOVE
.if eax != 0
invoke TranslateMessage, ADDR msg
invoke DispatchMessage, ADDR msg

CheckEvents ENDP

and then add...

invoke CheckEvents ; allow processing of waiting messages

inside your loop with the massive amount of calculations.

This way, you could also have a 'STOP' button to stop the calculating at any time.

Posted on 2002-08-22 06:58:38 by Scronty
congrats, you just discoverd the "DoEvents"-API :grin: :grin:
Posted on 2002-08-22 07:18:52 by bazik
Afternoon, bazik.

you just discoverd the "DoEvents"-API

That's exactly right. I saw it in the PB TRM demo proggy, and used it in the Masm32 one.:alright:

Posted on 2002-08-22 17:10:27 by Scronty
Many thanks Scronty and Mirno,

I tried both methods and both work in principle. However, using a timer and a separate thread for the calculation gives a smoother update and also seems to be the "textbook" way of doing it. Looking at Mirnos example file (many thanks) I was surprised how simple it can be implemented. But I guess that is what "know how" is all about.


Posted on 2002-08-23 02:56:02 by MrSmith