Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VC10.0
I had implemented a CRectTracker in Scrollview. The problem is the tracker works fine without scrolling. But when I scroll the window the tracker disappears. Could anyone give suggestions to solve my problem.
CFinalPDoc* pDoc = GetDocument();
tracker.m_nStyle = CRectTracker::dottedLine^CRectTracker::resizeOutside;		
//if not hitting any handle
  if(tracker.HitTest(point)<0)
  {
    //if mouse move and rectangle is not empty
    if(tracker.TrackRubberBand(this,point))
    {
      RedrawWindow();
      //make width and height positive and set trackerRect
      tracker.m_rect.NormalizeRect(); 
      trackerRect = &tracker.m_rect;
      //show resize handles
      tracker.GetHandleMask(); 
      //draw rectangle
      CClientDC dc(this);
      tracker.Draw(&dc);
    }
    else //no rubber band
    {
      //make width and height positive and set trackerRect
      tracker.m_rect.NormalizeRect();
      trackerRect = &tracker.m_rect;
			
      ((CStatic*)GetDlgItem(IDC_PICTURE))->SetBitmap(*currentBmp); 
    }
  }
Posted 25-Aug-11 18:35pm
Edited 25-Aug-11 21:58pm
CPallini328.8K
v4
Comments
SAKryukov at 26-Aug-11 1:34am
   
Not enough information. Use "Improve question" above. Consider making the simplest possible code sample which can demonstrate the problem and post it.
--SA
mbue at 26-Aug-11 4:59am
   
can you improve your question by showing the code for tracker.Draw? if you are painting the rect by DrawFocusRect or xor brush you should set the brushs origin by SetBrushOrg.
regards.
Priyarao14 at 30-Aug-11 23:26pm
   
I have written the code above in OnLButtonDown and set the OnSetCursor. It works fine without scrolling. But when I scroll the tracker disappears. I think the problem is because of not writing any code in OnDraw(CDC* pDC).

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Probably,
the mouse click sholud set the element's marking flag only...
...then, in your CXXXView::OnDraw(CDC*), you could use the flag
to draw the tracker arount the marked element(s) Smile | :)
 
/*afx_msg*/ void CYourView::OnMouseDown(UINT uiFlags, CPoint point)
{
  CPoint cptAbsoluteViewPosition(point + GetScrollPosition());
  CYourDoc* pcDoc(GetDocument);
  if (pcDoc) {
    CYourDocElementBase* pcElement(pcDoc->FindElementByPos(cptAbsoluteViewPosition));
    if (pcElement) {
      pcElement->SetMarked(true);
      Invalidate();
    }
  }
  CScrollView::OnMouseDown(uiFlags, point);
}
 
/*virtual*/ void CYourView::OnDraw(CDC* pDC)
{
  //..
  POSITION pos(pcDoc->GetFirstElementPos());
  while (pos) {
    CYourDocElementBase* pcElement(pcDoc->GetNextElement(pos));
    if (pcElement) {
      CRect crElement(pcElement->GetElemRect());
      if (/*IsElemRectClipped(pDC, crElement)*/) {
        pcElement->Draw(pDC);
        if (pcElement->IsMarked()) {
          // use the crElement to draw the tracker there :)
        }
      }
    }
  }
  //..

}
  Permalink  
v3
Comments
Priyarao14 at 26-Aug-11 3:37am
   
I think u r directing me in a different way. Could u provide some sample related to my code.
Eugen Podsypalnikov at 26-Aug-11 3:41am
   
Not sure, sory...
I think, only the drawing in the context of OnDraw(..) will "repare" the tracker after the scrolling :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 400
1 Jochen Arndt 190
2 Richard MacCutchan 135
3 DamithSL 95
4 Garth J Lancaster 90
0 OriginalGriff 6,045
1 DamithSL 4,601
2 Maciej Los 4,032
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,220


Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 26 Aug 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100