HTML(2):CHtmlView

Q简单的问题,关于CHtmlView的滚动条。急!
T现在有一个问题,我使用了CHtmlView类,但是不能得到CHtmlView滚动条事件。请问那位大虾有好的方法,可行立即给分。
AIHTMLWindow2::onscroll Property

--------------------------------------------------------------------------------

Sets or retrieves a pointer to the event handler function associated with the onscroll event.

Syntax

HRESULT IHTMLWindow2::get_onscroll(VARIANT* p);HRESULT IHTMLWindow2::put_onscroll(VARIANT v);
Parameters

p
Pointer to a variable of type VARIANT of type VT_DISPATCH that receives the IDispatch interface of an object with a default method that is invoked when the event occurs.
v
VARIANT of type VT_DISPATCH that specifies the IDispatch interface of an object with a default method that is invoked when the event occurs.
Return Value

Returns S_OK if successful, or an error value otherwise.

See Also

refer to m_pbrowserapp member of CHtmlView
Q关于CHtmlView的简单问题!!!!!!!!!!!!!!!!!!!!!!!! 
T我现在需要用CHtmlView来打开网页。
过程是一个页面完全显示后再显示下一个。总共需要打开上万个。
我发现很快内存就被消耗待尽了。
请问各位高人如何解决?
另外,我不想在页面里显示图片和flash,
请问如何处理?(不要通过设置IE选项)
Asee Walk All sample in MSDN
http://msdn.microsoft.com/downloads/samples/internet/default.asp?url=/downloads/samples/internet/browser/walkall/Default.asp

  MSDN Home >  MSDN Web & Internet Samples >  

 Reusing Browser Technology
Walkall
 
 Download sample
  Use automatic download. 
 
 
 view source common.h readme.txt walkall.cpp walkall.mak winsink.cpp winsink.h 


Description
This WALKALL sample demonstrates the use of MSHTML as a UI-less HTML parser.
More Details
To successfully walk the HTML Scripting Object Model that the parser exposes after loading the specified document, the host application must wait until MSHTML has finished loading the document. To track MSHTML's READYSTATE, the host implements a simple COM object that exposes IPropertyNotifySink. The host application connects to MSHTML using the standard connection point interfaces.
Browser/Platform Compatibility and Other Requirements
The Walkall sample is supported inMicrosoft® Internet Explorer 4 and greater, on Win32® platforms.
Usage
Note: To compile and build the Walkall sample, you will need the Internet Explorer 5.01 Headers and Libraries, as well as the Windows 2000 Headers and Libs from the Platform SDK, and include them in your development environment.
Related Links

Reusing Browser Technology 
Q高分:用HTMLView制作浏览器时,ctrl+c怎么不能用? 
T我用HTMLView做一个简单的浏览器,
在显示网页时,没有了像IE里使用的快捷键了,
我特别需要ctrl+c,ctrl+v!
请问如果修改程序?
AQ How do I get the edit control keys Strg+C, Strg+X and Strg+V to work in my MFC application? I want to use your old FormSwap application (see the September 1998 and December 1998 issues of Microsoft® Systems Journal). I realized that the edit controls don't execute the shortcuts (Strg+X,V,C) although in a normal dialog-based application they do without any effort.

Walter Reiser

A First of all, since Walter hails from Austria, let me clarify that Strg is the standard computer abbreviation for the German word Steuerung, which means control; in English we say Ctrl-C, Ctrl-X, and so on.
      Well, now that you've suffered through your international awareness lesson, let me turn to Walter's question. The problem here is very simple. In my original FormSwap program, the main resource (.rc) file has the following entries:
IDR_MAINFRAME ACCELERATORS PRELOAD MOVEABLE PURE
BEGIN
    "C", ID_EDIT_COPY, VIRTKEY, CONTROL, NOINVERT
    "V", ID_VIEW_TEST, VIRTKEY, CONTROL, NOINVERT
    "X", ID_EDIT_CUT,  VIRTKEY, CONTROL, NOINVERT
END

