0
我有GDI泄漏的小事,我想知道别人的关于如何解决this.Say我有enfolds具体的数据来创建和处理窗口前的一类观点:的Win32字体资源泄漏
class Wnd {
HWND hWnd;
HFONT hFont;
LOGFONT LogFont;
//etc
public:
//constructors and member functions
//The following function atempts to change the font of the window
//pointed to by the hWnd parameter
void ChangeFont (const LOGFONT& lf) {
std::memcpy (&LogFont,&lf,sizeof(LOGFONT));
hFont=CreateFontIndirect (&LogFont);
SendMessage (hWnd,WM_SETFONT,(WPARAM) hFont,(LPARAM) 1);
}
~Wnd() {
//i don't think this would work since i haven't used the SelectObject function
DeleteObject ((HGDIOBJ) hFont);
}
};
所以主要的问题是,在销毁时,我如何释放分配给h0Font参数的内存?我应该获得窗口的设备上下文并使用SelectObject()函数,以便在此之后我可以释放它调用函数为旧的字体和使用DeleteObject()释放内存?非常感谢。
非常感谢您的回答。 –