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