十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
在窗口过程中处理滚动条消息
我们提供的服务有:网站建设、网站制作、微信公众号开发、网站优化、网站认证、诏安ssl等。为上千企事业单位解决了网站和推广的问题。提供周到的售前咨询和贴心的售后服务,是有科学管理、有技术的诏安网站制作公司
WNDPROC pSubclassOldEditProc; INT iVScrollPos = 0, iVTextPos = 0; LRESULT winProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { //获取新设置的窗口属性,就是获取CNewEdit的指针,方便后面访问m_lOldProc这个成员 if (message == WM_VSCROLL) { //TRACE( _T("%d\n"), LOWORD(wParam)); switch (LOWORD(wParam)) { case SB_LINEDOWN: if (iVScrollPos != (NUMLINE - 1)) iVTextPos -= 1; TRACE(_T("向下滚动一行\n") ); break; case SB_LINEUP: if (iVScrollPos != 0) iVTextPos += 1; TRACE( _T("向上滚动一行\n")); break; case SB_PAGEUP: TRACE( _T("向上滚动一页\n")); break; case SB_PAGEDOWN: TRACE( _T("向下滚动一页\n")); break; case SB_THUMBPOSITION: CScale3DCListBox::AdjustListBox(iVScrollPos); break; case SB_THUMBTRACK: iVTextPos = -HIWORD(wParam); break; default: break; } iVScrollPos = -iVTextPos; SetScrollPos(hwnd, SB_VERT, iVScrollPos, TRUE); } //处理完需要截获(改变)的消息后接着返回旧的窗口过程 return CallWindowProc((WNDPROC)pSubclassOldEditProc, hwnd, message, wParam, lParam); }
创建窗口并替换过程函数,如下
m_pWndListBoxDlg = new CWnd; LPCTSTR lpszClassName = AfxRegisterWndClass(CS_HREDRAW | CS_VREDRAW, AfxGetApp()->LoadStandardCursor(IDC_ARROW), (HBRUSH)GetStockObject(LTGRAY_BRUSH), NULL); m_pWndListBoxDlg->Create(lpszClassName, _T(""), WS_CHILD | WS_VISIBLE| WS_VSCROLL| ES_AUTOHSCROLL, rt1, parentWnd, 5234); m_uID = 5234; m_nHeight = nHeight; //设置滚动条 m_hwndListbox = m_pWndListBoxDlg->GetSafeHwnd(); m_pWndListBoxDlg->SetScrollRange(SB_VERT, 0, NUMLINE - 1, FALSE); //设置 TRUE 滚动条立即重绘 这样才能看到新位置 m_pWndListBoxDlg->SetScrollPos(SB_VERT, 0, TRUE); //更换窗口过程 pSubclassOldEditProc = (WNDPROC)::SetWindowLong( m_pWndListBoxDlg->GetSafeHwnd(), GWL_WNDPROC,(DWORD)winProc);