我正在开发一个程序,它的bmp图像可以反映系统的状态(因此,这些灯可以根据状态变化)。这些图像位于主窗口上,旁边是一个有两个选项卡的选项卡窗口。当我第一次运行我的程序时,一切都很好。我可以改变标签和图片仍然在他们的右边,正确地反映状态。我整晚都在运行我的程序,当我回来的时候,程序仍将正常运行(我所有的按钮和标签都在工作),但是我的图像消失了。
我调试了我的WM_PAINT,并注意到以下代码
Light = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(LightSource[i]));现在返回NULL。
所以我的问题是,我怎样才能让这件事一直正常运作呢?有什么想法吗?
int LightSource[12] = { IDB_BITMAP1, IDB_BITMAP1, IDB_BITMAP1, IDB_BITMAP1, IDB_BITMAP1, IDB_BITMAP1, IDB_BITMAP1, IDB_BITMAP1, IDB_BITMAP1, IDB_BITMAP1, IDB_BITMAP1, IDB_BITMAP1 };
case WM_PAINT:
{
HBITMAP Light = NULL; //Bitmaps for the light indications
//Prepares for painting window
hdc = BeginPaint(hwnd, &ps);
//Retrieves the coordinates of the windows client area
GetClientRect(hwnd, &rc);
//creates a copy of the memory device context
HDC hdcDouble = CreateCompatibleDC(hdc);
HBITMAP bmOld;
for (int i = 0; i < 12; i++) //For all indicator lights
{
Light = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(LightSource[i])); //Get a bitmap of the picture to be updated
bmOld = (HBITMAP)SelectObject(hdcDouble, Light); //Get a handle to the image being replaced
BitBlt(hdc, xLight[i], yLight[i], rc.right, rc.bottom, hdcDouble, 0, 0, SRCCOPY); //Bit block transfer of the bitmap color data
}
SelectObject(hdcDouble, bmOld);
DeleteDC(hdcDouble);
EndPaint(hwnd, &ps);
//Set some window text, no need to show
DeleteObject(Light);
break;
}发布于 2014-09-19 09:40:30
回答这个问题,这样它就不会打开:因为你没有释放位图,所以看起来你的程序中有一个资源泄漏。使用后释放位图。
https://stackoverflow.com/questions/25889130
复制相似问题