FAQ: How to access the scroll bar of WebBrowser

xiaoxiao2021-03-06  91

Q======================================== I use the webbrowser control, but I want to use myself The scroll bar, but I don't know how to get the length of the scroll bar in WebBrowser. Thank you! ! 2004-10-24 answer =================================================================================================== Reply to your question. The scroll bar of WebBrowser is not a general Windows scroll bar, which is unacceptable to APIs such as GetScrollPos or GetScrollInfo. The following code demonstrates how to access the scroll bar of the browser through an HTML interface in the VC.

HRESULT hr; IDispatch * pDisp = GetHtmlDocument (); ASSERT (pDisp); // if NULL, we failed // get pointer Html Document IHTMLDocument2 * pDocument = NULL; hr = pDisp-> QueryInterface (IID_IHTMLDocument2, (void **) & pDocument ); Assert (ac); assert (pdocument);

IHTMLELEMENT * PBODY = NULL; HR = pDocument-> get_body (& pbody); assert (succeeded (hr)); assert (pbody);

// obtained from body IHTMLElement2 interface pointer to access the scroll bar IHTMLElement2 * pElement = NULL; hr = pBody-> QueryInterface (IID_IHTMLElement2, (void **) & pElement); ASSERT (SUCCEEDED (hr)); ASSERT (pElement);

/ / Scroll down 100 pixels Pelement-> PUT_SCROLLTOP (100); // Get the true height of the document, not the height of the visible area long scroll_height; pelement-> get_scrollheight (& scroll_height);

/ / Get the true width of the document, not the width of the visible area long scroll_width; pelement-> get_scrollwidth (& scroll_width);

// Get the rolling bar position, start long scroll_top from the top; pelement-> get_scrolltop (& scroll_top); reference address: FAQ: How to access WebBrowser scroll bar

转载请注明原文地址:https://www.9cbs.com/read-96096.html

New Post(0)