MFC发送消息到MAIN线程(而不是窗口)? [英] MFC Send message to MAIN thread (rather than a window)?
问题描述
我正在使用MFC和C ++为Windows编写GUI应用程序。
所以我需要从我的工作线程发送消息到我的MAIN线程,告诉它更新我的GUI。但是我不知道如何发送消息到实际的MAIN线程,而不是一个窗口。因为它是我可以看到它是在MAIN线程当它收到消息,但我不知道如果这是保证或只是运气。
在工人:
$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ p>
这是否意味着
线程ID,通过在主线程中使用 threadId = GetCurrentThreadId();
,然后通过调用 PostThreadMessage(threadId,...)
从您的工作者线程。
- > 这里 < - ,您应避免使用 PostThreadMessage
向UI线程发送消息,应该更好地发送消息到其窗口。
I'm writing a GUI application for Windows using MFC and C++.
So I need to send messages to my MAIN thread from my worker thread to tell it to update my GUI. However I'm not sure how to send a message to the actual MAIN thread rather than a Window. As it is I can see it is in the MAIN thread when it receives the message but I am not sure if this is guaranteed or just luck.
In worker: PostMessage( *myTestToolDlg, WM_YOU_HAVE_DATA,UPDATE_GUI, 0 );
In application window: LRESULT CTestToolDlg::OnData(WPARAM wp, LPARAM )
Does this somehow mean the that
You can get your main thread's thread id by using something like threadId = GetCurrentThreadId();
in the main thread, and then send a message to it by calling PostThreadMessage(threadId, ...)
from your worker thread.
However, as Hans Passant said -> here <-, you should avoid using PostThreadMessage
to send messages to UI threads, and should better send messages to its window.
这篇关于MFC发送消息到MAIN线程(而不是窗口)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!