📄 atlctl.h
字号:
// This is a part of the Active Template Library.
// Copyright (C) 1996-1998 Microsoft Corporation
// All rights reserved.
//
// This source code is only intended as a supplement to the
// Active Template Library Reference and related
// electronic documentation provided with the library.
// See these sources for detailed information regarding the
// Active Template Library product.
#ifndef __ATLCTL_H__
#define __ATLCTL_H__
#ifndef __cplusplus
#error ATL requires C++ compilation (use a .cpp suffix)
#endif
#include <atlwin.h>
#include <objsafe.h>
#include <urlmon.h>
#pragma comment(lib, "gdi32.lib")
#pragma comment(lib, "urlmon.lib")
#define DECLARE_VIEW_STATUS(statusFlags) \
DWORD _GetViewStatus() \
{ \
return statusFlags; \
}
// Include GUIDs for the new stock property dialogs contained in the dll MSStkProp.DLL
#include "msstkppg.h"
#include "atliface.h"
#define CLSID_MSStockFont CLSID_StockFontPage
#define CLSID_MSStockColor CLSID_StockColorPage
#define CLSID_MSStockPicture CLSID_StockPicturePage
struct ATL_DRAWINFO
{
UINT cbSize;
DWORD dwDrawAspect;
LONG lindex;
DVTARGETDEVICE* ptd;
HDC hicTargetDev;
HDC hdcDraw;
LPCRECTL prcBounds; //Rectangle in which to draw
LPCRECTL prcWBounds; //WindowOrg and Ext if metafile
BOOL bOptimize;
BOOL bZoomed;
BOOL bRectInHimetric;
SIZEL ZoomNum; //ZoomX = ZoomNum.cx/ZoomNum.cy
SIZEL ZoomDen;
};
namespace ATL
{
#pragma pack(push, _ATL_PACKING)
// Forward declarations
//
class ATL_NO_VTABLE CComControlBase;
template <class T, class WinBase> class CComControl;
//////////////////////////////////////////////////////////////////////////////
// CFirePropNotifyEvent
// Helper functions for safely communicating with objects who sink IPropertyNotifySink
class CFirePropNotifyEvent
{
public:
// Ask any objects sinking the IPropertyNotifySink notification if it is ok to edit a specified property
static HRESULT FireOnRequestEdit(IUnknown* pUnk, DISPID dispID)
{
CComQIPtr<IConnectionPointContainer, &IID_IConnectionPointContainer> pCPC(pUnk);
if (!pCPC)
return S_OK;
CComPtr<IConnectionPoint> pCP;
pCPC->FindConnectionPoint(IID_IPropertyNotifySink, &pCP);
if (!pCP)
return S_OK;
CComPtr<IEnumConnections> pEnum;
if (FAILED(pCP->EnumConnections(&pEnum)))
return S_OK;
CONNECTDATA cd;
while (pEnum->Next(1, &cd, NULL) == S_OK)
{
if (cd.pUnk)
{
HRESULT hr = S_OK;
CComQIPtr<IPropertyNotifySink, &IID_IPropertyNotifySink> pSink(cd.pUnk);
if (pSink)
hr = pSink->OnRequestEdit(dispID);
cd.pUnk->Release();
if (hr == S_FALSE)
return S_FALSE;
}
}
return S_OK;
}
// Notify any objects sinking the IPropertyNotifySink notification that a property has changed
static HRESULT FireOnChanged(IUnknown* pUnk, DISPID dispID)
{
CComQIPtr<IConnectionPointContainer, &IID_IConnectionPointContainer> pCPC(pUnk);
if (!pCPC)
return S_OK;
CComPtr<IConnectionPoint> pCP;
pCPC->FindConnectionPoint(IID_IPropertyNotifySink, &pCP);
if (!pCP)
return S_OK;
CComPtr<IEnumConnections> pEnum;
if (FAILED(pCP->EnumConnections(&pEnum)))
return S_OK;
CONNECTDATA cd;
while (pEnum->Next(1, &cd, NULL) == S_OK)
{
if (cd.pUnk)
{
CComQIPtr<IPropertyNotifySink, &IID_IPropertyNotifySink> pSink(cd.pUnk);
if (pSink)
pSink->OnChanged(dispID);
cd.pUnk->Release();
}
}
return S_OK;
}
};
//////////////////////////////////////////////////////////////////////////////
// CComControlBase
// Holds the essential data members for an ActiveX control and useful helper functions
class ATL_NO_VTABLE CComControlBase
{
public:
CComControlBase(HWND& h) : m_hWndCD(h)
{
memset(this, 0, sizeof(CComControlBase));
m_phWndCD = &h;
m_sizeExtent.cx = 2*2540;
m_sizeExtent.cy = 2*2540;
m_sizeNatural = m_sizeExtent;
}
~CComControlBase()
{
if (m_hWndCD != NULL)
::DestroyWindow(m_hWndCD);
ATLTRACE2(atlTraceControls,2,_T("Control Destroyed\n"));
}
// methods
public:
// Control helper functions can go here non-virtuals only please
// Mark the control 'dirty' so the container will save it
void SetDirty(BOOL bDirty)
{
m_bRequiresSave = bDirty;
}
// Obtain the dirty state for the control
BOOL GetDirty()
{
return m_bRequiresSave ? TRUE : FALSE;
}
// Get the zoom factor (numerator & denominator) which is factor of the natural extent
void GetZoomInfo(ATL_DRAWINFO& di);
// Sends a notification that the moniker for the control has changed
HRESULT SendOnRename(IMoniker *pmk)
{
HRESULT hRes = S_OK;
if (m_spOleAdviseHolder)
hRes = m_spOleAdviseHolder->SendOnRename(pmk);
return hRes;
}
// Sends a notification that the control has just saved its data
HRESULT SendOnSave()
{
HRESULT hRes = S_OK;
if (m_spOleAdviseHolder)
hRes = m_spOleAdviseHolder->SendOnSave();
return hRes;
}
// Sends a notification that the control has closed its advisory sinks
HRESULT SendOnClose()
{
HRESULT hRes = S_OK;
if (m_spOleAdviseHolder)
hRes = m_spOleAdviseHolder->SendOnClose();
return hRes;
}
// Sends a notification that the control's data has changed
HRESULT SendOnDataChange(DWORD advf = 0);
// Sends a notification that the control's representation has changed
HRESULT SendOnViewChange(DWORD dwAspect, LONG lindex = -1)
{
if (m_spAdviseSink)
m_spAdviseSink->OnViewChange(dwAspect, lindex);
return S_OK;
}
// Sends a notification to the container that the control has received focus
LRESULT OnSetFocus(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled)
{
if (m_bInPlaceActive)
{
CComPtr<IOleObject> pOleObject;
ControlQueryInterface(IID_IOleObject, (void**)&pOleObject);
if (pOleObject != NULL)
pOleObject->DoVerb(OLEIVERB_UIACTIVATE, NULL, m_spClientSite, 0, m_hWndCD, &m_rcPos);
CComQIPtr<IOleControlSite, &IID_IOleControlSite> spSite(m_spClientSite);
if (m_bInPlaceActive && spSite != NULL)
spSite->OnFocus(TRUE);
}
bHandled = FALSE;
return 1;
}
LRESULT OnKillFocus(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled)
{
CComQIPtr<IOleControlSite, &IID_IOleControlSite> spSite(m_spClientSite);
if (m_bInPlaceActive && spSite != NULL && !::IsChild(m_hWndCD, ::GetFocus()))
spSite->OnFocus(FALSE);
bHandled = FALSE;
return 1;
}
LRESULT OnMouseActivate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled)
{
BOOL bUserMode = TRUE;
HRESULT hRet = GetAmbientUserMode(bUserMode);
// UI activate if in user mode only
// allow activation if we can't determine mode
if (FAILED(hRet) || bUserMode)
{
CComPtr<IOleObject> pOleObject;
ControlQueryInterface(IID_IOleObject, (void**)&pOleObject);
if (pOleObject != NULL)
pOleObject->DoVerb(OLEIVERB_UIACTIVATE, NULL, m_spClientSite, 0, m_hWndCD, &m_rcPos);
}
bHandled = FALSE;
return 1;
}
BOOL PreTranslateAccelerator(LPMSG /*pMsg*/, HRESULT& /*hRet*/)
{
return FALSE;
}
HRESULT GetAmbientProperty(DISPID dispid, VARIANT& var)
{
HRESULT hRes = E_FAIL;
if (m_spAmbientDispatch.p != NULL)
hRes = m_spAmbientDispatch.GetProperty(dispid, &var);
return hRes;
}
HRESULT GetAmbientAppearance(short& nAppearance)
{
CComVariant var;
HRESULT hRes = GetAmbientProperty(DISPID_AMBIENT_APPEARANCE, var);
ATLASSERT(var.vt == VT_I2 || var.vt == VT_UI2 || var.vt == VT_I4 || var.vt == VT_UI4 || FAILED(hRes));
nAppearance = var.iVal;
return hRes;
}
HRESULT GetAmbientBackColor(OLE_COLOR& BackColor)
{
CComVariant var;
HRESULT hRes = GetAmbientProperty(DISPID_AMBIENT_BACKCOLOR, var);
ATLASSERT(var.vt == VT_I4 || var.vt == VT_UI4 || FAILED(hRes));
BackColor = var.lVal;
return hRes;
}
HRESULT GetAmbientDisplayName(BSTR& bstrDisplayName)
{
CComVariant var;
if (bstrDisplayName)
{
SysFreeString(bstrDisplayName);
bstrDisplayName = NULL;
}
HRESULT hRes = GetAmbientProperty(DISPID_AMBIENT_DISPLAYNAME, var);
if (SUCCEEDED(hRes))
{
if (var.vt != VT_BSTR)
return E_FAIL;
bstrDisplayName = var.bstrVal;
var.vt = VT_EMPTY;
var.bstrVal = NULL;
}
return hRes;
}
HRESULT GetAmbientFont(IFont** ppFont)
{
// caller MUST Release the font!
if (ppFont == NULL)
return E_POINTER;
*ppFont = NULL;
CComVariant var;
HRESULT hRes = GetAmbientProperty(DISPID_AMBIENT_FONT, var);
ATLASSERT((var.vt == VT_UNKNOWN || var.vt == VT_DISPATCH) || FAILED(hRes));
if (SUCCEEDED(hRes) && var.pdispVal)
{
if (var.vt == VT_UNKNOWN || var.vt == VT_DISPATCH)
hRes = var.pdispVal->QueryInterface(IID_IFont, (void**)ppFont);
else
hRes = DISP_E_BADVARTYPE;
}
return hRes;
}
HRESULT GetAmbientFontDisp(IFontDisp** ppFont)
{
// caller MUST Release the font!
if (ppFont == NULL)
return E_POINTER;
*ppFont = NULL;
CComVariant var;
HRESULT hRes = GetAmbientProperty(DISPID_AMBIENT_FONT, var);
ATLASSERT((var.vt == VT_UNKNOWN || var.vt == VT_DISPATCH) || FAILED(hRes));
if (SUCCEEDED(hRes) && var.pdispVal)
{
if (var.vt == VT_UNKNOWN || var.vt == VT_DISPATCH)
hRes = var.pdispVal->QueryInterface(IID_IFontDisp, (void**)ppFont);
else
hRes = DISP_E_BADVARTYPE;
}
return hRes;
}
HRESULT GetAmbientForeColor(OLE_COLOR& ForeColor)
{
CComVariant var;
HRESULT hRes = GetAmbientProperty(DISPID_AMBIENT_FORECOLOR, var);
ATLASSERT(var.vt == VT_I4 || var.vt == VT_UI4 || FAILED(hRes));
ForeColor = var.lVal;
return hRes;
}
HRESULT GetAmbientLocaleID(LCID& lcid)
{
CComVariant var;
HRESULT hRes = GetAmbientProperty(DISPID_AMBIENT_LOCALEID, var);
ATLASSERT((var.vt == VT_UI4 || var.vt == VT_I4) || FAILED(hRes));
lcid = var.lVal;
return hRes;
}
HRESULT GetAmbientScaleUnits(BSTR& bstrScaleUnits)
{
CComVariant var;
HRESULT hRes = GetAmbientProperty(DISPID_AMBIENT_SCALEUNITS, var);
ATLASSERT(var.vt == VT_BSTR || FAILED(hRes));
bstrScaleUnits = var.bstrVal;
return hRes;
}
HRESULT GetAmbientTextAlign(short& nTextAlign)
{
CComVariant var;
HRESULT hRes = GetAmbientProperty(DISPID_AMBIENT_TEXTALIGN, var);
ATLASSERT(var.vt == VT_I2 || FAILED(hRes));
nTextAlign = var.iVal;
return hRes;
}
HRESULT GetAmbientUserMode(BOOL& bUserMode)
{
CComVariant var;
HRESULT hRes = GetAmbientProperty(DISPID_AMBIENT_USERMODE, var);
ATLASSERT(var.vt == VT_BOOL || FAILED(hRes));
bUserMode = var.boolVal;
return hRes;
}
HRESULT GetAmbientUIDead(BOOL& bUIDead)
{
CComVariant var;
HRESULT hRes = GetAmbientProperty(DISPID_AMBIENT_UIDEAD, var);
ATLASSERT(var.vt == VT_BOOL || FAILED(hRes));
bUIDead = var.boolVal;
return hRes;
}
HRESULT GetAmbientShowGrabHandles(BOOL& bShowGrabHandles)
{
CComVariant var;
HRESULT hRes = GetAmbientProperty(DISPID_AMBIENT_SHOWGRABHANDLES, var);
ATLASSERT(var.vt == VT_BOOL || FAILED(hRes));
bShowGrabHandles = var.boolVal;
return hRes;
}
HRESULT GetAmbientShowHatching(BOOL& bShowHatching)
{
CComVariant var;
HRESULT hRes = GetAmbientProperty(DISPID_AMBIENT_SHOWHATCHING, var);
ATLASSERT(var.vt == VT_BOOL || FAILED(hRes));
bShowHatching = var.boolVal;
return hRes;
}
HRESULT GetAmbientMessageReflect(BOOL& bMessageReflect)
{
CComVariant var;
HRESULT hRes = GetAmbientProperty(DISPID_AMBIENT_MESSAGEREFLECT, var);
ATLASSERT(var.vt == VT_BOOL || FAILED(hRes));
bMessageReflect = var.boolVal;
return hRes;
}
HRESULT GetAmbientAutoClip(BOOL& bAutoClip)
{
CComVariant var;
HRESULT hRes = GetAmbientProperty(DISPID_AMBIENT_AUTOCLIP, var);
ATLASSERT(var.vt == VT_BOOL || FAILED(hRes));
bAutoClip = var.boolVal;
return hRes;
}
HRESULT GetAmbientDisplayAsDefault(BOOL& bDisplaysDefault)
{
CComVariant var;
HRESULT hRes = GetAmbientProperty(DISPID_AMBIENT_DISPLAYASDEFAULT, var);
ATLASSERT(var.vt == VT_BOOL || FAILED(hRes));
bDisplaysDefault = var.boolVal;
return hRes;
}
HRESULT GetAmbientSupportsMnemonics(BOOL& bSupportMnemonics)
{
CComVariant var;
HRESULT hRes = GetAmbientProperty(DISPID_AMBIENT_SUPPORTSMNEMONICS, var);
ATLASSERT(var.vt == VT_BOOL || FAILED(hRes));
bSupportMnemonics = var.boolVal;
return hRes;
}
HRESULT GetAmbientPalette(HPALETTE& hPalette)
{
CComVariant var;
HRESULT hRes = GetAmbientProperty(DISPID_AMBIENT_PALETTE, var);
ATLASSERT(var.vt == VT_I4 || var.vt == VT_UI4 || FAILED(hRes));
hPalette = reinterpret_cast<HPALETTE>(var.lVal);
return hRes;
}
HRESULT InternalGetSite(REFIID riid, void** ppUnkSite)
{
ATLASSERT(ppUnkSite != NULL);
if (ppUnkSite == NULL)
return E_POINTER;
if (m_spClientSite == NULL)
{
*ppUnkSite = NULL;
return S_OK;
}
return m_spClientSite->QueryInterface(riid, ppUnkSite);
}
BOOL DoesVerbUIActivate(LONG iVerb)
{
BOOL b = FALSE;
switch (iVerb)
{
case OLEIVERB_UIACTIVATE:
case OLEIVERB_PRIMARY:
b = TRUE;
break;
}
// if no ambient dispatch then in old style OLE container
if (DoesVerbActivate(iVerb) && m_spAmbientDispatch.p == NULL)
b = TRUE;
return b;
}
BOOL DoesVerbActivate(LONG iVerb)
{
BOOL b = FALSE;
switch (iVerb)
{
case OLEIVERB_UIACTIVATE:
case OLEIVERB_PRIMARY:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -