您好,登錄后才能下訂單哦!
在窗口過程中處理滾動條消息
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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。