C++ 如何在 Windows 钩子中打破消息循环 [英] C++ how to break message loop in windows hook
问题描述
我需要打破 win32 键盘钩子中的消息循环.循环看起来像这样,
I need to break the message loop in win32 keyboard hook. The loop look like this,
MSG msg;
while (GetMessage(&msg, NULL, NULL, NULL))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
我使用了 unhook 方法,但它不起作用.我还有另一个问题,如果我将 while 循环参数更改为 !GetMessage,它的工作方式与以前相同.如果我在 while 循环中添加 printf ,它不会打印任何内容.我只想为键盘钩子制作一个dll.和 dll 中的方法需要结束.有了这个(消息循环)我不能结束(或返回一些东西)那个方法.
I used unhook method but it doesn't work. and I have another Question that if I change while loop parameter to !GetMessage it work same as before. and if I add printf inside that while loop its not printing anything. I just want to make a dll for keyboard hook. and method in dll need to end. with this(message loop) I cant end(or return something) that method.
抱歉我的英语不好.
谢谢.
推荐答案
使用 PostQuitMessage(0)
来破坏程序.你可以把它放在你的窗口过程中,例如在WM_DESTROY
消息中来.
Use a PostQuitMessage(0)
to break the prodecure. You can put it in your window procedure, for example, in the WM_DESTROY
message comes.
这篇关于C++ 如何在 Windows 钩子中打破消息循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!