[ros-dev] [gvg] 19895: Make sure that WM_NCPAINT messages
aregenerated by calling BeginPaint
Ge van Geldorp
gvg at reactos.org
Mon Dec 5 12:09:53 CET 2005
> From: Thomas Weidenmueller
>
> Filip Navara wrote:
> > I overlooked that the code used GetUpdateRect with the last
> > parameter set to FALSE, it should be set to TRUE. In that
> > case GetUpdateRect is responsible for sending the WM_NCPAINT
> > message and cleaning the update region.
>
> No, that shouldn't be a problem. The last parameter just
> specifies if the update region is supposed to be erased (by
> sending a WM_ERASEBKGND message). It doesn't affect the
> validation of update region at all.
According to MSDN, you're right, it doesn't mention GetUpdateRect sending a
WM_NCPAINT message. According to the attached test program (gcc -o
gurtest.exe gurtest.c -lgdi32, click inside the window to invalidate the
whole window), Filip is right and a WM_NCPAINT is actually sent from within
GetUpdateRect.
GvG
-------------- next part --------------
#include <windows.h>
#include <stdio.h>
#include <tchar.h>
static LRESULT CALLBACK
MainWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hDC;
LRESULT Result;
RECT rc;
switch(msg)
{
case WM_DESTROY:
PostQuitMessage(0);
Result = 0;
break;
case WM_NCPAINT:
printf("received WM_NCPAINT\n");
Result = DefWindowProc(hWnd, msg, wParam, lParam);
break;
case WM_PAINT:
printf("Before GetUpdateRect\n");
GetUpdateRect(hWnd, &rc, TRUE);
printf("After GetUpdateRect\n");
hDC = BeginPaint(hWnd, &ps);
EndPaint (hWnd, &ps);
Result = 0;
break;
case WM_LBUTTONDOWN:
RedrawWindow(hWnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME);
Result = 0;
break;
default:
Result = DefWindowProc(hWnd, msg, wParam, lParam);
break;
}
return Result;
}
int WINAPI
WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpszCmdLine,
int nCmdShow)
{
WNDCLASS wc;
MSG msg;
HWND hWnd;
wc.lpszClassName = "GurTestClass";
wc.lpfnWndProc = MainWndProc;
wc.style = CS_VREDRAW | CS_HREDRAW;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, (LPCTSTR) IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, (LPCTSTR) IDC_ARROW);
wc.hbrBackground = (HBRUSH) GetStockObject(GRAY_BRUSH);
wc.lpszMenuName = NULL;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
if (RegisterClass(&wc) == 0)
{
fprintf(stderr, "RegisterClass failed (last error 0x%lX)\n",
GetLastError());
return(1);
}
hWnd = CreateWindow(_T("GurTestClass"),
_T("ReactOS test"),
WS_OVERLAPPEDWINDOW,
0, //Position; you can use CW_USEDEFAULT, too
0,
600, //height
400,
NULL,
NULL,
hInstance,
NULL);
if (hWnd == NULL)
{
fprintf(stderr, "CreateWindow failed (last error 0x%lX)\n",
GetLastError());
return(1);
}
ShowWindow(hWnd, nCmdShow);
while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
More information about the Ros-dev
mailing list