Home > Software engineering >  C how to interact with HTML in MFC
C how to interact with HTML in MFC

Time:09-20

Problem description:
This project through the Socket communication access to the longitude and latitude data of terminal transmission, need to be done by calling the baidu map data real-time calibration, however, baidu map API call is in MFC HTML file using Java script to write a file, in js for the creation of the map and according to the longitude and latitude of real-time calibration, my question is: how will the Socket communication mode to obtain the latitude and longitude data (this section is written by c + +) is passed to the HTML js?
For you help, the younger brother grateful,

CodePudding user response:

I don't know what do you want from the server or from the client to add, but that I have used in two ways, the service side I am by the latitude and longitude and device ID write to share files with a line of string, then the server backstage regularly read this file to get the latest GPS data, the client is passing data through a com component sends messages to the client, the parameter is the ID string contains latitude and longitude and equipment, also made a program to help a friend a few days ago, replace the client interface of words and images, IE I was achieved by BHO, you can use the BHO javascript calls to the current Internet explorer document, the hope can help you,

CodePudding user response:

Client to insert the ie control, access to baidu map, called directly baidu map API,

CodePudding user response:

Through the webbrowser - pass data to js

CodePudding user response:

http://blog.csdn.net/charlessimonyi/article/details/18447471

CodePudding user response:

http://bbs.csdn.net/topics/392320388
 
CWebBrowser20 m_WebBrowser;
IHTMLDocument2 * m_pIHTMLDoc;
M_WebBrowser. Navigate2 (& amp; CComVariant (_T (" about: blank ")), NULL, NULL, NULL, NULL);
M_WebBrowser. Put_Silent (TRUE);

LoadHTML (" HTML code ", length);
//get the Document refers to the clock
CComPtr PDocument=m_WebBrowser. Get_Document ();
If (pDocument)
{
If (m_pIHTMLDoc)
{
M_pIHTMLDoc - & gt; Release ();
M_pIHTMLDoc=NULL;
}

PDocument - & gt; QueryInterface (IID_IHTMLDocument2, (void * *) & amp; M_pIHTMLDoc);
}

//JS function called
If (m_pIHTMLDoc)
{
CComPtrIf (S_OK==m_pIHTMLDoc - & gt; Get_parentWindow (& amp; PHTMLWindow) & amp; & PHTMLWindow)
{
The VARIANT ret.
PHTMLWindow - & gt; ExecScript (CComBSTR (" JS function "), CComBSTR (" JScript "), & amp; Ret);
}
}

//================================================
//load the HTML code to the component

Void LoadHTML (LPVOID pData, int nLen)
{
CComPtr SpDoc (m_WebBrowser get_Document ());
If (NULL==spDoc | | NULL==pData)
{
return;
}

//get IPersistStreamInit pointer
CComQIPtrIf (NULL==spPSI)
{
return;
}

//the application memory, copy the HTML string
LPSTR lpMemory=(LPSTR) : : GlobalAlloc (GPTR, nLen + 1);
ZeroMemory (lpMemory nLen + 1);
Memcpy (lpMemory, pData, nLen);

//convert the memory to stream object pointer
CComPtr SpStream;
Retrieves the hr=CreateStreamOnHGlobal (lpMemory, TRUE, & amp; SpStream);
If (FAILED (hr) | |! SpStream)
{
return;
}

//after the initialization, loading according to
Hr=spPSI - & gt; InitNew ();
If (FAILED (hr))
{
return;
}

Hr=spPSI - & gt; Load (spStream);
If (FAILED (hr))
{
return;
}
}

CodePudding user response:

http://bbs.csdn.net/topics/392320388
To the code, direct COPY down to save

CodePudding user response:

Baidu map code, will give you the data through the above code is loaded into the control, can realize the transition of positioning, js function call

 


