• 转:CWebBrowser2去除边框、滚动条、右键菜单


    http://blog.csdn.net/tangyin025/article/details/8675513

    添加CWebBrowser2类

    右键项目-〉Add-〉Class...-〉MFC-〉MFC Class From ActiveX Control

    在Available ActiveX controls中选择Microsoft Web Browser<1.0>,然后在左侧Interfaces中选择IWebBrowser2,在点击“〉”,就会在右侧出现CWebBrowser2,按Finish就会生成对应的头文件和cpp文件

    添加CWebBrowser2控件

    在对话框资源中,右键Insert ActiveX Control...,然后在弹出的对话框中选择Microsoft Web Browser,就会添加对应的控件了,对其使用Add Variable...就会自动添加CWebBrowser2成员变量并绑定控件了

    添加必要的com事件处理,并实现DocHostUIHandler::GetHostInfo

    我这边直接把4个代码文件贴上来:idispimp.h、idispimp.cpp、custsite.h、custsite.cpp

    [cpp] view plaincopy
     
    1. /* 
    2.  * IDispimp.H 
    3.  * IDispatch 
    4.  * 
    5.  * Copyright (c)1995-2000 Microsoft Corporation, All Rights Reserved 
    6.  */  
    7.   
    8.   
    9. #ifndef _IDISPIMP_H_  
    10. #define _IDISPIMP_H_  
    11.   
    12. class CImpIDispatch : public IDispatch  
    13. {  
    14.     protected:  
    15.         ULONG               m_cRef;  
    16.   
    17.     public:  
    18.         CImpIDispatch(void);  
    19.         ~CImpIDispatch(void);  
    20.   
    21.         STDMETHODIMP QueryInterface(REFIID, void **);  
    22.         STDMETHODIMP_(ULONG) AddRef(void);  
    23.         STDMETHODIMP_(ULONG) Release(void);  
    24.   
    25.         //IDispatch  
    26.         STDMETHODIMP GetTypeInfoCount(UINT* pctinfo);  
    27.         STDMETHODIMP GetTypeInfo(/* [in] */ UINT iTInfo,  
    28.             /* [in] */ LCID lcid,  
    29.             /* [out] */ ITypeInfo** ppTInfo);  
    30.         STDMETHODIMP GetIDsOfNames(  
    31.             /* [in] */ REFIID riid,  
    32.             /* [size_is][in] */ LPOLESTR *rgszNames,  
    33.             /* [in] */ UINT cNames,  
    34.             /* [in] */ LCID lcid,  
    35.             /* [size_is][out] */ DISPID *rgDispId);  
    36.         STDMETHODIMP Invoke(  
    37.             /* [in] */ DISPID dispIdMember,  
    38.             /* [in] */ REFIID riid,  
    39.             /* [in] */ LCID lcid,  
    40.             /* [in] */ WORD wFlags,  
    41.             /* [out][in] */ DISPPARAMS  *pDispParams,  
    42.             /* [out] */ VARIANT  *pVarResult,  
    43.             /* [out] */ EXCEPINFO *pExcepInfo,  
    44.             /* [out] */ UINT *puArgErr);  
    45.   
    46. };  
    47. #endif //_IDISPIMP_H_  
    [cpp] view plaincopy
     
    1. /* 
    2.  * idispimp.CPP 
    3.  * IDispatch for Extending Dynamic HTML Object Model 
    4.  * 
    5.  * Copyright (c)1995-2000 Microsoft Corporation, All Rights Reserved 
    6.  */  
    7.   
    8. #include "stdafx.h"  
    9. #include "idispimp.h"  
    10.   
    11. #ifdef _DEBUG  
    12. #define new DEBUG_NEW  
    13. #undef THIS_FILE  
    14. static char THIS_FILE[] = __FILE__;  
    15. #endif  
    16.   
    17.   
    18. // Hardcoded information for extending the Object Model   
    19. // Typically this would be supplied through a TypeInfo  
    20. // In this case the name "xxyyzz" maps to DISPID_Extend   
    21. const   WCHAR pszExtend[10]=L"xxyyzz";  
    22. #define DISPID_Extend 12345  
    23.   
    24.   
    25.   
    26. /* 
    27.  * CImpIDispatch::CImpIDispatch 
    28.  * CImpIDispatch::~CImpIDispatch 
    29.  * 
    30.  * Parameters (Constructor): 
    31.  *  pSite           PCSite of the site we're in. 
    32.  *  pUnkOuter       LPUNKNOWN to which we delegate. 
    33.  */  
    34.   
    35. CImpIDispatch::CImpIDispatch( void )  
    36. {  
    37.     m_cRef = 0;  
    38. }  
    39.   
    40. CImpIDispatch::~CImpIDispatch( void )  
    41. {  
    42.     ASSERT( m_cRef == 0 );  
    43. }  
    44.   
    45.   
    46. /* 
    47.  * CImpIDispatch::QueryInterface 
    48.  * CImpIDispatch::AddRef 
    49.  * CImpIDispatch::Release 
    50.  * 
    51.  * Purpose: 
    52.  *  IUnknown members for CImpIDispatch object. 
    53.  */  
    54.   
    55. STDMETHODIMP CImpIDispatch::QueryInterface( REFIID riid, void **ppv )  
    56. {  
    57.     *ppv = NULL;  
    58.   
    59.   
    60.     if ( IID_IDispatch == riid )  
    61.     {  
    62.         *ppv = this;  
    63.     }  
    64.       
    65.     if ( NULL != *ppv )  
    66.     {  
    67.         ((LPUNKNOWN)*ppv)->AddRef();  
    68.         return NOERROR;  
    69.     }  
    70.   
    71.     return E_NOINTERFACE;  
    72. }  
    73.   
    74.   
    75. STDMETHODIMP_(ULONG) CImpIDispatch::AddRef(void)  
    76. {  
    77.     return ++m_cRef;  
    78. }  
    79.   
    80. STDMETHODIMP_(ULONG) CImpIDispatch::Release(void)  
    81. {  
    82.     return --m_cRef;  
    83. }  
    84.   
    85.   
    86. //IDispatch  
    87. STDMETHODIMP CImpIDispatch::GetTypeInfoCount(UINT/*pctinfo*/)  
    88. {  
    89.     return E_NOTIMPL;  
    90. }  
    91.   
    92. STDMETHODIMP CImpIDispatch::GetTypeInfo(/* [in] */ UINT /*iTInfo*/,  
    93.             /* [in] */ LCID /*lcid*/,  
    94.             /* [out] */ ITypeInfo** /*ppTInfo*/)  
    95. {  
    96.     return E_NOTIMPL;  
    97. }  
    98.   
    99. STDMETHODIMP CImpIDispatch::GetIDsOfNames(  
    100.             /* [in] */ REFIID riid,  
    101.             /* [size_is][in] */ OLECHAR** rgszNames,  
    102.             /* [in] */ UINT cNames,  
    103.             /* [in] */ LCID lcid,  
    104.             /* [size_is][out] */ DISPID* rgDispId)  
    105. {  
    106.     HRESULT hr;  
    107.     UINT    i;  
    108.   
    109.     // Assume some degree of success  
    110.     hr = NOERROR;  
    111.   
    112.     // Hardcoded mapping for this sample  
    113.     // A more usual procedure would be to use a TypeInfo  
    114.     for ( i=0; i < cNames; i++)  
    115.     {  
    116.         if (  2 == CompareString( lcid, NORM_IGNOREWIDTH, (TCHAR*)pszExtend, 3, (TCHAR*)rgszNames[i], 3 ) )  
    117.         {  
    118.             rgDispId[i] = DISPID_Extend;  
    119.         }  
    120.         else  
    121.         {  
    122.             // One or more are unknown so set the return code accordingly  
    123.             hr = ResultFromScode(DISP_E_UNKNOWNNAME);  
    124.             rgDispId[i] = DISPID_UNKNOWN;  
    125.         }  
    126.     }  
    127.     return hr;  
    128. }  
    129.   
    130. STDMETHODIMP CImpIDispatch::Invoke(  
    131.             /* [in] */ DISPID dispIdMember,  
    132.             /* [in] */ REFIID /*riid*/,  
    133.             /* [in] */ LCID /*lcid*/,  
    134.             /* [in] */ WORD wFlags,  
    135.             /* [out][in] */ DISPPARAMS* pDispParams,  
    136.             /* [out] */ VARIANT* pVarResult,  
    137.             /* [out] */ EXCEPINFO* /*pExcepInfo*/,  
    138.             /* [out] */ UINT* puArgErr)  
    139. {  
    140.   
    141.     // For this sample we only support a Property Get on DISPID_Extend  
    142.     // returning a BSTR with "Wibble" as the value  
    143.     if ( dispIdMember == DISPID_Extend )  
    144.     {  
    145.         if ( wFlags & DISPATCH_PROPERTYGET )  
    146.         {  
    147.             if ( pVarResult != NULL )  
    148.             {  
    149.                 WCHAR buff[10]=L"Wibble";  
    150.                 BSTR bstrRet = SysAllocString( buff );  
    151.                 VariantInit(pVarResult);  
    152.                 V_VT(pVarResult)=VT_BSTR;  
    153.                 V_BSTR(pVarResult) = bstrRet;  
    154.             }  
    155.         }  
    156.     }  
    157.   
    158.     return S_OK;  
    159. }  
    [cpp] view plaincopy
     
    1. //=--------------------------------------------------------------------------=  
    2. //  (C) Copyright 1996-2000 Microsoft Corporation. All Rights Reserved.  
    3. //=--------------------------------------------------------------------------=  
    4. #ifndef __CUSTOMSITEH__  
    5. #define __CUSTOMSITEH__  
    6.   
    7. #include "idispimp.h"  
    8. #include <mshtmhst.h>  
    9.   
    10. //   
    11. // NOTE:   
    12. // Some of the code in this file is MFC implementation specific.  
    13. // Changes in future versions of MFC implementation may require  
    14. // the code to be changed. Please check the readme of this  
    15. // sample for more information   
    16. //   
    17.   
    18. class CCustomControlSite:public COleControlSite  
    19. {  
    20. public:  
    21.     CCustomControlSite(COleControlContainer *pCnt):COleControlSite(pCnt){}  
    22.   
    23. protected:  
    24.   
    25.     DECLARE_INTERFACE_MAP();  
    26. BEGIN_INTERFACE_PART(DocHostUIHandler, IDocHostUIHandler)  
    27.     STDMETHOD(ShowContextMenu)(/* [in] */ DWORD dwID,  
    28.             /* [in] */ POINT __RPC_FAR *ppt,  
    29.             /* [in] */ IUnknown __RPC_FAR *pcmdtReserved,  
    30.             /* [in] */ IDispatch __RPC_FAR *pdispReserved);  
    31.     STDMETHOD(GetHostInfo)(   
    32.             /* [out][in] */ DOCHOSTUIINFO __RPC_FAR *pInfo);  
    33.     STDMETHOD(ShowUI)(   
    34.             /* [in] */ DWORD dwID,  
    35.             /* [in] */ IOleInPlaceActiveObject __RPC_FAR *pActiveObject,  
    36.             /* [in] */ IOleCommandTarget __RPC_FAR *pCommandTarget,  
    37.             /* [in] */ IOleInPlaceFrame __RPC_FAR *pFrame,  
    38.             /* [in] */ IOleInPlaceUIWindow __RPC_FAR *pDoc);  
    39.     STDMETHOD(HideUI)(void);  
    40.     STDMETHOD(UpdateUI)(void);  
    41.     STDMETHOD(EnableModeless)(/* [in] */ BOOL fEnable);  
    42.     STDMETHOD(OnDocWindowActivate)(/* [in] */ BOOL fEnable);  
    43.     STDMETHOD(OnFrameWindowActivate)(/* [in] */ BOOL fEnable);  
    44.     STDMETHOD(ResizeBorder)(   
    45.             /* [in] */ LPCRECT prcBorder,  
    46.             /* [in] */ IOleInPlaceUIWindow __RPC_FAR *pUIWindow,  
    47.             /* [in] */ BOOL fRameWindow);  
    48.     STDMETHOD(TranslateAccelerator)(   
    49.             /* [in] */ LPMSG lpMsg,  
    50.             /* [in] */ const GUID __RPC_FAR *pguidCmdGroup,  
    51.             /* [in] */ DWORD nCmdID);  
    52.     STDMETHOD(GetOptionKeyPath)(   
    53.             /* [out] */ LPOLESTR __RPC_FAR *pchKey,  
    54.             /* [in] */ DWORD dw);  
    55.     STDMETHOD(GetDropTarget)(  
    56.             /* [in] */ IDropTarget __RPC_FAR *pDropTarget,  
    57.             /* [out] */ IDropTarget __RPC_FAR *__RPC_FAR *ppDropTarget);  
    58.     STDMETHOD(GetExternal)(   
    59.             /* [out] */ IDispatch __RPC_FAR *__RPC_FAR *ppDispatch);  
    60.     STDMETHOD(TranslateUrl)(   
    61.             /* [in] */ DWORD dwTranslate,  
    62.             /* [in] */ OLECHAR __RPC_FAR *pchURLIn,  
    63.             /* [out] */ OLECHAR __RPC_FAR *__RPC_FAR *ppchURLOut);  
    64.     STDMETHOD(FilterDataObject)(   
    65.             /* [in] */ IDataObject __RPC_FAR *pDO,  
    66.             /* [out] */ IDataObject __RPC_FAR *__RPC_FAR *ppDORet);  
    67. END_INTERFACE_PART(DocHostUIHandler)  
    68. };  
    69.   
    70.   
    71. class CCustomOccManager :public COccManager  
    72. {  
    73. public:  
    74.     CCustomOccManager(){}  
    75.     COleControlSite* CreateSite(COleControlContainer* pCtrlCont)  
    76.     {  
    77.         CCustomControlSite *pSite = new CCustomControlSite(pCtrlCont);  
    78.         return pSite;  
    79.     }  
    80. };  
    81.   
    82. #endif  
    [cpp] view plaincopy
     
    1. //=--------------------------------------------------------------------------=  
    2. //  (C) Copyright 1996-2000 Microsoft Corporation. All Rights Reserved.  
    3. //=--------------------------------------------------------------------------=  
    4.   
    5.   
    6. //   
    7. // NOTE:   
    8. // Some of the code in this file is MFC implementation specific.  
    9. // Changes in future versions of MFC implementation may require  
    10. // the code to be changed. Please check the readme of this  
    11. // sample for more information   
    12. //   
    13.   
    14. #include "stdafx.h"  
    15. #undef AFX_DATA  
    16. #define AFX_DATA AFX_DATA_IMPORT  
    17.   
    18.   
    19. // NOTE: THis line is a hardcoded reference to an MFC header file  
    20. //  this path may need to be changed to refer to the location of VC5 install  
    21. //  for successful compilation.  
    22.   
    23.   
    24. //#include <..srcoccimpl.h>  
    25. #undef AFX_DATA  
    26. #define AFX_DATA AFX_DATA_EXPORT  
    27. #include "custsite.h"  
    28. #include "App类的头文件"  
    29.   
    30.   
    31. BEGIN_INTERFACE_MAP(CCustomControlSite, COleControlSite)  
    32.     INTERFACE_PART(CCustomControlSite, IID_IDocHostUIHandler, DocHostUIHandler)  
    33. END_INTERFACE_MAP()  
    34.   
    35.       
    36.   
    37. ULONG FAR EXPORT  CCustomControlSite::XDocHostUIHandler::AddRef()  
    38. {  
    39.     METHOD_PROLOGUE(CCustomControlSite, DocHostUIHandler)  
    40.     return pThis->ExternalAddRef();  
    41. }  
    42.   
    43.   
    44. ULONG FAR EXPORT  CCustomControlSite::XDocHostUIHandler::Release()  
    45. {                              
    46.     METHOD_PROLOGUE(CCustomControlSite, DocHostUIHandler)  
    47.     return pThis->ExternalRelease();  
    48. }  
    49.   
    50. HRESULT FAR EXPORT  CCustomControlSite::XDocHostUIHandler::QueryInterface(REFIID riid, void **ppvObj)  
    51. {  
    52.     METHOD_PROLOGUE(CCustomControlSite, DocHostUIHandler)  
    53.     HRESULT hr = (HRESULT)pThis->ExternalQueryInterface(&riid, ppvObj);  
    54.     return hr;  
    55. }  
    56.   
    57. // * CImpIDocHostUIHandler::GetHostInfo  
    58. // *  
    59. // * Purpose: Called at initialization  
    60. // *  
    61. HRESULT FAR EXPORT  CCustomControlSite::XDocHostUIHandler::GetHostInfo( DOCHOSTUIINFO* pInfo )  
    62. {  
    63.   
    64.     METHOD_PROLOGUE(CCustomControlSite, DocHostUIHandler)  
    65.     pInfo->dwFlags = DOCHOSTUIFLAG_NO3DBORDER | DOCHOSTUIFLAG_SCROLL_NO;  
    66.     pInfo->dwDoubleClick = DOCHOSTUIDBLCLK_DEFAULT;  
    67.   
    68.     return S_OK;  
    69. }  
    70.   
    71. // * CImpIDocHostUIHandler::ShowUI  
    72. // *  
    73. // * Purpose: Called when MSHTML.DLL shows its UI  
    74. // *  
    75. HRESULT FAR EXPORT  CCustomControlSite::XDocHostUIHandler::ShowUI(  
    76.                 DWORD dwID,   
    77.                 IOleInPlaceActiveObject * /*pActiveObject*/,  
    78.                 IOleCommandTarget * pCommandTarget,  
    79.                 IOleInPlaceFrame * /*pFrame*/,  
    80.                 IOleInPlaceUIWindow * /*pDoc*/)  
    81. {  
    82.   
    83.     METHOD_PROLOGUE(CCustomControlSite, DocHostUIHandler)  
    84.     // We've already got our own UI in place so just return S_OK  
    85.     return S_OK;  
    86. }  
    87.   
    88. // * CImpIDocHostUIHandler::HideUI  
    89. // *  
    90. // * Purpose: Called when MSHTML.DLL hides its UI  
    91. // *  
    92. HRESULT FAR EXPORT  CCustomControlSite::XDocHostUIHandler::HideUI(void)  
    93. {  
    94.     METHOD_PROLOGUE(CCustomControlSite, DocHostUIHandler)  
    95.     return S_OK;  
    96. }  
    97.   
    98. // * CImpIDocHostUIHandler::UpdateUI  
    99. // *  
    100. // * Purpose: Called when MSHTML.DLL updates its UI  
    101. // *  
    102. HRESULT FAR EXPORT  CCustomControlSite::XDocHostUIHandler::UpdateUI(void)  
    103. {  
    104.     METHOD_PROLOGUE(CCustomControlSite, DocHostUIHandler)  
    105.     // MFC is pretty good about updating it's UI in it's Idle loop so I don't do anything here  
    106.     return S_OK;  
    107. }  
    108.   
    109. // * CImpIDocHostUIHandler::EnableModeless  
    110. // *  
    111. // * Purpose: Called from MSHTML.DLL's IOleInPlaceActiveObject::EnableModeless  
    112. // *  
    113. HRESULT FAR EXPORT  CCustomControlSite::XDocHostUIHandler::EnableModeless(BOOL /*fEnable*/)  
    114. {  
    115.     METHOD_PROLOGUE(CCustomControlSite, DocHostUIHandler)  
    116.     return E_NOTIMPL;  
    117. }  
    118.   
    119. // * CImpIDocHostUIHandler::OnDocWindowActivate  
    120. // *  
    121. // * Purpose: Called from MSHTML.DLL's IOleInPlaceActiveObject::OnDocWindowActivate  
    122. // *  
    123. HRESULT FAR EXPORT  CCustomControlSite::XDocHostUIHandler::OnDocWindowActivate(BOOL /*fActivate*/)  
    124. {  
    125.     METHOD_PROLOGUE(CCustomControlSite, DocHostUIHandler)  
    126.     return E_NOTIMPL;  
    127. }  
    128.   
    129. // * CImpIDocHostUIHandler::OnFrameWindowActivate  
    130. // *  
    131. // * Purpose: Called from MSHTML.DLL's IOleInPlaceActiveObject::OnFrameWindowActivate  
    132. // *  
    133. HRESULT FAR EXPORT  CCustomControlSite::XDocHostUIHandler::OnFrameWindowActivate(BOOL /*fActivate*/)  
    134. {  
    135.     METHOD_PROLOGUE(CCustomControlSite, DocHostUIHandler)  
    136.     return E_NOTIMPL;  
    137. }  
    138.   
    139. // * CImpIDocHostUIHandler::ResizeBorder  
    140. // *  
    141. // * Purpose: Called from MSHTML.DLL's IOleInPlaceActiveObject::ResizeBorder  
    142. // *  
    143. HRESULT FAR EXPORT  CCustomControlSite::XDocHostUIHandler::ResizeBorder(  
    144.                 LPCRECT /*prcBorder*/,   
    145.                 IOleInPlaceUIWindow* /*pUIWindow*/,  
    146.                 BOOL /*fRameWindow*/)  
    147. {  
    148.     METHOD_PROLOGUE(CCustomControlSite, DocHostUIHandler)  
    149.     return E_NOTIMPL;  
    150. }  
    151.   
    152. // * CImpIDocHostUIHandler::ShowContextMenu  
    153. // *  
    154. // * Purpose: Called when MSHTML.DLL would normally display its context menu  
    155. // *  
    156. HRESULT FAR EXPORT  CCustomControlSite::XDocHostUIHandler::ShowContextMenu(  
    157.                 DWORD /*dwID*/,   
    158.                 POINT* /*pptPosition*/,  
    159.                 IUnknown* /*pCommandTarget*/,  
    160.                 IDispatch* /*pDispatchObjectHit*/)  
    161. {  
    162.     METHOD_PROLOGUE(CCustomControlSite, DocHostUIHandler)  
    163.     return S_OK; // We've shown our own context menu. MSHTML.DLL will no longer try to show its own.  
    164. }  
    165.   
    166. // * CImpIDocHostUIHandler::TranslateAccelerator  
    167. // *  
    168. // * Purpose: Called from MSHTML.DLL's TranslateAccelerator routines  
    169. // *  
    170. HRESULT FAR EXPORT  CCustomControlSite::XDocHostUIHandler::TranslateAccelerator(LPMSG lpMsg,  
    171.             /* [in] */ const GUID __RPC_FAR *pguidCmdGroup,  
    172.             /* [in] */ DWORD nCmdID)  
    173. {  
    174.     METHOD_PROLOGUE(CCustomControlSite, DocHostUIHandler)  
    175.     return S_FALSE;  
    176. }  
    177.   
    178. // * CImpIDocHostUIHandler::GetOptionKeyPath  
    179. // *  
    180. // * Purpose: Called by MSHTML.DLL to find where the host wishes to store   
    181. // *    its options in the registry  
    182. // *  
    183. HRESULT FAR EXPORT  CCustomControlSite::XDocHostUIHandler::GetOptionKeyPath(BSTR* pbstrKey, DWORD)  
    184. {  
    185.   
    186.     METHOD_PROLOGUE(CCustomControlSite, DocHostUIHandler)  
    187.     return E_NOTIMPL;  
    188. }  
    189.   
    190. STDMETHODIMP CCustomControlSite::XDocHostUIHandler::GetDropTarget(   
    191.             /* [in] */ IDropTarget __RPC_FAR *pDropTarget,  
    192.             /* [out] */ IDropTarget __RPC_FAR *__RPC_FAR *ppDropTarget)  
    193. {  
    194.     METHOD_PROLOGUE(CCustomControlSite, DocHostUIHandler)  
    195.     return E_NOTIMPL;  
    196. }  
    197.   
    198. STDMETHODIMP CCustomControlSite::XDocHostUIHandler::GetExternal(   
    199.             /* [out] */ IDispatch __RPC_FAR *__RPC_FAR *ppDispatch)  
    200. {  
    201.     // return the IDispatch we have for extending the object Model  
    202.     IDispatch* pDisp = (IDispatch*)theApp.m_pDispOM;  
    203.     pDisp->AddRef();  
    204.     *ppDispatch = pDisp;  
    205.     return S_OK;  
    206. }  
    207.           
    208. STDMETHODIMP CCustomControlSite::XDocHostUIHandler::TranslateUrl(   
    209.             /* [in] */ DWORD dwTranslate,  
    210.             /* [in] */ OLECHAR __RPC_FAR *pchURLIn,  
    211.             /* [out] */ OLECHAR __RPC_FAR *__RPC_FAR *ppchURLOut)  
    212. {  
    213.     METHOD_PROLOGUE(CCustomControlSite, DocHostUIHandler)  
    214.     return E_NOTIMPL;  
    215. }  
    216.           
    217. STDMETHODIMP CCustomControlSite::XDocHostUIHandler::FilterDataObject(   
    218.             /* [in] */ IDataObject __RPC_FAR *pDO,  
    219.             /* [out] */ IDataObject __RPC_FAR *__RPC_FAR *ppDORet)  
    220. {  
    221.     METHOD_PROLOGUE(CCustomControlSite, DocHostUIHandler)  
    222.     return E_NOTIMPL;  
    223. }  

    修改App类,截获COM容器事件

    在自己的App类中添加一个成员,注意正确的include

    [cpp] view plaincopy
     
    1. class CMyApp : public CWinApp  
    2. {  
    3. public:  
    4.     ...  
    5.     class CImpIDispatch* m_pDispOM;  
    6. };  


    在CMyApp::InitInstance中替换原来的AfxEnableControlContainer(在生成项目时选中支持ActiveX容器,就会有这一项)

    [cpp] view plaincopy
     
    1. BOOL CMyApp::InitInstance()  
    2. {  
    3.     ...  
    4.     CWinAppEx::InitInstance();  
    5.   
    6.     // Create a custom control manager class so we can overide the site  
    7.     CCustomOccManager *pMgr = new CCustomOccManager;  
    8.   
    9.     // Create an IDispatch class for extending the Dynamic HTML Object Model   
    10.     m_pDispOM = new CImpIDispatch;  
    11.   
    12.     // Set our control containment up but using our control container   
    13.     // management class instead of MFC's default  
    14.     AfxEnableControlContainer(pMgr);  
    15.     ...  
    16. }  


    最后不要忘记在析构函数中清理m_pDispOM

  • 相关阅读:
    【Golang】关于Go语言中如何控制goroutine的数量
    【Golang】 关于Go语言垃圾回收的历史进程
    Apache Hudi vs Delta Lake:透明TPCDS Lakehouse性能基准
    Apache Hudi数据跳过技术加速查询高达50倍
    使用 Apache Hudi 实现 SCD2(渐变维度)
    详解 Apache Hudi Schema Evolution(模式演进)
    基于 Apache Hudi + Presto + AWS S3 构建开放Lakehouse
    构建端到端的开源现代数据平台
    深入理解Apache Hudi异步索引机制
    基于Apache Hudi构建分析型数据湖
  • 原文地址:https://www.cnblogs.com/liubaocheng999/p/3595927.html
Copyright © 2020-2023  润新知