Click here to Skip to main content
13,046,176 members (69,589 online)
Rate this:
Please Sign up or sign in to 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.
CFinalPDoc* pDoc = GetDocument();
tracker.m_nStyle = CRectTracker::dottedLine^CRectTracker::resizeOutside;		
//if not hitting any handle
    //if mouse move and rectangle is not empty
      //make width and height positive and set trackerRect
      trackerRect = &tracker.m_rect;
      //show resize handles
      //draw rectangle
      CClientDC dc(this);
    else //no rubber band
      //make width and height positive and set trackerRect
      trackerRect = &tracker.m_rect;
Posted 25-Aug-11 17:35pm
Updated 25-Aug-11 20:58pm
SAKryukov 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.
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.
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

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

Solution 1

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

/*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) {
  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)*/) {
        if (pcElement->IsMarked()) {
          // use the crElement to draw the tracker there :)
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 26 Aug 2011
Copyright © CodeProject, 1999-2017
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