UINT CShortcutManager::ProcessMessage(const MSG* pMsg, DWORD* pShortcut) const { // 只处理可用的快捷键 if (!IsWindowEnabled() || !IsWindowVisible()) { return FALSE; } // 只处理键盘消息 if (pMsg->message != WM_KEYDOWN && pMsg->message != WM_SYSKEYDOWN) { return FALSE; } CWnd* pWnd = CWnd::FromHandle(pMsg->hwnd); CWnd* pMainWnd = GetCWnd(); CWnd* pTopParent = pWnd->GetParentOwner(); if (pTopParent != pMainWnd) { return FALSE; } switch (pMsg->wParam) { case VK_CONTROL: case VK_SHIFT: case VK_MENU: case VK_NUMLOCK: case VK_SCROLL: case VK_CAPITAL: return FALSE; // 不去处理 return/cancel 键 case VK_RETURN: case VK_CANCEL: return FALSE; case VK_MBUTTON: break; // 快捷键 default: { //不去处理发往hotkey控件的消息 if (IsClass(pMsg->hwnd, WC_HOTKEY)) { return FALSE; } // get 获取快捷方式DWORD值 BOOL bExtKey = (pMsg->lParam & 0x01000000); DWORD dwShortcut = GetShortcut((WORD)pMsg->wParam, bExtKey); // 查找相应的命令ID UINT nCmdID = 0; if (!m_mapShortcut2ID.Lookup(dwShortcut, nCmdID) || !nCmdID) { return FALSE; } if (m_wInvalidComb & HKCOMB_EDITCTRLS) { if (IsEditControl(pMsg->hwnd)) { if (IsEditShortcut(dwShortcut)) { return FALSE; } WORD wModifiers = HIWORD(dwShortcut); if (pMsg->wParam >= VK_F1 && pMsg->wParam <= VK_F24) { // ok } // 3. else must have <ctrl> or <alt> else { if (!(wModifiers & (HOTKEYF_ALT | HOTKEYF_CONTROL))) { return FALSE; } } } } // 返回 command ID if (m_bAutoSendCmds) { SendMessage(NULL, WM_COMMAND, nCmdID, 0); } if (pShortcut) { *pShortcut = dwShortcut; } return nCmdID; } } return FALSE; }
static void OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify) { switch (id) { case IDOK: EndDialog(hwnd, 1); break; case IDCANCEL: EndDialog(hwnd, 0); break; case IDC_TYPE_TABLE: case IDC_TYPE_INDEX: if (codeNotify == BN_CLICKED) { SetProp(hwnd, szErrorProp, (HANDLE)ERROR_NOSHOW); Adjust4FillFactors(hwnd); InitialiseSpinControls (hwnd); LimitNumericEditControls(hwnd); DoCalculation(hwnd); SetProp(hwnd, szErrorProp, (HANDLE)ERROR_SHOW); } break; case IDC_CLEAR: InitialiseSpinControls(hwnd); InitialiseEditControls(hwnd); UpdateControls(hwnd,TRUE); Adjust4FillFactors(hwnd); bUserChangeEdit = FALSE; break; case IDC_PAGESIZE: switch (codeNotify) { case CBN_SELCHANGE: // Inhibit error messages while we are updating since // the EN_CHANGE message causes all the edit controls to be // verified for this structure type, even the controls that // have not been reinitialised yet. SetProp(hwnd, szErrorProp, (HANDLE)ERROR_NOSHOW); Adjust4FillFactors(hwnd); InitialiseSpinControls (hwnd); LimitNumericEditControls(hwnd); DoCalculation(hwnd); SetProp(hwnd, szErrorProp, (HANDLE)ERROR_SHOW); break; } break; case IDC_STRUCTURE: switch (codeNotify) { case CBN_SELCHANGE: // Inhibit error messages while we are updating since // the EN_CHANGE message causes all the edit controls to be // verified for this structure type, even the controls that // have not been reinitialised yet. SetProp(hwnd, szErrorProp, (HANDLE)ERROR_NOSHOW); InitialiseSpinControls(hwnd); ResetWithDefaultEditCtrl(hwnd); //InitialiseEditControls(hwnd); UpdateControls(hwnd,FALSE); DoCalculation(hwnd); SetProp(hwnd, szErrorProp, (HANDLE)ERROR_SHOW); break; case CBN_KILLFOCUS: { // We must verify the edit controls on exiting the // structure field since we dont do any checking when // it gets the focus, therefore an edit control could // be invalid. VerifyAllNumericEditControls(hwnd, TRUE, TRUE); break; } } break; case IDC_ROWS: case IDC_ROWWIDTH: case IDC_UNIQUEKEYS: case IDC_KEYWIDTH: case IDC_DATA: case IDC_INDEX: case IDC_LEAF: { switch (codeNotify) { case EN_CHANGE: { int nCount; BOOL bShowError = (GetProp(hwnd, szErrorProp) == (HANDLE)ERROR_NOSHOW) ? FALSE : TRUE; if (id == IDC_DATA || id == IDC_INDEX || id == IDC_LEAF || id == IDC_ROWWIDTH) { // Do this even on INITDIALOG Adjust4FillFactors(hwnd); } if (!IsWindowVisible(hwnd)) break; // Test to see if the control is empty. If so then // set ERROR and break out. It becomes tiresome to edit // if you delete all characters and an error box pops up. nCount = Edit_GetTextLength(hwndCtl); if (nCount == 0) { SetCalcError(hwnd); break; } if (!bInitEdit && ( id == IDC_DATA || id == IDC_INDEX || id == IDC_LEAF )) { char szBuf[20]; INFOOFFSET infoIdx = GetSelectedStructure(hwnd); int nData,nIndex,nLeaf; GetDlgItemText (hwnd, IDC_DATA, szBuf, sizeof (szBuf)); nData = my_atoi(szBuf); GetDlgItemText (hwnd, IDC_INDEX, szBuf, sizeof (szBuf)); nIndex = my_atoi(szBuf); GetDlgItemText (hwnd, IDC_LEAF, szBuf, sizeof (szBuf)); nLeaf = my_atoi(szBuf); if ( SaveFillFactors.FillFactors.nData != nData) { SaveFillFactors.FillFactors.nData = nData; SaveFillFactors.DefaultData = infoDefaults[infoIdx].fillFactors.nData; bUserChangeEdit = TRUE; } if ( SaveFillFactors.FillFactors.nIndex != nIndex) SaveFillFactors.FillFactors.nIndex = nIndex; if ( SaveFillFactors.FillFactors.nLeaf != nLeaf) SaveFillFactors.FillFactors.nLeaf = nLeaf; } if (!VerifyAllNumericEditControls(hwnd, bShowError, TRUE)) break; DoCalculation(hwnd); break; } case EN_KILLFOCUS: { HWND hwndNew = GetFocus(); int nNewCtl = GetDlgCtrlID(hwndNew); if (!IsEditControl(hwnd, hwndNew) || !IsChild(hwnd, hwndNew)) // Dont recalc on any button hits or change of structure // or error message displays break; if (!VerifyAllNumericEditControls(hwnd, TRUE, TRUE)) break; UpdateSpinButtons(hwnd); DoCalculation(hwnd); break; } } break; } case IDC_SPINROWWIDTH: case IDC_SPINKEYWIDTH: case IDC_SPINROWS: case IDC_SPINKEYS: case IDC_SPINDATA: case IDC_SPINIDX: case IDC_SPINLEAF: { // Handle the spin button notifications switch (codeNotify) { case SN_INCBUTTONUP: case SN_DECBUTTONUP: { switch (id) { case IDC_SPINDATA: case IDC_SPINIDX: case IDC_SPINLEAF: { // Set for no error display so we do not get // errors in the row width while decreasing the // fillfactors and therefore lowering the row // width maximum. The edit box will just adjust // to the new maximum without showing an error. SetProp(hwnd, szErrorProp, (HANDLE)ERROR_NOSHOW); if (id == IDC_SPINDATA) bUserChangeEdit = TRUE; } } if (ProcessSpinControl(hwndCtl, codeNotify, limits)) DoCalculation(hwnd); SetProp(hwnd, szErrorProp, (HANDLE)ERROR_SHOW); break; } default: ProcessSpinControl(hwndCtl, codeNotify, limits); } break; } } }