gpt4 book ai didi

c++ - SetWinEventHook 和 GetMessage c++

转载 作者:行者123 更新时间:2023-11-28 05:33:32 24 4
gpt4 key购买 nike

我想用 SetWinEventHook 设置一些事件并等待。在五个事件之后,我想退出消息循环。问题是代码卡在 getMessage 中而没有进入循环。每当事件发生时,都会正确调用回调函数。

HWINEVENTHOOK hEvent = SetWinEventHook(EVENT_SYSTEM_FOREGROUND, EVENT_SYSTEM_FOREGROUND, NULL,
WinEventProcCallback, 0, 0, WINEVENT_OUTOFCONTEXT | WINEVENT_SKIPOWNPROCESS);

HWINEVENTHOOK hWinEventHook0 = SetWinEventHook(
EVENT_OBJECT_CREATE, EVENT_OBJECT_CREATE,
NULL, WinEventProcCallback, 0, 0,
WINEVENT_OUTOFCONTEXT | WINEVENT_SKIPOWNPROCESS);

HWINEVENTHOOK hWinEventHook1 = SetWinEventHook(
EVENT_OBJECT_DESTROY, EVENT_OBJECT_DESTROY,
NULL, WinEventProcCallback, 0, 0,
WINEVENT_OUTOFCONTEXT | WINEVENT_SKIPOWNPROCESS);

while (ret = GetMessage(&msg, NULL, 0, 0) > 0) {
if (ret == -1)
{
return;
}
if (cont >= 5) break;
TranslateMessage(&msg);
DispatchMessage(&msg);
cont++;
std::cout << "Reached : " << cont << std::endl;
}

我该如何解决这个问题?提前谢谢你

最佳答案

if (ret = GetMessage(&msg, NULL, 0, 0) > 0)

等于

if (ret = (GetMessage(&msg, NULL, 0, 0) > 0))

关于c++ - SetWinEventHook 和 GetMessage c++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38867942/

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