The basic use of CDHtmlDialog (c + + call JS function implementation) __JSONP

Source: Internet
Author: User

From: Qing Pan network-http://www.tsingfun.com/html/2015/dev_0826/CDHtmlDialog_cpp_call_js_interactive.html


"The basic use of CDHtmlDialog (JS call C + + function implementation)"
Based on the above articles, this article expands on its code base:
First, add a C + + button on the main dialog box, as follows:


The operation effect is as follows:


Second, for C + + button to add call JS code:
Jscppinteractive.htm to add a JS function for C + + calls, the code is as follows:

<script type= "Text/javascript" >
function Cppcalljsfunc () {
    alert ("JS Alert pop-up box. ");
}
</script>
Add the following code at the end of the JSCppInteractiveDlg.h:
	HRESULT calljsfunction (ihtmldocument2* pDoc2,
		CString strfunctionname,
		dispparams dispparams,
		variant* Varresult,
		excepinfo* exceptinfo,
		uint* nargerr);
Public:
	afx_msg void OnBnClickedButton1 ();
Add the following code at the end of the JSCppInteractiveDlg.cpp:
void Cjscppinteractivedlg::onbnclickedbutton1 () {//TODO: Add control notification handler code here ihtmldocument2* PDoc = NULL;

	Cdhtmldialog::getdhtmldocument (&pdoc);
	Dispparams param = {0};
	VARIANT Vtret;
Calljsfunction (PDoc, _t ("Cppcalljsfunc"), param, &vtret, null, NULL); HRESULT cjscppinteractivedlg::calljsfunction (ihtmldocument2* pDoc2, CString strfunctionname, Dispparam  S Dispparams, variant* varresult, excepinfo* exceptinfo, uint* nargerr) {IDispatch *pdispscript
	= NULL;
	HRESULT HRESULT;
	HResult = Pdoc2->get_script (&pdispscript);
	if (FAILED (HResult)) {return S_FALSE;   
	} DISPID DISPID;
	CComBSTR objbstrvalue = strfunctionname;
	BSTR Bstrvalue = Objbstrvalue.copy (); 
	Olechar *pszfunct = Bstrvalue; HResult = Pdispscript->getidsofnames (Iid_null, &pszfunct, 1, Locale_system_default, &dispid)
	;
		if (FAILED (HResult)) {pdispscript->release ();
	return hResult; } VARRESULT-&GT;VT = Vt_VARIANT;
				HResult = Pdispscript->invoke (DispID, Iid_null, Locale_user_default, Dispatch_method, &dispparams,  
	Varresult, Exceptinfo, Nargerr);

	Pdispscript->release ();
return hResult; }

The final operating effect is as follows:


Engineering code point for this download.

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.