【运行效果】
【相关代码】
void Character::DisplayInPictureCtrl(HWND hPictureCtrl, UINT flags)
{
RECT rect;
GetClientRect(hPictureCtrl, &rect);
HDC hdc = GetDC(hPictureCtrl);
HDC hdcMem = CreateCompatibleDC(hdc);
HBITMAP hbmp = (HBITMAP)SendMessage(hPictureCtrl, STM_GETIMAGE, IMAGE_BITMAP, NULL);
if (hbmp == NULL)
{
// When no bitmap is associated with the picture control, create one, according to the DC from the picture control
hbmp = CreateCompatibleBitmap(hdc, rect.right - rect.left, rect.bottom - rect.top);
SendMessage(hPictureCtrl, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hbmp);
}
ReleaseDC(hPictureCtrl, hdc);
DeleteDC(hdc);
SelectObject(hdcMem, hbmp);
Graphics graphics(hdcMem);
DrawIn(graphics, rect, flags);
DeleteDC(hdcMem);
InvalidateRect(hPictureCtrl, &rect, false);
}