CRectTracker & CScrollView

Intrebari legate de programarea cu biblioteci precum MFC, ATL, WTL si GDI+.
Post Reply
mesajflaviu
Membru++
Membru++
Posts: 687
Joined: 10 Sep 2008, 21:40
Judet: Cluj

CRectTracker & CScrollView

Post by mesajflaviu » 09 Aug 2010, 19:10

Am un CRectTracker pe care l-am folosit intr-un CScrollView . Cand dreptunghiul se muta pe view si iese din zona vizibila :

Code: Select all

void CTestTracker2View::OnLButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default

	CTestTracker2Doc* pDoc = GetDocument();

	if(pDoc->m_Tracker.HitTest(point) < 0)pDoc->m_Tracker.TrackRubberBand(this,point);
	else pDoc->m_Tracker.Track(this,point);

	CSize SizeTotal = GetTotalSize();
	if(SizeTotal.cx < pDoc->m_Tracker.m_rect.BottomRight().x)SizeTotal.cx = pDoc->m_Tracker.m_rect.BottomRight().x + 10;
	if(SizeTotal.cy < pDoc->m_Tracker.m_rect.BottomRight().y)SizeTotal.cy = pDoc->m_Tracker.m_rect.BottomRight().y + 10;
	SetScrollSizes(MM_TEXT,SizeTotal);

	Invalidate();

	CScrollView::OnLButtonDown(nFlags, point);
}
am pus cod pentru redimensionarea CScrollView-ului pentru a aparea scroll-urile . Functioneaza totul bine pana intr-o situatie : daca o parte a dreptunghiului desenat iese in afara zonei vizibile ( ma repet ) si se actioneaza scroll-ul , dreptunghiul nu respecta pozitia noua , ci isi mentine vechea pozitie , si ca sa fie si mai sugestiv am desenat dreptunghiul in rosu . Proiectul este atasat pentru exemplificare ...
Attachments
TestTracker2.rar
(86.14 KiB) Downloaded 300 times



User avatar
Ovidiu Cucu
Fondator
Fondator
Posts: 3778
Joined: 11 Jul 2007, 16:10
Judet: Iaşi
Location: Iasi
Contact:

Re: CRectTracker & CScrollView

Post by Ovidiu Cucu » 21 Aug 2010, 15:00

In primul rand, trebuie sa tii cont de pozitia scroll-ului atunci cand pictezi intr-un scroll view.
Poti rezolva asta modificand codul dupa cum urmeaza:

Code: Select all

class CRectTracker2
{
// ...
   void Draw(CDC* pDC, int X, int Y) const;
};

void CRectTracker2::Draw(CDC* pDC, int X, int Y) const
{
// ...
   CRect rcFill(m_rect);
   rcFill.OffsetRect(X, Y);
   pDC->FillSolidRect(rcFill, m_cRectColor);
}

void CTestTracker2View::OnDraw(CDC* pDC)
{
// ...
   CPoint point = GetScrollPosition();
   pDoc->m_Tracker.Draw(pDC, point.x, point.y);
}

Post Reply