您好,登錄后才能下訂單哦!
在窗口過程中處理滾動條消息
WNDPROC pSubclassOldEditProc; INT iVScrollPos = 0, iVTextPos = 0; LRESULT winProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { //獲取新設(shè)置的窗口屬性,就是獲取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("向下滾動一行\(zhòng)n") ); break; case SB_LINEUP: if (iVScrollPos != 0) iVTextPos += 1; TRACE( _T("向上滾動一行\(zhòng)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); }
創(chuàng)建窗口并替換過程函數(shù),如下
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; //設(shè)置滾動條 m_hwndListbox = m_pWndListBoxDlg->GetSafeHwnd(); m_pWndListBoxDlg->SetScrollRange(SB_VERT, 0, NUMLINE - 1, FALSE); //設(shè)置 TRUE 滾動條立即重繪 這樣才能看到新位置 m_pWndListBoxDlg->SetScrollPos(SB_VERT, 0, TRUE); //更換窗口過程 pSubclassOldEditProc = (WNDPROC)::SetWindowLong( m_pWndListBoxDlg->GetSafeHwnd(), GWL_WNDPROC,(DWORD)winProc);
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。