Click here to Skip to main content
15,891,372 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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.
C++
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
Updated 25-Aug-11 20:58pm
v4
Comments
Sergey Alexandrovich Kryukov 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 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 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

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) :)

C++
/*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 :)
        }
      }
    }
  }
  //..

}
 
Share this answer
 
v3
Comments
Priyarao14 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 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900