控制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 );
}
[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课