📄 occdlg.cpp
字号:
// This is a part of the Microsoft Foundation Classes C++ library.
// Copyright (C) 1992-1998 Microsoft Corporation
// All rights reserved.
//
// This source code is only intended as a supplement to the
// Microsoft Foundation Classes Reference and related
// electronic documentation provided with the library.
// See these sources for detailed information regarding the
// Microsoft Foundation Classes product.
#include "stdafx.h"
#include "occimpl.h"
#ifdef AFX_OCC_SEG
#pragma code_seg(AFX_OCC_SEG)
#endif
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define new DEBUG_NEW
/////////////////////////////////////////////////////////////////////////////
#define CH_SYSMENU ' '
#define WS_TYPEMASK 0xC0000000
#define BS_TYPEMASK 0x0000000F
static inline DWORD TestStyle(CWnd* pWnd, DWORD dwStyle)
{ return GetWindowLong(pWnd->m_hWnd, GWL_STYLE) & dwStyle; }
static inline DWORD TestExStyle(CWnd* pWnd, DWORD dwExStyle)
{ return GetWindowLong(pWnd->m_hWnd, GWL_EXSTYLE) & dwExStyle; }
static inline BOOL HasChildStyle(CWnd* pWnd)
{ return TestStyle(pWnd, WS_TYPEMASK) == WS_CHILD; }
static inline BOOL IsControlParent(CWnd* pWnd)
{ return TestExStyle(pWnd, WS_EX_CONTROLPARENT); }
AFX_STATIC DWORD AFXAPI _AfxGetDlgCode(CWnd* pWnd, LPMSG lpMsg=NULL)
{
if (pWnd == NULL)
return 0;
WPARAM wParam = (lpMsg == NULL) ? 0 : lpMsg->wParam;
return (DWORD)SendMessage(pWnd->m_hWnd, WM_GETDLGCODE,
wParam, (LPARAM)(LPMSG)lpMsg);
}
AFX_STATIC void AFXAPI _AfxDlgSetFocus(CWnd* pWnd)
{
// Select all text in an edit control.
if (_AfxGetDlgCode(pWnd) & DLGC_HASSETSEL)
pWnd->SendMessage(EM_SETSEL, 0, -1);
// Set focus as normal.
pWnd->SetFocus();
}
AFX_STATIC CWnd* AFXAPI _AfxGetChildControl(CWnd* pWndRoot, CWnd* pWndChild)
{
CWnd* pWndControl = NULL;
while ((pWndChild != NULL) && HasChildStyle(pWndChild) &&
(pWndChild != pWndRoot))
{
pWndControl = pWndChild;
pWndChild = pWndChild->GetParent();
if (IsControlParent(pWndChild))
break;
}
return pWndControl;
}
AFX_STATIC CWnd* AFXAPI _AfxNextControl(CWnd* pWndRoot, CWnd* pWndStart, UINT uFlags)
{
// if pWndStart is already equal to pWndRoot, this confuses this function
// badly.
ASSERT(pWndRoot != pWndStart);
if (pWndStart == NULL)
{
FirstChild:
pWndStart = pWndRoot->GetTopWindow();
if (pWndStart == NULL)
return pWndRoot;
goto Found;
}
else
{
// Are we at the last control within some parent? If so, pop back up.
while (pWndStart->GetNextWindow() == NULL)
{
// Popup to previous real ancestor. pWndStart will be NULL,
// pWndRoot, or the child of a recursive dialog.
pWndStart = _AfxGetChildControl(pWndRoot, pWndStart->GetParent());
if ((pWndStart == NULL) || (pWndStart == pWndRoot))
{
goto FirstChild;
}
}
ASSERT(pWndStart != NULL);
pWndStart = pWndStart->GetNextWindow();
}
Found:
if (IsControlParent(pWndStart))
{
if (((uFlags & CWP_SKIPINVISIBLE) && !pWndStart->IsWindowVisible()) ||
((uFlags & CWP_SKIPDISABLED) && !pWndStart->IsWindowEnabled()))
pWndStart = _AfxNextControl(pWndRoot, pWndStart, uFlags);
else
pWndStart = _AfxNextControl(pWndStart, NULL, uFlags);
}
return pWndStart;
}
BOOL AFX_CDECL COccManager::IsMatchingMnemonic(CWnd* pWnd, LPMSG lpMsg)
{
return (pWnd->m_pCtrlSite != NULL) &&
pWnd->m_pCtrlSite->IsMatchingMnemonic(lpMsg);
}
AFX_STATIC CWnd* AFXAPI _AfxFindNextMnem(CWnd* pWndDlg, CWnd* pWnd, LPMSG lpMsg)
{
CWnd* pWndStart;
CWnd* pWndT;
int i = 0;
// Check if we are in a group box so we can find local mnemonics.
pWndStart = _AfxGetChildControl(pWndDlg, pWnd);
while ((pWndT = pWndDlg->GetNextDlgGroupItem(pWndStart)) != NULL)
{
i++;
// Avoid infinite looping.
if (pWndT == pWnd || i > 60)
break;
pWndStart = pWndT;
if (COccManager::IsMatchingMnemonic(pWndT, lpMsg))
return pWndT;
}
pWnd = pWndStart = _AfxGetChildControl(pWndDlg, pWnd);
while (TRUE)
{
pWnd = _AfxNextControl(pWndDlg, pWnd, CWP_SKIPINVISIBLE | CWP_SKIPDISABLED);
if (COccManager::IsMatchingMnemonic(pWnd, lpMsg))
break;
if (pWnd == pWndStart)
return NULL;
}
return pWnd;
}
BOOL AFX_CDECL COccManager::IsLabelControl(CWnd* pWnd)
{
return pWnd->IsWindowEnabled() && (pWnd->m_pCtrlSite != NULL) &&
pWnd->m_pCtrlSite->m_dwMiscStatus & OLEMISC_ACTSLIKELABEL;
}
AFX_STATIC CWnd* AFXAPI _AfxGetNextMnem(CWnd* pWndDlg, CWnd* pWnd, LPMSG lpMsg)
{
CWnd* pWndFirstFound = NULL;
// Loop for a long time but not long enough so we hang...
for (int count = 0; count < 256*2; count++)
{
// If the dialog box doesn't has the mnemonic specified, return NULL.
if ((pWnd = _AfxFindNextMnem(pWndDlg, pWnd, lpMsg)) == NULL)
return NULL;
// If a non-disabled static item, then jump ahead to nearest tabstop.
if (COccManager::IsLabelControl(pWnd))
{
pWnd = pWndDlg->GetNextDlgTabItem(pWnd);
if (pWnd == NULL)
return NULL;
}
if (pWnd->IsWindowEnabled())
return pWnd;
// Stop if we've looped back to the first item we checked
if (pWnd == pWndFirstFound)
return NULL;
if (pWndFirstFound == NULL)
pWndFirstFound = pWnd;
}
return NULL;
}
void AFX_CDECL COccManager::UIActivateControl(CWnd* pWndNewFocus)
{
if (pWndNewFocus == NULL)
return;
// Find the nearest control in the window parent chain.
CWnd* pWndCtrl = pWndNewFocus;
COleControlContainer* pCtrlCont = NULL;
COleControlSite* pCtrlSite = NULL;
while ((pWndCtrl != NULL) &&
((pCtrlCont = pWndCtrl->m_pCtrlCont) == NULL) &&
((pCtrlSite = pWndCtrl->m_pCtrlSite) == NULL))
{
pWndCtrl = pWndCtrl->GetParent();
}
if ((pWndCtrl == NULL) || (pCtrlCont != NULL))
return;
// This will UI Activate the control.
pCtrlSite->SetFocus();
// Make sure focus gets set to correct child of control, if any.
if (CWnd::GetFocus() != pWndNewFocus)
pWndNewFocus->SetFocus();
}
void AFX_CDECL COccManager::UIDeactivateIfNecessary(CWnd* pWndOldFocus,
CWnd* pWndNewFocus)
{
if (pWndOldFocus == NULL || !::IsWindow(pWndOldFocus->m_hWnd))
return;
// Find the nearest control container in the window parent chain.
CWnd* pWndCtrlCont = pWndOldFocus->GetParent();
COleControlContainer* pCtrlCont = NULL;
while ((pWndCtrlCont != NULL) &&
((pCtrlCont = pWndCtrlCont->m_pCtrlCont) == NULL))
{
pWndCtrlCont = pWndCtrlCont->GetParent();
}
if (pCtrlCont == NULL)
return;
// Get the current UI Active control (if any).
CWnd* pWndUIActive = NULL;
COleControlSite* pSite = NULL;
if ((pCtrlCont != NULL) &&
((pSite = pCtrlCont->m_pSiteUIActive) != NULL))
{
pWndUIActive = CWnd::FromHandle(pSite->m_hWnd);
}
// Ignore if no control is UI Active.
if (pWndUIActive == NULL)
return;
// Ignore if the control getting the focus is the same control.
if ((pWndNewFocus == pWndUIActive) ||
((pWndNewFocus != NULL) && pWndUIActive->IsChild(pWndNewFocus)))
return;
// Tell the container to UI Deactivate the UI Active control.
pCtrlCont->OnUIActivate(NULL);
}
CWnd* AFXAPI _AfxFindDlgItem(CWnd* pWndParent, DWORD id)
{
CWnd* pWndChild;
CWnd* pWndOrig;
// QUICK TRY:
pWndChild = pWndParent->GetDlgItem(id);
if (pWndChild != NULL)
return pWndChild;
pWndOrig = _AfxNextControl(pWndParent, NULL, CWP_SKIPINVISIBLE);
if (pWndOrig == pWndParent)
return NULL;
pWndChild = pWndOrig;
do
{
if ((DWORD)pWndChild->GetDlgCtrlID() == id)
return(pWndChild);
pWndChild = _AfxNextControl(pWndParent, pWndChild, CWP_SKIPINVISIBLE);
}
while ((pWndChild != NULL) && (pWndChild != pWndOrig));
return NULL;
}
void COccManager::SetDefaultButton(CWnd* pWnd, BOOL bDefault)
{
if (pWnd->m_pCtrlSite != NULL)
{
pWnd->m_pCtrlSite->SetDefaultButton(bDefault);
}
else
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -