浅蓝色的琴弦
微风祈愿

当进程在执行时,系统会关联此进程的消息队列
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.
一个典型的程序注册主窗口的窗口类,创建,显示主窗口,接着启动消息循环,它们都放在在WINMAIN函数里。
You create a message loop by using the GetMessage and DispatchMessage functions
你创建的消息循环需使用GetMessage 和 DispatchMessage 函数
If your application must obtain character input from the user, include the TranslateMessage function in the loop.
如果你的程序必须得到用户的字符输入,那么就要在循环里包含TranslateMessage函数。
TranslateMessage translates virtual-key messages into character messages.
TranslateMessage 转换在字符消息里的虚拟键消息

The following example shows a message loop for a thread that uses accelerators and displays a modeless dialog box. When TranslateAccelerator or IsDialogMessage returns TRUE (indicating that the message has been processed), TranslateMessage and DispatchMessage are not called. The reason for this is that TranslateAccelerator and IsDialogMessage perform all necessary translating and dispatching of messages.
接着下面的列子演示了使用加速器和显示非模态对话框的线程的消息循环,什么时候TranslateAccelerator 或 IsDialogMessage 返回真(指示那些消息是经过处理的),  ), TranslateMessage 和 DispatchMessage是不能调用的。原因是TranslateAccelerator 和 IsDialogMessage执行所有必须转换或者派遣的消息。




大多数消息因用户与程序之间的交互而产生。命令通过鼠标单击菜单项或工具栏按钮或通过敲击快捷键生成。用户也通过其他方式生成 Windows 消息,例如移动窗口或调整窗口大小。当发生诸如程序启动或终止、窗口获取或失去焦点等事件时,将发送其他 Windows 消息。控件通知消息由鼠标单击或用户与某一控件(如对话框中的按钮或列表框 (ListBox) 控件)的其他交互生成。
CWinApp 类的 Run 成员函数检索消息并将其调度到适当的窗口。大多数命令消息被发送到应用程序的主框架窗口。由类库预定义的 WindowProc 获取消息并以不同的方式传送消息,传送方式取决于所接收的消息类别。
该过程接收部分

消息的初始接收器必须是窗口对象。Windows 消息通常直接由该窗口对象处理。通常产生于应用程序主框架窗口的命令消息被传送到命令传送中描述的命令目标链。

每一种能够接收消息或命令的对象都有各自的消息映射,该消息映射使消息或命令与其处理程序名配对。

当命令目标对象收到消息或命令后,它在其消息映射中搜索匹配项。如果找到该消息的处理程序,则调用此处理程序

通常将 Windows 消息发送到主框架窗口,而将命令消息传送到其他对象。框架通过命令目标对象的标准序列传送命令,而在这些对象中,有一个应具有该命令的处理程序。每一个命令目标对象检查其消息映射,查看是否能处理传入的消息。

不同的命令目标类在不同的时间检查各自的消息映射。通常,类将命令传送到某些其他对象,给它们首先处理命令的机会。如果这些对象都不能处理此命令,则原始类检查自己的消息映射。然后,如果它自己也无法提供处理程序,则可能将此命令传送到更多的命令目标。(微软的定义)

posted on 2010-08-28 14:39 Platox 阅读(223) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理