VC interacts with JavaScript (iii) ———— Cwebpage class calls the JavaScript function (arguments to the JS function and gets the return value)

Source: Internet
Author: User

① needs a class Cwebpagewritten by someone else, adding its two files WebPage.h and WebPage.cpp to the project.

② add webbrowser control in view / in the header file of the dialog class #include" webbrowser2.h ", add Member variable m_webbrowser , call navigate () function loads a html page.

③ in the dialog box or view implementation file, add the Span style= "margin:0px; padding:0px; line-height:1.8; Font-family: ' Times New Roman ' "> #include" WebPage.h ", you can call javascript function, the specific code is as follows:

              cwebpage   web;

                web. Setdocument (M_webbrowser.getdocument ());

ccomvariant varresult; Store return value

              // Note: Parameters are passed in string type

web.  Calljscript ("Tansto", M_latitude, M_longitude, &varresult); //CallJSThe functions inTansto (), and pass2A parameter(Latitude, longitude), writes the return value toVarresult

if (varresult dblval = = 122.211) //double type corresponding dblval, shaping corresponding intval

MessageBox (" successfully obtained the variable value from js ");

         ④ in html file script tag, with the following code:

                < Script type= "Text/javascript";

              function tansto (lat, LNG) // go to the specified location with two parameters, latitude and longitude

                {

                     < Span style= "margin:0px; padding:0px ">map.panto (New GLatLng (lat, LNG )); Google Maps api , jump to the coordinates at the specified place

                       return a double The value of the type is given to varresult

}

</script>

Attention:

(1) the panto () function in JavaScript above is a function in the Google Map API that can customize the relevant function according to different needs.

(2) The above implementation does not need to tube cwebpage class what role, directly with the line, if you want to learn more about the content, please search for "COM component Automation" "IDispatch interface" article.

VC interacts with JavaScript (iii) ———— Cwebpage class calls the JavaScript function (arguments to the JS function and gets the return value)

Related Article

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.