Вы можете изменить свой насос сообщений на использование PeekMessage()
вместо обычного GetMessage()
. Это позволит вам обрабатывать сообщения, если они есть, или делать что-то еще, пока цикл сообщений не используется.
При использовании Win32 API это выглядит примерно так:
for (bool running = true; running; )
{
// check for any window messages. this operation does not block
// if no messages are available.
::MSG message;
const ::BOOL fetched = ::PeekMessage(&message, 0, 0, 0, PM_REMOVE);
if (fetched)
{
// process window message.
TranslateMessage(&message);
DispatchMessage(&message);
// need to check explicitly for WM_QUIT message, since the "false"
// return value is already used to mean "there were no messages".
running = (message.message != WM_QUIT);
}
else
{
// no messages available, thread is idle. take time to check
// auxiliary input source. if no auxiliary input is available
// and checking (and processing) the auxiliary inputs is very
// fast, consider adding an extra ::Sleep() call to avoid hogging
// up the CPU.
}
}
Для приложений на основе .NET вы можете взглянуть на событие Application.Idle
.