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

    Keyboard ShortCut

    Hi All,
    I have developed a Dialog Based Application. I have a few buttons on the dialog box. I want to add Keyboard shortcuts so that the user can use the keyboard also(Right now only mouse can be used).
    Can any one tell me how to add keyboard shortcuts like (Alt+S or Ctrl+S etc).

    Thanks in Advance
    Vittal


  2. #2
    Guest

    Re: Keyboard ShortCut

    To put in Hotkeys, use the "&" e.g. for a button with Help, put in H&elp and then the "e" will be the hotkey (underscored)


  3. #3
    Join Date
    May 1999
    Location
    Mass, USA.
    Posts
    103

    Re: Keyboard ShortCut

    No, that's how you create accelerators.

    To use hot keys, do one of the following:


    1 Use a CHotKeyCtrl in your app's window
    2 Use ::RegisterHotKey, ::UnregisterHotKey



    /ravi


  4. #4
    Join Date
    May 1999
    Posts
    82

    Re: Keyboard ShortCut

    Actually with a little work you can use a real accelerator table in your dialog. Follow these steps...

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

    HACCEL m_hAccel;



    2) 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);
    }



    Thats all there is to it!!!


  5. #5
    Join Date
    May 1999
    Posts
    15

    Re: Keyboard ShortCut

    I have been following this thread... Can you give a sample of the use of RegisterHotKey?

    Thanks.

    Larry Woods
    l.woods, inc.
    Scottsdale, Arizona

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