capturing ESCAPE key - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

capturing ESCAPE key

pinkiepinkie Posts: 34Member
how do i prevent the dialog box from closing when ESCAPE key is pressed?

can anybody help
pinkie

Comments

  • stoberstober Posts: 9,765Member ✭✭✭
    : how do i prevent the dialog box from closing when ESCAPE key is pressed?
    :
    : can anybody help
    : pinkie
    :
    [blue]In the PreTranslateMessge() function. When the message is VK_ESCAPE just return TRUE. I put it in my project's CWinApp-derived class so that it will be disabled throughout the entire program, not just one specific view or dialog.[/blue]
  • pinkiepinkie Posts: 34Member
    i tried as u suggested. The ESCAPE key is working as expected, but TAB is not working now. what do i do?


    : : how do i prevent the dialog box from closing when ESCAPE key is pressed?
    : :
    : : can anybody help
    : : pinkie
    : :
    : [blue]In the PreTranslateMessge() function. When the message is VK_ESCAPE just return TRUE. I put it in my project's CWinApp-derived class so that it will be disabled throughout the entire program, not just one specific view or dialog.[/blue]
    :

  • stoberstober Posts: 9,765Member ✭✭✭
    : i tried as u suggested. The ESCAPE key is working as expected, but TAB is not working now. what do i do?
    :
    :

    post the OnTranslateMessage() function that you created. Disabling the ESC key should not have that side affect. That must be a different problem.
  • pinkiepinkie Posts: 34Member
    here it is


    BOOL CMyDlg::PreTranslateMessage(MSG* pMsg)
    {
    if (pMsg->message == VK_ESCAPE )
    {
    return TRUE;
    }
    else
    {
    return FALSE;// but TAB is not working
    }

    //return CDialog::PreTranslateMessage(pMsg);

    }

    Pl tell me is anything wrong with my code???



    : : i tried as u suggested. The ESCAPE key is working as expected, but TAB is not working now. what do i do?
    : :
    : :
    :
    : post the OnTranslateMessage() function that you created. Disabling the ESC key should not have that side affect. That must be a different problem.
    :

  • stoberstober Posts: 9,765Member ✭✭✭
    [b][red]This message was edited by stober at 2003-7-5 8:36:16[/red][/b][hr]
    : here it is
    :
    [code]
    BOOL CMyDlg::PreTranslateMessage(MSG* pMsg)
    {
    if (pMsg->message == VK_ESCAPE )
    {
    return TRUE;
    }
    [red]delete the else statement![/red]
    // else
    // {
    // return FALSE;// but TAB is not working
    // }

    [red]UN-delete this next line![/red]
    return CDialog::PreTranslateMessage(pMsg);

    }
    [/code]
    : Pl tell me is anything wrong with my code???
    :
    :
    :
    : : : i tried as u suggested. The ESCAPE key is working as expected, but TAB is not working now. what do i do?
    : : :
    : : :
    : :
    : : post the OnTranslateMessage() function that you created. Disabling the ESC key should not have that side affect. That must be a different problem.
    : :
    :
    :



  • pinkiepinkie Posts: 34Member
    this is not working.dont know why?? have u tried?

    : [b][red]This message was edited by stober at 2003-7-5 8:36:16[/red][/b][hr]
    : : here it is
    : :
    : [code]
    : BOOL CMyDlg::PreTranslateMessage(MSG* pMsg)
    : {
    : if (pMsg->message == VK_ESCAPE )
    : {
    : return TRUE;
    : }
    : [red]delete the else statement![/red]
    : // else
    : // {
    : // return FALSE;// but TAB is not working
    : // }
    :
    : [red]UN-delete this next line![/red]
    : return CDialog::PreTranslateMessage(pMsg);
    :
    : }
    : [/code]
    : : Pl tell me is anything wrong with my code???
    : :
    : :
    : :
    : : : : i tried as u suggested. The ESCAPE key is working as expected, but TAB is not working now. what do i do?
    : : : :
    : : : :
    : : :
    : : : post the OnTranslateMessage() function that you created. Disabling the ESC key should not have that side affect. That must be a different problem.
    : : :
    : :
    : :
    :
    :
    :
    :

  • stoberstober Posts: 9,765Member ✭✭✭
    : this is not working.dont know why?? have u tried?
    :
    [code]
    BOOL CTest5Dlg::PreTranslateMessage(MSG* pMsg)
    {
    if(pMsg->message == WM_KEYDOWN)
    {
    if(pMsg->wParam == VK_ESCAPE)
    return TRUE;
    }
    return CDialog::PreTranslateMessage(pMsg);
    }
    [/code]

  • weiccoweicco Posts: 950Member
    Another way to do this, but it will make life little harder on dialogs:

    [code]
    BOOL COwnApp::PreTranslateMessage(MSG* pMsg)
    {
    if (pMsg->message == WM_KEYDOWN)
    {
    SendMessage(GetActiveWindow(), pMsg->message, pMsg->wParam, pMsg->lParam);
    return TRUE;
    }

    return CDialog::PreTranslateMessage(pMsg);
    }
    [/code]

    : : this is not working.dont know why?? have u tried?
    : :
    : [code]
    : BOOL CTest5Dlg::PreTranslateMessage(MSG* pMsg)
    : {
    : if(pMsg->message == WM_KEYDOWN)
    : {
    : if(pMsg->wParam == VK_ESCAPE)
    : return TRUE;
    : }
    : return CDialog::PreTranslateMessage(pMsg);
    : }
    : [/code]
    :
    :

  • pinkiepinkie Posts: 34Member
    tnx it is working
    pinkie

    : : this is not working.dont know why?? have u tried?
    : :
    : [code]
    : BOOL CTest5Dlg::PreTranslateMessage(MSG* pMsg)
    : {
    : if(pMsg->message == WM_KEYDOWN)
    : {
    : if(pMsg->wParam == VK_ESCAPE)
    : return TRUE;
    : }
    : return CDialog::PreTranslateMessage(pMsg);
    : }
    : [/code]
    :
    :

Sign In or Register to comment.