Windows paint message

BlitzMax Forums/BlitzMax Programming/Windows paint message

TaskMaster(Posted 2007) [#1]
Is there a way I can detect the windows paint message to know that my Window needs to be redrawn? Maybe an Event that I can poll for?

I am writing a Windowed program and would like to not redraw over and over and use system resources if there is no reason to redraw the screen. So, I am wondering if I can catch the message windows sends that tells me a portion of my window has been uncovered or that my app was minimized and then maximized...

Thanks.


GfK(Posted 2007) [#2]
Just use WaitEvent()?


TaskMaster(Posted 2007) [#3]
Sorry, I am using a graphics window, not a maxgui window.

My app is a game, but it does not have constant movement on the screen. I want my program to still do stuff, but I don't want to take the time to redraw the screen unless something moves. I have this working fine, but now I need to know if another window has been moved in front of mine and my window needs to be redrawn.

Hope this makes more sense.


tonyg(Posted 2007) [#4]
The EVENT system is available in core Bmax rather than MaxGUI.
Graphics 640,480,0
Local myTimer:TTimer = CreateTimer(60)
Repeat
	Cls
	WaitEvent()
	Select EventID()
		Case EVENT_TIMERTICK
		DrawText "Timer has ticked",0,0
	EndSelect
	Flip
Until KeyHit(KEY_ESCAPE) Or AppTerminate()



TaskMaster(Posted 2007) [#5]
I understand that. Now that I see my response, it does look like i thought the Events were only for MaxGUI.

I was just trying to make the point that I am not waiting for user input. I am writing a game and stuff is going on, AI, and whatnot. It is just that nothing is moving on the screen most of the time, no reason to be constantly drawing and flipping if it isn't needed.

There is no Event that I can see that tells me my screen needs to be painted. Windows sends out a WS_PAINT message when a window needs to be redrawn. I was wondering if BlitzMax made that event available to the user somehow without using some sort of external API call or hook?

In a sample app, I ran a loop that DebugLog'd the Events and I did not see any events when I covered and uncovered my window with another window.

Am I missing something? Maybe this is a feature that can be added...

Thanks for the replys.


DJWoodgate(Posted 2007) [#6]
I have had a look at the system mod and in particular system.win32.c and it seems to me that paint messages are just dropped and have no corresponding Max event. My knowledge of C is very limited though so perhaps someone else can confirm this. I don't suppose it would be that difficult to modify for someone who is familiar with C. I can't see it being particularly important functionality to have though. You have the Appsuspended function which tells you if the window has lost focus and i would not have thought it consumed much processor time to just continue flipping?


Dreamora(Posted 2007) [#7]
Without MaxGUI and a Window with GraphicsCanvas you have no repaint message.

Graphics width,height,depth handles the messages and reaction itself as you would need to do the whole refresh and redraw yourself otherwise which is not really what users of graphics want.


TaskMaster(Posted 2007) [#8]
No I don't have to do the whole refresh redraw do I? I just don't draw and call Flip unless something on the screen has changed?

Does this not make sense? Seems to me Redrawing the screen over and over when nothing has changed is just a waste of CPU cycles...

I am going to try running my app, then I am going to comment out all the draw lines and see how much faster it runs. Seems like it would be MUCH faster to me. Which means it could return more time to the OS, or spend more time figuring the AI decisions.


Dreamora(Posted 2007) [#9]
You are messing something up there:

UI Refreshing has nothing to do with DX Flip and Draw!

UI Refresh just takes care that the content of the graphics stuff is visible at all. If you do not refresh it, it is just not there anymore, point.

If you want to free cpu cycles, just make sure you use flip 0 and use timed flipping (ie at a constant rate of 60 or 100 FPS)

This gives you a few hundred tousand mainloop runs per second which should be enough :)


And as mentioned: Unless you have maxgui and use a window + a canvas, there is no window redraw message.
As there are 2 events that needed to be handled for canvas to be redrawn (both have nothing to do with flip)
and users would have to do this manually if it were not handled automatically.

(PS: flip on repaint is no solution to solve tearing, performance stuff and the like as a repaint for the desktop does not take the same time as a 3d rendering and backbuffer chain flip which is what flip is. Flip is not, as in Blitz3D, just a flip. It includes renderworld as well)


kfprimm(Posted 2007) [#10]
Ok, here's what you want.


Just call InitAppRepaint after you create your graphics window and call AppRepaint to see if your window has recieved the WM_PAINT message.


TaskMaster(Posted 2007) [#11]
Thanks Khomy, I appreciate this. I will give it a shot and report back with how it goes...