I am using the double buffering method in main window of my program to prevent flickering, but I am have been getting entirely black window client area instead. What could be the problem.
The relvant codes are shown below:
Please note that the WriteDatah Function is not an actual part of the actual appliation. I created a new project and brought the problematic code to it in order to figure out was was wrong. The WriteData represent actual code in funinality. With this new test applicaion, I was able to narrow down the problem to be either the double buffering is not properly done or the mapping mode conflicts with it. What do you think.
case WM_CREATE:
{
HDC hdc = GetDC(hWnd);
std::tuple<double, double, int, int> Tuple = GetAppDocumentSize(hWnd, hdc, iPageWidth, iPageHeight);
iOneMMX = static_cast<int>(Approximate(get<0>(Tuple), 0));
iOneMMY = static_cast<int>(Approximate(get<1>(Tuple), 0));
int iWidth = GetSystemMetrics(SM_CXSCREEN);
int iHeight = GetSystemMetrics(SM_CYSCREEN);
hMemDC = CreateCompatibleDC(hdc);
hBitmap = CreateCompatibleBitmap(hdc, iWidth, iHeight);
hOldBitmap = (HBITMAP)SelectObject(hMemDC, hBitmap);
HBRUSH hBrush = (HBRUSH)GetStockObject(WHITE_BRUSH);
hOldBrush = (HBRUSH)SelectObject(hMemDC, hBrush);
ReleaseDC(hWnd,hdc);
break;
}
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hWnd, &ps);
std::tuple<double,double,int,int> Tuple = GetAppDocumentSize(hWnd, hdc, iPageWidth, iPageHeight);
BitBlt(hdc, 0, 0, iPageWidth, iPageHeight, hMemDC, 0, 0, SRCCOPY);
EndPaint(hWnd, &ps);
}
break;
This following code is lunched by the menu item with the ID ID_DRAW_DRAW_TEXT. So, it is handled by WM_COMMAND.
case ID_DRAW_DRAWTEXT:
{
Rectangle(hMemDC, 0, 0, iPageWidth, iPageHeight);
WriteDatah(hMemDC,iOneMMX,iOneMMY,iPageWidth,iPageHeight);
InvalidateRect(hWnd, NULL, FALSE);
break;
}
HFONT CreateAppFont(int cHeight, int cWeight, DWORD bItalic, int cEscapement, DWORD bUnderline, LPCWSTR pszFaceName)
{
return CreateFont(cHeight, 0, cEscapement, cEscapement, cWeight, bItalic, bUnderline, FALSE, DEFAULT_CHARSET, OUT_OUTLINE_PRECIS,
CLIP_DEFAULT_PRECIS, CLEARTYPE_QUALITY, VARIABLE_PITCH, pszFaceName);
}
double Approximate(double dNumber, int iDecimalPlaces)
{
int iMultipier = static_cast<int>(pow(10, iDecimalPlaces));
dNumber *= iMultipier;
double dInteger = 0.0;
double dDecimal = modf(dNumber, &dInteger);
int Integer = static_cast<int>(dInteger);
if (dDecimal >= 0.5)
{
Integer++;
}
double dResult = Integer / iMultipier;
return dResult;
}
void WriteDatah(HDC hdc,int iOneMMX,int iOneMMY,int iPageWidth,int iPageHeight)
{
UNREFERENCED_PARAMETER(iPageHeight);
std::wstring wstData = L"Jesus is Lord of the Nations";
int iOneINCHY = GetDeviceCaps(hdc, LOGPIXELSY);
double dOneFontPOINT = (double)iOneINCHY / 72.0;
int iOneFontPOINT = static_cast<int>(Approximate(dOneFontPOINT, 0));
int iFontSize = 10 * iOneFontPOINT;
HFONT hFont = CreateAppFont(iFontSize, FW_BOLD);
HFONT hOldFont = (HFONT)SelectObject(hdc, hFont);
int iLeft = 10 * iOneMMX;
int iTop = 10 * iOneMMY;
SIZE size;
GetTextExtentPoint32(hdc, wstData.c_str(), lstrlen(wstData.c_str()), &size);
TEXTMETRIC tm;
GetTextMetrics(hdc, &tm);
for (int i = 0; i < 100; i++)
{
TextOut(hdc, iLeft, iTop, wstData.c_str(), lstrlen(wstData.c_str()));
iTop += tm.tmHeight + tm.tmExternalLeading;
}
SelectObject(hdc, hOldFont);
}
What I have tried:
I have been debugging all day. I have quite ab amount of googling too.