Its source files are as follows:
#include "StdAfx.h" #include "SiteCtrl.h" #include "Custom.h" begin_interface_map (sitectrl,colecontrolsite) interface_part (Sitectrl,iid_idochostuihandler,dochostuihandler) end_interface_map () ulong sitectrl::xdochostuihandler::addref () { method_prologue ( Sitectrl, dochostuihandler) return pthis->externaladdref (); } ULONG Sitectrl::xdochostuihandler::release () { method_prologue (Sitectrl, dochostuihandler) return pthis- >externalrelease (); } hresult sitectrl:: Xdochostuihandler::queryinterface (refiid riid, void** ppvobj) { method_prologue (Sitectrl, dochostuihandler) hresult hr = (HRESULT) pthis->externalqueryinterface (&riid, ppvobj); return hr; } HRESULT Sitectrl::xdochostuihandler::gethostinfo (Dochostuiinfo* pinfo) { method_prologue (Sitectrl, dochostuihandler) pinfo->dwflags = DOCHOSTUIFLAG_NO3DBORDER; pInfo->dwDoubleClick = dochostuidblclk_default; return s_ok; } Hresult sitectrl::xdochostuihandler::showui ( DWORD dwID, ioleinplaceactiveobject* /* pactiveobject*/, IOleCommandTarget* pCommandTarget, IOleInPlaceFrame* /*pFrame*/, ioleinplaceuiwindow* /*pdoc*/) { method_prologue (SiteCtrl, dochostuihandler) Return s_ok; } hresult sitectrl:: Xdochostuihandler::hideui (void) { method_prologue (SiteCtrl, dochostuihandler) return S_OK; } hresult sitectrl::xdochostuihandler::updateui (void) { method_prologue (Sitectrl, dochostuihandler) return s_ok; } hresult sitectrl:: Xdochostuihandler::enablemodeless (bool /*fenable*/) { Method_prologue (Sitectrl, dochostuihandler) return E_NOTIMPL; } hresult sitectrl::xdochostuihandler::o Ndocwindowactivate (bool /*factivate*/) &NBSP;&NBsp { method_prologue (Sitectrl, dochostuihandler) return E_NOTIMPL; } HRESULT Sitectrl::xdochostuihandler::onframewindowactivate (bool /*factivate*/) { method_prologue (Sitectrl, dochostuihandler) return e_notimpl; } hresult sitectrl:: Xdochostuihandler::resizeborder ( LPCRECT /*prcBorder*/, IOleInPlaceUIWindow* /*pUIWindow*/, bool /*framewindow*/) &NBSP;&NBSP;{&NBSp; method_prologue (Sitectrl, dochostuihandler) return E_NOTIMPL; } HRESULT Sitectrl::xdochostuihandler::showcontextmenu ( DWORD /*dwID*/, POINT* pptPosition, iunknown* /* pcommandtarget*/, idispatch* /*pdispatchobjecthit*/) { Method_prologue (Sitectrl, dochostuihandler) return s_ok; // we ' Ve shown our&nbsP;own context menu. mshtml. dll will no longer try to show its own. } hresult sitectrl::xdochostuihandler::translateaccelerator ( /* [in] */ LPMSG lpmsg, /* [in] */ const GUID __RPC_FAR* pguidCmdGroup, /* [in] */ dword ncmdid) { method_prologue (Sitectrl, dochostuihandler) //disable F5 if (Lpmsg->message==wm_keydown && getasynckeystate (VK_F5) <0) { return s_ok; } if (Getkeystate (Vk_control) & 0x8000) { // disable ctrl + O if (lpmsg->message==wm_keydown && Getasynckeystate (0x4f) <0) { return S_OK; } //disable ctrl + p if (lpMsg->message==WM_ Keydown && getasYnckeystate (0x50) <0) { return S_OK; } //disable ctrl + n if (LpMsg->message==WM_KEYDOWN && getasynckeystate (0x4E) <0) { return s_ok; } } //disable back space // if (Lpmsg->wparam == vk_back) // { // return s_ok; // } return S_FALSE; } hresult sitectrl::xdochostuihandler::getoptionkeypath (BSTR* pbstrKey, DWORD) { method_prologue (Sitectrl, dochostuihandler) return E_NOTIMPL; } Stdmethodimp sitectrl::xdochostuihandler::getdroptarget ( /* [in] */ idroptarget __rpc_far* pdroptarget, /* [out] */ idroptarget __rpc_far*__rpc_far* ppdroptarget) { method_prologue (Sitectrl,&nbsP;dochostuihandler) return E_NOTIMPL; } stdmethodimp sitectrl::xdochostuihandler::getexternal ( /* [out] */ idispatch __rpc_far*__rpc_far* ppdispatch) { // return the IDispatch we have for extending the object Model *ppDispatch=theApp.pImp; return S_OK; } Stdmethodimp sitectrl::xdochostuihandler::translateurl ( /* [in] */ DWORD dwTranslate, /* [in] */ olechar __rpc_far *pchurlin, /* [out] */ olechar __ Rpc_far*__rpc_far* ppchurlout) { method_prologue (SiteCtrl, dochostuihandler) return E_NOTIMPL; } stdmethodimp sitectrl :: Xdochostuihandler::filterdataobject ( /* [in] */ IDataObject __RPC_FAR* pDO, /* [out] */ idataobject __rpc_ Far*__rpc_far* ppdoret) { method_prologue (SiteCtrl, Dochostuihandler) &NBSP;&NBsp; return e_notimpl; } Sitectrl::~sitectrl (void) { }
Get the IDispatch interface, where we only implement GetExternal, get IDispatch interface, such as Theapp in the function is the handle of the application, and pimp is the implementation of the IDispatch class pointer.
The next step is to implement the COccManager interface, which allows us to implement the parameters of the AfxEnableControlContainer function:
Class Csitemanager:public COccManager {Public:csitemanager () {} colecontrolsite* createsite (COleControlCon tainer* pctrlcont) {sitectrl*psite = NULL; Psite = new Sitectrl (pCtrlCont); return psite; } };
The final step, or the penultimate step, is to register the control,
As in the previous blog, add a constructor to the automatically generated class in the WebBrowser class:
CExplorer2 () {psitemag=new csitemanager (); :: AfxEnableControlContainer (PSITEMAG); }
Long March only the last step, is the writing of HTML, as follows:
<HTML> <HEAD> <meta name= "GENERATOR" content= "Microsoft Visual Studio 8.0" > <title></title& Gt </HEAD> <script type= "Text/javascript" > Function Test () {Window.external.TEST (); } </script> <BODY> <input type= "button" value= "Testing" onclick= "test ();"/> </BODY> </HTML>
PS: Here, the Web page call C + + function has been implemented, WebBrowser is based on the IE kernel, if we use the WebBrowser control to browse the Web page, while using window.eternal, if there is no connection, it will appear The object does not support this property or method, and it is that the procedure is passed without parameters, with the passing of parameters, to be continued ...
Now the following red is used, i.e., if the class is a, then, if you want to define the function outside of the class, use the
A::xlocalclass::method ()
You need to add an X to the localclass before you define it.
Begin_interface_part (Localclass,iinterface) End_interface_part (Localclass)
Where localclass can be thought of as an inline class, while IInterface is the interface to be implemented, and between Begin_interface_part and End_interface_part, all member functions that the interface implements
Declare_interface_map () is a macro declaration, which is primarily used in the base class, and is used
Begin_interface_map (theclass,thebase) Interface_part (Theclass,iid,localclass) End_interface_map ()
We can say that Theclass is an external class, Localclass is a local class, and IID is the interface to implement!
C + + MFC WebBrowser Exploration (III.)