Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. how to show a search bar in my class derived from CHtmlView

how to show a search bar in my class derived from CHtmlView

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelptutorialannouncement
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    joshua0137
    wrote on last edited by
    #1

    i write a class derived from CHtmlView, and write the code as below, when it run, no bar appear, and a messageBox show a string '0x80040100', what is the reason? how can i make it work. any suggestion or help are appreciated

    void CXxView::OnShowBar()
    {
    IWebBrowser2 *pBrowser = NULL;
    // Ensure that our site is an browser window
    HRESULT hr = m_pBrowserApp->QueryInterface(IID_IWebBrowser2, (void **) &pBrowser);
    if (SUCCEEDED(hr))
    {
    // Display the band object (the Search bar in this case)
    VARIANT vtBandGUID, vtShow;
    vtBandGUID.vt = VT_BSTR;
    //change the CLSID as your bar CLSID
    vtBandGUID.bstrVal = SysAllocString(OLESTR("{30D02401-6A81-11d0-8274-00C04FD5AE38}"));
    vtShow.vt = VT_BOOL;
    vtShow.boolVal = TRUE;
    HRESULT hrx = pBrowser->ShowBrowserBar(&vtBandGUID, &vtShow, 0);
    if (FAILED(hrx))
    {
    CString _str;
    _str.Format("0x%x", hrx);
    AfxMessageBox(_str);
    }

    	SysFreeString(vtBandGUID.bstrVal);
    	pBrowser->Release();
    }
    

    }

    L L 2 Replies Last reply
    0
    • J joshua0137

      i write a class derived from CHtmlView, and write the code as below, when it run, no bar appear, and a messageBox show a string '0x80040100', what is the reason? how can i make it work. any suggestion or help are appreciated

      void CXxView::OnShowBar()
      {
      IWebBrowser2 *pBrowser = NULL;
      // Ensure that our site is an browser window
      HRESULT hr = m_pBrowserApp->QueryInterface(IID_IWebBrowser2, (void **) &pBrowser);
      if (SUCCEEDED(hr))
      {
      // Display the band object (the Search bar in this case)
      VARIANT vtBandGUID, vtShow;
      vtBandGUID.vt = VT_BSTR;
      //change the CLSID as your bar CLSID
      vtBandGUID.bstrVal = SysAllocString(OLESTR("{30D02401-6A81-11d0-8274-00C04FD5AE38}"));
      vtShow.vt = VT_BOOL;
      vtShow.boolVal = TRUE;
      HRESULT hrx = pBrowser->ShowBrowserBar(&vtBandGUID, &vtShow, 0);
      if (FAILED(hrx))
      {
      CString _str;
      _str.Format("0x%x", hrx);
      AfxMessageBox(_str);
      }

      	SysFreeString(vtBandGUID.bstrVal);
      	pBrowser->Release();
      }
      

      }

      L Offline
      L Offline
      leon de boer
      wrote on last edited by
      #2

      It is what you asked for

      _str.Format("0x%x", hrx);
      AfxMessageBox(_str);

      "0x%x" means put a 0x in front and return the hex and hence you get 0x80040100 IWebBrowser2::ShowBrowserBar returns either S_OK status or E_FAIL see the documentation http://msdn.microsoft.com/en-us/library/aa768268%28v=vs.85%29.aspx[^] So it is returning E_FAIL and the value is given. Now as to what the problem is I have suspicions on this line

      vtShow.boolVal = TRUE;

      Are you sure I thought these had to be lower case true or VARIANT_TRUE which is the same thing but definitely all Microsoft code I have ever seen uses VARIANT_TRUE If that isn't it I guess there is something with the GUID implementation and talk to Microsoft.

      J 1 Reply Last reply
      0
      • L leon de boer

        It is what you asked for

        _str.Format("0x%x", hrx);
        AfxMessageBox(_str);

        "0x%x" means put a 0x in front and return the hex and hence you get 0x80040100 IWebBrowser2::ShowBrowserBar returns either S_OK status or E_FAIL see the documentation http://msdn.microsoft.com/en-us/library/aa768268%28v=vs.85%29.aspx[^] So it is returning E_FAIL and the value is given. Now as to what the problem is I have suspicions on this line

        vtShow.boolVal = TRUE;

        Are you sure I thought these had to be lower case true or VARIANT_TRUE which is the same thing but definitely all Microsoft code I have ever seen uses VARIANT_TRUE If that isn't it I guess there is something with the GUID implementation and talk to Microsoft.

        J Offline
        J Offline
        joshua0137
        wrote on last edited by
        #3

        thank you for your help. i use VARIANT_TRUE and true, the problem keeps the same. and i copy the guid from msdn, it also keeps the same. anyone more suggestions?

        1 Reply Last reply
        0
        • J joshua0137

          i write a class derived from CHtmlView, and write the code as below, when it run, no bar appear, and a messageBox show a string '0x80040100', what is the reason? how can i make it work. any suggestion or help are appreciated

          void CXxView::OnShowBar()
          {
          IWebBrowser2 *pBrowser = NULL;
          // Ensure that our site is an browser window
          HRESULT hr = m_pBrowserApp->QueryInterface(IID_IWebBrowser2, (void **) &pBrowser);
          if (SUCCEEDED(hr))
          {
          // Display the band object (the Search bar in this case)
          VARIANT vtBandGUID, vtShow;
          vtBandGUID.vt = VT_BSTR;
          //change the CLSID as your bar CLSID
          vtBandGUID.bstrVal = SysAllocString(OLESTR("{30D02401-6A81-11d0-8274-00C04FD5AE38}"));
          vtShow.vt = VT_BOOL;
          vtShow.boolVal = TRUE;
          HRESULT hrx = pBrowser->ShowBrowserBar(&vtBandGUID, &vtShow, 0);
          if (FAILED(hrx))
          {
          CString _str;
          _str.Format("0x%x", hrx);
          AfxMessageBox(_str);
          }

          	SysFreeString(vtBandGUID.bstrVal);
          	pBrowser->Release();
          }
          

          }

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Hi, I see two errors: Leon de Boer is correct that you should set vtShow.boolVal to VARIANT_TRUE; I see another error... the third argument to ShowBrowserBar Function[^] should be a pointer to an empty VARIANT... not a NULL pointer.

          VARIANT vtEmpty = {0};

          Best Wishes, -David Delaune

          J 1 Reply Last reply
          0
          • L Lost User

            Hi, I see two errors: Leon de Boer is correct that you should set vtShow.boolVal to VARIANT_TRUE; I see another error... the third argument to ShowBrowserBar Function[^] should be a pointer to an empty VARIANT... not a NULL pointer.

            VARIANT vtEmpty = {0};

            Best Wishes, -David Delaune

            J Offline
            J Offline
            joshua0137
            wrote on last edited by
            #5

            thank your help info. i change the variable as code below, but the problem keeps the same:

            IWebBrowser2 \*pBrowser = NULL;
            // Ensure that our site is an browser window
            HRESULT hr = m\_pBrowserApp->QueryInterface(IID\_IWebBrowser2, (void \*\*) &pBrowser);
            if (!SUCCEEDED(hr))
            	return;
            
            // Display the band object (the Search bar in this case)
            VARIANT vtBandGUID, vtShow;
            vtBandGUID.vt = VT\_BSTR;
            //把这里的CLSID换成你的工具条CLSID
            vtBandGUID.bstrVal = SysAllocString(OLESTR("{30D02401-6A81-11D0-8274-00C04FD5AE38}"));
            vtShow.vt = VT\_BOOL;
            vtShow.boolVal = VARIANT\_TRUE;
            VARIANT vtEmpty = {0};
            hr = pBrowser->ShowBrowserBar(&vtBandGUID, &vtShow, &vtEmpty);
            SysFreeString(vtBandGUID.bstrVal);
            pBrowser->Release();
            
            L 1 Reply Last reply
            0
            • J joshua0137

              thank your help info. i change the variable as code below, but the problem keeps the same:

              IWebBrowser2 \*pBrowser = NULL;
              // Ensure that our site is an browser window
              HRESULT hr = m\_pBrowserApp->QueryInterface(IID\_IWebBrowser2, (void \*\*) &pBrowser);
              if (!SUCCEEDED(hr))
              	return;
              
              // Display the band object (the Search bar in this case)
              VARIANT vtBandGUID, vtShow;
              vtBandGUID.vt = VT\_BSTR;
              //把这里的CLSID换成你的工具条CLSID
              vtBandGUID.bstrVal = SysAllocString(OLESTR("{30D02401-6A81-11D0-8274-00C04FD5AE38}"));
              vtShow.vt = VT\_BOOL;
              vtShow.boolVal = VARIANT\_TRUE;
              VARIANT vtEmpty = {0};
              hr = pBrowser->ShowBrowserBar(&vtBandGUID, &vtShow, &vtEmpty);
              SysFreeString(vtBandGUID.bstrVal);
              pBrowser->Release();
              
              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              Hi, Your code appears to be absolutely correct. The error you are encountering could be caused by the browser control not supporting explorer bars. Best Wishes, -David Delaune

              J 1 Reply Last reply
              0
              • L Lost User

                Hi, Your code appears to be absolutely correct. The error you are encountering could be caused by the browser control not supporting explorer bars. Best Wishes, -David Delaune

                J Offline
                J Offline
                joshua0137
                wrote on last edited by
                #7

                thank you for you reply. i think the reason is as you pointed out. my enviroment: windowsXP sp3 + IE8

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups