首页
社区
课程
招聘
[求助]控制WebBrowser的滚动条没有反应 有源码
发表于: 2018-1-18 07:30 2340

[求助]控制WebBrowser的滚动条没有反应 有源码

2018-1-18 07:30
2340
控制WebBrowser的滚动条没有反应 有源码,大家帮忙看下。
在初始化函数中打开百度首页,点击按钮滚动条没反应。不懂怎么回事!请大牛帮忙下。折腾两天了。。。

BOOL CWebDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);

CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog.  The framework does this automatically
//  when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon

CString URL="https://www.baidu.com";
m_ctrlWeb.Navigate(URL,NULL,NULL,NULL,NULL);     

return TRUE;  // return TRUE  unless you set the focus to a control
}


void CWebDlg::OnButton1() 
{
        HRESULT hr;
LPDISPATCH pDisp=m_ctrlWeb.GetDocument();
        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_width; 
    pElement->get_scrollWidth( &scroll_width );
    // 获得滚动条位置,从顶端开始
    long scroll_top;
    pElement->get_scrollTop( &scroll_top );

}


[培训]《安卓高级研修班(网课)》月薪三万计划,掌握调试、分析还原ollvm、vmp的方法,定制art虚拟机自动化脱壳的方法

上传的附件:
收藏
免费 0
支持
分享
最新回复 (1)
雪    币: 49
活跃值: (261)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
2
有人知道什么原因吗!
2018-1-18 17:30
0
游客
登录 | 注册 方可回帖
返回
//