Click to See Complete Forum and Search --> : 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
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)
Ravi Bhavnani
May 25th, 1999, 01:10 PM
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
Dan Haddix
May 26th, 1999, 12:41 AM
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!!!
Larry Woods
May 29th, 1999, 12:49 PM
I have been following this thread... Can you give a sample of the use of RegisterHotKey?
Thanks.
Larry Woods
l.woods, inc.
Scottsdale, Arizona
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.