locked
BHO & context menu customization RRS feed

  • Question

  • I have pretty simple question: How to customize the context menu of the Internet Explorer in BHO?
    I see 2 possible solutions:
    1. via ICustomDoc::SetUIHandler. It seems to be wrong solution because if user has more than 1 such extensions, only 1 extension will work, because chaining is impossible. If I'm wrong, let me know please.

    2. via some work with registry. It seems to be correct solution. But in this case I have to write JavaScript code. All I need is to call my BHO, which is ALREADY loaded, not to load the new one. And I don't know, how to do this.

    Saturday, January 27, 2007 1:16 PM

All replies

  • To customize the context menu derive your object form ICustomDoc and call SetUIHandler.  This is called in the document complete handler within my object only for certain web pages. The rest of the time the default IE context menu is shown. . Once you have hooked up the UI handler in the ShowContextMenu method you need to build and show the context menu. Hope this helps.    (pseudo code below) 

     case DISPID_DOCUMENTCOMPLETE:
      // [0]: Document URL - VT_BYREF|VT_VARIANT
      // [1]: An object that evaluates to the top-level or frame
      //      WebBrowser object corresponding to the event.

       spWebBrowser2 = pDispParams->rgvarg[1].pdispVal;

      // Get the WebBrowser's document object
       hr = spWebBrowser2->get_Document(&spDisp);
       if (SUCCEEDED(hr) && m_bSetSite)
       {
        // Verify pointer to a MSHTML::IHTMLDocument2
        // interface by querying for the MSHTML::IHTMLDocument2 interface (through smart pointers)
         
        MSHTML::IHTMLDocument2Ptr spHTML;
        spHTML = spDisp;
        // Check not not dealing with Explorer or
        // an Acrobat Reader (pdf) file.
       
        if (spHTML.GetInterfacePtr() && IsDocumentSafe())
        {
            
         ICustomDocPtr spCustomDoc;
         hr = spHTML->QueryInterface(IID_ICustomDoc, (void**)&spCustomDoc);
         if (spCustomDoc)
         { 

           //Only SetUIHandler for certain web pages determined in CheckHandler()

          int dHandlerCode = CheckHandler();

          if (dHandlerCode!=0)
          { 
           spCustomDoc->SetUIHandler(this);
           ..........

          }
         }  
        }
       }
       break;

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

    STDMETHODIMP CYour_Main_Object::ShowContextMenu(DWORD dwID, POINT FAR* ppt, IUnknown FAR* pcmdTarget, IDispatch FAR* pdispReserved)
    {
      return m_YourUIClass.ContextMenu(dwID, ppt, pcmdTarget,pdispReserved);
    }

     

     

    Saturday, January 27, 2007 10:20 PM
  • Thanks, but you write exactly what I mean as 1-st solution. The drawback is, that only one extension at the time can do this trick.
    Sunday, January 28, 2007 9:26 AM