Jump to content
  • Advertisement
Sign in to follow this  
cptrnet

win32 render loop in WM_PAINT

This topic is 4842 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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++

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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#.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!