how to show a search bar in my class derived from CHtmlView
-
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(); }
}
-
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(); }
}
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.
-
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.
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?
-
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(); }
}
Hi, I see two errors: Leon de Boer is correct that you should set
vtShow.boolVal
toVARIANT_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
-
Hi, I see two errors: Leon de Boer is correct that you should set
vtShow.boolVal
toVARIANT_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
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();
-
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();
-
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
thank you for you reply. i think the reason is as you pointed out. my enviroment: windowsXP sp3 + IE8