How to get rid of the scrollbars in a WebBrowser control?
-
Hi, I'm using a WebBrowser control inside a CView class. I've used the ClassWizard to encapsulate the control's functionality, but although I've used SetWidth() and SetHeight() to set the right values, I can't get rid of the vertical scrollbar on the right. SetResizeable(FALSE) returns a funny message, and none of the CWnd scrollbar functions seem to have any effect. Any help will be greatly appreciated.
-
Hi, I'm using a WebBrowser control inside a CView class. I've used the ClassWizard to encapsulate the control's functionality, but although I've used SetWidth() and SetHeight() to set the right values, I can't get rid of the vertical scrollbar on the right. SetResizeable(FALSE) returns a funny message, and none of the CWnd scrollbar functions seem to have any effect. Any help will be greatly appreciated.
This can be done with the IDocHostUIHandler interface that you must implement in your container (CView derived class). Look at GetHostInfo and returning with docHostUIFlagSCROLL_NO flag set. In ATL support for this interface is built in. You can look at the implementation of CAxHostWindow for an example implementation. A description of some of this can be found in ATL Internals.
-
This can be done with the IDocHostUIHandler interface that you must implement in your container (CView derived class). Look at GetHostInfo and returning with docHostUIFlagSCROLL_NO flag set. In ATL support for this interface is built in. You can look at the implementation of CAxHostWindow for an example implementation. A description of some of this can be found in ATL Internals.
void CDaTestView::OnInitialUpdate() { CView::OnInitialUpdate(); m_WebBrowserCtrl.SetLeft(0); m_WebBrowserCtrl.SetTop(0); m_WebBrowserCtrl.SetWidth(156); m_WebBrowserCtrl.SetHeight(92); if(m_WebBrowserCtrl.EnableScrollBar(SB_BOTH, ESB_DISABLE_BOTH) == TRUE) TRACE("Cannot disable scrollbars!"); m_WebBrowserCtrl.ShowScrollBar(SB_BOTH, FALSE); // Initialize the first URL. COleVariant noArg; m_WebBrowserCtrl.Navigate("file://D:/PROJECTS/MosaicLCD/default.html",&noArg,&noArg,&noArg,&noArg); LPDISPATCH pDisp = NULL; IDocHostUIHandler *pHostUIHandler = NULL; pDisp = m_WebBrowserCtrl.GetDocument(); ASSERT(pDisp); pDisp->QueryInterface(IID_IDocHostUIHandler, (LPVOID*)&pHostUIHandler); ASSERT(pHostUIHandler); if(pHostUIHandler) { DOCHOSTUIINFO *pInfo = NULL; pHostUIHandler->GetHostInfo(pInfo); if(pInfo) { if(((pInfo->dwFlags) & DOCHOSTUIFLAG_SCROLL_NO) == (pInfo->dwFlags)) TRACE("Scrolling enabled"); else TRACE("Scrolling disabled"); } } if(pHostUIHandler) pHostUIHandler->Release(); // release document's command target if(pDisp) pDisp->Release(); // release document's dispatch interface } I'm creating the m_WebBrowserCtrl in CDaTestView::OnCreate() but I get an assertion in the line pDisp = m_WebBrowserCtrl.GetDocument(); ASSERT(pDisp); pDisp is NULL! Any idea why? Is there something else wrong with this code? Thanks in advance
-
void CDaTestView::OnInitialUpdate() { CView::OnInitialUpdate(); m_WebBrowserCtrl.SetLeft(0); m_WebBrowserCtrl.SetTop(0); m_WebBrowserCtrl.SetWidth(156); m_WebBrowserCtrl.SetHeight(92); if(m_WebBrowserCtrl.EnableScrollBar(SB_BOTH, ESB_DISABLE_BOTH) == TRUE) TRACE("Cannot disable scrollbars!"); m_WebBrowserCtrl.ShowScrollBar(SB_BOTH, FALSE); // Initialize the first URL. COleVariant noArg; m_WebBrowserCtrl.Navigate("file://D:/PROJECTS/MosaicLCD/default.html",&noArg,&noArg,&noArg,&noArg); LPDISPATCH pDisp = NULL; IDocHostUIHandler *pHostUIHandler = NULL; pDisp = m_WebBrowserCtrl.GetDocument(); ASSERT(pDisp); pDisp->QueryInterface(IID_IDocHostUIHandler, (LPVOID*)&pHostUIHandler); ASSERT(pHostUIHandler); if(pHostUIHandler) { DOCHOSTUIINFO *pInfo = NULL; pHostUIHandler->GetHostInfo(pInfo); if(pInfo) { if(((pInfo->dwFlags) & DOCHOSTUIFLAG_SCROLL_NO) == (pInfo->dwFlags)) TRACE("Scrolling enabled"); else TRACE("Scrolling disabled"); } } if(pHostUIHandler) pHostUIHandler->Release(); // release document's command target if(pDisp) pDisp->Release(); // release document's dispatch interface } I'm creating the m_WebBrowserCtrl in CDaTestView::OnCreate() but I get an assertion in the line pDisp = m_WebBrowserCtrl.GetDocument(); ASSERT(pDisp); pDisp is NULL! Any idea why? Is there something else wrong with this code? Thanks in advance
You must wait for the DocumentComplete event from the Web browser control before you can get the document. Also you must implement the IDocHostUIHandler interface. The Web browser control will call your GetHostInfo method. You might be able to find some example code for this interface using MFC.