📄 occdlg.cpp
字号:
DWORD code = _AfxGetDlgCode(pWnd);
if (code & (bDefault ? DLGC_UNDEFPUSHBUTTON : DLGC_DEFPUSHBUTTON))
pWnd->SendMessage(BM_SETSTYLE,
(WPARAM)(bDefault ? BS_DEFPUSHBUTTON : BS_PUSHBUTTON),
(LPARAM)(DWORD)TRUE);
}
}
DWORD AFX_CDECL COccManager::GetDefBtnCode(CWnd* pWnd)
{
if (pWnd == NULL)
return 0;
if (pWnd->m_pCtrlSite != NULL)
return pWnd->m_pCtrlSite->GetDefBtnCode();
return _AfxGetDlgCode(pWnd) & (DLGC_UNDEFPUSHBUTTON | DLGC_DEFPUSHBUTTON);
}
AFX_STATIC void AFXAPI _AfxRemoveDefaultButton(CWnd* pWndRoot, CWnd* pWndStart)
{
if ((pWndStart == NULL) || IsControlParent(pWndStart))
pWndStart = _AfxNextControl(pWndRoot, NULL, CWP_SKIPINVISIBLE | CWP_SKIPDISABLED);
else
pWndStart = _AfxGetChildControl(pWndRoot, pWndStart);
if (pWndStart == NULL)
return;
CWnd* pWnd = pWndStart;
CWnd* pWndNext;
do
{
COccManager::SetDefaultButton(pWnd, FALSE);
pWndNext = _AfxNextControl(pWndRoot, pWnd, 0);
pWnd = pWndNext;
}
while ((pWnd != NULL) && (pWnd != pWndStart));
}
AFX_STATIC int AFXAPI _AfxOriginalDefButton(CWnd* pWndRoot)
{
LRESULT lResult = pWndRoot->SendMessage(DM_GETDEFID, 0, 0L);
return HIWORD(lResult) == DC_HASDEFID ? LOWORD(lResult) : IDOK;
}
AFX_STATIC void AFXAPI _AfxCheckDefPushButton(CWnd* pWndRoot, CWnd* pWndOldFocus,
CWnd* pWndNewFocus)
{
DWORD code = 0;
CWnd* pWndT;
// If the focus has gone to a totally separate window, bail out.
if (!pWndRoot->IsChild(pWndNewFocus))
return;
if (pWndNewFocus != NULL)
{
// Do nothing if clicking on dialog background or recursive dialog
// background.
if (IsControlParent(pWndNewFocus))
return;
code = COccManager::GetDefBtnCode(pWndNewFocus);
}
if (pWndOldFocus == pWndNewFocus)
{
// Check the default ID and see if is the same as pwndOldFocus' ID.
// If not, find it and use it as pwndOldFocus
if (code & DLGC_UNDEFPUSHBUTTON)
{
if (pWndOldFocus != NULL)
{
pWndOldFocus = _AfxFindDlgItem(pWndRoot, _AfxOriginalDefButton(pWndRoot));
if ((pWndOldFocus != NULL) && (pWndOldFocus != pWndNewFocus))
{
if (COccManager::GetDefBtnCode(pWndOldFocus) & DLGC_DEFPUSHBUTTON)
{
_AfxRemoveDefaultButton(pWndRoot, pWndOldFocus);
goto SetNewDefault;
}
}
}
COccManager::SetDefaultButton(pWndNewFocus, TRUE);
}
return;
}
// If the focus is changing to or from a pushbutton, then remove the
// default style from the current default button
if (((pWndOldFocus != NULL) && (COccManager::GetDefBtnCode(pWndOldFocus) != 0)) ||
((pWndNewFocus != NULL) && (code != 0)))
{
_AfxRemoveDefaultButton(pWndRoot, pWndNewFocus);
}
SetNewDefault:
// If moving to a button, make that button the default.
if (code & (DLGC_UNDEFPUSHBUTTON | DLGC_DEFPUSHBUTTON))
{
COccManager::SetDefaultButton(pWndNewFocus, TRUE);
}
else
{
// Otherwise, make sure the original default button is default
// Get the original default button
pWndT = _AfxFindDlgItem(pWndRoot, _AfxOriginalDefButton(pWndRoot));
if ((COccManager::GetDefBtnCode(pWndT) & DLGC_UNDEFPUSHBUTTON) &&
pWndT->IsWindowEnabled())
{
COccManager::SetDefaultButton(pWndT, TRUE);
}
}
}
BOOL COccManager::IsDialogMessage(CWnd* pWndDlg, LPMSG lpMsg)
{
// If an OLE Control has the focus, then give it the first crack at key
// and mouse messages.
CWnd* pWndFocus = CWnd::GetFocus();
HWND hWndFocus = pWndFocus->GetSafeHwnd();
HWND hWndDlg = pWndDlg->GetSafeHwnd();
UINT uMsg = lpMsg->message;
if (((uMsg >= WM_KEYFIRST) && (uMsg <= WM_KEYLAST)) ||
((uMsg >= WM_MOUSEFIRST) && (uMsg <= WM_MOUSELAST)))
{
CWnd* pWndCtrl = pWndFocus;
// Walk up the parent chain, until we find an OLE control.
while ((pWndCtrl != NULL) && (pWndCtrl->m_pCtrlSite == NULL) &&
(pWndCtrl->GetParent() != pWndDlg))
{
pWndCtrl = pWndCtrl->GetParent();
}
// let the control attempt to translate the message
if (pWndCtrl != NULL && pWndCtrl->m_pCtrlSite != NULL &&
pWndCtrl->m_pCtrlSite->m_pActiveObject != NULL &&
pWndCtrl->m_pCtrlSite->m_pActiveObject->TranslateAccelerator(lpMsg) == S_OK)
{
return TRUE;
}
// handle CTRLINFO_EATS_RETURN and CTRLINFO_EATS_ESCAPE flags
if ((uMsg == WM_KEYUP || uMsg == WM_KEYDOWN || uMsg == WM_CHAR) &&
pWndCtrl != NULL && pWndCtrl->m_pCtrlSite != NULL &&
((LOWORD(lpMsg->wParam) == VK_RETURN &&
(pWndCtrl->m_pCtrlSite->m_ctlInfo.dwFlags & CTRLINFO_EATS_RETURN)) ||
(LOWORD(lpMsg->wParam) == VK_ESCAPE &&
(pWndCtrl->m_pCtrlSite->m_ctlInfo.dwFlags & CTRLINFO_EATS_ESCAPE))))
{
return FALSE;
}
}
BOOL bResult = FALSE;
CWnd* pWndMsg = CWnd::FromHandle(lpMsg->hwnd);
CWnd* pWndNext = NULL;
DWORD code;
BOOL bBack = FALSE;
int iOK = IDCANCEL;
switch (uMsg)
{
case WM_SYSCHAR:
// If no control has focus, and Alt not down, then ignore.
if ((pWndFocus == NULL) && (GetKeyState(VK_MENU) >= 0))
break;
// If alt+menuchar, process as menu.
if (LOWORD(lpMsg->wParam) == CH_SYSMENU)
break;
// FALL THRU
case WM_CHAR:
// Ignore chars sent to the dialog box (rather than the control).
if (pWndMsg == pWndDlg)
return TRUE;
code = _AfxGetDlgCode(pWndMsg, lpMsg);
// If the control wants to process the message, then don't check
// for possible mnemonic key.
if (uMsg == WM_CHAR && (code & (DLGC_WANTCHARS|DLGC_WANTMESSAGE)))
break;
// If the control wants tabs, then don't let tab fall thru here
if (LOWORD(lpMsg->wParam) == VK_TAB && (code & DLGC_WANTTAB))
break;
// Don't handle space as a mnemonic
if (LOWORD(lpMsg->wParam) == VK_SPACE)
return TRUE;
if ((pWndNext = _AfxGetNextMnem(pWndDlg, pWndMsg, lpMsg)) != NULL)
{
if (pWndNext->m_pCtrlSite != NULL)
{
// UI Activate new control, and send the mnemonic to it.
pWndNext->m_pCtrlSite->SendMnemonic(lpMsg);
bResult = TRUE;
}
}
break;
case WM_KEYDOWN:
code = _AfxGetDlgCode(pWndMsg, lpMsg);
switch (LOWORD(lpMsg->wParam))
{
case VK_TAB:
if (code & DLGC_WANTTAB) // If control wants tabs, bail out.
break;
pWndNext = pWndDlg->GetNextDlgTabItem(pWndMsg,
(GetKeyState(VK_SHIFT) < 0));
if (pWndNext != NULL)
{
_AfxDlgSetFocus(pWndNext);
UIDeactivateIfNecessary(pWndFocus, pWndNext);
}
bResult = TRUE;
break;
case VK_LEFT:
case VK_UP:
bBack = TRUE;
// FALL THRU
case VK_RIGHT:
case VK_DOWN:
if (_AfxGetDlgCode(pWndFocus, lpMsg) & DLGC_WANTARROWS)
break;
pWndNext = pWndDlg->GetNextDlgGroupItem(pWndFocus, bBack);
if ((pWndNext != NULL) && (pWndNext->m_pCtrlSite != NULL))
{
_AfxDlgSetFocus(pWndNext);
bResult = TRUE;
}
break;
case VK_EXECUTE:
case VK_RETURN:
// Return was pressed. Find default button and click it.
if (GetDefBtnCode(pWndFocus) & DLGC_DEFPUSHBUTTON)
{
pWndNext = pWndFocus;
iOK = (DWORD)pWndNext->GetDlgCtrlID();
}
else
{
iOK = _AfxOriginalDefButton(pWndDlg);
}
// FALL THRU
case VK_ESCAPE:
case VK_CANCEL:
if (pWndNext == NULL)
{
pWndNext = _AfxFindDlgItem(pWndDlg, iOK);
if (pWndNext == NULL)
break;
}
ASSERT(pWndNext != NULL);
// Make sure button is not disabled.
if (!pWndNext->IsWindowEnabled())
{
MessageBeep(0);
}
else if (pWndNext->m_pCtrlSite != NULL)
{
// "push" the pWndNext control.
TRY
{
pWndNext->InvokeHelper(DISPID_DOCLICK, DISPATCH_METHOD,
VT_EMPTY, NULL, VTS_NONE);
}
END_TRY
bResult = TRUE;
}
break;
}
break;
}
// As a last resort, delegate to the Windows implementation
if (!bResult)
{
bResult = ::IsDialogMessage(pWndDlg->m_hWnd, lpMsg);
if (bResult && (CWnd::GetFocus() != pWndFocus))
UIActivateControl(CWnd::GetFocus());
}
if (::IsWindow(hWndFocus))
{
UIDeactivateIfNecessary(pWndFocus, CWnd::GetFocus());
if (::IsWindow(hWndDlg))
_AfxCheckDefPushButton(pWndDlg, pWndFocus, CWnd::GetFocus());
}
return bResult;
}
/////////////////////////////////////////////////////////////////////////////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -