在窗口过程中处理滚动条消息
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);
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。