IWebBrowser2在没有焦点时响应滚轮事件

 首先, 获得IE控件窗口句柄, 父窗口调用EnumChildWindows, 回调函数代码:

BOOL CALLBACK CWebDialog::EnumChildProc(HWND hwnd, LPARAM lParam) { CWebDialog* webDialog = (CWebDialog*)(lParam); return webDialog->EnumChildProc(hwnd); } BOOL CWebDialog::EnumChildProc(HWND hwnd) { // 窗口类别名 TCHAR classname[200]; GetClassName(hwnd, classname, _countof(classname)); // 窗口类型 DWORD style = 0; style = (DWORD)GetWindowLong(hwnd, GWL_STYLE); // 查找IE控件窗口 if (CString(_T("Internet Explorer_Server")).Compare(classname) == 0) { m_htmlWindow = hwnd; } return true; }

 

其次, 截获WM_MOUSEWHEEL事件

BOOL CXXXView::PreTranslateMessage(MSG* pMsg) { if (pMsg->message == WM_MOUSEWHEEL) { if (m_dlgXXX.Scroll(pMsg)) { return TRUE; } } return CXXXDialog::PreTranslateMessage(pMsg); }

 

再次, 转发WM_MOUSEWHEEL事件

BOOL CWebDialog::Scroll(MSG* pMsg) { if (pMsg->message == WM_MOUSEWHEEL && m_htmlWindow != NULL && m_htmlWindow != pMsg->hwnd) { ::PostMessage(m_htmlWindow, WM_MOUSEWHEEL, pMsg->wParam, pMsg->lParam); return TRUE; } return FALSE; }

 

最后, 感谢许冬、周宏杰的帮助!

 

你可能感兴趣的:(IWebBrowser2在没有焦点时响应滚轮事件)