win32 render loop in WM_PAINT

Started by
6 comments, last by Andrew Russell 18 years, 8 months ago
Hi how would I get the WM_PAINT message to act as a Render Loop. In c# all you do is this.Invalidate() and setstyle(Controlstyle.AllPaintinginWm | Opaque, true), but when I try to Invalidate in c++ and win32 I get a blank screen. I dont know how to set those styles either can someone help me?
If you insist on saying "DUH", try to make a post that makes a little more sense
Advertisement
Well you could put Invalidate() in WM_PAINT, but I probably would not do this. Rather, I have a seperate method that I use to paint the window called from the message loop which polls the message queue. There really doesn't seem to be a need to handle paint messages if you're using a render loop.

I am looking at the code from the kickstart book, its in c#. And uses the OnPaint method for rendering. They just put this.Invalidate() in the OnPaint, and setstyle(Controlstyle.AllPaintinginWm | Opaque, true) in the Constructor. I would just like to convert it to c++
If you insist on saying "DUH", try to make a post that makes a little more sense
WM_PAINT is sent when your window needs to be repainted. If you are writing a game you will be updating the window x times per second anyway so you don't really need to worry too much about responding to this message.

Look at creating your render loop further back at the message loop instead.
"Absorb what is useful, reject what is useless, and add what is specifically your own." - Lee Jun Fan
Yah I was looking to convert the C# into C++ so I can tell what does what in both languages. And how I could do something in C++ the same way in C#. I know I could do a render loop when there are no messages in PeekMessage. I just wanted to see if I could do this they way they do it in c#.
If you insist on saying "DUH", try to make a post that makes a little more sense
Quote:Original post by cptrnet
I am looking at the code from the kickstart book, its in c#. And uses the OnPaint method for rendering. They just put this.Invalidate() in the OnPaint, and setstyle(Controlstyle.AllPaintinginWm | Opaque, true) in the Constructor. I would just like to convert it to c++


I'm just not sure that's the best way to implement a rendering loop. In fact now that I think about it, I would guess that it is one of the worst ways to do this.
Of course its not a good way to do it. Thats why all the major books out there have you create another render loop. This way is just teaching how to put stuff on the screen with already defined method OnPaint(). You can say its not the best way all you want, but if you do save your typing for a post that is helpful.
If you insist on saying "DUH", try to make a post that makes a little more sense
Well, first of all, I must say - oh goodness this is a terrible way of doing what you are trying to do. Even in C# you shouldn't abuse the paint message to hack in a render loop.

Anyway, that being said, what you are looking for is InvalidateRect (with the rectangle covering your entire client area).

This topic is closed to new replies.

Advertisement