读书人

有的书上的对话框程序OnPaint函数

发布时间: 2013-12-19 00:33:34 作者: rapoo

有的书上的对话框程序,OnPaint函数,用了GetDC都没有ReleaseDC?
void CSimpleTextOutDlg::OnPaint()
{
if (IsIconic())
{
//......
}
else
{
CDC*pDC = GetDC();//获取窗口设备上下文
pDC->TextOut(50, 60, "我和你,心连心...");//在窗口客户区域指定位置输出文本
CDialog::OnPaint();
}
}

是因为这个对话框程序不需要,还是这本书的问题?

[解决办法]
这本书的问题

引用
Unless the device context belongs to a window class, the ReleaseDC member function must be called to release the context after painting. Since only five common device contexts are available at any given time, failure to release a device context can prevent other applications from accessing a device context.

[解决办法]
ReleaseDC()需要调用
[解决办法]
不要尽信书, 相对来说MSDN的比较准确的, 但也不能保证百分之百, 因为不同编译器, 不同的操作系统都有区别.
[解决办法]
写代码要严谨啊,不然等你写个几千上万行代码,发现内存或GDI泄漏,有你哭的。
[解决办法]
书不靠谱,鉴定完毕

读书人网 >VC/MFC

热点推荐