-
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
-
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)
-
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
-
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!!!
-
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