2

I have SDI application that hand view, doc and mainframe. In view class, I have button to open another dialog, let say Chartering dialog. I would like to open that dialog and send initial value from view to assign some variable at dialog, but I can not catch message event at dialog class. Below as my code:

    // button onclick to show new dialog
    charteringDlg = new CharteringDlg();
// show chartering dialog
if(charteringDlg->Create(IDD_DIALOG_CHATTERING, GetDesktopWindow()))
{
    bChartering = true;
    charteringDlg->MoveWindow(900,300,450,300);
    charteringDlg->ShowWindow(SW_SHOW); 

    int temp = 12;

    GetMain()->SendMessage(UWM_MYMESSAGE_CHARTERING, 0,(LPARAM)&temp);
}

and in chartering dialog I handle message like below

ON_MESSAGE(UWM_MYMESSAGE_CHARTERING, &CharteringDlg::OnSetShowTemp)

chartering function

LRESULT CharteringDlg::OnSetShowTemp(WPARAM, LPARAM lParam)
{
    int * s = (int *)lParam;

    return 0;
}

I set break point at OnSetShowTemp() function but it cannot jump there. Any idea would be great appreciated.

  • `GetMain()->SendMessage(UWM_MYMESSAGE_CHARTERING, 0,(LPARAM)&temp);` -> `charteringDlg->SendMessage(UWM_MYMESSAGE_CHARTERING, 0,(LPARAM)&temp);`. Or even simpler: `charteringDlg->thevalueorwhatever = 12`. – Jabberwocky Jan 18 '19 at 14:01
  • thank you very much, I don't think that is simple like that. if you post as answer, I will accept ^^ – Lê Duy Cường Jan 18 '19 at 14:35
  • BTW, are you creating a modeless or a modal dialog? If it's a modeless one, googling _modeless dialog mfc_ might be helpful. You need to take care of the deletion of the modal dialog once it is closed. – Jabberwocky Jan 18 '19 at 14:46

1 Answers1

1

For assigning an initial value to one of your dialog's members you don't need to send it a message.

You can just assign the value directly:

So instead of

GetMain()->SendMessage(UWM_MYMESSAGE_CHARTERING, 0,(LPARAM)&temp);

you should have something like:

charteringDlg->thevalueorwhatever = 12;

And BTW:

GetMain()->SendMessage(UWM_MYMESSAGE_CHARTERING, 0,(LPARAM)&temp);

is wrong anyway, you should send the message to the dialog and not to the main window:

charteringDlg->SendMessage(UWM_MYMESSAGE_CHARTERING, 0,(LPARAM)&temp);
Jabberwocky
  • 48,281
  • 17
  • 65
  • 115