-Se da o aplicatie tip MDI in care incarc o imagine dintr-un fisier, imaginea deschizandu-se intr-o fereastra child.
-Am facut ca imaginea sa se deschida/pastreze tot timpul centrata pe mijlocul ferestrei child cind fereastra se redimensioneaza, iar cand dimensiunea ferestrei este mai mica ca imaginea, am facut sa apara scrollbar-ul vertical/orizontal, iar aceste scrollbar-uri vor apare de asemeni centrate pe mijlocul ferestrei din cauza ca si imaginea va fi tot pe mijloc.
-Problema e ca atunci cand fac scroll imaginea nu-si mai face update, apar niste linii in locul unde ar trebui sa apara imaginea scroll-ata.Am incercat eu sa-i fac niste update-uri la imagine dar fara efect.Am atasat si-o imagine in sensul asta + niste bucati de cod mai reprezentativ din clasa Child.
Merci.
Code: Select all
void CChildFrame::OnSize(UINT u, int x, int y)
{
CMDIChildWnd::OnSize(u, x, y);
cx = x;
cy = y;
m_nViewWidth = CImageEditorDoc::x;
m_nViewHeight = CImageEditorDoc::y;
//////////////////////////
//////////////////////////
//
// Set the horizontal scrolling parameters.
//
int nHScrollMax = 0;
m_nHScrollPos = m_nHPageSize = 0;
if (cx < m_nViewWidth)
{
nHScrollMax = m_nViewWidth - 1;
m_nHPageSize = cx;
m_nHScrollPos = /*min (m_nHScrollPos,*/ (m_nViewWidth - m_nHPageSize - 1) / 2;
}
SCROLLINFO si;
si.fMask = SIF_PAGE | SIF_RANGE | SIF_POS;
si.nMin = 0;
si.nMax = nHScrollMax;
si.nPos = m_nHScrollPos;
si.nPage = m_nHPageSize;
SetScrollInfo (SB_HORZ, &si, TRUE);
//
// Set the vertical scrolling parameters.
//
int nVScrollMax = 0;
m_nVScrollPos = m_nVPageSize = 0;
if (cy < m_nViewHeight)
{ //if the client area height is less than the workspace height then execute
nVScrollMax = m_nViewHeight - 1;
m_nVPageSize = cy; // sets VPageSize to the client areas height
m_nVScrollPos = /*min (m_nVScrollPos,*/ (m_nViewHeight - m_nVPageSize - 1) / 2;
}
si.fMask = SIF_PAGE | SIF_RANGE | SIF_POS;
si.nMin = 0;
si.nMax = nVScrollMax;
si.nPos = m_nVScrollPos;
si.nPage = m_nVPageSize;
SetScrollInfo (SB_VERT, &si, TRUE);
}
void CChildFrame::OnPaint () // this is the paint command.
{
CPaintDC dc (this); // creates a paint device context.
dc.UpdateColors();
/* dc.SetWindowOrg (m_nHScrollPos, m_nVScrollPos);
CBrush brush (HS_DIAGCROSS, RGB (255,0,0)); // sets the criscrosses to bright red.
dc.SelectObject (&brush); //selects the brush into the DC (device context)
dc.SetBkColor (RGB (0,0,0)); // sets the background color to BLACK
dc.Rectangle (0,0,300,300);//Draws a rectangle that is 10000 by 10000
*/
}
void CChildFrame::OnHScroll (UINT nCode, UINT nPos, CScrollBar* pScrollBar)
{
int nDelta;
//
// Compute the horizontal scroll distance, or "delta."
//
switch (nCode) {
case SB_LINELEFT:
nDelta = -LINESIZE;
break;
case SB_PAGELEFT:
nDelta = -m_nHPageSize;
break;
case SB_THUMBTRACK:
nDelta = (int) nPos - m_nHScrollPos;
break;
case SB_PAGERIGHT:
nDelta = m_nHPageSize;
break;
case SB_LINERIGHT:
nDelta = LINESIZE;
break;
default: // Ignore other scroll bar messages
return;
}
//
// Adjust the delta if adding it to the current scroll position would
// cause an underrun or overrun.
//
int nScrollPos = m_nHScrollPos + nDelta;
int nMaxPos = m_nViewWidth - m_nHPageSize;
if (nScrollPos < 0)
nDelta = -m_nHScrollPos;
else if (nScrollPos > nMaxPos)
nDelta = nMaxPos - m_nHScrollPos;
//
// Update the scroll position and scroll the window.
//
if (nDelta != 0)
{
m_nHScrollPos += nDelta;
SetScrollPos (SB_HORZ, m_nHScrollPos, TRUE);
ScrollWindow (-nDelta, 0);
}
}
//************************************************************************
//************************************************************************
//************************************************************************
void CChildFrame::OnVScroll (UINT nCode, UINT nPos, CScrollBar* pScrollBar)
{
int nDelta;
//
// Compute the vertical scroll distance, or "delta."
//
switch (nCode) {
case SB_LINEUP:
nDelta = -LINESIZE;
break;
case SB_PAGEUP:
nDelta = -m_nVPageSize;
break;
case SB_THUMBTRACK:
nDelta = (int) nPos - m_nVScrollPos;
break;
case SB_PAGEDOWN:
nDelta = m_nVPageSize;
break;
case SB_LINEDOWN:
nDelta = LINESIZE;
break;
default: // Ignore other scroll bar messages
return;
}
//
// Adjust the delta if adding it to the current scroll position would
// cause an underrun or overrun.
//
int nScrollPos = m_nVScrollPos + nDelta;
int nMaxPos = m_nViewHeight - m_nVPageSize;
if (nScrollPos < 0)
nDelta = -m_nVScrollPos;
else if (nScrollPos > nMaxPos)
nDelta = nMaxPos - m_nVScrollPos;
//
// Update the scroll position and scroll the window.
//
if (nDelta != 0)
{
m_nVScrollPos += nDelta;
SetScrollPos (SB_VERT, m_nVScrollPos, TRUE);
ScrollWindow (0, -nDelta);
}
}