上班活不是很多,完了我手机的拼图游戏,突然想自己写一个自己的拼图游戏。
在动手之后,在位图导入之后只要保存有用的位图信息,不想全部保存,于是我想到了用兼容DC来保存于是我写了如下代码
CPicture::CPicture(const HDC& hdc):m_x(0), m_y(0),m_width(0), m_height(0),m_curIndex(0)
{
m_bitmap = CreateCompatibleBitmap(hdc, )
}
但是这样在贴图的时候 发现图片没有上来,于是我又修改了成保存兼容位图和兼容DC 代码如下
BOOL CPicture::CreatePicture(const HWND& hWnd, int x, int y, int width, int height)
{
m_x = x;
m_y = y;
m_width = width;
m_height = height;
if (m_bitmap == NULL)
{
HDC hdc = GetDC(hWnd);
m_bitmap = CreateCompatibleBitmap(hdc, width, height);
if (m_bitmap == NULL)
{
MessageBox(NULL, "", "", MB_OK);
return FALSE;
}
ReleaseDC(hWnd, hdc);
}
return (TRUE);
}