IHTMLDocument2-3的一些小问题!
9hi 2018-05-23 09:59:24 https://bbs.csdn.net/topics/390796241
CComQIPtr<IHTMLDocument3> spDoc = GetHtmlDocument();
CComPtr<IHTMLElement> spElem;
CComQIPtr<IHTMLIFrameElement3> spIfeameElem;
CComQIPtr<IHTMLInputElement> spInputElem;
CComDispatchDriver spDispatch;
CComBSTR bstrValue;
spDoc->getElementById(CComBSTR(L"mainframe"), &spElem);
spDoc.Release();
spIfeameElem = spElem;
spElem.Release();
spIfeameElem->get_contentDocument(&spDispatch);
spDoc = spDispatch;
spDoc->getElementById(CComBSTR(L"mobileNo"), &spElem);
spInputElem = spElem;
spInputElem->get_value(&bstrValue);
MessageBox(bstrValue);
谁了解以上代码,我想再问下如果我们不知道任何的iframe名字,怎么去获取iframe名?
HRESULT hr = -1;
LPDISPATCH lpDisp = m_WebQ.get_Document();
CComQIPtr<IHTMLDocument2>spHtmlDoc2 = lpDisp;
// IHTMLElement *pHtmlEle;
IHTMLFramesCollection2 *pHtmlFrameColl2;
hr = spHtmlDoc2->get_frames(&pHtmlFrameColl2);
if (hr != S_OK)return;
long len = -1;
pHtmlFrameColl2->get_length(&len);
for (long i = 0; i < len; i++)
{
COleVariant varIndex, varRes;
hr = pHtmlFrameColl2->item(&varIndex, &varRes);
IHTMLWindow2 *pIHtmlWin2 = (IHTMLWindow2*)varRes.pdispVal;
BSTR bstrName;
pIHtmlWin2->get_name(&bstrName);
}
这是我个人通过许多坑才挖出来的些许头续,hr = pHtmlFrameColl2->item(&varIndex, &varRes);
俩个参数基本上什么也获取不到啊啊啊!求助.