1.注册C++函数。
//注册回调函数宏 //根据不同需要支持注册两个函数原型,注意CONNECT_JS_CALL_SIMPLE_HANDLER中注册的函数 //需要提前和HTML调用协调好,参数必须都为字符,负责会引起未知问题 #define CONNECT_JS_CALL_HANDLER(name, func, pContext) do \ {\ if (!CBKCallBackFuncContainer::GetFuncPtr()->NameId(L#name)) \ CBKCallBackFuncContainer::GetFuncPtr()->ConnectJSFuncHandler(L#name, (JSCallbackFunction)&func, FALSE, pContext);\ } while (FALSE); CONNECT_JS_CALL_HANDLER(OpenCustomStockDlg, (JSCallbackFunction)&OpenCustomStockDlg, this);
2.被调函数声明。
static int OpenCustomStockDlg(DISPPARAMS* params, VARIANT* retval , void* pContext);
3.被调函数实现。
int CXXWindow::OpenCustomStockDlg(DISPPARAMS* params, VARIANT* retval , void* pContext) { CFinancialMainWindow* _pThis = static_cast<CFinancialMainWindow*>(pContext); ATLASSERT(_pThis); CString strCur = "0"; if (params->cArgs == 1) { strCur = params->rgvarg[0]; } //_pThis->OpenLogingSetDlg(StrToLong(strCur)); CString strPara = _pThis->Get_SignPara(); CustomStockSynchronous dlgCustomStock(strPara); dlgCustomStock.DoModal(); return 0; }
4.html编写
<HTML> <HEAD><TITLE>js 按键记录</TITLE> </HEAD> <script type="text/javascript"> function $(s){return document.getElementById(s)?document.getElementById(s):s;} function keypress(e) { var e=e||event; var currKey=e.keyCode||e.which||e.charCode; if (currKey == 27)//ESC = 27 { if (external != undefined) { external.KeyElvesClose("clear"); //关掉键盘精灵界面,传clear则清空键盘精灵字符串,不传或者为空则只关闭界面 } } else { if (external != undefined ) { external.OpenCustomStockDlg(currKey); //向键盘精灵传字符 } } $("test1").focus();//设置焦点 } </script> <body > <input type="text" id="test1" onkeypress="keypress(event);"/> <p>文本框内按键触发键盘精灵</p> </body> </HTML>