WM_PAINT 返回 0 导致 CPU 使用率 2% [英] WM_PAINT return 0 causing cpu usage 2%
问题描述
我的 WM_Paint 有问题
Im having a problem with my WM_Paint
如果我让它返回 0/1,即使程序被最小化,我的 CPU 也会保持在 1% 左右.
If i make it return 0/1 it makes my cpu to stay around 1% even if the program is minimised.
我的绘画窗口使用 OpenGL
My paint window is using OpenGL
如果我从 WM_PAINT 中断,它会在调整大小时导致绘图问题
If i break from WM_PAINT it causes drawing isues when resizing
case WM_PAINT:
{
application->paint_window();
return 0;
}
window = std::make_unique<platform::window>(
L"Main window",
CW_USEDEFAULT, CW_USEDEFAULT,
1200, 600,
WS_OVERLAPPEDWINDOW /*| WS_CLIPSIBLINGS | WS_CLIPCHILDREN*/, 0,
CS_OWNDC,
this, process_message
);
while (::GetMessage(&msg, 0, 0, 0) > 0)
{
if (!::TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
::TranslateMessage(&msg);
::DispatchMessage(&msg);
}
}
如果我在 WM_PAINT 中删除我的函数调用,我的 CPU 会上升到 15%.如果我什么都不做,它为什么会涨得这么高.
edit: if i remove my function call in WM_PAINT my cpu goes up to 15%. why does it go so high if im not doing anything.
推荐答案
如 WM_PAINT 消息:
当对窗口的更改改变了客户区的内容时,系统将此消息发送到窗口过程.
The system sends this message to a window procedure when changes to the window have altered the content of the client area.
系统保留一个内部更新区域来确定窗口的任何部分是否需要绘制.然后应用程序负责验证它所绘制的区域(通过调用 BeginPaint、ValidateRect 或 ValidateRgn).
The system keeps an internal update region to determine, whether any parts of the window need painting. It is the application's responsibility to then validate the area it has painted to (either by a call to BeginPaint, ValidateRect, or ValidateRgn).
未能验证不再需要更新的区域将使系统重新生成WM_PAINT
消息.这会导致您观察到的资源消耗.
Failing to validate the region that no longer needs to be updated will have the system re-generate a WM_PAINT
message. That leads to the resource consumption you observe.
这篇关于WM_PAINT 返回 0 导致 CPU 使用率 2%的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!