Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to send messages to the dialog in the other thread? 1

Status
Not open for further replies.

uncool

Programmer
Jun 20, 2002
4
CN
I created a dialog based mfc project in which another dialog can be started with a new thread. My question is that how can i send some messages to the newly started dialog in the main dialog? TIA.
 
Hi uncool, welcome to Tek-Tips [cheers]

Take a look at the SDK docs for PostThreadMessage()

Good luck

-pete
 
That would be a message to the newly created thread.

If you want to send it to the dialog itself use Send- or PostMessage().

Greetings,
Rick
 
Yeah SendMessage will ensure that message is delivered and will not return unless it does its task but nothing such with PostMessage
 
thanks pete and rick!

Sorry I didn't make my question clear:) I knew how to send messages with Post/SendMessage but does it mean that I need to make the dialog a global variable? I hate this:( I don't know how to visit this dialog class in the Main Dialog. Because the dialog is started with a thread.
 
You only need to have a handle to the dialog if you want to send it messages. Since this is all about sending messages, you might consider sending this handle to the main dialog using SendMessage :)

Greetings,
Rick
 
( Sorry I don't know how to edit my posted messages )

The dialog is started within the newly created thread, in other word, the dialog is not a member of the main dialog. I tried to use AfxGetApp->m_pMainWnd to visit the main dialog, failed. And I also tried to post some messages to the thread based dialog from main dialog but no way was found. Of course I can visit this dialog by clarfying it as a global variable, but it's not a good one. So what I gonna do? Thanks!
 
You can send a pointer to the main dialog into the newly created thread. This way you can "visit" it from within the second dialog.

>>And I also tried to post some messages to the thread based dialog from main dialog but no way was found.
How did you do this? You'll need a handle to the dialog to be able to send messages to it, don't you?

If all you want is communication between the two dialogs, I would suggest you send in a pointer to the main dialog when creating the second thread. Then, from the second thread, send in a pointer to the second dialog by creating some method called "Set2ndDlgPtr" or something like that....

Greetings,
Rick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top