【SDK】关于WM_CTLCOLORSTATIC消息的问题
VS2010的本地MSDN上说
If an application processes this message, the return value is a handle to a brush that the system uses to paint the background of the static control. The system deletes this brush when it is no longer needed.
拙劣翻译:如果应用程序处理此消息,返回值是一个画刷,系统用这个画刷来绘制静态控件的背景。当该画刷不再需要时,系统将删除它。
并给出如下示例代码片段:
case WM_CTLCOLORSTATIC:
{
HDC hdcStatic = (HDC)wParam;
SetTextColor(hdcStatic, RGB(255, 255, 255));
SetBkColor(hdcStatic, RGB(0, 0, 0));
return (INT_PTR)CreateSolidBrush(RGB(0, 0, 0));
}
-----------------------------------------------------
而在线版的(http://technet.microsoft.com/zh-cn/subscriptions/aa923148)则这样说
The system does not automatically destroy the returned brush. It is the application's responsibility to destroy the brush when it is no longer needed.
拙劣翻译:系统不会自动销毁返回的画刷。当不再需要时,应该由应用程序负责销毁。
-----------------------------------------------------
我的问题是,
这个画刷要不要自己释放?
顺便问下,有什么方法能检测GDI泄露
谢谢
SDK
------解决方案--------------------MSDN说了要你自己释放,那就肯定要自己释放啊。
自己释放也不难吧,你自己的窗口类,画刷保存为成员变量,在构造函数中创建、析构函数中销毁就是了。
如果你用的是系统样式中的画刷的话,用GetStockObject获取出来的,就用不着释放了
------解决方案--------------------最好是自己释放掉!只有在程序退出时系统才帮你释放。
------解决方案--------------------在构造函数中CreateSolidBrush
在析构函数中DeleteObject
return (INT_PTR)CreateSolidBrush(RGB(0, 0, 0)); 这岂不是每次都会Create
------解决方案--------------------http://blog.csdn.net/wqsailor12/article/details/7482253
------解决方案--------------------Remarks
If the application returns a brush that it created (for example, by using the CreateSolidBrush or CreateBrushIndirect function), the application must free the brush. If the application returns a system brush (for example, one that was retrieved by the GetStockObject or GetSysColorBrush function), the application does not need to free the brush.
http://msdn.microsoft.com/zh-cn/library/windows/desktop/bb787524(v=vs.85).aspx