I try paint on overlapped and child windows using WinApi. For overlapped is OK, but for WS_CHILD dirty/invalidate rect ps.rcPaint is always (0,0,0,0)
I add WS_OVERLAPPEDWINDOW to WS_CHILD window to better seeing. Pivotal is "if ((style & WS_CHILD) != 0) "
It is a Windows error?
#include <windows.h> LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); int RegClass(HINSTANCE hInstance,LPCTSTR lpszClassName) { WNDCLASS wc; wc.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS | CS_OWNDC; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; wc.lpfnWndProc = WndProc; wc.lpszClassName = (LPCTSTR)lpszClassName; wc.lpszMenuName = (LPCTSTR)NULL; wc.hbrBackground = (HBRUSH)(COLOR_WINDOW); wc.hCursor = (HCURSOR)LoadCursor(NULL,IDC_CROSS); wc.hIcon = (HICON)LoadIcon(NULL,IDI_APPLICATION); return RegisterClass(&wc); } int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) { HWND hWnd0, hWnd1; MSG message; static LPCTSTR lpszClName = L"Wnd Class"; static LPCTSTR lpszCl0Name = L"Child Class"; if(!RegClass(hInstance,lpszClName)) exit(0); if(!RegClass(hInstance,lpszCl0Name)) exit(0); hWnd0 = CreateWindow( lpszClName, L"Overlapped", WS_OVERLAPPEDWINDOW | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 800, 600, 0, 0, hInstance, NULL ); hWnd1 = CreateWindow( lpszClName, L"Child", WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_CHILD, 100, 100, 80, 60, hWnd0, 0, hInstance, NULL ); ShowWindow(hWnd0,SW_SHOWNORMAL); UpdateWindow(hWnd0); ShowWindow(hWnd1,SW_SHOWNORMAL); UpdateWindow(hWnd1); while (GetMessage(&message,0,0,0)) { TranslateMessage(&message); DispatchMessage(&message); } return message.wParam; } LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) /* handle the messages */ { case WM_DESTROY: PostQuitMessage(0); /* send a WM_QUIT to the message queue */ break; case WM_ERASEBKGND: { if (true) { PAINTSTRUCT ps; HDC hdc = BeginPaint(hWnd, &ps); HBRUSH hBrush = CreateSolidBrush(RGB(255, 0, 0)); unsigned style = GetWindowLong(hWnd, GWL_STYLE); if ((style & WS_CHILD) != 0) FillRect((HDC)wParam, &ps.rcPaint, hBrush); DeleteObject(hBrush); EndPaint(hWnd, &ps); } } break; default: /* for messages that we don't deal with */ return DefWindowProc(hWnd, message, wParam, lParam); } return 0; }