LoadBitmap在程序运行一段时间后返回NULL
LoadBitmap returns NULL after program has been running for a while
我正在开发一个程序,该程序具有反映系统状态的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;
}
回答这个问题,这样它就不会一直打开:由于您没有释放位图,所以您的程序中似乎存在资源泄漏。使用位图后释放位图。
相关文章:
- 如何在映射中返回null
- 为什么返回 NULL 不会破坏函数?
- fopen 在 gdb 中返回 NULL
- 为什么要从main()返回NULL?
- 为什么TinyXML2的XMLDocument::FirstChild()函数在尝试解析这个有效的XML文件时返回NULL?
- Box2D World.GetBodyList() 返回 NULL,但 World 显然正在更新对象
- boost::p ython:PyErr_Fetch始终返回 NULL 回溯
- 如何在 Visual C++ 中从返回类型为 map 的函数返回 null?
- 如何在C++中返回Null作为引用
- 从模板化函数返回Null对象
- GDALOpen 在 GEOTiff 文件上返回 null
- PyThreadState_GET() 从 PyImport_GetModuleDict() 中返回 NULL
- (位图)LoadImage() 返回 NULL,GetLastError() 返回 0
- 在构造函数处将类对象强制转换为接口始终返回 NULL
- 如何为迭代器返回"null"值?
- 具有 4 个指针的节点的递归插入函数返回 null
- winAPI FindResource 仅在 DLL 中返回 NULL
- 使用 dlopen/dlsym 打开C++共享库 - dlsym 返回 NULL
- SetWindowsHookEx 在挂接到其他线程时返回 NULL
- 尚未归shared_ptr所有的实例的 shared_from_this() 总是返回 null?