HBITMAP hBitmap = (HBITMAP)::LoadImage(NULL,lpszName,IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
把hBitmap设为全局变量,在一个OPEN的按钮中打用上面一句打开,在OnPaint()里面用这个hBitmap来画图为什么画不出来
把hBitmap设为全局变量,在一个OPEN的按钮中打用上面一句打开,在OnPaint()里面用这个hBitmap来画图为什么画不出来
CBitmap bmp;
if (bmp.LoadBitmap(IDB_BITMAP1))
{
// Get the size of the bitmap
BITMAP bmpInfo;
bmp.GetBitmap(&bmpInfo); // Create an in-memory DC compatible with the
// display DC we're using to paint
CDC dcMemory;
dcMemory.CreateCompatibleDC(pDC); // Select the bitmap into the in-memory DC
CBitmap* pOldBitmap = dcMemory.SelectObject(&bmp); // Find a centerpoint for the bitmap in the client area
CRect rect;
GetClientRect(&rect);
int nX = rect.left + (rect.Width() - bmpInfo.bmWidth) / 2;
int nY = rect.top + (rect.Height() - bmpInfo.bmHeight) / 2; // Copy the bits from the in-memory DC into the on-
// screen DC to actually do the painting. Use the centerpoint
// we computed for the target offset.
pDC->BitBlt(nX, nY, bmpInfo.bmWidth, bmpInfo.bmHeight, &dcMemory,
0, 0, SRCCOPY); dcMemory.SelectObject(pOldBitmap);
}
else
TRACE0("ERROR: Where's IDB_BITMAP1?\n");
转化,你懂的
CBitmap::FromHandlestatic CBitmap* PASCAL FromHandle( HBITMAP hBitmap );
如果 m_hBitmap = NULL( 须初始化为NULL)
if ( !m_hBitmap ) /* HBITMAP */ m_hBitmap = (HBITMAP)::LoadImage(NULL,lpszName,IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
else
{// do others
}
2。如果hBitmap 定义成全局的,它不会自动释放,除非程序结束
最有可能就是绘图部分代码问题