"Dialog containing Menus"

I have a dialog.I have inserted a menu(IDR_XXX)into this dialog by creating a new menu item nd enabling the menu property of the dialog.I have Exit as a menu item.I want the dialog to be dismissed when I click Exit, but I don't want the dialog to be dismissed when I click Esc key or Enter Key.Give me an example.
gurukg102498Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Vinayak KumbarSr Program ManagerCommented:
Hi,

Map the Exit menu command to ur dialog say OnExit()
Then in OnExit() call OnOK() or OnCancel() of CDialog.

To trap those default messages,
Map IDOK and IDCANCEL functions say OnOK() and OnCancel() and there dont call the base class functions.

Hope this helps.
VinExpert
0
Vinayak KumbarSr Program ManagerCommented:
Hi,

Follow the steps to achieve that

Go to class wizard and select that dialog class say CDlgMenuDlg.
Then U get IDOK message, add a function OnOk() to it, and comment the base class call as

void CDlgMenuDlg::OnOK()
{
    //CDialog::OnOK();
}

Similarly map the IDCANCEL and comment the line
void CDlgMenuDlg::OnCancel()
{
    //CDialog::OnCancel();
}

Add the function for ID_EXIT(menu item ID) and place the following code
void CDlgMenuDlg::OnExit()
{
    CDialog::OnOK();      
}

That will satisfy Ur requirement.

Cheers,

VinExpert
0
gurukg102498Author Commented:
If I do like that it will give me an error.Suggest some other method.
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Vinayak KumbarSr Program ManagerCommented:
Hi,

What error it gave?
Pls specify.

Cheers,
VinExpert
0
Vinayak KumbarSr Program ManagerCommented:
Hi,

I am giving some steps regarding that.

1.U have created a new menu say IDR_MENU1 using resource       wizard. That contains one menu item as ID_EXIT
2.Now u created a dialog resource IDD_DIALOG1 and attached    IDR_MENU1 to it.
3. Add a class to the dialog box say CDlgMenuDlg.
4. Close the class wizard, open the menu(IDR_MENU1). From     resource view, double click on the menu->IDR_MENU1.
5. Now select the class wizard from menu options(ctrl+w)
6. At this time it may ask u to create/select new class, say     cancel, now in the class wizard dialog box u will get the     ID_EXIT option for CDlgMenuDlg class. Map the function for it     as OnExit() and follow the same procedure as I told u before.

Thats it. Try it out.

VinExpert
0
Vinayak KumbarSr Program ManagerCommented:
Hi,

If u want give me Ur email Id I will send u the sample code.

Cheers,
VinExpert
0
leflonCommented:
maybe you better use PreTranslateMessage function
BOOL CDialogXXXX::PreTranslateMessage(MSG* pMsg)
{
      // TODO: Add your specialized code here and/or call the base class
      switch(pMsg->message)
      {
      case WM_KEYDOWN:
            if(pMsg->wParam==VK_ESCAPE || pMsg->wParam==VK_RETURN)
            {
                  TRACE("*** key pressed\n");
                  return FALSE;
            }
            break;
      }
      return CDialog::PreTranslateMessage(pMsg);
}

this will catch return and escape key and just make a trace  output.
0
Vinayak KumbarSr Program ManagerCommented:
Hi,

U can map the PreTranslateMessage() function to that dialog box(as suggested by leflon) and put the following code in it.

if((pMsg->message == WM_KEYDOWN) && (pMsg->wParam==VK_ESCAPE || pMsg->wParam==VK_RETURN))
{
    return FALSE;
}

And map the menu item function OnExit() and place the code as I have told in my previous comment.

That should give U another method to achieve that.

Try it out.

VinExpert
0
abdijCommented:
Here is a peice of code that does waht you need:

My dialog class is CCaptureKeysDlg.

I have used the class wizard to map the PreTranslateMesage() function for the dialog

BOOL CCaptureKeysDlg::PreTranslateMessage(MSG* pMsg)
{      
      switch(pMsg->message)
      {
      case 0x100:
            {
                  if(pMsg->lParam == 0x10001 && pMsg->wParam == 0x1b)
                        return TRUE;
                  if(pMsg->lParam == 0x1c0001 && pMsg->wParam == 0x0d)
                        return TRUE;
            }
      }

      return CDialog::PreTranslateMessage(pMsg);
}

Keep the ID of the Exit Menu item as ID_APP_EXIT. (Use resource editor to map it).

Hope this is what you need
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Vinayak KumbarSr Program ManagerCommented:
Hi abdij,

I think leflon and me have given the same comments. And U are using some hardcoded values.(which are/may be the hex codes of the messages and key codes).

Hope u go through the comments once again.

Regards,
VinExpert
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.