MFC registers the hotkey for the dialog box and the hotkey for the mfc dialog box.
Add the following content to the header file:
//} AFX_MSG
Afx_msg LRESULT OnHotKey (WPARAM wParam, LPARAM lParam); // (this behavior is added)
BEGIN_MESSAGE_MAP (DlgYesNo, CDialog)
// {AFX_MSG_MAP (DlgYesNo)
Add the following to the cpp file:
//} AFX_MSG_MAP
ON_MESSAGE (WM_HOTKEY, OnHotKey) // (this behavior is added)
END_MESSAGE_MAP ()
You can also add the WM_HOTKEY message method in the "Class Wizard" to generate the preceding steps.
Add the following content to the OnCreat event: (add message response> WM_CREAT)
RegisterHotKey (m_hWnd, 1001, MOD_ALT, 'q ');
Add: (add message response> WM_DESTROY) to the OnDestroy event)
UnregisterHotKey (m_hwnd, 1001 );
Add the message processing function: (paste it in. Note that CHotkeyDlgDlg is changed to its own class)
LRESULT CHotkeyDlgDlg::OnHotKey(WPARAM wParam,LPARAM lParam){ if(wParam == 1001) { int nMod = LOWORD(lParam); int Vk = HIWORD(lParam); CString str; str.Format(_T("Mod = %d, Vk = %d"), nMod, Vk); AfxMessageBox(str); } return true;}