In other words, the main app's accelerator table is overriding the control keys for the edit controls. So all you have to do is remove the three entries above and presto, the problem is solved. This is a common bug that creeps in when you copy code from one app to another. It doesn't happen with AppWizard-generated dialog apps because Visual Studio® is smart enough to omit the edit keys from the main accelerator table in the case of a dialog-based app. But if you copy the resource file from a normal (non-dialog-based) app, you can introduce this bug.
      The answer also reveals, by the way, one way to override the edit keys if you want to make them do something else: just bind the keys to new commands in your app's accelerator table. Of course, this would be most bizarre and even sadistic to your users: Ctrl-C, X, and V should always be Copy, Cut, and Paste, no matter what. But you might want to trap these keys in order to extend, rather than change, their behavior.
      I said the accelerator is one way to override the edit keys, implying that there are others. Indeed, accelerators aren't really even the best way to override edit keys in an edit control. Why not? Because they override the keys at the application or global level. In most cases, a more sensible and object-oriented way is to override the keys in the edit control itself, because conceptually the special behavior is usually a property of the edit control, not the application. If you want to use the same specialized behavior in another app, should you really have to modify the app's accelerator table and reimplement special commands? Wouldn't it be easier and make more sense to simply (re)use your already modified CSpecialEdit, or what-ever you called it, in the second app?
      Overriding the edit keys in an edit control is easy. Edit controls process these keys as ordinary WM_CHAR messages, not as accelerators, so all you have to do in this case is override WM_CHAR/OnChar. But that's if you want to override the keystrokes only (which would be rather strange), as opposed to the commands they invoke (Copy, Cut, Paste), which can come from either keyboard or context menu. In order to override the commands, you have to handle the WM_CUT, WM_COPY, and WM_PASTE messages. Got it?
