主题:为什么打开位图一闪就没有了
我用按钮打开一幅位图,想让它显示在客户区一个指定的区域,但位图只在窗户区闪了一下就没有了,请问是什么原因呢?
程序代码如下:
HBITMAP hBitmap;
HDC hdc,hdcMem;
BITMAP bitmap;
RECT ClientRect;
hdc = GetDC(hWnd);
GetClientRect(hWnd, &ClientRect); // 获得客户区大小
hBitmap = LoadImage(hWnd);
if(hBitmap)
{
GetObject(hBitmap, sizeof(BITMAP), &bitmap);
hdcMem = CreateCompatibleDC(hdc);
SelectObject(hdcMem, hBitmap);
/*BitBlt(hdc, ClientRect.right/30, ClientRect.bottom*2/50, bitmap.bmWidth, bitmap.bmHeight,
hdcMem, 0, 0, SRCCOPY);*/
StretchBlt(hdc,ClientRect.right/30, ClientRect.bottom*2/50,ClientRect.right/3, ClientRect.bottom*2/5,
hdcMem,0,0,bitmap.bmWidth, bitmap.bmHeight,SRCCOPY);
DeleteDC(hdcMem);
}
ReleaseDC(hWnd, hdc);
程序代码如下:
HBITMAP hBitmap;
HDC hdc,hdcMem;
BITMAP bitmap;
RECT ClientRect;
hdc = GetDC(hWnd);
GetClientRect(hWnd, &ClientRect); // 获得客户区大小
hBitmap = LoadImage(hWnd);
if(hBitmap)
{
GetObject(hBitmap, sizeof(BITMAP), &bitmap);
hdcMem = CreateCompatibleDC(hdc);
SelectObject(hdcMem, hBitmap);
/*BitBlt(hdc, ClientRect.right/30, ClientRect.bottom*2/50, bitmap.bmWidth, bitmap.bmHeight,
hdcMem, 0, 0, SRCCOPY);*/
StretchBlt(hdc,ClientRect.right/30, ClientRect.bottom*2/50,ClientRect.right/3, ClientRect.bottom*2/5,
hdcMem,0,0,bitmap.bmWidth, bitmap.bmHeight,SRCCOPY);
DeleteDC(hdcMem);
}
ReleaseDC(hWnd, hdc);