Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Need some help on how to create a Line and how to move that line using mouse options

Need some help on how to create a Line and how to move that line using mouse options

Scheduled Pinned Locked Moved C / C++ / MFC
c++helptutorialquestion
7 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    John502
    wrote on last edited by
    #1

    Hello, This is Venkatesh, I am working on VC++ (MFC). Currently i am working on one application which deals with the graphs and lines. i want to create one line and have to move (drag) that line horizotally from one end to other using mouse. Can any one help me out regarding this...? Any help would be much appreciated, because as it is very urgent requirement for me.. Thanks Venkatesh. :)

    H PJ ArendsP B 3 Replies Last reply
    0
    • J John502

      Hello, This is Venkatesh, I am working on VC++ (MFC). Currently i am working on one application which deals with the graphs and lines. i want to create one line and have to move (drag) that line horizotally from one end to other using mouse. Can any one help me out regarding this...? Any help would be much appreciated, because as it is very urgent requirement for me.. Thanks Venkatesh. :)

      H Offline
      H Offline
      Hamid Taebi
      wrote on last edited by
      #2

      You need to declare WM_MOUSEMOVE and WM_LBUTTONUP/DOWN and you need to get current postion of mouse with GetCursorPos and then you can use of LineTo/MoveTo.

      Of one Essence is the human race thus has Creation put the base One Limb impacted is sufficient For all Others to feel the Mace (Saadi )

      J 1 Reply Last reply
      0
      • J John502

        Hello, This is Venkatesh, I am working on VC++ (MFC). Currently i am working on one application which deals with the graphs and lines. i want to create one line and have to move (drag) that line horizotally from one end to other using mouse. Can any one help me out regarding this...? Any help would be much appreciated, because as it is very urgent requirement for me.. Thanks Venkatesh. :)

        PJ ArendsP Offline
        PJ ArendsP Offline
        PJ Arends
        wrote on last edited by
        #3

        In addition to what Hamid said, you will also have to set the raster operation code to R2_XORPEN when you draw your line. Doing so you will be able to draw the line once to show the line, and then draw it again in the same spot to erase the line. Use CDC::SetROP2(R2_XORPEN) in your drawing code.


        You may be right I may be crazy -- Billy Joel -- Within you lies the power for good - Use it!

        Within you lies the power for good; Use it!

        J 1 Reply Last reply
        0
        • J John502

          Hello, This is Venkatesh, I am working on VC++ (MFC). Currently i am working on one application which deals with the graphs and lines. i want to create one line and have to move (drag) that line horizotally from one end to other using mouse. Can any one help me out regarding this...? Any help would be much appreciated, because as it is very urgent requirement for me.. Thanks Venkatesh. :)

          B Offline
          B Offline
          bob16972
          wrote on last edited by
          #4

          You can use Rubberbanding[^] to create the line. (Ivor Horton is the best author to reference for sample graphics applications using MFC :) ) To interact with it you could simply use CRectTracker with a few modifications if you don't mind a simple rectangular hit test region. This is more than adequate for forms based line manipulations since a good portion or the lines will be vertical or horizontal. If you need more advanced hit testing that is not restricted to a rectangle, such as for an advanced graphics application, then you will likely need to roll your own tracker class.

          J 1 Reply Last reply
          0
          • H Hamid Taebi

            You need to declare WM_MOUSEMOVE and WM_LBUTTONUP/DOWN and you need to get current postion of mouse with GetCursorPos and then you can use of LineTo/MoveTo.

            Of one Essence is the human race thus has Creation put the base One Limb impacted is sufficient For all Others to feel the Mace (Saadi )

            J Offline
            J Offline
            John502
            wrote on last edited by
            #5

            Thanks Hamid ,thanks for your valuable reply.

            1 Reply Last reply
            0
            • PJ ArendsP PJ Arends

              In addition to what Hamid said, you will also have to set the raster operation code to R2_XORPEN when you draw your line. Doing so you will be able to draw the line once to show the line, and then draw it again in the same spot to erase the line. Use CDC::SetROP2(R2_XORPEN) in your drawing code.


              You may be right I may be crazy -- Billy Joel -- Within you lies the power for good - Use it!

              J Offline
              J Offline
              John502
              wrote on last edited by
              #6

              Thanks Arends ,thanks for your valuable reply.

              1 Reply Last reply
              0
              • B bob16972

                You can use Rubberbanding[^] to create the line. (Ivor Horton is the best author to reference for sample graphics applications using MFC :) ) To interact with it you could simply use CRectTracker with a few modifications if you don't mind a simple rectangular hit test region. This is more than adequate for forms based line manipulations since a good portion or the lines will be vertical or horizontal. If you need more advanced hit testing that is not restricted to a rectangle, such as for an advanced graphics application, then you will likely need to roll your own tracker class.

                J Offline
                J Offline
                John502
                wrote on last edited by
                #7

                Thanks bob, Thanks for spending your valuable time for getting me to the conclusion page.

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups