As modoran has already said, you should never send WM_PAINT directly; you should use InvalidateRect (you can also use UpdateWindow if you need an immediate repaint, but this should be used very sparingly.)
And neither WM_PRINT nor WM_PRINTCLIENT are approriate here, as you don't want to ask another window to draw into your device context.
The other part of the puzzle is that InvalidateRect should be called from the window's thread, not the worker thread (you should not call GUI-related API calls like InvalidateRect, FindWindow, etc. from worker threads.)
The way you do this is to define a custom message, e.g.
#define WM_USER_INVALRECT (WM_USER + 100)
And then post this message to the main window where you have a handler which invalidates the window in response to it.
You can either use PostMessage, if you provide the thread with the HWND for the main windows, or PostThreadMessage, if you provide the thread ID rather than the HWND.
To avoid an evil global, you can pass the HWND (or thread ID) to the thread via the start parameter, e.g.
DWORD WINAPI ProgramMain(LPVOID pvParam);
Assumed to be in WM_CREATE message handler or similar?
1 2
|
DWORD qThreadID1 = 0;
HANDLE hThread1 = CreateThread(0, 0, ProgramMain, (LPVOID)hWnd, 0, &qThreadID1);
|
And
1 2 3 4 5 6 7 8 9
|
DWORD WINAPI ProgramMain(LPVOID pvParam) {
HWND hWnd = (HWND)pvParam;
// Some Code here
PostMessage(hWnd, WM_USER_INVALRECT, 0, 0);
return 0;
}
|
Andy
PS You should use _beginthreadex rather than CreateThread if you use any CRT calls in your thread routine.