Webbrowser full contact

Source: Internet
Author: User

Webbrowser full contact
In the process of daily program development, I often encounter the problem of using IE. There are two general cases of using IE, one is as mentioned in monitoring the gmmail mailbox, the other is a program similar to crazybrowser that uses the webbrowser control.
In fact, using webbrowser in a program is actually very simple, because webbrowser can be used directly, but it is not the same thing to use and use. The following is a brief introduction to some features that are frequently used.

1. How to shield the default IE right-click menu and use the custom menu that is most frequently used. There are many articles on the Internet to illustrate this, so I will not be ugly. Because the method I used is said to be the least creative. In pretranslatemessage.

2. In most cases, we also need to dynamically set the HTML attributes in the webbrowser control, similar to software such as automatic table filling. Such code is similar to the method used to monitor the gmmail mailbox.

3. we know that in similar programs, we generally want to intercept some JavaScript events in webbrowser. For example, software such as Adblock needs to intercept windows. open code, if we use the IE control in our own program, we will expect the button text link on the IE page to match the button, text, link is completely controlled by us with ease.
We first plan to create a global hook to monitor such operations, but it is too troublesome, the interface is too complicated, and it is not a standard practice.

By viewing msdn, we found that mshtml actually provides such an interface (rather than the interface provided by mshtml, rather than the interface provided by COM ), the following code demonstrates how to intercept an href hypertext link.

On_event (cdialog1, idc_explorer1, 259, documentcompleteexplorer1, vts_dispatch vts_pvariant)

So that we can analyze the entire document after loading all the documents, and then find the href to be monitored by monitoring the methods described in the gmmail mailbox.
If (Strid. Find (cstrlink, 0 )! =-1 ){
Ihtmlanchorelement * pbuttonelem = NULL;
HR = Pdisp-> QueryInterface (iid_ihtmlanchorelement, (void **) & panchorelem );
Hijackhref (panchorelem );
}
In hijackhref code, we perform the following operations:
HR = panchorelem-> QueryInterface (iid_iconnectionpointcontainer, (void **) & pcpc );

If (hR = s_ OK)

{
HR = pcpc-> findconnectionpoint (diid_htmlanchorevents2, & PCP );
If (hR = s_ OK)
{
If (m_phtmlevent)
{
Delete m_phtmlevent;
M_phtmlevent = NULL;
}
M_phtmlevent = new htmlevent;
M_phtmlevent-> setparent (this );
Iunknown * punk = m_phtmlevent 2-> getinterface (& iid_iunknown );
HR = PCP-> advise (punk, & dwcookie );
PCP-> release ();
}
Pcpc-> release ();
}
So far, we have successfully built a bridge between form and HTML. We only need to use the standard comevent
You can easily process all HTML events. The following lists some common events.

"Htmlelementevents2_onclick", dispid_htmlelementevents2_onclick

"Htmlelementevents2_onmouseover", dispid_htmlelementevents2_onmouseover

"Htmlelementevents2_onmousemove", dispid_htmlelementevents2_onmousemove

"Htmlelementevents2_ondblclick", dispid_htmlelementevents2_ondblclick

"Htmlelementevents2_onmouseup", dispid_htmlelementevents2_onmouseup

"Htmlelementevents2_onmousedown", dispid_htmlelementevents2_onmousedown

Well, this problem has ended more than half. Why is it more than half? Let's first recall the previous red text. The biggest problem we have in doing this is that if I add an element through DHTML, the hijack program will not be able to intercept it, you can only redo hijack once. This is inconvenient. It is obviously not the style of bean curd.

Let us know how to set a custom attribute with the same name for the element we need to manipulate, such as vid, and then define a vname, in this way, in documentcompletetrigger1, hook the element with the vid as a specific value, and then htmlevent performs different operations based on the vname.
So far, all the problems are solved, and the rest depends on you.

Note:

I haven't updated my blog for a long time, and I have been excited again and again. However, there is really no way to do it. I 've been too busy for the last six months, I will share my experiences with you.
 

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.