bartc
bartc

Reputation: 324

Win32 message timeout clears my window

Take the simplest possible Windows program with a window and message loop, such as a Hello, World program.

Suppose that just before I enter the message loop, I draw into the window (naughtily done outside processing of wm_paint, but bear with me).

If I spend more than about 5 seconds doing this, or I draw something then spend 5 seconds doing something else, before I start the message loop, then the message system seems to 'time out'. The MSDN docs for PeekMessage says it becomes 'unresponsive' and turns it into a 'ghost' window.

My problem however is that it also clears the contents of the window!

Is there way of stopping it doing that? The same 'unresponsive' caption is shown if I spend too long drawing into the window even during offical wm_paint processing; it also starts to behave oddly by generating more wm_paint messages.

It seems very restrictive if everything (eg. complicated rendering, or image processing) must be done within 5 seconds, or if any algorithm needs to keep prodding the message queue to stop it timing out!

Upvotes: 2

Views: 439

Answers (2)

milevyo
milevyo

Reputation: 2180

create a thread for extensive drawing on a cache bitmap. while bitmap is not ready just print on WM_PAIN event "processing please wait..." for example. when ready print that bitmap. and destroy the thread.

Upvotes: 0

Zebra North
Zebra North

Reputation: 11492

This is by design. You must keep checking for messages so that you can respond to user events such as resizing or closing the window. Even worse, if your application is not responding to events then that may cause other applications to freeze, as they may send your application a message and be stuck waiting for a reply.

If you have to do a lot of processing then either check for messages periodically, or do the work in a separate thread.

Upvotes: 1

Related Questions