關鍵:
MSG msg;
int bRet = 1;
while (bRet != 0)
{
if (PeekMessageW(&msg, (IntPtr)0, 0u, 0u, 0u) != 0)
{
if ((bRet = GetMessageW(&msg, (IntPtr)0, 0u, 0u)) != 0)
{
if (bRet == -1)
{
// handle the error and possibly exit
}
else
{
IntPtr h = GetAncestor(msg.hwnd, GA_ROOT);
if (IsDialogMessageW(h, &msg) == 0 &&
TranslateAcceleratorW(h, (IntPtr)0, &msg) == 0)
{
TranslateMessage(&msg);
DispatchMessageW(&msg);
}
}
}
}
else
{
WaitMessage();
}
}