本文介绍了永不结束与ATL CWindowImpl的WM_PAINT循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用CAtlExeModuleT的非常简单的Win32应用程序.该模块仅创建一个从CWindowImpl派生的CTestWindow类.它只有一个用于WM_PAINT的消息处理程序.创建窗口并将其显示后,将无限调用OnPaint方法(WM_PAINT消息),从而消耗100%的CPU.

I have a very simple Win32 application that uses CAtlExeModuleT. The module simply creates a class CTestWindow derived from CWindowImpl. It just has a single message handler for WM_PAINT. After I create the window and display it, the OnPaint method (WM_PAINT message) is called infinitely and there by consumes 100% CPU.

创建窗口的代码非常简单:

The code that creates the window is very simple:

    m_pMainWnd = new CTestWindow();
if(NULL == m_pMainWnd->Create(NULL, CWindow::rcDefault, _T("Test Window"), WS_OVERLAPPEDWINDOW, 0, hMenu)){
    DWORD dwErr = GetLastError();
    return E_FAIL;
}
m_pMainWnd->ShowWindow(nShowCmd);

OnPaint消息处理程序也非常简单(它不执行任何操作):

The OnPaint message handler is very simple as well (it doesn't do anything):

LRESULT CTestWindow::OnPaint(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
    // TODO: Add your message handler code here and/or call default

    return 0;
}

推荐答案

我的猜测是您不是在绘画处理程序中验证窗口.

这意味着操作系统将认为仍然需要绘制窗口,然后再次致电给您.

This would mean the OS will think the window still needs to be painted, and call you again.

这篇关于永不结束与ATL CWindowImpl的WM_PAINT循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 18:23