+ 5
Creating a Line in Paint...
In MS - Paint, creating a straight line is simply done by pressing shift and moving the mouse to the required length. I wish to create a similar function in my ASCII Paint Program. I thought of the following... 0) Read the Starting cursor position when the user presses the SHIFT Key and the Mouse Button. 1) If the user presses the left Shift, keep the Y coordinate constant. 2) Paint the line keeping X const or Y const. But in this approach, the X is read on each movement. So, how to achieve my goal?
20 Respostas
+ 7
@Kinshuk. You will have to create a WndProc function to handle messages. You might find some tips here:
https://social.msdn.microsoft.com/Forums/vstudio/en-US/ef5a76cd-966b-4cf3-a05e-7b809918cedc/message-handling-in-a-console-app?forum=vcgeneral
And here:
https://stackoverflow.com/questions/41311474/how-to-register-wndproc-in-console-app
But the important part is the drawing and you will have to use GDI to draw a line which you can find some info on here:
https://www.daniweb.com/programming/software-development/code/216430/add-a-little-graphics-to-your-console
+ 8
@Karl T.
I tried a similar approach without the DrawLine Function. I first read the coord of the place where the mouse was first pressed and simultaneously shift was pressed. Then I stored that index and used it to get a coordpos for the CHAR_INFO array for updating.
But the problem I faced was that the stored coord was getting updated on each movement of the mouse with the left button pressed. Maybe my. approach wasn't able to distinguish between a starting click and holding of a button...
Ill try again...
+ 8
Yeah make sure you store the clicked coordinates separately from the current mouse movement coordinates.
+ 7
You don't even need to use a shift key. You just need to detect a mouse down message and get the original clicked x y coordinates. Then you detect a mouse move message with current coords x2 y2 and update the line drawing using DrawLine(x,y,x2,y2) from a HDC (from GDI lib)
I suggest you get acquainted with common Win32 functions and message handling first...such as mouse clicks.
https://msdn.microsoft.com/en-us/library/windows/desktop/gg153548(v=vs.85).aspx
+ 6
https://code.sololearn.com/cAlNxwpPFqST/?ref=app
Here I use FinalY to save the Y coordinate when Shift is pressed...
This will be line 577...
But It changes when I move the mouse, and continue keeping shift pressed. I want that to remain const...
+ 6
Why don't you use device context line drawing functions?
+ 6
@Karl T.
Ill try implementing that. Thank You!
+ 6
@Jay
Not yet... I am still trying to find a way without using translatemessage, dispatchmessage, etc...
I wish to rely only on INPUT_RECORD, but as I move on, it seems that this will not be possible...
+ 6
Supercool idea. Cant wait to see the results.
I was only doing mine as an image editor for an ascii game. I gave up on that idea and decided just to do in sdl 😴
+ 5
it should be possible.. . i made a program almost exactly the same but didnt bother with lines. i will revisit it and see if i can do it. its 3am here atm.. otherwise i would look now.
in my version i kept the pixels in memory (1D array) at all times so working with screen data is really straight forward.
+ 5
@jay
All I need is a way to forcefully fix the Y coordinate and Im done. But WM_MOUSEMOVE is a Message, and currently I don't read messages in my code.
Now, Ill either redefine the code completely for reading messages as cases or write seperate code for the Line Drawing part.
+ 5
@Karl T.
Thank You for the info. I want ascii lines in this version of paint, and so will create a GDI version seperately. That will also offer fill, ellipses, circles, rectangles, etc...
+ 4
you should use WinAPI functions
+ 4
No, unfortunately not.
+ 4
did you solve this?
+ 3
Which one? Im currently using Buf.Event.MouseEvent.dwMousePosition.Y for the position and GetKeyState for the key event .
+ 3
Is that working?
+ 3
could i see your code?
+ 3
I also need this program 😅
But I'll be making it in Java
+ 2
I'd love to have this program!
I'm working on a program that would compliment this