请输入您要查询的百科知识:

 

词条 MessageLoop
释义

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可以将一个虚拟按键消息转化成字符消息。

随便看

 

百科全书收录4421916条中文百科知识,基本涵盖了大多数领域的百科知识,是一部内容开放、自由的电子版百科全书。

 

Copyright © 2004-2023 Cnenc.net All Rights Reserved
更新时间:2025/2/4 6:54:59