[英]Message queue - WinAPI
the message queue is present in any type of program or Unix is present only in programs written in Windows interface? 消息队列存在于任何类型的程序中,还是Unix仅存在于以Windows界面编写的程序中?
For example this programm: 例如,该程序:
int main()
{
short int n;
while(1)
{
if (n = GetKeyState(VK_UP))
{
cout << n;
}
else
{
cout << n;
}
Sleep(150);
}
return 0;
}
have or not the message queue? 是否有消息队列? If yes, the GetKeyState function retrieves the keyboard messages from the message queue? 如果是,GetKeyState函数是否从消息队列中检索键盘消息?
Yes, you must call PeekMessage
or GetMessage
to make GetKeyState
return new values, for further reading look here: 是的,您必须调用PeekMessage
或GetMessage
来使GetKeyState
返回新值,以在此处进一步阅读:
http://blogs.msdn.com/b/oldnewthing/archive/2004/11/30/272262.aspx http://blogs.msdn.com/b/oldnewthing/archive/2004/11/30/272262.aspx
and here: 和这里:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms646301%28v=vs.85%29.aspx http://msdn.microsoft.com/zh-cn/library/windows/desktop/ms646301%28v=vs.85%29.aspx
If you dont want message loop use GetAsyncKeyState
. 如果您不希望消息循环,请使用GetAsyncKeyState
。
GetKeyState
is a Windows function that interacts closely with the Windows message queue. GetKeyState
是Windows函数,与Windows消息队列紧密交互。 The function does not exist in Unix. 该函数在Unix中不存在。
As I explained in your previous question, GetKeyState
provides information about the key state associated with the most recently retrieved message. 正如我在上一个问题中解释的那样, GetKeyState
提供有关与最近检索到的消息相关联的键状态的信息。 Since your console application does not have a message queue, and is not pumping messages, GetKeyState
yields no useful information. 由于您的控制台应用程序没有消息队列,也没有泵送消息,因此GetKeyState
产生有用的信息。
Again, as explained in your previous question, you use GetAsyncKeyState
to obtain information about the state at the instant that the API call is made . 同样,如上一个问题所述,您可以使用GetAsyncKeyState
来获取有关API调用时的状态信息。
Finally, again repeating statements from your earlier question, test for a key being pressed by checking for a negative return value. 最后,再次重复您先前的问题,通过检查负返回值来测试是否按下了某个键。 For instance: 例如:
if (GetAsyncKeyState(VK_UP) < 0)
....
My most important advice to you is that when you ask a question here on Stack Overflow, you read the answers! 我给您的最重要建议是,当您在Stack Overflow上提问时,请阅读答案! If you don't understand them, leave comments asking for clarification. 如果您不理解它们,请留下评论要求澄清。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.