📄 atlvcl.h
字号:
else
{
ControlWndProc(Message);
pT->SendOnViewChange(DVASPECT_CONTENT);
}
break;
case CM_INVALIDATE:
case WM_SETTEXT:
ControlWndProc(Message);
if (!m_bInPlaceActive)
pT->SendOnViewChange(DVASPECT_CONTENT);
break;
case WM_NCHITTEST:
ControlWndProc(Message);
if (Message.Result == HTTRANSPARENT)
Message.Result = HTCLIENT;
break;
default:
ControlWndProc(Message);
}
if (FilterMessage)
m_spSimpleFrameSite->PostMessageFilter(Handle, Message.Msg,
Message.WParam,
Message.LParam,
(LRESULT*)&Message.Result,
dwCookie);
}
// TWinControlAccess: Template which wraps the Window interface of an ActiveX Control
//
template <class T>
class TWinControlAccess: public T
{
__fastcall virtual TWinControlAccess(Classes::TComponent* AOwner): T(AOwner) {}
public:
__fastcall TWinControlAccess(HWND ParentWindow): T(ParentWindow) {}
HWND GetWindowHandle(void) {return WindowHandle;}
void DoDestroyHandle(void) {DestroyHandle();}
};
// TVclControlImpl
//
template <class T, // User class implementing Control
class TVCL, // Underlying VCL type used in One-Step Conversion
const CLSID* pclsid, // Class ID of Control
const IID* piid, // Primary interface of Control
const IID* peventsid, // Event (outgoing) interface of Control
const GUID* plibid> // GUID of TypeLibrary
class ATL_NO_VTABLE TVclControlImpl:
public CComObjectRootEx<CComObjectThreadModel>,
public CComCoClass<T, pclsid>,
public TVclComControl<T, TVCL>,
public IProvideClassInfo2Impl<pclsid, peventsid, plibid>,
public IPersistStorageImpl<T>,
public IPersistStreamInitImpl<T>,
public IQuickActivateImpl<T>,
public IOleControlImpl<T>,
public IOleObjectImpl<T>,
public IOleInPlaceActiveObjectImpl<T>,
public IViewObjectExImpl<T>,
public IOleInPlaceObjectWindowlessImpl<T>,
public IDataObjectImpl<T>,
public ISpecifyPropertyPagesImpl<T>,
public IConnectionPointContainerImpl<T>,
public IPropertyNotifySinkCP<T, CComDynamicUnkArray>,
public ISupportErrorInfo,
public ISimpleFrameSiteImpl<T>
{
public:
TVclControlImpl()
{}
~TVclControlImpl()
{}
// Returns pointer to outer IUnknown
//
virtual IUnknown* GetControllingUnknown()
{
return (static_cast<T*>(this))->GetUnknown();
}
// Empty Message Map provides default implementation of 'ProcessWindowMessage'
//
BEGIN_MSG_MAP(TVclControlImpl)
END_MSG_MAP()
// Map of connection points supported
//
BEGIN_CONNECTION_POINT_MAP(T)
CONNECTION_POINT_ENTRY(*peventsid)
CONNECTION_POINT_ENTRY(IID_IPropertyNotifySink)
END_CONNECTION_POINT_MAP()
// This macro declares a static routine which returns the default OLEMISC_xxxx
// flags used for controls. The macro may be redefined in the derived class
// to specify other OLEMISC_xxxx values.
//
DECLARE_OLEMISC_FLAGS(dwDefaultControlMiscFlags);
// Verbs supported by Control. Provides default implementation of _GetVerbs()
// This table can be redefined in the user's class if the latter supports additional
// Verbs (or does not want the default 'Properties' verb).
//
BEGIN_VERB_MAP()
VERB_ENTRY(0, L"Properties")
END_VERB_MAP()
// IOleInPlaceObject
//
STDMETHOD(SetObjectRects)(LPCRECT prcPos,LPCRECT prcClip)
{
try
{
if (m_VclWinCtl)
m_VclWinCtl->SetBounds(prcPos->left, prcPos->top,
prcPos->right - prcPos->left, prcPos->bottom - prcPos->top);
}
catch (Exception& e)
{
return (static_cast<T*>(this))->Error(e.Message.c_str());
}
return S_OK;
}
HRESULT FinalConstruct()
{
try
{
Initialize();
}
catch(Exception &e)
{
return (static_cast<T*>(this))->Error(e.Message.c_str());
}
return S_OK;
}
void FinalRelease()
{}
// IViewObjectEx
//
STDMETHOD(GetViewStatus)(DWORD* pdwStatus)
{
ATLTRACE(_T("IViewObjectExImpl::GetViewStatus\n"));
*pdwStatus = VIEWSTATUS_SOLIDBKGND | VIEWSTATUS_OPAQUE;
return S_OK;
}
// ISupportErrorInfo
//
STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid)
{
ATLTRACE(_T("ISupportErrorInfo::InterfaceSupportsErrorInfo\n"));
const _ATL_INTMAP_ENTRY *pentries = static_cast<T*>(this)->_GetEntries();
while (pentries->piid)
{
if (InlineIsEqualGUID(*(pentries->piid),riid))
return S_OK;
pentries++;
}
return S_FALSE;
}
// IOleControl
// The following implementation supports BACKCOLOR, FORECOLOR, and FONT ambient
// properties. Note that a VCL control will ignore the container's BACKCOLOR
// property unless the control's ParentColor property is True. FORECOLOR and
// FONT properties are ignored unless the control's ParentFont property is True.
//
STDMETHOD(OnAmbientPropertyChange)(DISPID dispid)
{
ATLTRACE(_T("IOleControl::OnAmbientPropertyChange\n"));
ATLTRACE(_T(" -- DISPID = %d (%d)\n"), dispid);
if (m_VclWinCtl == NULL || !m_AmbientDriver)
return S_OK;
if (dispid == DISPID_AMBIENT_BACKCOLOR || dispid == 0)
{
TAutoArgs<0> arg;
HRESULT hres = m_AmbientDriver.OlePropertyGet(DISPID_AMBIENT_BACKCOLOR, arg);
if (hres != S_OK)
return hres;
m_VclWinCtl->Perform(CM_PARENTCOLORCHANGED, 1, arg.GetRetVariant());
}
if (dispid == DISPID_AMBIENT_FORECOLOR ||
dispid == DISPID_AMBIENT_FONT ||
dispid == 0)
{
TAutoArgs<0> arg;
TPtr<TFont> pFont = new TFont;
HRESULT hres = m_AmbientDriver.OlePropertyGet(DISPID_AMBIENT_FORECOLOR, arg);
if (hres != S_OK)
return hres;
pFont->Color = (TColor)(int)arg.GetRetVariant();
hres = m_AmbientDriver.OlePropertyGet(DISPID_AMBIENT_FONT, arg);
if (hres != S_OK)
return hres;
SetOleFont(pFont, (IFontDisp*)(IUnknown*)arg.GetRetVariant());
m_VclWinCtl->Perform(CM_PARENTFONTCHANGED, 1, int(&pFont));
}
return S_OK;
}
// IAtlSubCtl
//
HRESULT OnDraw(ATL_DRAWINFO& di)
{
try
{
if (m_VclCtl)
m_VclCtl->PaintTo(di.hdcDraw, di.prcBounds->left, di.prcBounds->top);
}
catch (Exception& e)
{
return (static_cast<T*>(this))->Error(e.Message.c_str());
}
return S_OK;
}
};
// TValidateLicense - Standard implementation of 'IsLicenseValid' that simply returns
// TRUE. When Control Licensing support is enabled, the Wizard
// automatically assigns your control a GUID as the Runtime License
// string. However, your control still needs to validate whether the
// it is licensed on the machine (before handing out the runtime
// license string for example). This class provides a standard implementation
// of the validation routine that simply returns TRUE.
//
class TValidateLicense
{
public:
static BOOL IsGUIDInFile(const WCHAR *szGUID, const CHAR *szLicFileName)
{
LPCSTR pName = 0;
// Find name of LicFileName
//
OFSTRUCT ofs;
ZeroMemory(&ofs, sizeof(ofs));
ofs.cBytes = sizeof(OFSTRUCT);
// We'll look for the license file in the directory of the OCX..
// Then in the current, app, Windows, System or PATH directories!!
//
CHAR szModule[_MAX_PATH];
::GetModuleFileNameA(_Module.GetModuleInstance(), szModule, sizeof(szModule));
CHAR szDir[_MAX_DIR];
CHAR szDrv[_MAX_DRIVE];
fnsplit(szModule, szDrv, szDir, 0, 0);
fnmerge(szModule, szDrv, szDir, 0, 0);
::lstrcatA(szModule, szLicFileName);
if (::OpenFile(szModule, &ofs, OF_EXIST) != HFILE_ERROR ||
::OpenFile(szLicFileName, &ofs, OF_EXIST) != HFILE_ERROR)
{
pName = ofs.szPathName;
}
else
{
// Could not find file anywhere
//
ATLTRACE(_T("Could not find License File\n"));
return false;
}
// Create a TStringList and load from the file
//
_ASSERTE(pName);
TPtr<TStringList> pList = new TStringList;
pList->LoadFromFile(pName);
int index = pList->IndexOf(AnsiString(szGUID));
return (index != -1);
}
};
// TLicenseString
// Template built around the runtime license string of a Control.
// 'VerifyLicenseKey' compares string passed in to the runtime license key
// 'GetLicenseKey' returns the runtime license key
// 'IsLicenseValid' delegates to T::IsLicenseValid allowing a separate class to
// handle the license verification.
//
template <class T>
class TLicenseString
{
protected:
static BOOL VerifyLicenseKey(BSTR str)
{
ATLTRACE(_T("TLicenseString::VerifyLicenseKey\n"));
return !lstrcmpW(str, T::GetLicenseString());
}
static BOOL GetLicenseKey(DWORD /*dwReserved*/, BSTR *pStr)
{
ATLTRACE(_T("TLicenseString::GetLicenseKey\n"));
*pStr = ::SysAllocString(T::GetLicenseString());
return TRUE;
}
static BOOL IsLicenseValid()
{
ATLTRACE(_T("TLicenseString::IsLicenseValid\n"));
return T::IsLicenseValid();
}
};
#include <axctrls.hpp>
#include <vclhew.hpp>
// TVCLPropertyPage
//
template <class IMPLCLASS, const CLSID* P_COCLASS_CLSID, class VCLCLASS>
class ATL_NO_VTABLE TVCLPropertyPage: public CComObjectRootEx<CComSingleThreadModel>,
public IUnknown,
public CComCoClass<IMPLCLASS, P_COCLASS_CLSID>
{
public:
TVCLPropertyPage(void): m_PPImpl(0), m_InnerUnk(0)
{}
~TVCLPropertyPage()
{}
DECLARE_PROTECT_FINAL_CONSTRUCT()
HRESULT FinalConstruct(void)
{
ATLTRACE(_T("TVCLPropertyPage::FinalConstruct\n"));
try
{
// Chain to Base Class
HRESULT hres = CComObjectRootEx<CComSingleThreadModel>::FinalConstruct();
if (hres != S_OK)
return hres;
// Create PropertyPageImpl passing it us as Controlling IUnknown
IUnknown* pUnk = (static_cast<IMPLCLASS*>(this))->GetUnknown();
m_PPImpl = new TPropertyPageImplHack(_di_IUnknown(pUnk));
// Get IUnknown of PropertyPageImpl
// using GetInterface hack.
m_PPImpl->GetInterface(IID_IUnknown, reinterpret_cast<void*>(&m_InnerUnk));
// Create Underlying VCL class
m_PPImpl->PropertyPage = new VCLCLASS((TComponent*)NULL);
// Initialize PropertyPage
m_PPImpl->InitPropertyPage();
}
catch (Exception& e)
{
return (static_cast<IMPLCLASS*>(this))->Error(e.Message.c_str());
}
return S_OK;
}
void FinalRelease(void)
{
ATLTRACE(_T("TVCLPropertyPage::FinalRelease\n"));
try
{
if (m_PPImpl->PropertyPage)
delete m_PPImpl->PropertyPage;
if (m_PPImpl)
delete m_PPImpl;
CComObjectRootEx<CComSingleThreadModel>::FinalRelease();
}
catch (Exception& e)
{
// don't propagate exception
}
}
// Data members
//
TPropertyPageImplHack* m_PPImpl;
IUnknown* m_InnerUnk;
};
// VCL_CONTROL_COM_INTERFACE_ENTRIES
//
// This macro defines the entries of the required Interfaces for exposing a VCL
// component as an ActiveX Control
//
#define VCL_CONTROL_COM_INTERFACE_ENTRIES(intf) \
COM_INTERFACE_ENTRY_IMPL(IViewObjectEx) \
COM_INTERFACE_ENTRY_IMPL_IID(IID_IViewObject2, IViewObjectEx) \
COM_INTERFACE_ENTRY_IMPL_IID(IID_IViewObject, IViewObjectEx) \
COM_INTERFACE_ENTRY_IMPL_IID(IID_IOleInPlaceObject, IOleInPlaceObjectWindowless) \
COM_INTERFACE_ENTRY_IMPL_IID(IID_IOleWindow, IOleInPlaceObjectWindowless) \
COM_INTERFACE_ENTRY_IMPL(IOleInPlaceActiveObject) \
COM_INTERFACE_ENTRY_IMPL(IOleControl) \
COM_INTERFACE_ENTRY_IMPL(IOleObject) \
COM_INTERFACE_ENTRY_IMPL(IQuickActivate) \
COM_INTERFACE_ENTRY_IMPL(IPersistStorage) \
COM_INTERFACE_ENTRY_IMPL(IPersistStreamInit) \
COM_INTERFACE_ENTRY_IMPL(ISpecifyPropertyPages) \
COM_INTERFACE_ENTRY_IMPL(IDataObject) \
COM_INTERFACE_ENTRY_IMPL(ISimpleFrameSite) \
COM_INTERFACE_ENTRY(IProvideClassInfo) \
COM_INTERFACE_ENTRY(IProvideClassInfo2) \
COM_INTERFACE_ENTRY_IMPL(IConnectionPointContainer) \
COM_INTERFACE_ENTRY(ISupportErrorInfo) \
COM_INTERFACE_ENTRY(intf) \
COM_INTERFACE_ENTRY2(IDispatch, intf)
// VCLCONTROL_IMPL
// This macro is used to encapsulate the various base classes an ActiveX VCL Control derives from.
//
#define VCLCONTROL_IMPL(cppClass, CoClass, VclClass, intf, EventID) \
public TVclControlImpl<cppClass, VclClass, &CLSID_##CoClass, &IID_##intf, &EventID, LIBID_OF_##CoClass>,\
public IDispatchImpl<intf, &IID_##intf, LIBID_OF_##CoClass>, \
public TEvents_##CoClass<cppClass>
// COM_MAP entry for VCL-based Property Page
//
#define PROPERTYPAGE_COM_INTERFACE_ENTRIES \
COM_INTERFACE_ENTRY(IUnknown) \
COM_INTERFACE_ENTRY_AGGREGATE(IID_IPropertyPage, m_InnerUnk) \
COM_INTERFACE_ENTRY_AGGREGATE(IID_IPropertyPage2, m_InnerUnk)
// Base classes of RemoteDataModule
//
// WARNING: this has changed between BCB 4 and BCB 5 due to changes in MIDAS
#define REMOTEDATAMODULE_IMPL(cppClass, CoClass, VclClass, intf) \
public CComObjectRootEx<CComObjectThreadModel>, \
public CComCoClass<cppClass, &CLSID_##CoClass>, \
public IAppServerImpl<VclClass, cppClass, intf, &IID_##intf, LIBID_OF_##CoClass>
// Base class of VCL-based Property Page
//
#define PROPERTYPAGE_IMPL(cppClass, CoClass, VclClass) \
public TVCLPropertyPage<cppClass, &CLSID_##CoClass, VclClass>
#define DECLARE_REMOTEDATAMODULE_REGISTRY(progid) \
UPDATE_REGISTRY_METHOD( \
TRemoteDataModuleRegistrar RDMRegistrar(GetObjectCLSID(), progid); \
hres = RDMRegistrar.UpdateRegistry(bRegister);)
#define DECLARE_ACTIVEXCONTROL_REGISTRY(progid, idbmp) \
UPDATE_REGISTRY_METHOD( \
TAxControlRegistrar AXCR(GetObjectCLSID(), progid, idbmp, _GetObjectMiscStatus(), _GetVerbs()); \
hres = AXCR.UpdateRegistry(bRegister);)
#pragma option pop
#endif //__ATLVCL_H_
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -