CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2005
    Posts
    173

    Issue with dialog

    Hi all
    I am making a dialog based application.
    Now when we press "Esc" button then dialog is closed.
    Now I want to stop this activity that is if press Esc button then dialog should not be closed.

    Please help ( better if provide some code snippet for implementing this)

    Thanks

  2. #2
    Join Date
    Jun 2005
    Location
    Chennai , India
    Posts
    1,375

    Thumbs up Re: Issue with dialog

    Quote Originally Posted by hash123
    Hi all
    I am making a dialog based application.
    Now when we press "Esc" button then dialog is closed.
    Now I want to stop this activity that is if press Esc button then dialog should not be closed.

    Please help ( better if provide some code snippet for implementing this)

    Thanks
    Code:
    BOOL CDlg::PreTranslateMessage(MSG* pMsg)
    {
                    BOOL             handled;               // indicates if message was handled
    
            // assume that we didn't handle the message
            handled = FALSE;
    
            if (pMsg->wParam == VK_ESCAPE)
            {
                    // prevent escape key from trickling
                    handled = TRUE;
            }
    
            // else let base class handle
            else
            {
                    handled = CDialog::PreTranslateMessage(pMsg);
            }
            return handled;
    
    }
    It takes seconds for rating…that actually compensates the minutes taken for giving answers
    The biggest guru-mantra is: Never share your secrets with anybody. It will destroy you.
    Regards, Be generous->Rate people
    Jayender!!

  3. #3
    Join Date
    Sep 2002
    Location
    14° 39'19.65"N / 121° 1'44.34"E
    Posts
    9,815

    Re: Issue with dialog

    Take a look at this FAQ - it also explains that overriding PreTranslateMessage is not recommended in this situation.

    Besides that: Dismissing a dialog with the Esc key is expected behaviour for dialogs - users will think something is wropng with your dialog if it doesn't behave that way. So I guess that your application probably shouldn't be a dialog, but a regualar application in the first place.

  4. #4
    Join Date
    Jun 2005
    Location
    Chennai , India
    Posts
    1,375

    Thumbs up Re: Issue with dialog

    Quote Originally Posted by gstercken
    Take a look at this FAQ - it also explains that overriding PreTranslateMessage is not recommended in this situation.

    Besides that: Dismissing a dialog with the Esc key is expected behaviour for dialogs - users will think something is wropng with your dialog if it doesn't behave that way. So I guess that your application probably shouldn't be a dialog, but a regualar application in the first place.
    If that is the case..
    Override the OnCancel function for the dialog and Possible also to override OnOk and OnClose..
    Ok .. Gstercken ?
    Anyway thanks for the info ...
    It takes seconds for rating…that actually compensates the minutes taken for giving answers
    The biggest guru-mantra is: Never share your secrets with anybody. It will destroy you.
    Regards, Be generous->Rate people
    Jayender!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured