gpt4 book ai didi

windows - 使用 ATL CWindowImpl 永不结束 WM_PAINT 循环

转载 作者:可可西里 更新时间:2023-11-01 10:02:07 24 4
gpt4 key购买 nike

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

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

    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 消息处理程序也非常简单(它什么都不做):

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

return 0;
}

最佳答案

我猜你不是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.

这意味着操作系统会认为窗口仍然需要绘制,并再次调用您。

关于windows - 使用 ATL CWindowImpl 永不结束 WM_PAINT 循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1117511/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com