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. How do I Dynamically Draw Lines with the Mouse

How do I Dynamically Draw Lines with the Mouse

Scheduled Pinned Locked Moved C / C++ / MFC
graphicsquestionjsonperformancetutorial
4 Posts 3 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.
  • A Offline
    A Offline
    Anonymous
    wrote on last edited by
    #1

    I am currently trying to write a simple program that allows the user to click in the "view" to define the start of a line, draw a line from the start to the mouse (where ever the mouse moves to and while it moves) and then complete the line when the user clicks in the view again. The only hangup that I'm having is that after I click in the view and begin to move the mouse, I end up drawing lines to everywhere the mouse goes and eventually the screen looks a mess with lines all over it. I understand why this happens, I just don't know how not to make it happen. In psuedocode, my code goes something like this. OnLButtonDown CreateStartPoint GetScreenCoord OnMouseMove(POINT point) LineTo(StartPoint, point) OnLButtonDown CreateEndPoint GetScreenCoord LineTo(StartPoint,EndPoint) I'm missing something to "brush" over the old mouse position each time OnMouseMove is called. I've looked at some sample code but haven't been able to get it to work. Other samples have mentioned using Memory DC's and Storing the view as a Bitmap. Anyone out there got a simple solution? I'm fairly confident that once someone explains how to accomplish this, I'll be able to figure out the rest. Thanks

    P C 2 Replies Last reply
    0
    • A Anonymous

      I am currently trying to write a simple program that allows the user to click in the "view" to define the start of a line, draw a line from the start to the mouse (where ever the mouse moves to and while it moves) and then complete the line when the user clicks in the view again. The only hangup that I'm having is that after I click in the view and begin to move the mouse, I end up drawing lines to everywhere the mouse goes and eventually the screen looks a mess with lines all over it. I understand why this happens, I just don't know how not to make it happen. In psuedocode, my code goes something like this. OnLButtonDown CreateStartPoint GetScreenCoord OnMouseMove(POINT point) LineTo(StartPoint, point) OnLButtonDown CreateEndPoint GetScreenCoord LineTo(StartPoint,EndPoint) I'm missing something to "brush" over the old mouse position each time OnMouseMove is called. I've looked at some sample code but haven't been able to get it to work. Other samples have mentioned using Memory DC's and Storing the view as a Bitmap. Anyone out there got a simple solution? I'm fairly confident that once someone explains how to accomplish this, I'll be able to figure out the rest. Thanks

      P Offline
      P Offline
      Prakash Nadar
      wrote on last edited by
      #2

      There is a sample project called as DRAW that comes with VC installation. This project will provide all the inputs needed for ur application.


      MSN Messenger. prakashnadar@msn.com

      A 1 Reply Last reply
      0
      • A Anonymous

        I am currently trying to write a simple program that allows the user to click in the "view" to define the start of a line, draw a line from the start to the mouse (where ever the mouse moves to and while it moves) and then complete the line when the user clicks in the view again. The only hangup that I'm having is that after I click in the view and begin to move the mouse, I end up drawing lines to everywhere the mouse goes and eventually the screen looks a mess with lines all over it. I understand why this happens, I just don't know how not to make it happen. In psuedocode, my code goes something like this. OnLButtonDown CreateStartPoint GetScreenCoord OnMouseMove(POINT point) LineTo(StartPoint, point) OnLButtonDown CreateEndPoint GetScreenCoord LineTo(StartPoint,EndPoint) I'm missing something to "brush" over the old mouse position each time OnMouseMove is called. I've looked at some sample code but haven't been able to get it to work. Other samples have mentioned using Memory DC's and Storing the view as a Bitmap. Anyone out there got a simple solution? I'm fairly confident that once someone explains how to accomplish this, I'll be able to figure out the rest. Thanks

        C Offline
        C Offline
        Christopher Lloyd
        wrote on last edited by
        #3

        An easy solution is to use an XOR pen. When you draw your line it'll be XORed with whatever is already on the screen. When the mouse moves draw the previous line again using the XORed pen (this will remove the previous line) and then draw the new line, again using the XORed pen. This works because XOR is it's own inverse. To actually code this you'll need to use the api function SetROP2 before drawing. This determines how GDI merges pens (and some other drawing objects too) with what's already on the screen. The only disadvantge is that an XOR pen isn't a solid colour, rather it appears as the inverse of the colour on the screen. Of course, this might actually be a good thing as it ensures your line is always visible no matter what you draw over. Hope that helps.

        1 Reply Last reply
        0
        • P Prakash Nadar

          There is a sample project called as DRAW that comes with VC installation. This project will provide all the inputs needed for ur application.


          MSN Messenger. prakashnadar@msn.com

          A Offline
          A Offline
          Anonymous
          wrote on last edited by
          #4

          I don't have a "DRAW" sample. I have a "DRAWCLI" sample. If these are the same then I know what you're talking about. However, the code isn't very portable and is way to complex for what I'm trying to do. The DRAWCLI sample uses OLE and ties the drawtool objects into the drawview cview so tightly that it becomes very difficult to pull just the drawtool object into a project and put it to use. Eventually I suppose I could trim the code down and disect it to where it fit my needs.

          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