Q使用CHTMLVIEW,当REFRESH()结束后,会有什么消息产生?
T使用CHTMLVIEW,当REFRESH()结束后,会有什么消息产生?
Adownloadcomplete
CommandStateChange(cmdid=0xffffffff
Q关于CHtmlView的问题,请大侠留步吧,应该对大家不难!
T我想用类CHtmlView做了一个简单的浏览器来打开网页,可是在里面点键接时,对于不用新窗子打开网页的还好,会在本窗口显示,而对于用新窗口打开网页时,却会自动调用IE来打开,怎样让它不调用IE,而是仍然在我的浏览器中打开新网页呀???
Aexpert.csdn.net/Expert/FAQ/FAQ_Index.asp?id=1761

单文档??单文档开新窗口之后,原来的窗口怎么办?
这是对话框的处理……你看看是不是要显示一堆对话框……
void CYourDlg::OnNewWindow2(LPDISPATCH FAR* ppDisp, BOOL FAR* Cancel)
   {
      m_dlgNewWB = new CYourDlg;
      m_dlgNewWB->Create(IDD_WBDLG_DIALOG);

      m_dlgNewWB->m_webBrowser.SetRegisterAsBrowser(TRUE);

      *ppDisp = m_dlgNewWB->m_webBrowser.GetApplication();
   }

*ppDisp 设置为当前浏览器的IWebBrowser2

MSDN
Knowledge Base
Q185538 HOWTO: Cause Navigation to Occur in Same WebBrowser Window
Q294870 BUG: Using NewWindow or NewWindow2 to Always Navigate in the Same Window Fails in Some Instances

If you have a Microsoft Foundation Classes (MFC) application and use NewWindow to navigate in the same window, the following code fails in Internet Explorer 5.5:
void CDWebBrowserEvents::OnNewWindow(BSTR URL, long Flags, BSTR TargetFrameName,
     VARIANT* PostData, BSTR Headers, BOOL FAR* Processed)
{
 if (m_Browser) {
     COleVariant varEmpty;
     *Processed = TRUE;
     m_Browser->Navigate((LPCSTR)URL, &varEmpty, &varEmpty, &varEmpty, &varEmpty);
 }
}
 
If you use NewWindow2, the following code fails in all versions of the Internet Explorer:
void CIEDlg::OnNewWindow2(LPDISPATCH FAR* ppDisp, BOOL FAR* Cancel)
{

 IUnknown* pUnk = m_Browser.GetControlUnknown();
 if (pUnk)
 {
  IDispatch* pDisp = NULL;
  HRESULT hr = pUnk->QueryInterface(IID_IDispatch, (void**)&pDisp);

  if (SUCCEEDED(hr) && pDisp)
   *ppDisp = pDisp;
 }
}
Q求救:寻求在HtmlEditView上选择单元格的代码(快要崩溃)请做过类似项目的高手指点 
THDC hdc = ::GetWindowDC(this->GetSafeHwnd());
CDC * pDC = CDC::FromHandle(hdc);
pDC->DeleteDC
频繁是否使用就会出错?

Tasehouny(阿甘):
SORRY,那是我自己的一个错,现在找到原因了,主要问题就是标题的问题
jiangsheng(蒋晟.Net)
我去看过,但还是有几点不明白
if (FAILED(pelmBodyTwo->createControlRange(&pdispCtrlRange))
            || pdispCtrlRange == NULL)
     goto Cleanup;
 
if (FAILED(pdispCtrlRange->QueryInterface(IID_IHTMLControlRange, (void**) &pCtrlRange))
            || pCtrlRange == NULL)
         goto Cleanup;

if (FAILED(pdispImgElement->QueryInterface(IID_IHTMLControlElement, (void**) &pCtrlElement))
            || pCtrlElement == NULL)
         goto Cleanup;
 
      hr = pCtrlRange->add(pCtrlElement);

      if (SUCCEEDED(hr))
         hr = pCtrlRange->execCommand(bstrCommand, VARIANT_FALSE, vEmpty, &vbReturn);
 
      pCtrlElement->Release();
      hr = S_OK;
//以上操作是否是创建了一个ControlRange,然后获取Img的ControlElement,加入到ControlRange,再由ControlRange发送命令到此元素。

我在MSDN中查阅execCommand所发送的消息,似乎只有MultipleSelection合乎选择要求,但是它是选择整个Control控件,而我只是要选择Table中的一些cells,使这些cells所在rect内都反色显示(也就是选择,但不是选择文字,而是选择整个cell)
Aexpert.csdn.net/Expert/topic/1462/1462971.xml?temp=.6424677

反色显示的话,insert一些<font>就可以了,看起来和选中差不多的

http://www.codeguru.com/ieprogram/HtmlMemory.html

客户端用的是IE4.0以上的话,可考虑用filter中的grow或者xray来突出显示。

IE中选择必须是连续的,不能同时存在多个选择范围
Q提问:使用htmlview的问题,高手请进来!! 
T我想在Htmlview中自定义左右键弹出的Menu,所以就捕获了鼠标点击的事件:

 if( (pMsg->message==WM_LBUTTONDOWN) || (pMsg->message==WM_RBUTTONDOWN))
 {
  CPoint ptClient = pMsg->pt; ScreenToClient(&ptClient);
  CMenu *pmnu = m_mnuContext.GetSubMenu(0); ASSERT(pmnu);

  pmnu->TrackPopupMenu(TPM_RIGHTBUTTON, pMsg->pt.x ,  pMsg->pt.y, this);

  return true;
 }

问题是此时如果我还想获得鼠标点击处的网页的超链,该怎么办?
另外,Htmlview中能使用OnContextMenu消息处理来弹出Menu吗?请高手帮忙,分不够可以加,在线等候!!!
A可以。
http://www.microsoft.com/mind/1098/advhost/advhost.asp
http://www.siteexperts.com/tips/hj/ts01/samples/url_clpb.asp

获取页面的超链地址……好像应该用IHTMLAnchorElement吧……
去看看MFC7的源代码里面DDX_DHtml_Anchor_Target的定义

/* Get URL associated with an element in a collection. Element must be an
image or an anchor. */
BOOL HTMLParser::GetURLFromCollection(IHTMLElementCollection *pCollection,
                                  REFIID rIID, long lIndex, string &rstrURL)
{
    VARIANT     varIndex;
    VARIANT     var2;
    HRESULT     hr;
    IDispatch*  pDisp = NULL;
    BOOL        bFound = FALSE;

    varIndex.vt = VT_UINT;
    varIndex.lVal = lIndex;
    VariantInit( &var2 );
    hr = pCollection->raw_item( varIndex, var2, &pDisp );

    if ( SUCCEEDED(hr) && pDisp)
    {
        IHTMLImgElement* pImgElem = NULL;
        IHTMLAnchorElement* pAnchorElem = NULL;
        BSTR bstr = NULL;
        if ( rIID == IID_IHTMLImgElement &&            
             SUCCEEDED(pDisp->QueryInterface(rIID, (void **)&pImgElem)) )
        {
            pImgElem->get_href(&bstr);
            pImgElem->Release();
            bFound = (bstr != NULL);
        }
        else if ( rIID == IID_IHTMLAnchorElement &&            
                  SUCCEEDED(pDisp->QueryInterface(rIID,
                                              (void **)&pAnchorElem)) )
        {
            pAnchorElem->get_href(&bstr);
            pAnchorElem->Release();
            bFound = (bstr != NULL);
        }

       pDisp->Release();
        if ( bFound && bstr )
        {
            // _bstr_t wrapper will delete since fCopy is FALSE
            _bstr_t bstrHREF(bstr, FALSE);
            rstrURL = (LPCSTR)bstrHREF;
        }
    }
    return bFound;
}

没要你从IHTMLElementCollection开始啊,IHTMLElementCollection 也是一个个元素处理的(虽然用的是IDispatch来QueryInterface),我要你看的是怎么处理获得的element的,不是看怎么获得element的
Qjiangsheng老大:一个让我头大的问题,不知如何解决,请帮帮忙,急 
T// 我想用自己的插入图片对话框代替CEDITHTMLVIEW中的插入图片对话框,
// 代码如下

 CPoint point;
 point = GetCaretPos();

 IHTMLDocument2 * pDoc;
 GetDHtmlDocument(&pDoc);
 IHTMLElement * pElement = NULL;
 IHTMLSelectionObject * pSelection = NULL;
 IHTMLImgElement * pAnchor = NULL;
 IHTMLTxtRange * pTextAreaElement = NULL;

 if(SUCCEEDED(pDoc->elementFromPoint(point.x,point.y,&pElement)))
 {
  CInsertPicDlg dlg;
  VARIANT p;
  VariantInit(&p);
  p.vt = VT_I4;
  BSTR bStr;
  pElement->get_outerHTML(&bStr);
// 此处获得的bStr从HTML语法来说,没错,但是此处总判断为不是IHTMLImgElement
// 用类似的地址,也就是加入后htmlview自动修正后所得<img src="file:///c:/123.jpg">居然不行
  if(SUCCEEDED(pElement->QueryInterface(IID_IHTMLImgElement,(void **)&pAnchor)))
  {
   BSTR bURL,bBorder,bAlign,bAlt;
   long vspace,hspace;
   pAnchor->get_src(&bURL);
   pAnchor->get_align(&bAlign);
   dlg.m_pic_path = (CW2A)bURL;
   dlg.m_stralign = (CW2A)bAlign;
  }
  else
  {
   BSTR value;
   pDoc->get_selection(&pSelection);
   IDispatch * pDisp;
   if(SUCCEEDED(pSelection->createRange(&pDisp)))
   {
    pDisp->QueryInterface(IID_IHTMLTxtRange,(void**)&pTextAreaElement);
    pDisp->Release();
   }
  }
  if(dlg.DoModal()==IDOK&&dlg.m_pic_path!="")
  {
   if(pAnchor)
   {
    pAnchor->put_src(dlg.m_pic_path.AllocSysString());
    pAnchor->put_align(dlg.m_stralign.AllocSysString());
    pAnchor->Release();
   }
   else if(pTextAreaElement)
   {
    CString picpath;
    picpath.Format("<img src=/"%s/" align=/"%s/">",dlg.m_pic_path,dlg.m_stralign);
    pTextAreaElement->pasteHTML(picpath.AllocSysString());
    pTextAreaElement->Release();
    pSelection->Release();
   }
  }
  pElement->Release();
 }
 pDoc->Release();
A
从你的代码来看,当前位置的元素已经是Img了你才执行你的代码?一般来说,插入图片的位置的元素不一定是Img的

用IMarkupService来insert element吧,
Implementing Edit Designers 2: The Annotator Sample

--------------------------------------------------------------------------------

This topic and its accompanying sample explain how to implement an edit designer that enables users to annotate a Web page. This topic also shows how to create a Web page with an editable region and attach the annotation component to it.

www.csdn.net/develop/article/13/13462.shtm
http://www.codeguru.com/ieprogram/HtmlMemory.html
QCHtmlView中如何屏蔽页面 "退格键"???-----高分求救
T通过chtmlview打开页面,现在想实现屏蔽页面后退的功能:即,当用户敲键盘上面的"Back Space"键时,chtmlview不会回退到上一个已经打开过的页面!
A如果要屏蔽一个键
如下实现IDocHostUIHandler::TranslateAccelerator 通过ICustomDoc或者IOleClientSite设置IHtmlDocument2的IDocHostUIHandler。
This example shows how to override the default host behavior that occurs when a user tabs out of the first or last element.
CYourControlSite::TranslateAccelerator(MSG *pMsg, DWORD dwFlags)
{
 if (pMsg && pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_TAB) {
  return S_FALSE;
 }
 //return baseclassControlSite::TranslateAccelerator( pMsg, dwFlags);
}
可能还需要判断焦点所在是否是编辑窗口,这个比较简单,就不写了
QCHtmlView如何打开pdf,swf,doc文档?
T
CHTMLView可以浏览网页文件,txt,但是用相同方法打开pdf,swf,doc文档失败。
在IE里面,输入pdf,swf,doc文档,IE会自动使用在线激活技术,将文档直接在IE中打开。
请问在CHtmlView中,如何像IE一样打开pdf,swf,doc文档?
A创建的时候要支持Active Document Container
Qvc6是不是没有CHtmlEditView?vc6要进行简单的超文本编辑应该怎么办? 
T 
A直接调用文档的EditMode就行了
CHtmlEditView实际上就是CHtmlView+editmode而已

You can use the IHTMLDocument2::designMode property to put Microsoft&reg; Internet Explorer into a mode where you can edit the current document.

While the browser is in design mode, objects enter a UI-activated state when the user presses ENTER or clicks an object that has focus, or when the user double-clicks the object. Objects that are UI-activated have their own window within the document. You can modify the UI only when the object is in a UI-activated state.

You cannot execute script when the value of the IHTMLDocument2::designMode property is set to On.

QHtmlView编程中,用OnBeforeNavigate2来得传递的值,那用什么将值赋给另一个页面并显示出来呢? 
T 
AGet the IHTMLDocument2 pointer from web browser,and get the IHTMLElement pointer to the INPUT element,then set the "value" property for it.
see also
http://www.csdn.net/develop/read_article.asp?id=9408
在对话框中使用网页输入数据 (jiangsheng原创)
(use DHTMLEdit control to host a web page on a dialog)

Project->Add to Project->Registered Controls->DHTMLEdit

DHTMLEDIT的操作很简单啊,它把所有的操作都封成了成员函数。你用COM的方法会更复杂,要自己一步步QueryInterface,然后调用相应函数(名称基本类似)。
这里有一个例子。
BOOL    CAboutBox::ReplaceHtmlByID(LPCTSTR  lpszTagID,LPCTSTR lpszHtml,BOOL bIsInnerHtml)
{
    CComDispatchDriver  pHTMLDispatch(m_wndBrowser.GetDocument());
    if(pHTMLDispatch.p){
        HRESULT hr;
        CComQIPtr<IHTMLDocument2, &IID_IHTMLDocument2> pHTMLDocument(pHTMLDispatch);
        if(pHTMLDocument.p){
            CComPtr<IHTMLElementCollection> pHTMLElementCollection;
            hr=pHTMLDocument->get_all(&pHTMLElementCollection);
            if(hr==S_OK &&  pHTMLElementCollection.p!=NULL){
                LONG    celem;
                hr=pHTMLElementCollection->get_length(&celem);
                if(hr==S_OK){
                    for(int i=0;i<celem;i++){
                        COleVariant varIndex,var2;//var2 is not used because accessing index,not name
                        varIndex.vt=VT_UINT;
                        varIndex.lVal=i;
                        CComDispatchDriver  pDisp;
                        hr=pHTMLElementCollection->item(varIndex,var2,&pDisp);
                        if(hr==S_OK){
                            CComQIPtr<IHTMLElement, &IID_IHTMLElement> pHTMLElement(pDisp);
                            if(pHTMLElement){
                                //find html element
                                BSTR    bstrTagID;
                                if(pHTMLElement->get_id(&bstrTagID)==S_OK){
                                    if(bstrTagID!=NULL){
                                        _bstr_t bstrHTML(lpszHtml);
                                        _bstr_t bstrTagIDToCompare(lpszTagID);
                                        _bstr_t _bstrTagID(bstrTagID,FALSE);
                                        if(_bstrTagID==bstrTagIDToCompare){
                                            if(bIsInnerHtml)
                                                pHTMLElement->put_innerHTML(bstrHTML);
                                            else
                                                pHTMLElement->put_outerHTML(bstrHTML);
            #ifdef  _DEBUG
                                            BSTR    bstrTag;
                                            hr=pHTMLElement->get_outerHTML(&bstrTag);
                                            CString strTag=bstrTag;
                                            ::afxDump<<strTag;
            #endif
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return TRUE;
}
Q在CHtmlView中怎样实现象IE的“查找(在当前页)”的功能
T在WebBrowser2控件中也行。
A
call IWebBrowser2::ExecWB Method with OLECMDID_FIND

--------------------------------------------------------------------------------

Implements a wrapper that allows you to execute a command on an OLE object using the IOleCommandTarget::Exec method.

Syntax

HRESULT ExecWB(
    OLECMDID cmdID,
    OLECMDEXECOPT cmdexecopt,
    VARIANT *pvaIn,
    VARIANT *pvaOut
);

Parameters

cmdID
[in] OLECMDID value that specifies the command to execute. For a discussion of command identifiers, see MSHTML Editing Command Identifiers.
cmdexecopt
[in] OLECMDEXECOPT value that specifies the command options.
pvaIn
[in] Pointer to a VARIANT structure that contains command input arguments. This argument can be NULL.
pvaOut
[out, in] Pointer to a VARIANT structure that receives and specifies command output. This argument can be NULL.
Return Value

Returns S_OK if successful, or an error value otherwise.


FILE: Invoke Find, View Source, Options Dialog Boxes for WebBrowser
ID: Q175513


--------------------------------------------------------------------------------
The information in this article applies to:

Microsoft Internet Explorer (Programming) versions 3.0, 3.01, 3.02, 4.0, 4.01, 5, 5.5

--------------------------------------------------------------------------------


SUMMARY
This article illustrates how to invoke the Internet Explorer Find, Internet Options, and View Source dialog boxes from within an application that is hosting the WebBrowser control. The following file is available for download from the Microsoft Download Center. Click the file name below to download the file:


Wbsample.exe
For more information about how to download files from the Microsoft Download Center, please visit the Download Center at the following Web address
http://www.microsoft.com/downloads/search.asp
and then click How to use the Microsoft Download Center.

Microsoft used the most current virus detection software available on the date of posting to scan this file for viruses. Once posted, the file is housed on secure servers that prevent any unauthorized changes to the file.





MORE INFORMATION
WARNING: This sample uses an undocumented command group GUID that is subject to change in the future. Although this sample has been tested to work correctly with Internet Explorer 3.0 and 4.0, there is no guarantee that these techniques will continue to work successfully in future versions. Please use caution when adding this code to an application.

The WBSampl example is a mini-browser application that illustrates how to create an application in Microsoft Visual C++ that uses the WebBrowser control. This example provides code to invoke the Find, Internet Options, and View Source items that are part of the WebBrowser control but are not exposed as methods.

In order to implement the items listed above, the following steps should be followed.



Define the command group GUID for the WebBrowser control as follows:



DEFINE_GUID(CGID_IWebBrowser,0xED016940L,0xBD5B,0x11cf,0xBA,
      0x4E,0x00,0xC0,0x4F,0xD7,0x08,0x16);
Define the CommandTarget ids for menu driving as follows:



      #define HTMLID_FIND 1
      #define HTMLID_VIEWSOURCE 2
      #define HTMLID_OPTIONS 3
Execute a CommandTarget id as follows:



      HRESULT CMainFrame::ExecCmdTarget(DWORD nCmdID)
      {
         LPDISPATCH lpDispatch = NULL;
         LPOLECOMMANDTARGET lpOleCommandTarget = NULL;

         lpDispatch =
            ((CWebSurferView*)GetActiveView())->m_webBrowser.GetDocument();
         ASSERT(lpDispatch);

         // Get an IDispatch pointer for the IOleCommandTarget interface.
         lpDispatch->QueryInterface(IID_IOleCommandTarget,
      (void**)&lpOleCommandTarget);
         ASSERT(lpOleCommandTarget);

         lpDispatch->Release();

         // Invoke the given command id for the WebBrowser control
              return lpOleCommandTarget->Exec(&CGID_IWebBrowser, nCmdID, 0,
                                         NULL, NULL);
      }
Note that m_webBrowser is an instance of the WebBrowser control and is defined in the CView-derived class for this project. Also, nCmdID is one of the IDs defined in step 2.
&copy; Microsoft Corporation 1997, All Rights Reserved.
Contributions by Scott Roberts, Microsoft Corporation


Additional query words: WebBrowser WBSampl Find Source Options Internet Explorer IE

Keywords : kbfile kbsample kbIE300 kbIE301 kbIE400 kbIE401 kbWebBrowser kbIE302 kbGrpInet kbIE500 kbDSupport kbIE550 kbIEFAQ
Version : WINDOWS:3.0,3.01,3.02,4.0,4.01,5,5.5
Platform : WINDOWS
Issue type : kbinfo
Technology :
Q如何取得鼠标点击的超链接的url?
T我用chtmlview实现的浏览器,在鼠标右击时,如何取得鼠标所在位置的超链接的url?
Aimplement ShowContextMenu method of IDocHostUI
see http://www.csdn.net/develop/read_article.asp?id=21702

call IUnknown::QueryInterface with IID_IHtmlAnchorElement on ihtmlelement

那就是点的位置不是<A>
正规的方法是实现IDocHostUI::ShowContextMenu
参见
http://msdn.microsoft.com/workshop/browser/hosting/reference/ifaces/idochostuihandler/showcontextmenu.asp

IHtmlAnchorElement *pAnchorElement;

if(SUCCEEDED(elementHit->QueryInterface(IID_IHtmlAnchorElement,(void**)&pAnchorElement)))

顺便说一下,可以判断IDispatch支持哪些属性和方法,据此判断是否存在tagName属性。如果支持的话,判断tagName是否A,如果是a,那么可以查询对象的IHtmlAnchorElement接口。
参见http://www.csdn.net/develop/read_article.asp?id=21702
HRESULT CIEAutomationView::DumpTypeInfo(LPDISPATCH pDisp)
Q来者有分:谈谈CHtmlView编程
T不好意思,兄弟的msdn买了不能用。只好什么问题都拿到csdn上来了,幸好还有分,呵呵。
各位能谈谈怎么使用CHtmlView类么?比如怎么从资源中装载一个网页并显示呢?
我发现重载CHtmlView::OnDraw()居然没有用,这是怎么回事啊?
ACHtmlView::GetHtmlDocument
LPDISPATCH GetHtmlDocument( ) const;


你要自己通过这个接口访问元素。
    CComDispatchDriver  pHTMLDispatch(m_wndBrowser.GetDocument());
    if(pHTMLDispatch.p){
        HRESULT hr;
        CComQIPtr<IHTMLDocument2, &IID_IHTMLDocument2> pHTMLDocument(pHTMLDispatch);
        if(pHTMLDocument.p){
            CComPtr<IHTMLElementCollection> pHTMLElementCollection;
            hr=pHTMLDocument->get_all(&pHTMLElementCollection);
            if(hr==S_OK &&  pHTMLElementCollection.p!=NULL){
                LONG    celem;
                hr=pHTMLElementCollection->get_length(&celem);
                if(hr==S_OK){
                    for(int i=0;i<celem;i++){
                        COleVariant varIndex,var2;//var2 is not used because accessing index,not name
                        varIndex.vt=VT_UINT;
                        varIndex.lVal=i;
                        CComDispatchDriver  pDisp;
                        hr=pHTMLElementCollection->item(varIndex,var2,&pDisp);
                        if(hr==S_OK){
                            CComQIPtr<IHTMLElement, &IID_IHTMLElement> pHTMLElement(pDisp);
                            if(pHTMLElement){
                                //find html element
                                BSTR    bstrTagID;
                                if(pHTMLElement->get_id(&bstrTagID)==S_OK){
                                    if(bstrTagID!=NULL){
                                        _bstr_t bstrHTML(lpszHtml);
                                        _bstr_t bstrTagIDToCompare(lpszTagID);
                                        _bstr_t _bstrTagID(bstrTagID,FALSE);
                                        if(_bstrTagID==bstrTagIDToCompare){
                                            if(bIsInnerHtml)
                                                pHTMLElement->put_innerHTML(bstrHTML);
                                            else
                                                pHTMLElement->put_outerHTML(bstrHTML);
            #ifdef  _DEBUG
                                            BSTR    bstrTag;
                                            hr=pHTMLElement->get_outerHTML(&bstrTag);
                                            CString strTag=bstrTag;
                                            ::afxDump<<strTag;
            #endif
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }

Q高手看过来,CHtmlView 在什么地方响应wm_paint 事件,我在源吗上看不到,viewhtml.cpp中也没有
A
说实话我烦透了。我想看看他是怎样paint web页的但就是找不着,我的本意是让他paint到我的dc上,然后。。嘿嘿,我可以将web页存为图像,为什么就那么难啊

……
这个家伙实际上是FormView,上面有个webbrowser控件占了所有client:(
记得以前有人干过在里面加注释的,找找看
去看看http://www.csdn.net/expert/Topic/265/265582.shtm
没有响应paint:(
http://www.csdn.net/expert/Topic/242/242146.shtm
http://www.csdn.net/expert/Topic/265/265582.shtm
我只是提提意见,你可以去问问他们实现得怎么样了
Q各位大虾:我从CHtmlView派生的类显示一个htm文件,打开后显示文件最上端,如何显示到文件底部?
T或知道真正视的大小,现在只能得到可显示出来的视的大小;我发送WM_VSCROLL消息不行。设置了SCROLL视大了,发送滚动到底部消息后,这个视显示出两个垂直滚动条。哪位高人知道,请援手!
A
需要用COM来访问DOM
用CHtmlView::GetDocument得到IHtmlDocument2接口,通过访问IHTMLDocument2::parentWindow 属性得到IHTMLWindow2接口
Q白捡的高分
T
我想拦截下来HtmlView外发的数据。
只要有有效代码,立即送分。
如果嫌分不高,还可加送。


A
CHtmlView::OnBeforeNavigate2
virtual void OnBeforeNavigate2( LPCTSTR lpszURL, DWORD nFlags, LPCTSTR lpszTargetFrameName, CByteArray& baPostedData, LPCTSTR lpszHeaders, BOOL* pbCancel );

baPostedData就是数据

或许你自己可以通过 WinInet 来下载网页。
Q在基于CHtmlView的程序中,当鼠标停留在一个超链上时,怎样得到该链指向的地址
T怎么样得到超链地址以及其它元素的属性,属于按钮,编辑框。。。
A
IHTMLDocument2::elementFromPoint Method

--------------------------------------------------------------------------------

Returns the element for the specified x and y coordinates.

Syntax

HRESULT elementFromPoint(
    long x,
    long y,
    IHTMLElement **elementHit
);

Parameters

x
[in] long that specifies the X-offset, in pixels.
y
[in] long that specifies the Y-offset, in pixels.
elementHit
[out, retval] Address of a pointer to an element object.
IHTMLAnchorElement::href Property

--------------------------------------------------------------------------------

Sets or retrieves the destination URL or anchor point.

Syntax

HRESULT IHTMLAnchorElement::get_href(BSTR *p);HRESULT IHTMLAnchorElement::put_href(BSTR v);

Q高分求助:怎样编程实现拷贝,打印那些屏蔽了拷贝,打印功能的网页?
T有时候打开某个网页时,浏览器的菜单、工具栏及地址栏都不在了,此时无论是鼠标右键还是按下Ctrl+A都不能实现选中网页的内容,当然也不能打印了。请问各位高手怎样把这些网页里的好东东拷贝出来,或者编辑或者保存或者打印出来呢?
A
/
// CSRWOnlineView

IMPLEMENT_DYNCREATE(CSRWOnlineView, CHtmlView)

BEGIN_MESSAGE_MAP(CSRWOnlineView, CHtmlView)
......
 ON_COMMAND(ID_EDIT_COPY, OnEditCopy)
 ON_COMMAND(ID_EDIT_PASTE, OnEditPaste)
 ON_COMMAND(ID_EDIT_CUT, OnEditCut)
.....
void CSRWOnlineView::OnEditCopy()
{
 CComQIPtr<IHTMLDocument2> pWin(GetHtmlDocument());
 VARIANT_BOOL boolDummy;
 _variant_t  varDummy;
 if(pWin)pWin->execCommand(_bstr_t("Copy"),VARIANT_FALSE,varDummy,&boolDummy);
 
}

void CSRWOnlineView::OnEditPaste()
{
 CComQIPtr<IHTMLDocument2> pWin(GetHtmlDocument());
 VARIANT_BOOL boolDummy;
 _variant_t  varDummy;
 if(pWin)pWin->execCommand(_bstr_t("Paste"),VARIANT_FALSE,varDummy,&boolDummy);
}

void CSRWOnlineView::OnEditCut()
{
 CComQIPtr<IHTMLDocument2> pWin(GetHtmlDocument());
 VARIANT_BOOL boolDummy;
 _variant_t  varDummy;
 if(pWin)pWin->execCommand(_bstr_t("Cut"),VARIANT_FALSE,varDummy,&boolDummy);
}

1用CHtmlView自己写一个浏览器
2连接到已经存在的IE窗口
http://www.csdn.net/Expert/TopicView1.asp?id=710303
Q关于自制浏览器的问题 请高手帮忙!!
T
我做的浏览器程序,用的chtmlview生成的多文档程序,为了用我的程序打开超联接弹出的新窗口,我重载了OnNewWindow2()
void CUClientView::OnNewWindow2(LPDISPATCH* ppDisp, BOOL* Cancel)
{
  CWinApp* pApp = AfxGetApp();
  POSITION pos = pApp->GetFirstDocTemplatePosition();
  CDocTemplate* pDocTemplate = pApp->GetNextDocTemplate( pos );
  CFrameWnd* pFrame = pDocTemplate->CreateNewFrame(
                                          GetDocument(),
                                          (CFrameWnd*)AfxGetMainWnd() );
  pDocTemplate->InitialUpdateFrame( pFrame,NULL);
  CUClientView* pView = (CUClientView*)pFrame->GetActiveView();
  pView->SetRegisterAsDropTarget(TRUE);
  *ppDisp = pView->GetApplication();
 
}
这样就能用我的新窗口来打开联接的弹出窗口(要不总是弹出ie的窗口)。

为了在点击网页中的关闭窗口按钮时,能关闭窗口,我重载了
BOOL CUClientView::PreTranslateMessage(MSG* pMsg)
{
if(pMsg->message==WM_CLOSE && pMsg->hwnd==m_wndBrowser.GetSafeHwnd())

PostMessage(WM_COMMAND,ID_FILE_CLOSE);
    return CHtmlView::PreTranslateMessage(pMsg);

}


结果是点击网页中的关闭窗口按钮时,把所有有联接关系的网页都关闭了!!
怎样结决这个问题!
问题很是麻烦,期待有高手帮帮我!非常感谢!!





A
有没有搞错?不是捕获WM_CLOSE的

In Internet Explorer 5.5, the WebBrowser control's default source interface, DWebBrowserEvents2, exposes a new event called WindowClosing. You can sink DWebBrowserEvents2 and set the Cancel parameter of the event to TRUE to prevent the close from occurring, or you can close the host windows.

In Internet Explorer 5.01 and earlier, the WM_PARENTNOTIFY message is sent to the parent of a child window when the child window is created or destroyed, or when the user clicks a mouse button while the cursor is over the child window. Thus, the hosting container of the WebBrowser control can watch for a WM_DESTROY notification message. If LOWORD of the wParam field of the WM_PARENTNOTIFY message is set to WM_DESTROY, the HIWORD of wParam contains the child window identifier, and the lParam field contains the hWnd of the child control. If the hWnd in lParam matches the hWnd of the WebBrowser control, you can determine that the WebBrowser control is being destroyed. You can then take the appropriate action, which typically means to close the child window for multiple-document interface (MDI) applications and quit the applications for single-document interface (SDI) applications.
void CMyHtmlView::OnParentNotify(UINT message, LPARAM lParam ) 
{ 
 if ((LOWORD(message) == WM_DESTROY) && ((HWND)lParam == m_wndBrowser)) 
 { 
  // Close the parent frame window.
  GetParentFrame()->PostMessage(WM_CLOSE, 0, 0);
 } 
 else  
  CHtmlView::OnParentNotify(message, lParam );
}
首先要获取IE的版本,看是用EventSink还是WM_PARENTNOTIFY
自己写啦,classwizard又不是万能的
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值