每次绘制列表框都要重绘某项,通过消息WM_CTLCOLOR从父窗口获得DC颜色.因此每欠列表框的滚动你都可以用WM_CTLCOLOR来检验是否滚动.
HBRUSH CParentDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
// is the control _the_ list box we're interested in?
if( nCtlColor == CTLCOLOR_LISTBOX &&
pWnd->GetDlgCtrlID() == IDC_LIST )
{
// if the top index changed, the list box has been scrolled
int iTop = ((CListBox*)pWnd)->GetTopIndex();
if( iTop != m_iTopOld )
{
// keeps tracking of the top index changes
m_iTopOld = iTop;
// process scrolling
...
}
}
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
return hbr;
使用这种方法可以不必为了实现这个功能而去产生一个继承类.
Bookmark
Email This
Hits: 3497
Comments (0)

Write comment



