問========================================
我使用webbrowser控件,但是想用自己的滾動條,但不知如何得到webbrowser中滾動條的長度,怎么辦?謝謝!!
2004-10-24
答========================================
    抱歉拖了很久才回復你的問題。
    WebBrowser的滾動條不是一般的Windows滾動條,用GetScrollPos或GetScrollInfo等API是不能訪問的。下面的代碼演示了在VC中如何通過HTML接口來訪問瀏覽器的滾動條。
    HRESULT hr;
    IDispatch *pDisp = GetHtmlDocument();
    ASSERT( pDisp ); //if NULL, we failed
    
    // 獲得Html文檔指針
    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 );
    // 從body獲得IHTMLElement2接口指針,用以訪問滾動條
    IHTMLElement2 *pElement = NULL;
    hr = pBody->QueryInterface(IID_IHTMLElement2,(void**)&pElement);
    ASSERT(SUCCEEDED(hr));
    ASSERT( pElement );
    // 向下滾動100個像素
    pElement->put_scrollTop( 100 ); 
    
    // 獲得滾動條高度
    long scroll_height; 
    pElement->get_scrollHeight( &scroll_height );
    // 獲得滾動條寬度
    long scroll_height; 
    pElement->get_scrollWidth( &scroll_width );
    // 獲得滾動條位置,從頂端開始
    long scroll_top;
    pElement->get_scrollTop( &scroll_top );
新聞熱點
疑難解答