Code for duilib's IE browser controls to move borders and to the scroll bar

Source: Internet
Author: User
Tags blank page

Recently, some friends in the duilib group often asked how to enable the IE control of duilib to go to the border, to the scroll bar, or to control the behavior of the IE control. To avoid repeated answers, I will write a blog post to describe the handling method.

Duilib has the webbrowser control, which is an encapsulation of ie After inheriting the activexui control. It is used when the IE control is used. This control leaves an interface named setwebbrowsereventhandler. This function uses the specified event processor to control ie behavior. This function requires a cwebbrowsereventhandler Object Pointer. This cwebbrowsereventhandler class has been written in the duilib utils directory and is a basic event processor framework, you only need to override the gethostinfo function of the cwebbrowsereventhandler class to control the removal of the border and scroll bar of IE browser, and other functions, such as controlling whether the IE right-click menu can be displayed, navigatecomplete2 is used to intercept events completed by the browser.

So if we want to control the browser, the correct method is to write a class, inherit cwebbrowsereventhandler and then rewrite the function you need. I simply wrote a code named ccustomwebeventhandler:

# Ifndef _ blank _ # DEFINE _ blank _ # pragma onceclass ccustomwebeventhandler: Public cwebbrowsereventhandler {public: ccustomwebeventhandler (){}~ Ccustomwebeventhandler () {} virtual void beforenavigate2 (idispatch * Pdisp, variant * & URL, variant * & flags, variant * & targetframename, variant * & postdata, variant * & headers, variant_bool * & cancel) {} virtual void navigateerror (idispatch * Pdisp, variant * & URL, variant * & targetframename, variant * & statuscode, variant_bool * & cancel) {} virtual void navigatecomplete2 (idispatch * Pdisp, variant * & URL) {} virtual Void progresschange (long nprogress, long nprogressmax) {} virtual void newwindow3 (idispatch ** Pdisp, variant_bool * & cancel, DWORD dwflags, BSTR bstrurlcontext, BSTR bstrurl) {} virtual void commandstatechange (long command, variant_bool enable) {} // interface idochostuihandler virtual hresult stdmethodcalltype showcontextmenu (/* [in] */DWORD dwid, /* [in] */point _ rpc_far * PPT,/* [in] */iunknown _ Rpc_far * pcmdtreserved,/* [in] */idispatch _ rpc_far * pdispreserved) {return s_ OK; // return s_false} virtual hresult stdmethodcalltype gethostinfo (/* [out] [in] */dochostuiinfo _ rpc_far * pinfo) {If (pinfo! = NULL) {pinfo-> cbsize = sizeof (dochostuiinfo); pinfo-> dwdoubleclick = dochostuidblclk_default; pinfo-> dwflags | = empty | dochostuiflag_dialog | empty; // | dochostuiflag_scroll_no; // you can add other code to control the webpage. // lpwstr m_pzoom = l "body {ZOOM: 100% ;}"; // pinfo-> pchhostcss = (lpwstr): cotaskmemalloc (lstrlenw (m_pzoom) + 1) * 2); // lstrcpyw (pinfo-> pchhostcss, m_pzoom );} return s_ OK;} virtual hresult stdmethodcalltype showui (/* [in] */DWORD dwid,/* [in] */ioleinplaceactiveobject _ rpc_far * pactiveobject, /* [in] */iolecommandtarget _ rpc_far * pcommandtarget,/* [in] */ioleinplaceframe _ rpc_far * pframe, /* [in] */ioleinplaceuiwindow _ rpc_far * pdoc) {return s_false;} virtual hresult stdmethodcalltype hideui (void) {return s_ OK;} virtual hresult stdmethodcalltype updateui (void) {return s_ OK;} virtual hresult stdmethodcalltype enablemodeless (/* [in] */bool fenable) {return s_ OK;} virtual hresult stdmethodcalltype ondocwindowactivate (/* [in] */bool factivate) {return s_ OK;} virtual hresult stdmethodcalltype onframewindowactivate (/* [in] */bool factivate) {return s_ OK;} virtual hresult stdmethodcalltype resizeborder (/* [in] */lpcrect prcborder, /* [in] */ioleinplaceuiwindow _ rpc_far * puiwindow,/* [in] */bool framewindow) {return s_ OK ;} virtual hresult stdmethodcalltype translateaccelerator (/* [in] */lpmsg,/* [in] */const guid _ rpc_far * pguid1_group,/* [in] */DWORD n1_id) {return s_ OK;} virtual hresult stdmethodcalltype getoptionkeypath (/* [out] */lpolestr _ rpc_far * pchkey,/* [in] */dword dw) {return s_ OK ;} virtual hresult implements getdroptarget (/* [in] */idroptarget _ rpc_far * pdroptarget,/* [out] */idroptarget _ rpc_far * handle) {return s_ OK;} virtual hresult stdmethodcalltype getexternal (/* [out] */idispatch _ rpc_far * ppdispatch) {return s_ OK ;} virtual hresult stdmethodcalltype translateurl (/* [in] */DWORD dwtranslate,/* [in] */olechar _ rpc_far * pchillin, /* [out] */olechar _ rpc_far * ppchurchill) {return s_ OK ;} virtual hresult stdmethodcalltype filterdataobject (/* [in] */idataobject _ rpc_far * PDO,/* [out] */idataobject _ rpc_far * ppdoret) {return s_ OK;} // virtual hresult stdmethodcalltype getoverridekeypath (// * [annotation] [out] * // _ deref_out lpolestr * pchkey, /// * [in] */dword dw) // {// return e_notimpl; /// idownloadmanager virtual hresult stdmethodcalltype download (/* [in] */imoniker * PMK,/* [in] */ibindctx * PBC, /* [in] */DWORD dwbindverb,/* [in] */long grfbindf,/* [in] */bindinfo * pbindinfo, /* [in] */lpcolestr pszheaders,/* [in] */lpcolestr pszredir,/* [in] */uint UICP) {return s_ OK ;}}; # endif/_ ccustom_webbrowser_event_handler_h _

Use the following method:

 

First, write a webbrowser control in XML and use findcontrol in the C ++ code to find the pointer to the control, and then write similar code:

Cwebbrowserui * pactivexui = static_cast <cwebbrowserui *> (m_paintmanager.findcontrol (_ T ("activexdemo1"); If (pactivexui) {pactivexui-> setdelaycreate (false ); optional * pwebhandle = new ccustomwebeventhandler; pactivexui-> setwebbrowsereventhandler (pwebhandle); pactivexui-> navigate2 (L "about: blank"); // if this line of code is commented out, will not remove the border, ie has a bug, the second loading page will make the event processor effective pactivexui-> navigate2 (L "http://www.kugou.com /");}

I would like to emphasize two points here

First, I am here only for demonstration. For convenience, I used the aliml demo and changed several lines of code. We can see that I have a new ccustomwebeventhandler, but I have not deleted it. Therefore, you must pay attention to the code specifications when using it yourself !!

2. Load a blank page first, and then jump to the target page. loading the page for the first time will not trigger the event processor, but it will only take the second time. In order not to affect the efficiency, I will load blank directly. I have forgotten the specific address of this bug on the Microsoft official website ~~

Code for duilib's IE browser controls to move borders and to the scroll bar

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.