How can I repaint a window? I've tried update window but it never works for some reason.
Printable View
How can I repaint a window? I've tried update window but it never works for some reason.
UpdateWindow just forces a WM_PAINT message. You have to answer that WM_PAINT message by redrawing anything you drew before. Using the HDC given from BeginPaint() you need to redraw.
you can also use Invalidate
I gathered I was handling the WM_PAINT message...
Code:case WM_PAINT:
{
EnumChildWindows(hwnd,EnumProc,0);
PAINTSTRUCT ps;
HDC dc = BeginPaint(hwnd,&ps);
DrawMCB(hwnd,dc,status);
EndPaint(hwnd,&ps);
ReleaseDC(hwnd,dc);
return 0;
}
easiest way is to use your debugger. break inside the WM_PAINT handler. See what happens. If it doesn't get there, you aren't InvalidateRect()-ing in the right place.
Ok, well I have to learn to use the debugger first so I'll go off to read the relevant stuff on that and then try. :)
Thanks so far.
You must use InvalidateRect() then UpdateWindow()
that is tell the app
InvalidateRect();//this is the area I want updated
UpdateWindow()//do it NOW by bypassing the msg que
If the rect invalidated is empty the paint msg will not be sent/responded to.
if using MSVC, highlight a line in your code. Press F9 to place a break point (a red dot appears). Run the app and it will stop at the break point. Drag a variable to teh 'watch' window or highlight to see the contents.
PS Normally you have to ReleaseDC() but seeing you use the one BeginPaint() created (and will be cleaned up by EndPaint() ) you don't need the ReleaseDC(). (as you did not GetDC() it)
I've tried and tried but still can't get it to update!
I gathered that was right. Or should I be using the windows parent there?Code:rc.left = p1.x;
rc.top = p1.y;
rc.right-=rc.left;
rc.bottom-=rc.top;
InvalidateRect(hwnd,&rc,TRUE);
UpdateWindow(hwnd);
The parent hwnd, as it is the dialogs callback that will get the msg to paint.
Yeah I figured that out when I read the MSDN stuff again . :)...
Cheers anyways!