<meta HTTP - equiv="content-type" Content="text/HTML. Charset=utf-8 "/& gt;
<meta name="viewport" content="initial - scale=1.0, user - scalable=no"/& gt;
<style type="text/css">
Body, HTML, # baiduMaps {width: 100%; height: 100%; overflow: hidden; margin:0; The font-family: "Microsoft jas black"; }
# r - result {width: 100%; font-size:14px; }
</style>
Asynchronous loading map & lt;/title> <br/></head> <br/><The body onl oad="loadJScript ()" & gt; <br/><Div id="baiduMaps" & gt; </div> <br/><! - div id="r - result" & gt; <br/>Longitude: & lt; Input the id="longitude" type="text" style="width: 100 px; Margin - right: 10 px;"/& gt; <br/>Latitude: & lt; Input the id="latitude" type="text" style="width: 100 px; Margin - right: 10 px;"/& gt; <br/><Input type="button" value="https://bbs.csdn.net/topics/" onclick="theLocation ()"/& gt; <br/></div - & gt; <br/></body> <br/></html> <br/><br/><The script type="text/javascript" & gt; <br/>Var map; <br/>//var top_right_navigation;//the top right corner, contains only pan and zoom button <br/>/* zoom control type, there are four types: <br/>BMAP_NAVIGATION_CONTROL_SMALL: contains only the pan and zoom button; <br/>BMAP_NAVIGATION_CONTROL_PAN: contains only translation button; <br/>BMAP_NAVIGATION_CONTROL_ZOOM: contains only the zoom button */<br/>//the window. The onl oad=loadJScript;//the asynchronous loading map <br/>//baidu map API function <br/>The function loadJScript () {<br/>Var script=document. The createElement method (" script "); <br/>Script. The type="text/javascript"; <br/>Script. The SRC="http://api.map.baidu.com/api? V=2.0 & amp; Ak=vBRmI1ieQo0HykbZ7O1IIuIMU3c7CBnN & amp; The callback=init "; <br/>Document. The body. The appendChild (script); <br/>} <br/><br/>//based on the current city locate <br/>The function localCity (result) {<br/>Var cityName=result. The name; <br/>Map. SetCenter (cityName); <br/>Map. SetCurrentCity (cityName);//with 3 d figure, you need to set up the city oh <br/>//map. AddControl (new BMap. MapTypeControl ({anchor: BMAP_ANCHOR_TOP_RIGHT mapTypes: [BMAP_NORMAL_MAP BMAP_HYBRID_MAP]}));//add the map type control, three control button in the top right corner of the <br/>nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull </div> <div class="th_page th_page_color"></div> <div class="umCopyright"> <p>Page link:<a href="/Softwareengineering/16646.html" target="_blank" style="color:#999">https//www.codepudding.com/Softwareengineering/16646.html</a></p> </div> <div class="detail-arr"> <div class="detail-arr-left">Prev:<a href='/Softwareengineering/16645.html'>VS2010 of MFC achieved ACCESS database table export EXCEL file specified</a></div> <div class="detail-arr-right">Next:<a href='/Softwareengineering/16647.html'>Windows upload FTP file coding issues</a></div> </div> </div> </div> </div> </div> <div class="container th_top"> <div class="row"> <div class="col-md-12"> <div class="hot-tags neitags"> <ul> <li><i class="iconfont icon-x-tags"></i> Tags:  </li> <a href='/e/tags/?tagname=HTML%2FXML' target='_blank'>HTML/XML</a> </ul> </div> </div> </div> </div> <div class="container th_top"> <div class="row"> <div class="col-md-12"> <div class="xiangguan"> <ul class="msg msghead"> <li class="tbname">Related</li> </ul> <ul> </ul> </div> </div> </div> </div> <div class="container th_top"> <div class="row"> <div class="col-md-12"> <div class="flinks"> <ul> <li><i class="iconfont icon-x-tags"></i> Links:  </li> <li class="liflinks"><a target="_blank" href="/" title="CodePudding">CodePudding</a></li> </ul> </div> </div> </div> </div> <div class="footer"> <p><span style="font-size:16px;color:#666;font-weight: bold">About Us:</span>  <a href="https://www.codepudding.com/contact.html">Contact Us</a>      <a href="https://www.codepudding.com/service.html">Terms of Service</a>      <a href="https://www.codepudding.com/privacy.html"> Privacy Policy</a></p> <p class="foot_info">Copyright © 2010-2023,Powered By <a href="/" target="_blank">CodePudding</a> </p> </div> <script type="text/javascript" src="/skin/code/tianhu.js"></script> </body></html>