我实现了一个显示图表的MFC 应用程序。有一些数据点(例如 2000),其中一部分将显示在图表中。该子集必须使用滚动条进行更改。所以我在我的对话框类中添加了CScrollBar
类并监听ON_WM_HSCROLL
调用该OnHScroll
方法的事件。
void CChartWithRealTimeDataDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
UINT nCurrentPos;
nCurrentPos = pScrollBar->GetScrollPos();
// nCurrentPos = m_X_Axis_Scrollbar->GetScrollPos();
bool bDoRepaint = false;
switch (nSBCode)
{
//case SB_THUMBPOSITION:
case SB_THUMBTRACK:
nCurrentPos = nPos;
pScrollBar->SetScrollPos (nPos);
bDoRepaint = true;
break;
case SB_LINELEFT:
nCurrentPos = (UINT)(std::max( (int)0, (int)nCurrentPos-1));
pScrollBar->SetScrollPos (nCurrentPos);
bDoRepaint = true;
break;
case SB_LINERIGHT:
nCurrentPos = std::min((UINT)(m_ChartControl.getTotalEnd()), nCurrentPos+1);
pScrollBar->SetScrollPos (nCurrentPos);
bDoRepaint = true;
break;
case SB_PAGELEFT:
nCurrentPos = (UINT)(std::max( (int)0, (int)nCurrentPos-10));
pScrollBar->SetScrollPos (nCurrentPos);
bDoRepaint = true;
break;
case SB_PAGERIGHT:
nCurrentPos = std::min( (UINT)(m_ChartControl.getTotalEnd()), nCurrentPos+10);
pScrollBar->SetScrollPos (nCurrentPos);
bDoRepaint = true;
break;
}
if ( bDoRepaint )
{
m_ChartControl.setShift(nCurrentPos);
Invalidate();
}
CDialogEx::OnHScroll(nSBCode, nPos, pScrollBar);
}
如果用户每次移动拇指滑块,整个窗口将被重新绘制并开始闪烁。
有没有办法避免闪烁?
谢谢,
托马斯