64,662
社区成员
发帖
与我相关
我的任务
分享
UINT ElementClick::FrameElementInput(IDispatch *curDisp, CString csText, CString csID, UINT nFrame)
{
CComQIPtr<IHTMLDocument2> pHtmlDoc2 = curDisp;
HRESULT hr;
if(pHtmlDoc2)
{
CComPtr<IHTMLFramesCollection2> frame = NULL;
hr = pHtmlDoc2->get_frames(&frame);//获取所有框架;
if(SUCCEEDED(hr) && NULL != frame)
{
VARIANT var;
var.vt = VT_I4;
var.intVal = nFrame;
CComVariant vDispWin2 = NULL;
hr = frame->item(COleVariant((long)0),&vDispWin2);
if(SUCCEEDED(hr))
{
CComQIPtr<IHTMLWindow2> spWin2 = vDispWin2.pdispVal;
CComPtr <IHTMLDocument2> spDoc2;
spDoc2 = HtmlWindowToHtmlDocument(spWin2); //获取子框架Doc2;
IHTMLElementCollection *spAllElement = NULL;
hr=spDoc2->get_all(&spAllElement);//获取子框架所有元素;
if(SUCCEEDED(hr) && NULL != spAllElement)
{
IDispatch *pFrameDisp = NULL;
VARIANT index;
VARIANT varID;
V_VT(&index) = VT_I4;
V_I4(&index) = nFrame; //我也不知道这里什么意思``暂时就这么写``出问题在说;
varID = StringToVariant(csID); //格式转换;
hr = spAllElement->item(varID, index, &pFrameDisp); //获取控件位置;
if(SUCCEEDED(hr) && NULL != pFrameDisp)
{
IHTMLElement *pElement = NULL;
hr = pFrameDisp->QueryInterface(IID_IHTMLElement, (void **)&pElement); //获取元素接口;
if(SUCCEEDED(hr) && NULL != pElement)
{
pElement->put_innerText(StringToBstr(csText)); //输入文字;
pElement->Release();
curDisp->Release();
spAllElement->Release();
pFrameDisp->Release();
return ELEMENT_OK;
}
curDisp->Release();
spAllElement->Release();
pFrameDisp->Release();
return FRAME_ELE_ERROR;
}
curDisp->Release();
spAllElement->Release();
return FRAME_FDISP_ERROR;
}
curDisp->Release();
return FRAME_ALL_ERROR;
}
curDisp->Release();
return FRAME_FDISP_ERROR;
}
curDisp->Release();
return FRAME_FRAME_ERROR;
}
curDisp->Release();
return FRAME_DOC_ERROR;
}