hotkeys on a dialog
-
hello, I would like to type a shortcut on my dialog and that it executes a particular routine I have coded (ie set the focus on a particular input control). I have no menu on my dialog window . How should I do this ? I have created a accelerator to set my shortcut, linked the accelerator to my code using the class wizard, but when I launch my appli, nothing happens when I press my shortcut ... What is missing ? Is it the correct way to do this ? Thanks in advance DD
-
hello, I would like to type a shortcut on my dialog and that it executes a particular routine I have coded (ie set the focus on a particular input control). I have no menu on my dialog window . How should I do this ? I have created a accelerator to set my shortcut, linked the accelerator to my code using the class wizard, but when I launch my appli, nothing happens when I press my shortcut ... What is missing ? Is it the correct way to do this ? Thanks in advance DD
I did a quick search for "dialog AND accelerator" in MSDN and came up with the following: Q222829 HOWTO: Using Accelerator Keys Within a Modal Dialog Box which should give you exactly what you want. Classwizard won't help you much though... I don't remember the last time I used CW! Iain.
-
I did a quick search for "dialog AND accelerator" in MSDN and came up with the following: Q222829 HOWTO: Using Accelerator Keys Within a Modal Dialog Box which should give you exactly what you want. Classwizard won't help you much though... I don't remember the last time I used CW! Iain.
-
I did a quick search for "dialog AND accelerator" in MSDN and came up with the following: Q222829 HOWTO: Using Accelerator Keys Within a Modal Dialog Box which should give you exactly what you want. Classwizard won't help you much though... I don't remember the last time I used CW! Iain.
yes, it works but ... what happens when I defined several keys combinations in my accelerator, as it can be considered as a table of keystrokes. I loaded my accelerator table in the OnInitDialog() : m_hAccelTable = LoadAccelerators(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDR_ACCELERATOR1)); These special keystroke can be recognized in the override routine : BOOL CDialogDlg::PreTranslateMessage(MSG* pMsg) if (m_hAccelTable) { if (::TranslateAccelerator(m_hWnd, m_hAccelTable, pMsg)) { return(TRUE); } } return CDialog::PreTranslateMessage(pMsg); } What I understood is that, when ::TranslateAccelerator recognizes a keystroke existing in accelerator, it send a WM_COMMAND message. Then, using class wizard, I created a routine corresponding to dialog IDR_ACCELERATOR1-WM_COMMAND message: void CDialogDlg::OnAccelerator1() { GetDlgItem(IDC_EDIT3)->SetFocus(); //special keystroke => set focus here } It works, but how can I perform different actions depending on keystroke? Can I get the keystroke or is there any way to distinguish them? Should I have several Accelerator and load them all and perform the ::TranslateAccelerator on each of them? Could you still give me some help on this? Thanks in advance DD
-
yes, it works but ... what happens when I defined several keys combinations in my accelerator, as it can be considered as a table of keystrokes. I loaded my accelerator table in the OnInitDialog() : m_hAccelTable = LoadAccelerators(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDR_ACCELERATOR1)); These special keystroke can be recognized in the override routine : BOOL CDialogDlg::PreTranslateMessage(MSG* pMsg) if (m_hAccelTable) { if (::TranslateAccelerator(m_hWnd, m_hAccelTable, pMsg)) { return(TRUE); } } return CDialog::PreTranslateMessage(pMsg); } What I understood is that, when ::TranslateAccelerator recognizes a keystroke existing in accelerator, it send a WM_COMMAND message. Then, using class wizard, I created a routine corresponding to dialog IDR_ACCELERATOR1-WM_COMMAND message: void CDialogDlg::OnAccelerator1() { GetDlgItem(IDC_EDIT3)->SetFocus(); //special keystroke => set focus here } It works, but how can I perform different actions depending on keystroke? Can I get the keystroke or is there any way to distinguish them? Should I have several Accelerator and load them all and perform the ::TranslateAccelerator on each of them? Could you still give me some help on this? Thanks in advance DD
Real life slowed my reply. You can set various key combinations in the accelerator, each associated with a command value. e.g.
ALT-Q => IDC_Q
CTRL-j => IDC_JIn your dlgs message map you would have
ON_COMMAND(IDC_Q, OnQ)
ON_COMMAND(IDC_Q, OnQ)(I never use class wizard, as it runs into too many limitations, e.g. ON_COMMAND_RANGE()) If you are only using the accelerator for settings focus on other controls, you can just put a static control before them in the tab order with one of the keys underlined (i.e. Qeue: _______. When you press Alt Q, the dialog tries to put focus on the static control, which then puts in on the next control with the WS_TABSTOP style. So you may not need the accelerator after all! Iain.
-
Real life slowed my reply. You can set various key combinations in the accelerator, each associated with a command value. e.g.
ALT-Q => IDC_Q
CTRL-j => IDC_JIn your dlgs message map you would have
ON_COMMAND(IDC_Q, OnQ)
ON_COMMAND(IDC_Q, OnQ)(I never use class wizard, as it runs into too many limitations, e.g. ON_COMMAND_RANGE()) If you are only using the accelerator for settings focus on other controls, you can just put a static control before them in the tab order with one of the keys underlined (i.e. Qeue: _______. When you press Alt Q, the dialog tries to put focus on the static control, which then puts in on the next control with the WS_TABSTOP style. So you may not need the accelerator after all! Iain.