在窗口过程中处理滚动条消息

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);