win32编程 画图
void cDefense::DrawAll() { HDC hDc = GetDC(m_hWnd);//获取客户区窗口,如果该值为NULL,GetDC则获整个屏幕的窗口。 HDC dcMem = CreateCompatibleDC(hDc);//该创建一个与设备兼容的窗口 HBITMAP hBitmap = CreateCompatibleBitmap(hDc, 700, 600);//创建一个兼容的位图 SelectObject(dcMem, hBitmap);//把一个对象(位图、画笔、画刷等)选入指定的窗口。新的对象代替同一类型的老对象。 //要把所有的图形绘制到dcMem上 DrawMap(dcMem); //把dcMem绘制到Dc上 BitBlt(hDc, 0, 0, 700, 600, dcMem, 0, 0, SRCCOPY); ReleaseDC(m_hWnd, hDc); DeleteObject(dcMem); DeleteObject(hBitmap); } void cDefense::DrawMap(HDC dcMem) { HDC dcTemp; dcTemp = CreateCompatibleDC(NULL); HBITMAP hBitmap = (HBITMAP)LoadImage(NULL, L"images\\maps\\bg.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); SelectObject(dcTemp, hBitmap); BITMAP bitInfo; GetObject(hBitmap, sizeof(BITMAP), &bitInfo);//得到图像的信息储存到bitInfo中 BitBlt(dcMem, 0, 0, bitInfo.bmWidth, bitInfo.bmHeight, dcTemp, 0, 0, SRCCOPY); DeleteObject(dcTemp); DeleteObject(hBitmap); }