将消息发布到模型对话框 [英] Post messages to model dialog

查看:107
本文介绍了将消息发布到模型对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我打算创建无模式对话框并从另一个线程接收消息.根据对创建无模式对话框的理解,我需要在CWinThread派生类对象内部创建CWinThread和某些框架或对话框.但是我真的需要创建框架/对话框吗?为什么我不能直接将消息发布到CWinThread派生的类对象?

I'm planning to create modeless dialog and to receive messages from another thread. According to my understanding to creating modeless dialog I need to create CWinThread and some frame or dialog inside of CWinThread derived class object. But do I really need to create frame/dialog? Why I can't post messages direct to CWinThread derived class object?

推荐答案

您不需要对话框来接收消息,但确实需要窗口句柄.该窗口句柄不需要与视觉对象相关联.我认为您需要的是仅消息窗口.

You don't need a dialog to receive messages, but you do need a window handle. That window handle does not need to be associated with something visual. What I think you need is a message only window.

在MFC中,您可以使用CreateEx方法使用CWnd创建仅消息窗口.将HWND_MESSAGE传递给CreateExhWndParent参数.

In MFC you can do this with CWnd using the CreateEx method to create the message only window. Pass HWND_MESSAGE to the hWndParent parameter of CreateEx.

确实可以创建一个隐藏的无模式对话框来接收消息.但是,这是非常浪费的.而且,MFC是围绕在主UI线程中创建对话框的概念而设计的.因此,出于多种不同的原因,您确实希望避免创建仅用于在线程中接收消息的对话框.使用仅消息窗口.

It is true that you can create a hidden modeless dialog just to receive messages. However, this is grossly wasteful. What's more, MFC is designed around the concept that dialogs are created in the main UI thread. So for a number of different reasons you really do want to avoid creating a dialog just to receive messages in a thread. Use a message only window.

这篇关于将消息发布到模型对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