我在一个mfc程序里面放了一个ie控件,一个按钮。想实现按按钮的时候向ie控件里面具有焦点的地方填入一些内容,实现代码如下:
m_pTargetWnd->SetActiveWindow(); //m_pTargetWnd为ie控件的CWnd指针
m_pTargetWnd->SetFocus();
for(int j=0;j<strInfo.GetLength();j++)
{
m_pTargetWnd->PostMessage(WM_KEYDOWN,strInfo.GetAt(j),1);
}可是却没办法把东西写到ie控件里面去。以前我试过从一个程序向ie浏览器里面发送键盘消息,是成功了的,运行时ie浏览器是活动窗口。请各位高手帮我看看怎么回事,先谢谢了
m_pTargetWnd->SetActiveWindow(); //m_pTargetWnd为ie控件的CWnd指针
m_pTargetWnd->SetFocus();
for(int j=0;j<strInfo.GetLength();j++)
{
m_pTargetWnd->PostMessage(WM_KEYDOWN,strInfo.GetAt(j),1);
}可是却没办法把东西写到ie控件里面去。以前我试过从一个程序向ie浏览器里面发送键盘消息,是成功了的,运行时ie浏览器是活动窗口。请各位高手帮我看看怎么回事,先谢谢了
{
ULONG CryptAppID=lParam;
if(pDoc2==NULL)
return 0;
IHTMLElementCollection *pColl=NULL;
CComPtr<IHTMLElement> pElement;
pDoc2->get_body(&pElement);
if(pElement==NULL)
return 0;
HRESULT hr=pDoc2->get_all(&pColl);
if(SUCCEEDED(hr) && pColl!=NULL)
{
/////////////////////////////////////////
long lcount = 0;
pColl->get_length(&lcount);
for(int i=0;i<lcount;i++)
{
CComVariant index;
index.vt=VT_I4;
index.intVal=i;
CComPtr<IDispatch> disp;
pColl->item(index,index,&disp);
if(disp==NULL)
hr=E_FAIL;
else
{
//////////////////////////
CComPtr<IHTMLInputTextElement> pPwdElement;
hr=disp->QueryInterface(IID_IHTMLInputTextElement,
(void**)&pPwdElement);
if(SUCCEEDED(hr))
{
CComBSTR type;
hr=pPwdElement->get_type(&type);
if(SUCCEEDED(hr))
{
//set edit text
if(type==_T("text"))
{
{
CComBSTR name("Test");
hr=pPwdElement->put_value(name);
}
}
}
}
}
}
}
}
pColl->Release();
}
pDoc2->Release();
return 1;
}