① 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)