Line tracker class similar to CRectTracker


Desktop-as-a-Service Designed for Any Cloud ? Nutanix Frame

Line tracker class (KLineTracker) that I present here performs dragging and resizing of lines with left mouse button. It does for lines the same thing CRectTracker does for rectangles.

When I needed to add to my application possibility to draw, move and resize lines using mouse, I looked for line tracker class in MFC. Because I used CRectTracker for resizing and moving rectangles, I expected to see CLineTracker for moving and resizing lines. But unfortunately I did not find one. Then I went to the Internet (Deja News, Alta Vista, InfoSeek, etc.), but they did not give me the answer too. The only thing I saw were requests for line tracker class from other people.

In the end, I decided to write line tracker class myself. I choose name KLineTracker instead of CLineTracker, so that if CLineTracker class will be sometimes added to MFC, my program will not run into clash.

Usage of the class is very similar to that of CRectTracker. Details should be obvious from the demo project (look at TrackerWnd.cpp). Suggessions for changes, improvements and bug reports are welcome. Although, I don't promise to fix all the bugs fast :-).

Download demo project - 42 KB

Download source - 4 KB


  • How can I use it with CScrollView?

    Posted by Legacy on 06/18/2003 07:00am

    Originally posted by: Tran Cong Khanh

    KLineTracker class is great!. But it doesn't care about scrolling. So when using it with CScollView, what additional code I must add?

  • i thik KLineTracker can be created dynamically.

    Posted by Legacy on 01/20/2002 08:00am

    Originally posted by: JinSoo

    Hello!!! Ivan.

    My name is JinSoo.

    I am Korean. I am now using your KLineTracker From CodeGuru.

    when i create dynamically the KLineTracker , A Strange thing occured.

    and when i also delete the KLineTracker. An Error occured.

    i thik KLineTracker can be created dynamically.

    I hope you thai i can create and delete dynamically the KLineTracker.

    please, have a nice day. and Good Answer !!!

  • Would't it be great if it was resizable ?

    Posted by Legacy on 07/21/1999 07:00am

    Originally posted by: George Sgouros

    First of all congratulations to Ivan for this excellent
    piece of code.

    I only have a request :

    I really need this control to be resizable.
    If the control had something like an OnSize handler
    AND it could use the client area of a Static control,
    then I guess everything would not be so difficult
    (I could use cdxCSizingDialog classes (described elswhere in Code Guru ) to resize the static control and hopefully
    the line tracker control should resize as well.

    However , being a newbie, I cannot yet add this functionality on my own.

    To be more specific :
    1. I cannot make TrackerWnd use the client area of a static control that is binded with a CStatic variable (I get an assertion during subclassing. CStatic variable declaration is necessary for using cdx... resizing classes)

    2. I do not know what exactly should I write inside the OnSize() handler.

    So, any suggestions on this issues would be highly appreciated.

    Best regards


  • BUG: when input canceled, temp rubber line stays visible

    Posted by Legacy on 06/22/1999 07:00am

    Originally posted by: Vadim Mikhailov

    in LineTracker.cpp about 311 line
    // 8<-----------
    // handle cancel messages
    case WM_KEYDOWN:
    if (msg.wParam == VK_ESCAPE)
    bCanceled = TRUE;
    bExit = TRUE;

    bCanceled = TRUE;
    bExit = TRUE;
    // 8<-----------

    // 8<-----------
    // handle cancel messages
    case WM_KEYDOWN:
    if (msg.wParam == VK_ESCAPE)
    bCanceled = TRUE;
    bExit = TRUE;
    dc.MoveTo(CurPos.Begin );
    dc.LineTo( CurPos.End );
    // 8<-----------

    bCanceled = TRUE;
    bExit = TRUE;
    dc.MoveTo( CurPos.Begin );
    dc.LineTo( CurPos.End );

  • Not release GDI resourses

    Posted by Legacy on 04/03/1999 08:00am

    Originally posted by: Fabian

    Actully if you are using
    the correct way should be

    int oldDC = pDC->SaveDC();



    and also the GDI objects should be delete to avoid resuorces leaking


    Anyway, the KLineTracker is very nice and handy.
    Thank Ivan.


  • when line is moved, original line is erased.

    Posted by Legacy on 03/08/1999 08:00am

    Originally posted by: Kang Seung Bum

    When LineTracker is moving, or resizing, original line is erased!!
    Is there solution?

  • No viruses reported in Demo project when checked by McAfee NTScan

    Posted by Legacy on 11/14/1998 08:00am

    Originally posted by: Ivan Krivyakov

    When I seen the comment about the virus, 
    I re-checked Demo project with McAfee NTScan 3.2.0,
    virus data file V3108. It did not detect any viruses.
    As far as I know, V3108 is the latest data file
    available from McAfee.

    If you are still afraid of virus, you can download
    Demo project without running its EXE file. Because
    Demo project contains all the sources, you can
    re-create EXE file using your compiler.

    Ivan Krivyakov, software engineer

  • WebScan alert for a virus on .EXE file

    Posted by Legacy on 11/13/1998 08:00am

    Originally posted by: Davide Zaccanti

    I don't known if this is true, but I've avoided to download demo project.

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date