Question ===================================================== =
I use the webbrowser control but want to use my own scroll bar, but I don't know how to get the length of the scroll bar in webbrowser. What should I do? Thank you !!
2004-10-24
A: ===================================================== =
Sorry, it took a long time to reply to your question.
Webbrowser's scroll bar is not a common Windows scroll bar. It cannot be accessed using APIs such as getscrollpos or getscrollinfo. The followingCodeDemonstrate how to access the browser's scroll bar through the HTML interface in VC.
Hresult hr;
Idispatch * Pdisp = gethtmldocument ();
Assert (Pdisp); // If null, we failed
// Obtain the HTML document pointer
Ihtmldocument2 * pdocument = NULL;
HR = Pdisp-> QueryInterface (iid_ihtmldocument2, (void **) & pdocument );
Assert (succeeded (HR ));
Assert (pdocument );
Ihtmlelement * pbody = NULL;
HR = pdocument-> get_body (& pbody );
Assert (succeeded (HR ));
Assert (pbody );
// Obtain the ihtmlelement2 interface pointer from the body 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 );
// Obtain the true height of the document, not the height of the visible area
Long scroll_height;
Pelement-> get_scrollheight (& scroll_height );
// Obtain the true width of the document, not the width of the visible area
Long scroll_width;
Pelement-> get_scrollwidth (& scroll_width );
// Obtain the position of the scroll bar, starting from the top
Long scroll_top;
Pelement-> get_scrolltop (& scroll_top );
Reference address: FAQ: how to access the webbrowser scroll bar