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

Not repainting. Win32

This topic is 4545 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
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));
    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
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.


Share this post

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

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!