📄 ctlcore.cpp
字号:
}
}
break;
}
}
HRESULT COleControl::OnHide()
{
#ifdef _AFXDLL
CWnd* pWnd = m_bOpen ? m_pWndOpenFrame : GetOuterWindow();
#else
CWnd* pWnd = GetOuterWindow();
#endif
if (pWnd != NULL && pWnd->m_hWnd != NULL)
::ShowWindow(pWnd->m_hWnd, SW_HIDE);
RELEASE(m_pInPlaceFrame);
RELEASE(m_pInPlaceDoc);
#ifdef _AFXDLL
if (m_bOpen)
SendAdvise(OBJECTCODE_HIDEWINDOW);
#endif
return S_OK;
}
HRESULT COleControl::OnOpen(BOOL bTryInPlace, LPMSG pMsg)
{
#ifndef _AFXDLL
ASSERT(bTryInPlace); // fully-open mode not supported in static builds
UNUSED_ALWAYS(bTryInPlace);
#endif
#ifndef _AFXDLL
return OnActivateInPlace(TRUE, pMsg);
#else
if (!m_bOpen)
{
// If not already open, try in-place activating.
if (bTryInPlace && SUCCEEDED(OnActivateInPlace(bTryInPlace, pMsg)))
return S_OK;
// If already in-place active, deactivate first.
if (m_bInPlaceActive)
m_xOleInPlaceObject.InPlaceDeactivate();
m_bOpen = TRUE;
// Open a separate window.
if (m_pWndOpenFrame == NULL)
{
// Create frame window
m_pWndOpenFrame = CreateFrameWindow();
if (m_pWndOpenFrame == NULL)
return E_FAIL;
// Size frame window to exactly contain the control.
int cx;
int cy;
GetControlSize(&cx, &cy);
ResizeFrameWindow(cx, cy);
// Create and/or reparent the control's window.
CRect rectClient;
m_pWndOpenFrame->GetClientRect(&rectClient);
if (!CreateControlWindow(m_pWndOpenFrame->m_hWnd, rectClient, rectClient))
return E_FAIL;
}
}
// Make the frame window visible and activate it.
ASSERT(m_pWndOpenFrame != NULL);
m_pWndOpenFrame->ShowWindow(SW_SHOW);
m_pWndOpenFrame->SetActiveWindow();
SendAdvise(OBJECTCODE_SHOWWINDOW);
return S_OK;
#endif
}
#ifdef _AFXDLL
CControlFrameWnd* COleControl::CreateFrameWindow()
{
TCHAR szUserType[256];
GetUserType(szUserType);
CControlFrameWnd* pWnd = new CControlFrameWnd(this);
if (!pWnd->Create(szUserType))
{
// If Create failed, then frame window has deleted itself.
pWnd = NULL;
}
return pWnd;
}
void COleControl::OnFrameClose()
{
// Reparent control to prevent its window from being destroyed.
CWnd* pWnd = GetOuterWindow();
if (pWnd != NULL)
{
::SetWindowPos(pWnd->m_hWnd, NULL, 0, 0, 0, 0,
SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|
SWP_HIDEWINDOW);
pWnd->SetParent(NULL);
}
m_pWndOpenFrame = NULL;
m_bOpen = FALSE;
m_xOleObject.Close(OLECLOSE_SAVEIFDIRTY);
SendAdvise(OBJECTCODE_HIDEWINDOW);
SendAdvise(OBJECTCODE_CLOSED);
}
void COleControl::ResizeOpenControl(int cx, int cy)
{
CWnd* pWndOuter = GetOuterWindow();
if ((pWndOuter != NULL) && (pWndOuter->m_hWnd != NULL))
::SetWindowPos(pWndOuter->m_hWnd, NULL, 0, 0, cx, cy,
SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER);
ResizeFrameWindow(cx, cy);
}
void COleControl::ResizeFrameWindow(int cxCtrl, int cyCtrl)
{
m_pWndOpenFrame->SetWindowPos(NULL, 0, 0, 100, 100,
SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER);
CRect rectClient;
m_pWndOpenFrame->GetClientRect(&rectClient);
CRect rectWindow;
m_pWndOpenFrame->GetWindowRect(&rectWindow);
int cx = cxCtrl + rectWindow.Width() - rectClient.Width();
int cy = cyCtrl + rectWindow.Height() - rectClient.Height();
m_pWndOpenFrame->SetWindowPos(NULL, 0, 0, cx, cy,
SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER);
}
#endif //_AFXDLL
BOOL COleControl::GetRectInContainer(LPRECT lpRect)
{
if (m_bInPlaceActive)
CopyRect(lpRect, &m_rcPos);
return m_bInPlaceActive;
}
LPCLSID COleControl::GetPropPageIDs(ULONG& cPropPages)
{
cPropPages = 0;
return NULL;
}
BOOL COleControl::OnEdit(LPMSG lpMsg, HWND, LPCRECT lpRect)
{
CopyRect(m_rcPos, lpRect);
return SUCCEEDED(OnActivateInPlace(TRUE, lpMsg));
}
HWND AFXAPI _AfxGetTopLevelWindow(HWND hWnd)
{
HWND hWndTop;
do
{
hWndTop = hWnd;
hWnd = ::GetParent(hWnd);
}
while (hWnd != NULL);
return hWndTop;
}
BOOL COleControl::OnProperties(LPMSG, HWND hWndParent, LPCRECT)
{
USES_CONVERSION;
HRESULT hr;
if ((m_pControlSite == NULL) ||
FAILED(hr = m_pControlSite->ShowPropertyFrame()))
{
LPUNKNOWN pUnk = GetIDispatch(FALSE);
HWND hWndOwner = CWnd::GetSafeOwner_(hWndParent, NULL);
LCID lcid = AmbientLocaleID();
ULONG cPropPages;
LPCLSID pclsidPropPages = GetPropPageIDs(cPropPages);
RECT rectParent;
RECT rectTop;
::GetWindowRect(hWndParent, &rectParent);
::GetWindowRect(hWndOwner, &rectTop);
TCHAR szUserType[256];
GetUserType(szUserType);
PreModalDialog(hWndOwner);
hr = ::OleCreatePropertyFrame(hWndOwner, rectParent.left - rectTop.left,
rectParent.top - rectTop.top, T2COLE(szUserType), 1, &pUnk,
cPropPages, pclsidPropPages, lcid, NULL, 0);
PostModalDialog(hWndOwner);
}
return SUCCEEDED(hr);
}
DWORD COleControl::GetControlFlags()
{
return clipPaintDC;
}
void COleControl::OnPaint(CDC* pDC)
{
if (m_bNoRedraw)
{
// flicker-free activation: no need to repaint
ValidateRect(NULL);
m_bNoRedraw = FALSE; // one time only
return;
}
AfxLockTempMaps();
GetWindowRect(m_rcBounds);
m_rcBounds.OffsetRect(-m_rcBounds.left, -m_rcBounds.top);
// Adjust bounds for size of UI Active tracker, if any.
#ifdef _AFXDLL
if (!m_bOpen && (m_pRectTracker != NULL))
#else
if (m_pRectTracker != NULL)
#endif
{
int nHandleSize = (int)m_pRectTracker->m_nHandleSize - 1;
m_rcBounds.InflateRect(-nHandleSize, -nHandleSize);
}
CRect rcClient;
GetClientRect(rcClient);
if (pDC != NULL)
{
// We were passed a device context: use it.
int iSaveDC = pDC->SaveDC();
OnDraw(pDC, rcClient, rcClient);
pDC->RestoreDC(iSaveDC);
}
else
{
#ifdef _DEBUG
int nFlags = GetControlFlags();
if (nFlags & fastBeginPaint)
TRACE0("Warning: COleControl::fastBeginPaint is obsolete.\n");
#endif
CPaintDC dc(this);
OnDraw(&dc, rcClient, &dc.m_ps.rcPaint);
}
AfxUnlockTempMaps();
}
BOOL COleControl::OnEraseBkgnd(CDC* pDC)
{
// do nothing -- controls erase their background in their OnDraw
if (IsSubclassedControl())
return CWnd::OnEraseBkgnd(pDC);
else
return TRUE;
}
void COleControl::Serialize(CArchive& ar)
{
CArchivePropExchange px(ar);
DoPropExchange(&px);
if (ar.IsLoading())
{
BoundPropertyChanged(DISPID_UNKNOWN);
InvalidateControl();
}
}
void COleControl::DoPropExchange(CPropExchange* pPX)
{
ASSERT_POINTER(pPX, CPropExchange);
ExchangeExtent(pPX);
ExchangeStockProps(pPX);
}
/////////////////////////////////////////////////////////////////////////////
// Wrappers for IOleControlSite
void COleControl::ControlInfoChanged()
{
if (m_pControlSite != NULL)
m_pControlSite->OnControlInfoChanged();
}
BOOL COleControl::LockInPlaceActive(BOOL bLock)
{
if (m_pControlSite != NULL)
return SUCCEEDED(m_pControlSite->LockInPlaceActive(bLock));
return FALSE;
}
LPDISPATCH COleControl::GetExtendedControl()
{
LPDISPATCH pDispatch = NULL;
if (m_pControlSite != NULL)
m_pControlSite->GetExtendedControl(&pDispatch);
return pDispatch;
}
void COleControl::TransformCoords(POINTL* lpptlHimetric,
POINTF* lpptfContainer, DWORD flags)
{
if ((m_pControlSite == NULL) ||
(FAILED(m_pControlSite->TransformCoords(lpptlHimetric,
lpptfContainer, flags))))
{
// Transformation failed, use the identity transformation
if (flags & XFORMCOORDS_CONTAINERTOHIMETRIC)
{
lpptlHimetric->x = (long)lpptfContainer->x;
lpptlHimetric->y = (long)lpptfContainer->y;
}
else
{
lpptfContainer->x = (float)lpptlHimetric->x;
lpptfContainer->y = (float)lpptlHimetric->y;
}
}
}
/////////////////////////////////////////////////////////////////////////////
// COleControl::XOleControl
STDMETHODIMP_(ULONG) COleControl::XOleControl::AddRef()
{
METHOD_PROLOGUE_EX_(COleControl, OleControl)
return (ULONG)pThis->ExternalAddRef();
}
STDMETHODIMP_(ULONG) COleControl::XOleControl::Release()
{
METHOD_PROLOGUE_EX_(COleControl, OleControl)
return (ULONG)pThis->ExternalRelease();
}
STDMETHODIMP COleControl::XOleControl::QueryInterface(
REFIID iid, LPVOID* ppvObj)
{
METHOD_PROLOGUE_EX_(COleControl, OleControl)
return (HRESULT)pThis->ExternalQueryInterface(&iid, ppvObj);
}
STDMETHODIMP COleControl::XOleControl::GetControlInfo(LPCONTROLINFO pCI)
{
METHOD_PROLOGUE_EX(COleControl, OleControl)
pThis->OnGetControlInfo(pCI);
return S_OK;
}
STDMETHODIMP COleControl::XOleControl::OnMnemonic(LPMSG pMsg)
{
METHOD_PROLOGUE_EX(COleControl, OleControl)
pThis->OnMnemonic(pMsg);
return S_OK;
}
STDMETHODIMP COleControl::XOleControl::OnAmbientPropertyChange(DISPID dispid)
{
METHOD_PROLOGUE_EX(COleControl, OleControl)
if (dispid == DISPID_AMBIENT_UIDEAD || dispid == DISPID_UNKNOWN)
pThis->m_bUIDead = (BYTE)(pThis->AmbientUIDead());
pThis->OnAmbientPropertyChange(dispid);
return S_OK;
}
STDMETHODIMP COleControl::XOleControl::FreezeEvents(BOOL bFreeze)
{
METHOD_PROLOGUE_EX(COleControl, OleControl)
ULONG& cEventsFrozen = pThis->m_cEventsFrozen;
if (bFreeze)
++(cEventsFrozen);
else
--(cEventsFrozen);
ASSERT(cEventsFrozen >= 0); // Should never go below zero!
if ((cEventsFrozen == 1 && bFreeze) ||
(cEventsFrozen == 0 && !bFreeze))
{
pThis->OnFreezeEvents(bFreeze);
}
return S_OK;
}
void COleControl::OnGetControlInfo(LPCONTROLINFO pControlInfo)
{
// Subclass may override
pControlInfo->hAccel = NULL;
pControlInfo->cAccel = 0;
pControlInfo->dwFlags = 0;
}
void COleControl::OnMnemonic(LPMSG)
{
// To be implemented by subclass
}
void COleControl::OnAmbientPropertyChange(DISPID)
{
// To be implemented by subclass
}
void COleControl::OnFreezeEvents(BOOL)
{
// To be implemented by subclass
}
void COleControl::OnSetClientSite()
{
if (!m_bDataPathPropertiesLoaded)
{
CAsyncPropExchange PX(m_dwDataPathVersionToReport);
DoPropExchange(&PX);
m_bDataPathPropertiesLoaded=TRUE;
}
}
LPOLECLIENTSITE COleControl::GetClientSite()
{
return m_pClientSite;
}
COLORREF COleControl::TranslateColor(OLE_COLOR clrColor, HPALETTE hpal)
{
COLORREF cr = RGB(0x00,0x00,0x00);
::OleTranslateColor(clrColor, hpal, &cr);
return cr;
}
void COleControl::Refresh()
{
InvalidateControl();
if (m_hWnd != NULL)
UpdateWindow();
}
void COleControl::DoClick()
{
OnClick(LEFT_BUTTON);
}
BOOL COleControl::OnNcCreate(LPCREATESTRUCT lpCreateStruct)
{
if (m_pReflect != NULL)
m_pReflect->SetControl(this);
return CWnd::OnNcCreate(lpCreateStruct);
}
void COleControl::RecreateControlWindow()
{
if (m_bInPlaceActive)
{
BOOL bUIActive = m_bUIActive;
m_xOleInPlaceObject.InPlaceDeactivate();
DestroyWindow();
OnActivateInPlace(bUIActive, NULL);
}
#ifdef _AFXDLL
else if (m_bOpen)
{
DestroyWindow();
CRect rectClient;
m_pWndOpenFrame->GetClientRect(&rectClient);
CreateControlWindow(m_pWndOpenFrame->m_hWnd, rectClient, rectClient);
}
#endif //_AFXDLL
else
{
HWND hWndParent = _AfxGetParkingWindow();
if (hWndParent != NULL)
{
DestroyWindow();
int cx;
int cy;
GetControlSize(&cx, &cy);
CRect rect(0, 0, cx, cy);
CreateControlWindow(hWndParent, rect);
}
}
}
void COleControl::CreateWindowForSubclassedControl()
{
if (IsSubclassedControl() && (m_hWnd == NULL))
{
// If this is a subclassed control, we should create the window
// for it now, in case the window is needed by the DoSuperclassPaint
// implementation.
HWND hWndParent = _AfxGetParkingWindow();
if (hWndParent != NULL)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -