简体   繁体   English

MFC PostMessage从主项目到UI线程

[英]MFC PostMessage from main project to UI thread

I'm programming a very big software. 我正在编写一个非常大的软件。 It has a lot of projects inside it. 它里面有很多项目。

One of my projects is a UI thread. 我的项目之一是UI线程。 I want to post messages to this UI thread, from the main project. 我想将消息从主项目发布到此UI线程。

When I use PostThreadMessage (after getting the thread by GetCurrentThreadId() ), everything works fine, except the times when a MessageBox is open... 当我使用PostThreadMessage时(在通过GetCurrentThreadId()获取线程之后),一切正常,除了打开MessageBox的时间...

So I want to send messages from the main project by PostMessage. 所以我想通过PostMessage从主项目发送消息。 How exactly can I send messages in that way? 我该如何准确地发送消息? how do I know which window to send the message to? 我如何知道将消息发送到哪个窗口?

Thanks 谢谢

If it is an UI thread then you must have a primary window created in that thread. 如果它是UI线程,则必须在该线程中创建一个主窗口。 Just post message to this window. 只需将消息发布到此窗口即可。 That's it. 而已。

EDIT 1: If it is another process, then probably you can create a hidden window with some unique title with special characters and underscores and use FindWindow API to find that window or use EnumWindows to enumerate top level windows and match the title. 编辑1:如果这是另一个过程,则可能您可以创建一个隐藏的窗口,该窗口具有一些带有特殊字符和下划线的唯一标题,并使用FindWindow API查找该窗口,或使用EnumWindows枚举顶级窗口并匹配标题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM