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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Issue with menus' in MFC 1

Status
Not open for further replies.

Wings

Programmer
Feb 14, 2002
247
0
0
US
Hello,
I am using a menu as a navigation device.
Select an option on the menu , and I modally show the correct dialog. I have all the code for the menu in my main dialogs class. My issue arises though when I want to use the same menu for all the dialogs. If I am on the main dialog, and I use the menu to open Dialog B. Dialog B is using the same menu so when the user clicks on the menu to go to another dialog, I need to close dialog B, but the code for the menu is in the main dialog. Any ideas on how to close the current dialog providing its not the main dialog, and proceed from there?

Thanks
 
You could pass all dialogs' WM_COMMAND messages to a common function. For example (assuming MFC)

Code:
bool
CMyDialog::OnCommand (WPARAM wparam, LPARAM lparam)
{
  if (!lparam)
    return common_menu_handler (wparam, this);
  else
    return CDialog::OnCommand (wparam, lparam);
}

bool
common_menu_handler (WPARAM wparam, CWnd *source)
{
  switch (HIWORD(wparam))
    {
    case ID_FILE_SWITCHTOSOMEOTHERDIALOG:
      source->DestroyWindow ();
      CSomeOtherDialog *other = new CSomeOtherDialog;
      other->Create (CSomeOtherDialog::IDD,
                     AfxGetMainWnd ());
      return true;

    /* ... */
    default:
      return false;
    }
}

I don't know, use that for inspiration.

[sub]I REALLY hope that helps.[/sub]
Will
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top