Enter information in the webbrowser control input box and press enter to jump

Source: Internet
Author: User

When you use the webbrowser control to browse a Web page, you can jump to the page by pressing enter after entering the information,

There are two ways to let the program do this.

Method 1: Simulate submitting carriage return information

First, let the input box get the focus

 

Ihtmlelementcollection * pcoll = NULL;

HR = prightdoc-> get_all (& pcoll); // retrieves a set of webpage Elements

 

Variant index;

V_vt (& Index) = vt_i4;

V_i4 (& Index) = 0;

Variant varid = stringtovariant (strdocid); // the ID of the webpage element in the input box-analyzed by packet capture tools such as httpwatch

HR = pcoll-> item (varid, index, & Pdisp );

 

 

Ihtmlelement2 * pelem2;

HR = Pdisp-> QueryInterface (iid_ihtmlelement2, (void **) & pelem2 );

If (hR = s_ OK)

{

Pelem2-> focus (); // obtain the focus

Pelem2-> release ();

}

Send the carriage return message hwnd h_wnd =: findwindow (null, "program window title") to the webbrowser control; hwnd hshell =: find1_wex (h_wnd, null, "shell embedding ", null); hwnd hview =: find1_wex (hshell, null, "shell docobject View", null); hwnd hieserver =: find1_wex (hview, null, "Internet assumer_server ", null);: postmessage (hieserver, wm_keydown, vk_return, 0);: postmessage (hieserver, wm_keyup, vk_return, 0, reload pretranslatemessage ().

Method 2: Let webbrowser execute JavaScript Functions

First, use httpwatch and other web page listening tools to obtain the webpage code, as shown below:

Onkeypress = "If (window. event. keycode = 13) {Wade. event. stopevent (); Return jsfunctin ();}"

In this way, the JavaScript function name executed by pressing the Enter key is jsfunctin ()

Secondly, webbrowser calls execScript () and executes the JS function. The Code is as follows:

 

 

Ihtmlwindow2 * pwindow;

HR = prightdoc-> get_parentwindow (& pwindow );

 

Variant ret;

Ret. Vt = vt_empty;

BSTR bstrcode = sysallocstring (L "jsfunctin ()");

BSTR bstrlanguage = sysallocstring (L "JavaScript ");

HR = pwindow-> execScript (bstrcode, bstrlanguage, & RET );

 

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.