//////////////////////////////////////////////////////////////// // If this code works, it was written by Paul DiLascia. // If not, I don't know who wrote it. // Compiles with Visual C++ 6.0, runs on Windows 98 and probably NT too. // #include "StdAfx.h" #include "MmsHtmlCtrl.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif void CMmsHtmlCtrl::OnAppCmd(LPCTSTR lpszWhere) { if (_tcsicmp(lpszWhere,_T("ok"))==0) { GetParent()->SendMessage(WM_COMMAND,IDOK); } } void CMmsHtmlCtrl::OnDocumentComplete(LPCTSTR lpszURL) { CHtmlView::OnDocumentComplete(lpszURL); Show_Scroll(); } void CMmsHtmlCtrl::OnNavigateComplete2(LPCTSTR strURL) { CHtmlView::OnNavigateComplete2(strURL); } BOOL CMmsHtmlCtrl::Show_Scroll() { HRESULT hr; IHTMLDocument2* pDoc = (IHTMLDocument2*)GetHtmlDocument(); if ( !pDoc ) { return false; } /* IHTMLDocument3 *piDoc3 = NULL; IHTMLElement *piDocElement = NULL; IHTMLElement2 *piDocElement2 = NULL; pDoc->QueryInterface(__uuidof(IHTMLDocument3), (void**) &piDoc3); piDoc3->get_documentElement(&piDocElement); piDocElement->QueryInterface(__uuidof(IHTMLElement2), (void**) &piDocElement2); long l=0; piDocElement2->get_clientHeight(&l); */ IHTMLElement *phtmlElement = NULL; pDoc->get_body(&phtmlElement); pDoc->Release(); if ( !phtmlElement ) { return false; } IHTMLElement2 *phtmlElement2 = NULL; hr = phtmlElement->QueryInterface(IID_IHTMLElement2, (void**)&phtmlElement2); if(FAILED(hr)) { phtmlElement->Release(); return false; } if ( !phtmlElement2) { phtmlElement->Release(); return false; } long lHeight=0; long lHeight4=0; phtmlElement2->get_clientHeight(&lHeight); phtmlElement2->get_scrollHeight(&lHeight4); phtmlElement2->Release(); /* long lHeight2=0; CRect rect; m_Html.GetWindowRect(&rect); lHeight2=rect.Height(); */ IHTMLBodyElement *phtmlbody = NULL; phtmlElement->QueryInterface(IID_IHTMLBodyElement, (void**)&phtmlbody); if(phtmlbody != NULL) { if (lHeightput_scroll(BSTR(_T("yes"))); else phtmlbody->put_scroll(BSTR(_T("no"))); phtmlbody->Release(); phtmlElement->Release(); } phtmlElement->Release(); return true; } BOOL CMmsHtmlCtrl::PreTranslateMessage(MSG* pMsg) { if ((pMsg->message == WM_RBUTTONDOWN)||(pMsg->message == WM_RBUTTONDBLCLK)) { CPoint point(pMsg->pt); ScreenToClient(&point); /* IHTMLDocument2* pdoc2=NULL; IHTMLElement* pElement=NULL; IDispatch* pDisp=NULL; pDisp=GetHtmlDocument(); pDisp->QueryInterface(IID_IHTMLDocument2,(void**)&pdoc2); pDisp->Release(); pdoc2->elementFromPoint(point.x,point.y,&pElement); pdoc2->Release(); if(pElement){ BSTR ID; pElement->get_id(&ID); pElement->Release(); CString str=(LPCTSTR)(_bstr_t)ID; if(str==_T("Layer1")){ CMenu menu; menu.LoadMenu(IDR_MENU1 ); CMenu* pmenu=menu.GetSubMenu(0); pmenu->TrackPopupMenu(0,pMsg->pt.x,pMsg->pt.y,this); } } */ return TRUE;//如果想完全屏蔽掉,不显示任何菜单,直接返回TRUE就行,上面这些代码演示了怎么对html中特定ID的元素弹出自己想要显示的菜单 } else { return CHtmlView::PreTranslateMessage(pMsg); } }