CDialog ScrollBar

  • Thread starter Thread starter sgrm123
  • Start date Start date
S

sgrm123

Guest
Hi,

In my MFC dialog application I am using CMFCTabCtrl.

I am having a dialog in one of the tab page. In that dialog I am displaying multiple child dialogs dynamically.The contents of dialog exceeds the dialog's client area. The dialog which has tab control is resizable dialog.

Now I added scroll bar to the dialog of tab page.

Now my problem is after scrolling to some position If I resize the dialog or maximize or minimize the dialog, the client are is not getting scrolled up to top.

The mousewheel and scrolling bar operation are working fine.

Below is my code

void CMyDlg::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{

// TODO: Add your message handler code here and/or call default.
int nDelta;
int nMaxPos = m_rect.Height() - m_nCurHeight;

switch (nSBCode)
{
case SB_LINEDOWN:
if (m_nScrollPos >= nMaxPos)
return;
nDelta = min(nMaxPos/20,nMaxPos-m_nScrollPos);
break;

case SB_LINEUP:
if (m_nScrollPos <= 0)
return;
nDelta = -min(nMaxPos/20,m_nScrollPos);
break;

case SB_PAGEDOWN:
if (m_nScrollPos >= nMaxPos)
return;
nDelta = min(nMaxPos/10,nMaxPos-m_nScrollPos);
break;

case SB_THUMB nDelta = (int)nPos - m_nScrollPos;
break;

case SB_PAGEUP:
if (m_nScrollPos <= 0)
return;
nDelta = -min(nMaxPos/10,m_nScrollPos);
break;

default:
return;
}
m_nScrollPos += nDelta;
SetScrollPos(SB_VERT,m_nScrollPos,TRUE);
ScrollWindow(0,-nDelta);
CDialog::OnVScroll(nSBCode, nPos, pScrollBar);

}
void CMyDlg::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy);
m_nCurHeight = cy;
SCROLLINFO si;
si.cbSize = sizeof(SCROLLINFO);
si.fMask = SIF_ALL; // SIF_ALL = SIF_PAGE | SIF_RANGE | SIF_POS;
si.nMin = 0;
si.nMax = m_rect.Height();
si.nPage = cy;
si.nPos = 0;
SetScrollInfo(SB_VERT, &si, TRUE);
Invalidate(TRUE);
}
BOOL CMyDlg::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
{
int nMaxPos = m_rect.Height() - m_nCurHeight;
if (zDelta<0)
{
if (m_nScrollPos < nMaxPos)
{
zDelta = min(max(nMaxPos/20,5),nMaxPos-m_nScrollPos);

m_nScrollPos += zDelta;
SetScrollPos(SB_VERT,m_nScrollPos,TRUE);
ScrollWindow(0,-zDelta);
}
}
else
{
if (m_nScrollPos > 0)
{
zDelta = -min(max(nMaxPos/20,5),m_nScrollPos);

m_nScrollPos += zDelta;
SetScrollPos(SB_VERT,m_nScrollPos,TRUE);
ScrollWindow(0,-zDelta);
}
}

return CDialog::OnMouseWheel(nFlags, zDelta, pt);
}


Here m_rect is sum of size of all the child dialogs which are diaplayed(it means the contents size) not the dialog's client area.

Images


1306079.png

Now I scrolled to some position.

1306080.png

Now I maximized , but the child dialog with text implicit msg1 is missing.


1306081.png

Now I minimized , now also the child dialog with text implicit msg1 is missing in the dialog.

1306083.png

Continue reading...
 
Back
Top