MessageLoop

王朝百科·作者佚名  2010-04-08  
宽屏版  字体: |||超大  

MessageLoop

来自MSDN(原文)

-----------------------------------------------------------------------------------

Message Loop

The system automatically creates a message queue for each thread. If the thread creates one or more windows, a message loop must be provided; this message loop retrieves messages from the thread's message queue and dispatches them to the appropriate window procedures.

Because the system directs messages to individual windows in an application, a thread must create at least one window before starting its message loop. Most applications contain a single thread that creates windows. A typical application registers the window class for its main window, creates and shows the main window, and then starts its message loop — all in the WinMain function.

You create a message loop by using the GetMessage and DispatchMessage functions. If your application must obtain character input from the user, include the TranslateMessage function in the loop. TranslateMessage translates virtual-key messages into character messages.

-----------------------------------------------------------------------------------

翻译

-----------------------------------------------------------------------------------

消息循环

操作系统自动为每一个线程创建一个信息队列。如果这个线程创建了一个或多个窗口,则你必须建立一个消息循环。

你建立的这个消息循环可以从消息队列里面获取消息,然后发送到合适的窗口进程中去。

因为操作系统要将消息发送给一个应用程序中单个的窗口,所以在开始建立消息循环前,你的线程必须要创建个窗口。

大部分的应用程序都包含着一个线程,线程拥有着一个窗口。

最典型的应用程序包含了:注册窗口类、创建窗口、显示窗口,然后开始消息循环——这都可以在WinMain函数里按顺序编写。

创造一个消息循环要使用GetMessage和DispatchMessage这两个函数。

如果你的应用程序必须获得用户输入的字符,那还需要TranslateMessage这个函数。

TranslateMessage可以将一个虚拟按键消息转化成字符消息。

 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
© 2005- 王朝百科 版权所有