Moving a single control in on HScroll in a CScrollView class
-
I need to move just a single control in my view to keep it centered on the screen. I have tried overriding the OnHScroll() and adding code to MoveWindow() for my control to move it. I can't seem to keep it visible. Here is the code sample:
void CMYView::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar *pScrollBar) { CRect r; int nNewCalPos; if(pScrollBar) return; //should be NULL; switch(nSBCode) { case SB_LINERIGHT: m_nHPos += 204; if(m_nHPos > m_nMaxRange) { m_nHPos = m_nMaxRange; nNewCalPos = m_nMaxRange - 204; } break; case SB_LINELEFT: m_nHPos -= 204; if(m_nHPos < 0) { m_nHPos = 0; nNewCalPos = 150; } break; } CScrollView::OnHScroll(nSBCode, nPos, pScrollBar); //Size the control m_cCalanderCtrl.GetMinReqRect(&r); m_cCalanderCtrl.MoveWindow(nNewCalPos, 0, ((r.right * 4) + 20), r.bottom, TRUE); }
Any ideas? Thanks, -Eric