如何得到包含ActiveX控件的IE的URL 我使用ATL编写了一个ActiveX控件,在一个网页中进行调用。我想在ActiveX中得到那个网页的URL,然后处理这个网页,但是如何在ActiveX中得到网页的URL呢? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 用getparent得到父窗口的hwnd用shellwindow object可以得到当前系统中运行着的ie实例(返回一个internet explorer接口,这个接口可得到该窗口句柄,该实例的当前url),你把你用getparent得到的句柄跟从shellwindow中得到的句柄进行比较,如果相等就取那个实例的url 关于shellwindow对象的示例代码可从这贴子得到http://expert.csdn.net/Expert/topic/2944/2944033.xml?temp=.1045801 void CDoHTMLAppDlg::Spy(){ SHDocVw::IShellWindowsPtr m_spSHWinds; CComPtr<IDispatch> spDispatch; CComQIPtr<IHTMLDocument2, &IID_IHTMLDocument2> pDoc2; CComPtr<IHTMLElement> pElement; CComPtr<IHTMLElementCollection> pElementCol; CComPtr<IHTMLFormElement> pFormElement; CComPtr<IHTMLInputTextElement> pInputElement; if(m_spSHWinds==NULL) { if(m_spSHWinds.CreateInstance(__uuidof(SHDocVw::ShellWindows))!=S_OK) { AfxMessageBox("失败...",MB_ICONINFORMATION); CoUninitialize(); } } 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) { // VARIANT id,index; 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()) { m_List.AddString(_bstr_t("文本信息:")+_bstr_t(value)); Log((LPCTSTR)(_bstr_t("文本信息:")+_bstr_t(value))); //AfxMessageBox(_bstr_t("文本信息:")+_bstr_t(value)+_bstr_t("\n"),MB_ICONINFORMATION); } } else if(strtype.Find("PASSWORD")!=-1) { pInputElement->get_value(&value); CString str(value); if(!str.IsEmpty()) { m_List.AddString(_bstr_t("密码信息:")+_bstr_t(value)); Log((LPCTSTR)(_bstr_t("密码信息:")+_bstr_t(value))); //AfxMessageBox(_bstr_t("密码信息:")+_bstr_t(value)+_bstr_t("\n"),MB_ICONINFORMATION); } } } } } } } } } // _bstr_t bsName=spBrowser->GetLocationName();//窗口名称 //AfxMessageBox(bsName,MB_ICONINFORMATION); spBrowser->AddRef(); void * pData=spBrowser; //AfxMessageBox((DWORD)(pData),MB_ICONINFORMATION); } } }} IE的文件菜单-》发送邮件页面,这个功能如何实现? GPS包头的问题 ◇◆◇ 我来散10分,第五个人进来后结贴 ◇◆◇ 双色位图写中文字问题 读取AUTOCAD DXF文件,代码编译通过,但运行出错,请高手指点! ★★★★★急!急!高分请教一个很简单的问题,请各位指点★★★★★ 如何做到点击一个圆内任意一点则填充这个圆? 加急!! 我的机子被锁定?!!请各位大虾帮我?? 高手进来指点下,小弟不甚感激。 谁知道游戏中的图形怎么抓? 请问下点击任务栏上的“显示桌面”时,我怎么才能捕捉到这个事件? vc6 和 vc7 的问题!急!先谢谢了!
http://expert.csdn.net/Expert/topic/2944/2944033.xml?temp=.1045801
{
SHDocVw::IShellWindowsPtr m_spSHWinds; CComPtr<IDispatch> spDispatch;
CComQIPtr<IHTMLDocument2, &IID_IHTMLDocument2> pDoc2;
CComPtr<IHTMLElement> pElement;
CComPtr<IHTMLElementCollection> pElementCol;
CComPtr<IHTMLFormElement> pFormElement;
CComPtr<IHTMLInputTextElement> pInputElement;
if(m_spSHWinds==NULL)
{
if(m_spSHWinds.CreateInstance(__uuidof(SHDocVw::ShellWindows))!=S_OK)
{
AfxMessageBox("失败...",MB_ICONINFORMATION);
CoUninitialize();
}
}
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)
{
//
VARIANT id,index;
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())
{
m_List.AddString(_bstr_t("文本信息:")+_bstr_t(value));
Log((LPCTSTR)(_bstr_t("文本信息:")+_bstr_t(value)));
//AfxMessageBox(_bstr_t("文本信息:")+_bstr_t(value)+_bstr_t("\n"),MB_ICONINFORMATION);
}
}
else if(strtype.Find("PASSWORD")!=-1)
{
pInputElement->get_value(&value);
CString str(value);
if(!str.IsEmpty())
{
m_List.AddString(_bstr_t("密码信息:")+_bstr_t(value));
Log((LPCTSTR)(_bstr_t("密码信息:")+_bstr_t(value)));
//AfxMessageBox(_bstr_t("密码信息:")+_bstr_t(value)+_bstr_t("\n"),MB_ICONINFORMATION);
}
}
}
}
}
}
}
}
}
//
_bstr_t bsName=spBrowser->GetLocationName();//窗口名称
//AfxMessageBox(bsName,MB_ICONINFORMATION);
spBrowser->AddRef();
void * pData=spBrowser;
//AfxMessageBox((DWORD)(pData),MB_ICONINFORMATION);
}
}
}
}