void CGetIhtmlDlg::OnLButtonUp(UINT nFlags, CPoint point)
{
if(m_bCapture){
m_bCapture=FALSE;
ReleaseCapture();
static TCHAR buf[100];
POINT pt;
GetCursorPos(&pt);
HWND hwnd=::WindowFromPoint(pt);
if(hwnd!=NULL){
::GetClassName( hwnd, (LPTSTR)&buf, 100 );
if ( _tcscmp( buf, _T("Internet Explorer_Server"
) == 0 ){
if(m_uAction==_GETHTML_)
GetHtmlSource(GetDocInterface(hwnd));
// GetHtmlSource(GetDocInterfaceByMSAA(hwnd));
else{
POINT iept=pt;
::ScreenToClient(hwnd,&iept);
GetPassword(GetDocInterface(hwnd),iept);
// GetPassword(GetDocInterfaceByMSAA(hwnd),iept);
}
}
}
}
void CGetIhtmlDlg::GetHtmlSource(IHTMLDocument2* pHDoc2)
{
if(pHDoc2==NULL)return;
CComPtr<IHTMLElementCollection> pAllColl;
HRESULT hr;
hr=pHDoc2->get_all(&pAllColl);
if(hr==S_OK){
LONG length=0;
hr=pAllColl->get_length(&length);
if(hr==S_OK){
for(int i=0;i<length;i++){
VARIANT vIndex,vName;
vName.vt=vIndex.vt=VT_I4;
vName.lVal=vIndex.lVal=i;
CComPtr<IDispatch> pDisp;
hr=pAllColl->item(vName,vIndex,&pDisp);
if( hr==S_OK ){
CComPtr<IHTMLElement> pElement;
hr=pDisp->QueryInterface(IID_IHTMLElement,(void**)&pElement);
if( hr==S_OK ){
CComBSTR tagName;
hr=pElement->get_tagName(&tagName);
if(hr==S_OK){
CString str(tagName);
if(str=="HTML"
{
CComBSTR pContent;
hr=pElement->get_outerHTML(&pContent);
if(hr==S_OK){
SaveAndShow(pContent);
i=length;//以便退出循环
}
else{//if get_outerHTML failed
AfxMessageBox("can't get html code"
;
}
}//else if tagName isnot 'HTML'
}//else if get_tagName failed
}//else if don't get IHMTLElement interface
}//if no items
}
}//if get_length failed
}//if get_all failed
pHDoc2->Release();
}