mfc中web插件与c++之间相互调用方案

一、javascript调用c++,方法有两种

方案1:

1.html编写

<html>
<head>
</head>
<body>
<h1>
TEST
</h1>
<input type='button'name="xx3" value=调用c++函数 οnclick="window.navigate('app:command&arg1=1&arg2=2')">
</body>
<script language="javascript">
function TestFunc()
{
 alert("TestFunc");

</script>
</html>

 2.C++的CHtmlView类重写OnBeforeNavigate2函数

void CAddGoogleMap_CHtmlView::OnBeforeNavigate2(LPCTSTR lpszURL, DWORD nFlags, LPCTSTR lpszTargetFrameName, CByteArray& baPostedData, LPCTSTR lpszHeaders, BOOL* pbCancel) 
{
 // TODO: Add your specialized code here and/or call the base class
 CString strUrl = lpszURL;
 if(strUrl.Left(4) == _T("app:"))
 {
  // cancel the common url navigate and call your c++ code here
  *pbCancel = TRUE;
  MessageBox("调用了C++函数", "来自对话框消息");
  // call other c++ function here or parse the argument in the strUrl
  
 }

 CHtmlView::OnBeforeNavigate2(lpszURL, nFlags, lpszTargetFrameName, baPostedData, lpszHeaders, pbCancel);
}

方案2:

1.编写html

<html>

<head>

</head>

<body>

<script language="javascript">
function CallCpp()

{

alert('start to call cpp here');

window.external.JavaScriptCallCpp('This is a test for call C++ in JavaScript');

}

</script>

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值