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

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.