Code:
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
hfFontDefault = CreateFont(lfHeight, 0, 0, 0, 0, TRUE, 0, 0, 0, 0, 0, 0, 0, _T("Times New Roman"));
bmTest= (HBITMAP)LoadBitmap(hInstance, _T("MyBitmap"));
}
…
WM_PAINT:
image_dc = CreateCompatibleDC(hdc);
SelectObject(image_dc, hfFontDefault);
old_hbitmap = (HBITMAP)SelectObject(image_dc, bmTest);
BitBlt(hdc ,10 , 10, 1000, 1000, image_dc, 0, 0, SRCCOPY);
wsprintf(szSize, _T(""));
SelectObject(image_dc, old_hbitmap);
DeleteDC(image_dc);
Hello,
In the code above used the function CreateCompatibleDC to create a device context called image_dc for double buffering. I select hfFontDefault and bmTest bitmap into it. At the end of the WM_PAINT message, I select the old_hbitmap back into the image_dc.
Question 1: I have attached a diagram. Is the diagram an accurate representation of the device context in the code?
Question 2: I think it’s safe to skip the last message to select the old_hbitmap back into image_dc before I DeleteDC(image_dc). However I would assume it’s always a good idea to put it back. Is that true?
Question 3: the bmTest needs to be deleted, and I did so at the WM_DESTORY message. Right?