Jump to content
  • Advertisement
Sign in to follow this  
Servant of the Lord

Not repainting. Win32

This topic is 4448 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

This is driving me crazy. My application isn't repainting when I tell it to. I've tried many things I've found online, but I just can't get it to repaint when I want. This is the current code: (I changed it to see if it was a error in my functions)
#include <windows.h>
#include <iostream>


//project headers, shouldn't effect the painting at all.
#include "resource.h"
#include "Mapping.h"

//Currently globalled
PAINTSTRUCT ps;
HDC hdc;

    case WM_PAINT:
    {
    hdc = BeginPaint(hwnd, &ps);
    
    HDC hdcMem = CreateCompatibleDC(hdc);

            
    sprintf(buffer,"WM_PAINT called %d times  ", ++wm_paint_count);
    TextOut(hdc, 128,0, buffer, strlen(buffer));
            
    DeleteDC(hdcMem);
            
    EndPaint(hwnd, &ps);
    return 0;
}
This repaints when WM_PAINT trips, and the screen gets covered or unminimized, but not when I call PostMessage(hwnd, WM_PAINT, 0, 0) or UpdateWindow(hwnd) etc... I looked up and tried InvalidateRgn(hwnd, 0, true) and I put the paint process in a function for calling by WM_PAINT and my areas that need the screen to refresh. I used the HDCs as local and global, just in case I didn't understand how it works, but it didn't solve it, needless to say. To explain what happens better, the above WM_ case, which I had even directly cut out of a tutorial and placed it in my code to see if it worked, when mine didn't, causes "WM_PAINT called x times" where x is the amount of times WM was called, as you can see from the code. What it does is display a line on the screen, like say, "WM_PAINT called 1 times" and never updates it, no matter how much I try and get it to, unless the window gets covered or minimized. Once it DOES update the screen, it jumps from, say, "called 1 times" to "called 12 times" or however many times the program called it before it updates. It seems something is effecting the HDC in some way, as the 'wm_paint_count' gets incremented, but the screen just doesn't update the graphics. I've run it through with a debugger, and my guess is that is has to do with the fRestore and fIncUpdate bools in the PAINTSTRUCT struct, but MSDN only tells me that they're reserved for internal use, so perhaps not. Please help me, I'm lost and confused again. (I seem to be getting confused alot with Win32)

Share this post


Link to post
Share on other sites
Advertisement
I would guess you are not invalidating a region prior to calling BeginPaint().

What you are describing suggests you are not handling WM_PAINT, and only see updates when Windows handles a different message (WM_NCPAINT or WM_ERASEBKGND maybe). If you want Windows to perform default behavior still, call DefWindowProc().

Share this post


Link to post
Share on other sites
*Groan* Following your guess, I've found the problem, and it make me angry how blantantly obvious it was, that I missed it so. Sorry for your trouble.

As a bit of amusement, it troubled me for three days and was merely a local variable named the same as a global. [embarrass] I really need to stop forgetting to put gbl_ and loc_ prefixes on my variables. (Actually, I was busy with meetings these three days, so I had only worked about an hour or two, but it was three days that it ate at my mind whenever I stopped to think about it.)

Thanks for WM_NCPAINT and WM_ERASEBKGND also. I've glanced at them before on msdn when I was trying to figure out errors, but this time I inputted them into my code and messed around with them. Really cool. It gives me ideas of how I could use it, and almost makes me want to drop my current project(but I won't, I must finish this one first). Many thanks for that! And thanks again for your help.

-Servant

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!