如何获得Internet Explorer_Server窗口的边框和滚动条的宽度信息

解决方案 »

  1.   

    通过IHtmlDocument2接口获取IHtmlDocument2接口IHTMLElement2::scrollWidth获取滚动条的宽度边框信息获取
    IHTMLElement2::clientHeight
    IHTMLElement2::clientLeft
    IHTMLElement2::clientRight
    IHTMLElement2::clientTop
      

  2.   

    滚动条不是窗口本身的,是body、frame、textarea、div等元素的
      

  3.   

    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 );