Never ending WM_PAINT loop with ATL CWindowImpl

感情迁移 提交于 2019-12-22 12:20:13

问题


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);

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;
}

回答1:


My guess is that you are not validating the window in your paint handler.

An application must call BeginPaint and EndPaint in response to WM_PAINT messages, or pass the message to the DefWindowProc function to validate the window. DefWindowProc validates the update region; it can send the WM_ERASEBKGND message if the window background needs to be erased.

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



来源:https://stackoverflow.com/questions/1117511/never-ending-wm-paint-loop-with-atl-cwindowimpl

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!