[英]Viewing Win32 messages
Hello everyone I am new to windows32 programming and I have a couple of questions-:大家好,我是 windows32 编程的新手,我有几个问题:
When I use the following code in a program it works fine -:当我在程序中使用以下代码时,它工作正常-:
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
But when I replace null of GetMessage to hwnd(the handle of the window just created) the doesn't seem to close it still remains running in the background.但是当我将 GetMessage 的 null 替换为 hwnd(刚刚创建的 window 的句柄)时,它似乎并没有关闭,它仍然在后台运行。 Why does this happen when I replace NULL with hwnd means I am receiving messages for only one window then why doesn't it work????
为什么当我用 hwnd 替换 NULL 时会发生这种情况意味着我只收到一个 window 的消息那么为什么它不起作用????
while(GetMessage(&msg,hwnd,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
By the way the windows function is-:顺便说一下 windows function 是:
LRESULT CALLBACK WinProc(HWND hWnd, UINT message,
WPARAM wparam, LPARAM lparam){
switch(message){
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wparam, lparam);
}
return 0;
}
Secondly-:第二-:
Is there any way I can see all the messages sent to any particular window????有什么办法可以看到发送到任何特定 window 的所有消息????
Thirdly-:第三-:
What is the reason behind writing __stdcall(WINAPI) when compiling my windows programs????编译我的 windows 程序时写 __stdcall(WINAPI) 的原因是什么????
A quick reply would be appreciated.Thank You.快速回复将不胜感激。谢谢。
GetMessage
returns 0
(making the loop end) only when it receives a WM_QUIT
, but a WM_QUIT
is not associated to any particular window, so it is never received if you have a GetMessage
that asks only messages for a certain hWnd
. GetMessage
仅在收到WM_QUIT
时返回0
(使循环结束),但WM_QUIT
不与任何特定的 window 相关联,因此如果您的GetMessage
只询问特定hWnd
的消息,则永远不会收到它。
If it's a window of yours, you already see them inside their window procedure;如果它是你的 window,你已经在他们的 window 过程中看到他们; if you want to filter them before dispatching them to their window procedure, you can check the
msg
structure that is populated by GetMessage
before calling DispatchMessage
.如果你想在将它们分派到它们的 window 过程之前过滤它们,你可以在调用
DispatchMessage
之前检查由GetMessage
填充的msg
结构。
The whole Windows API uses the stdcall
calling convention (I think because it is slightly faster/produces less boilerplate code than the usual cdecl
), so also your callbacks must follow that calling convention.整个 Windows API 使用
stdcall
调用约定(我认为是因为它比通常的cdecl
稍快/产生的样板代码更少),因此您的回调也必须遵循该调用约定。 Notice that you must use WINAPI
(ie stdcall
) only on functions that are called by Windows API functions, for the other ones you are free to use whatever calling convention you like best.请注意,您必须仅在 Windows API 函数调用的函数上使用
WINAPI
(即stdcall
),对于其他函数,您可以自由使用您最喜欢的任何调用约定。
PostQuitMessage
generates WM_QUIT
which is processed by the message queue, but not associated with a particular window. By filtering only hwnd
messages in your call to GetMessage
, you don't process WM_QUIT
. PostQuitMessage
生成WM_QUIT
,它由消息队列处理,但不与特定的 window 关联。通过在调用GetMessage
时仅过滤hwnd
消息,您不会处理WM_QUIT
。
Regarding seeing all messages being sent to a window / thread / process, see https://stackoverflow.com/questions/4038730/i-am-looking-for-a-windows-spy-application关于查看发送到 window/线程/进程的所有消息,请参阅https://stackoverflow.com/questions/4038730/i-am-looking-for-a-windows-spy-application
Finally, regarding __stdcall
, see What does "WINAPI" in main function mean?最后,关于
__stdcall
,参见What does "WINAPI" in main function mean?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.