Originally Posted by
matsp
Well, you must call Invalidate at some point if you want your application to draw onto an existing window. There will only be one call to WM_PAINT if there's no Invalidate calls (and your window isn't being hidden by some other window that is later removed).
--
Mats
Ok, let me show you what i've done
1. In WM_PAINT
Code:
case WM_PAINT:
{
hdc=BeginPaint(hwnd, &pntS);
//.... Function shown below
CreateBuffer(0, hdc);
/* *** User Interface *** */
// In this area, i draw 5 rectangles and display text (i call about 7 functions here)...
// .................
// .................
// Here i calculate & display results
output = ProcessData(hwnd);
DisplayResults(hwnd, my_DC_Buffer[0], &output, rsltFont);
// Here, i Bitblt (function shown below)
CopyToScreen(hdc, 0);
EndPaint(hwnd, &pntS);
}
return 0;
Function CreateBuffer
Code:
/* Create Device Context on buffer for client window */
void CreateBuffer(int which, HDC hDc)
{
GetClientRect(my_handle,&dc_rect[which]);
// my_DC = GetDC(my_handle);
my_DC_Buffer[which] = CreateCompatibleDC(hDc);
hbm_Buffer[which] = CreateCompatibleBitmap(hDc,dc_rect[which].right ,
dc_rect[which].bottom );
hbm_oldBuffer[which] = (HBITMAP) SelectObject(my_DC_Buffer[which],
hbm_Buffer[which]);
}
Function CopyToScreen()
Code:
/* Copy Device Context from buffer to screen */
void CopyToScreen(HDC hdc, int which)
{
BitBlt(hdc,0,0,dc_rect[which].right,dc_rect[which].bottom,my_DC_Buffer[which],0,0,SRCCOPY);
}
Problems...
1. The background is now black
2. When i add InvalidateRect() in WM_TIMER, flickering is worse
3. At first, i tried moving the drawing section to WM_TIMER, got problems there, then moved it back to WM_PAINT
Concerns...
When creating a CompatibleDC, should i use hdc from BeginPaint() or should i rather GetDC() of the ClientArea (note the commented GetDC()), then create a compatible DC from it?