CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: CTRL + X

  1. #1
    Join Date
    May 1999
    Posts
    1

    CTRL + X

    I am very new to C++ in a Visual environment. Does anyone have a suggestion how to implement CTRL + X into a dialog to exit the
    program. Have tried various combinations to no avail, if someone can help, it would be much appreciated.

    kj


  2. #2
    Join Date
    May 1999
    Posts
    2

    Re: CTRL + X

    I don't think it's possible in the context of your dialog.
    Supposedly, what you are trying to do can only be done in a dialog
    with no controls on it, such as painting with a mouse.
    Methinks Darren expects the impossible, or at least something
    he hasn't explained yet.

    See my posting - OnKeyDown -
    The code there works if you create a form with nothing else on it.

    Pete.


  3. #3
    Join Date
    May 1999
    Posts
    82

    Re: CTRL + X

    Yes it can be done, it just takes a little ingenuity!! Try this

    1) Create a new accelerator resource, and make and entry for Ctrl+X who's ID is mapped to IDCANCLE

    2) Create a member variable in your dialog class like this

    HACCEL m_hAccel;



    3) Initialize the variable in the dialogs constructor, and load the accelerator into the dialog like so

    m_hAccel = ::LoadAccelerators(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDR_ACCELERATOR1));



    3) Overload the PreTranslateMessage handler in the dialog like so

    BOOL CYourtDlg::PreTranslateMessage(MSG* pMsg)
    {
    if (m_hAccel != NULL)
    if(::TranslateAccelerator(m_hWnd, m_hAccel, pMsg))
    return TRUE;

    return CDialog::PreTranslateMessage(pMsg);
    }



    That all there is to it!!!



  4. #4
    Join Date
    Jun 1999
    Posts
    1

    Re: CTRL + X

    Hi,

    I'd like to define hot keys for edit box in my dialog. One of the hot keys is like "Ctrl+Alt+A" which ideally could insert "ALPHA" in Edit box when it gets pressed. I've tried the method you posted and it failed on "::TranslateAccelerator(m_hWnd, m_hAccel, pMsg)". (the returned value is 0. When I tried to capture the error code with GetLastError, it returned 0.) What might be wrong? Please help. Also do you other ways that I can use? Thank you very much for your time.

    mxu

    MXu

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