关于DialogBox和消息循环

aBigWood 2010-09-19 09:26:34
我在Windows程序设计11.2看到:
The messages for a modal dialog box don't go through your program's message queue, so you needn't worry about the effect of keyboard accelerators within the dialog box.

那是不是就意味着DialogBox函数内部有一个消息循环?
...全文
283 10 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
aBigWood 2010-09-19
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 freelaxy 的回复:]

"your program's message queue"?

message queue是按线程分配的, 一个program可以有多个message queue


=======================================================
FreeLaxy, your backup.
============================……
[/Quote]

那也就是说,窗口是属于线程的?
freelaxy 2010-09-19
  • 打赏
  • 举报
回复
"your program's message queue"?

message queue是按线程分配的, 一个program可以有多个message queue


=======================================================
FreeLaxy, your backup.
=======================================================
aBigWood 2010-09-19
  • 打赏
  • 举报
回复
谢谢VisualEleven, 这我就明白了。看到线程,我又想到一个问题,在设计Windows窗口程序的时候,是不是应该尽量保持只有一个线程的消息循环在运行呢? 否则岂不是很混乱?
aBigWood 2010-09-19
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 visualeleven 的回复:]

http://hi.baidu.com/piperworldcup/blog/item/789bd6896003a9b40f2444d5.html
[/Quote]

1、非模态对话框和父窗口共享当前线程的消息循环

2、模态对话框新建一个新的消息循环,并由当前消息循环派发消息,而父窗口。模态对话框屏蔽了用户对它父窗口的操作,但是不是在消息循环里面屏蔽,所以给父窗口发送消息,父窗口还是可以接收得到。

3、调用模态对话框的窗口处理函数会被阻塞,但是新的消息循环仍然可以调用父窗口的消息处理函数,所以,发送给父窗口的新消息仍然可以被及时处理。
gameslq 2010-09-19
  • 打赏
  • 举报
回复
>>那是不是就意味着DialogBox函数内部有一个消息循环?

DialogBox内部是不是有一个消息循环不好说,肯定的一点是系统提供了modal dialog 键盘接口,而非模态对话框则不是.这一点在MSDN 上有说明:(Dialog Box Keyboard Interface)

The system automatically provides the keyboard interface for all modal dialog boxes.
It does not provide the interface for modeless dialog boxes unless the application
calls the IsDialogMessage function to filter messages in its main message loop. This
means that the application must pass the message to IsDialogMessage immediately
after retrieving the message from the message queue. The function processes
the messages if it is for the dialog box and returns a nonzero value to indicate
that the message has been processed and must not be passed to the TranslateMessage or DispatchMessage function.

aBigWood 2010-09-19
  • 打赏
  • 举报
回复
哦……我想我明白了,DialogBox是在父窗口的消息响应函数中调的,直到dialog销毁DialogBox才返回,所以主程序中的消息循环不可能再处理其它消息。 那就是说,DialogBox里必然有一个消息循环了?
jieleiping 2010-09-19
  • 打赏
  • 举报
回复
你就新建一个最简单的那种win32的窗口过程,里面有一个about窗口,看看就明白了。。。
ji1bing 2010-09-19
  • 打赏
  • 举报
回复
DialogBox弹出的是 模态窗口。其窗口内部会自己封装一个消息循环,并且拦截了包括对父窗口发出的所有消息, 所以弹出模态窗口后,父窗口会全部失效,只能作用于该模态窗口中。

15,980

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