如何获得IE的URL地址?? 如何获得IE的URL地址??请详细说说! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你看一下CHtmlView的成员函数不就知道了。CString GetLocationURL( ) const; include <Mshtml.h>#include <windows.h>#include <stdio.h>#include <comdef.h>#include <tchar.h>#include <atlbase.h>#include <oleacc.h>BOOL CALLBACK EnumChildProc(HWND hwnd,LPARAM lParam){ TCHAR buf[100]; ::GetClassName( hwnd, (LPTSTR)&buf, 100 ); if ( _tcscmp( buf, _T("Internet Explorer_Server") ) == 0 ) { *(HWND*)lParam = hwnd; return FALSE; } else return TRUE;};IHTMLDocument2* GetDocInterface(HWND hWnd) { // 我们需要显示地装载OLEACC.DLL,这样我们才知道有没有安装MSAA HINSTANCE hInst = ::LoadLibrary( _T("OLEACC.DLL") ); IHTMLDocument2* pDoc2=NULL; if ( hInst != NULL ){ HWND hWndChild=NULL; // Get 1st document window ::EnumChildWindows( hWnd, EnumChildProc, (LPARAM)&hWndChild ); if ( hWndChild != NULL ){ CComPtr<IHTMLDocument> spDoc=NULL; LRESULT lRes; UINT nMsg = ::RegisterWindowMessage( _T("WM_HTML_GETOBJECT") ); ::SendMessageTimeout( hWndChild, nMsg, 0L, 0L, SMTO_ABORTIFHUNG, 1000, (DWORD*)&lRes ); LPFNOBJECTFROMLRESULT pfObjectFromLresult = (LPFNOBJECTFROMLRESULT)::GetProcAddress( hInst, _T("ObjectFromLresult") ); if ( pfObjectFromLresult != NULL ){ HRESULT hr; hr=pfObjectFromLresult(lRes,IID_IHTMLDocument,0,(void**)&spDoc); if ( SUCCEEDED(hr) ) { printf("here\n"); CComPtr<IDispatch> spDisp; CComQIPtr<IHTMLWindow2> spWin; spDoc->get_Script( &spDisp ); spWin = spDisp; spWin->get_document( &pDoc2 ); } } else { printf("pfObjectFromLresult == NULL\n"); } } ::FreeLibrary(hInst); } else{//如果没有安装MSAA printf(_T("请您安装Microsoft Active Acces\nsibility")); } return pDoc2; } BOOL CALLBACK EnumWindowsProc( HWND hwnd, // handle to parent window LPARAM lParam // application-defined value){ IHTMLDocument2* pdoc2=GetDocInterface(hwnd); if(pdoc2!=NULL) { BSTR bsturl; pdoc2->get_URL(&bsturl); printf("find IE window:%x,url:%s\n",hwnd,(char*)_bstr_t(bsturl)); SysFreeString(bsturl); pdoc2->Release(); }// else// printf("%x is not IE window\n",hwnd); return true;}void main(){ CoInitialize(NULL); EnumWindows(EnumWindowsProc,0); CoUninitialize();} 新手求助!!急! 请问:mdi程序初始化时显示多个视图,应该如何做? 装上虚拟机之后,程序获取的IP地址不正确,容易获取到虚拟网卡地址,如何获取正确IP! 有人知道cfg和ini文件是做什么的么~?有这样的例子么,这样的文件到底怎么用呀 DLL注册失败,急,来者有分!!!!!!! 怎么在一个view中得到另一个view的指针? 《windows核心编程》中的问题 help me ?? 如何开发VB可调用 VC动态库,请大虾看小弟的做法,并指教,参与有分 怎么编写将unicode文本文件转换为utf-8的文本文件 如何得到IE地址栏中的链接 怪问题?请教高手!
CString GetLocationURL( ) const;
#include <windows.h>
#include <stdio.h>
#include <comdef.h>
#include <tchar.h>
#include <atlbase.h>
#include <oleacc.h>
BOOL CALLBACK EnumChildProc(HWND hwnd,LPARAM lParam)
{
TCHAR buf[100]; ::GetClassName( hwnd, (LPTSTR)&buf, 100 );
if ( _tcscmp( buf, _T("Internet Explorer_Server") ) == 0 )
{
*(HWND*)lParam = hwnd;
return FALSE;
}
else
return TRUE;
};IHTMLDocument2* GetDocInterface(HWND hWnd)
{
// 我们需要显示地装载OLEACC.DLL,这样我们才知道有没有安装MSAA
HINSTANCE hInst = ::LoadLibrary( _T("OLEACC.DLL") );
IHTMLDocument2* pDoc2=NULL;
if ( hInst != NULL ){
HWND hWndChild=NULL;
// Get 1st document window
::EnumChildWindows( hWnd, EnumChildProc, (LPARAM)&hWndChild ); if ( hWndChild != NULL ){
CComPtr<IHTMLDocument> spDoc=NULL;
LRESULT lRes;
UINT nMsg = ::RegisterWindowMessage( _T("WM_HTML_GETOBJECT") );
::SendMessageTimeout( hWndChild, nMsg, 0L, 0L, SMTO_ABORTIFHUNG, 1000, (DWORD*)&lRes );
LPFNOBJECTFROMLRESULT pfObjectFromLresult = (LPFNOBJECTFROMLRESULT)::GetProcAddress( hInst, _T("ObjectFromLresult") );
if ( pfObjectFromLresult != NULL ){
HRESULT hr;
hr=pfObjectFromLresult(lRes,IID_IHTMLDocument,0,(void**)&spDoc);
if ( SUCCEEDED(hr) )
{
printf("here\n");
CComPtr<IDispatch> spDisp;
CComQIPtr<IHTMLWindow2> spWin;
spDoc->get_Script( &spDisp );
spWin = spDisp;
spWin->get_document( &pDoc2 );
}
}
else
{
printf("pfObjectFromLresult == NULL\n");
}
}
::FreeLibrary(hInst);
}
else{//如果没有安装MSAA
printf(_T("请您安装Microsoft Active Acces\nsibility"));
}
return pDoc2;
}
BOOL CALLBACK EnumWindowsProc(
HWND hwnd, // handle to parent window
LPARAM lParam // application-defined value
)
{
IHTMLDocument2* pdoc2=GetDocInterface(hwnd);
if(pdoc2!=NULL)
{
BSTR bsturl;
pdoc2->get_URL(&bsturl); printf("find IE window:%x,url:%s\n",hwnd,(char*)_bstr_t(bsturl));
SysFreeString(bsturl);
pdoc2->Release();
}
// else
// printf("%x is not IE window\n",hwnd);
return true;
}
void main()
{
CoInitialize(NULL);
EnumWindows(EnumWindowsProc,0);
CoUninitialize();
}