[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 246
  • Last Modified:

"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.
0
gurukg102498
Asked:
gurukg102498
1 Solution
 
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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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
 
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

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now