I have created a dialog class of type CDHtmlDialog. I want to show google map on the basis of lat long position. I want to call the html page which contain javascript to load the google map. BUt I don't know how to load that html page and how to use the function of java script. In resource of my dialof there is one HTML page, if I am change the contain of that HTML with my sample html, I am able to load the google map. But I am not able to call the function of that javascript. PLease help me to load and call function of java script used in html.
HRESULT myHtmlDlg::OnButtonOK(IHTMLElement* /*pElement*/)
{
CWebPage M_WEBpAGE;
CComPtr<ihtmldocument2> pDoc2;
CComPtr<idispatch> spDispatch;
HRESULT hr2 = GetDHtmlDocument(&pDoc2);
if (SUCCEEDED(hr2))
{
M_WEBpAGE.SetDocument(pDoc2);
CString cs = _T("initialize") ;
CComBSTR bstrMember(cs);
if(!M_WEBpAGE.CallJScript(cs)) // in this call it fails....
{
return false;
}
}
return S_OK;
}
bool CWebPage::CallJScript(const CString strFunc, const CStringArray& paramArray,CComVariant* pVarResult)
{
CComPtr<idispatch> spScript;
if(!GetJScript(spScript))
{
ShowError("Cannot GetScript");
return false;
}
CComBSTR bstrMember(strFunc);
DISPID dispid = NULL;
HRESULT hr = spScript->GetIDsOfNames(IID_NULL,&bstrMember,1,
LOCALE_SYSTEM_DEFAULT,&dispid);
if(FAILED(hr))
{
ShowError((LPCSTR)(LPCTSTR)GetSystemErrorMessage(hr));
return false;
}
const int arraySize = paramArray.GetSize();
DISPPARAMS dispparams;
memset(&dispparams, 0, sizeof dispparams);
dispparams.cArgs = arraySize;
dispparams.rgvarg = new VARIANT[dispparams.cArgs];
for( int i = 0; i < arraySize; i++)
{
CComBSTR bstr = paramArray.GetAt(arraySize - 1 - i); // back reading
bstr.CopyTo(&dispparams.rgvarg[i].bstrVal);
dispparams.rgvarg[i].vt = VT_BSTR;
}
dispparams.cNamedArgs = 0;
EXCEPINFO excepInfo;
memset(&excepInfo, 0, sizeof excepInfo);
CComVariant vaResult;
UINT nArgErr = (UINT)-1; // initialize to invalid arg
hr = spScript->Invoke(dispid,IID_NULL,0,
DISPATCH_METHOD,&dispparams,&vaResult,&excepInfo,&nArgErr);
delete [] dispparams.rgvarg;
if(FAILED(hr))
{
//ShowError(GetSystemErrorMessage(hr));
return false;
}
if(pVarResult)
{
*pVarResult = vaResult;
}
return true;
}