suman reddy
suman reddy

Reputation: 51

To send a custom Message from Parent Dialog Box to child Dialog Box using SendMessage() function

There are several ways to use SendMessage()

  1. WIN32API modal

::SendMessage(h, MY_MSG ,0,0);

  1. MFC modal

    Let's ptr having child Dialog box Handle then we can use this modal

ptr->SendMessage(MY_MSG,0,0);

But How can I get child dialog Box handle once I clicked a button in parent Dialog box see this.. I write the code

 void CCustomMessageDlg::OnBnClickedOpen(){   

     MyDialog2 d2(IDD_CHILD_DIALOG);
     d2.DoModal();

         }

I Need Send Custom Message to child Dialog using SendMessage() API once Button is clicked. Can You Please Suggest A solution for this problem

Upvotes: 0

Views: 1363

Answers (1)

Danny_ds
Danny_ds

Reputation: 11406

You cannot send a message to the dialog after DoModal() returns, because the dialog will already be destroyed.

In case you want to pass data to the dialog, you can add a member variable to your child dialog, say:

CString m_strMyData;

Then use:

 MyDialog2 d2(IDD_CHILD_DIALOG);
 d2.m_strMyData = "Test";
 d2.DoModal();

and access m_strMyData from within the child dialog.

Upvotes: 1

Related Questions