Anyone have a simple line drawing program?
-
Hi. Does anyone have a simple C++ program that I can use to draw lines on a PC display? I would like something that I could just pass x and y start and end points, and have it plot a line. I have Microsoft Visual C++. version 4.0. I am not a professional programmer, so I would also appreciate an example of how this code could be called from the main program. Thank you. Bill
-
Hi. Does anyone have a simple C++ program that I can use to draw lines on a PC display? I would like something that I could just pass x and y start and end points, and have it plot a line. I have Microsoft Visual C++. version 4.0. I am not a professional programmer, so I would also appreciate an example of how this code could be called from the main program. Thank you. Bill
Hi Bill, I would say that it depends partly on the OS being used. Is it Windows 9X, NT (or greater), or DOS, etc. If it's Windows, there are API functions available that are as simple to use as:
pDC->MoveTo(x1, y1); pDC->LineTo(x2, y2);
Which together will draw a line starting at (x1, y1) and ending at (x2, y2). Are you familiar with these kinds of functions? Also, check out http://www.codeproject.com/gdi/[^] If you haven't seen these articles yet, there are a bunch of good ones, and some are marked as 'Beginner'. In particular, check out: http://www.codeproject.com/gdi/dcdrawing.asp[^] Drawing took me some getting used to (I'm also far from a pro programmer) but after a few practice programs you'll get the hang of drawing in Windows. Best, Eric -
Hi Bill, I would say that it depends partly on the OS being used. Is it Windows 9X, NT (or greater), or DOS, etc. If it's Windows, there are API functions available that are as simple to use as:
pDC->MoveTo(x1, y1); pDC->LineTo(x2, y2);
Which together will draw a line starting at (x1, y1) and ending at (x2, y2). Are you familiar with these kinds of functions? Also, check out http://www.codeproject.com/gdi/[^] If you haven't seen these articles yet, there are a bunch of good ones, and some are marked as 'Beginner'. In particular, check out: http://www.codeproject.com/gdi/dcdrawing.asp[^] Drawing took me some getting used to (I'm also far from a pro programmer) but after a few practice programs you'll get the hang of drawing in Windows. Best, Eric -
Thanks for the information, Eric! I will be running Windows XP. Can those APIs be used stand-alone, or do I have to use some sort of class thing? What inculdes do I have to put into my programs? Do you have a simple example? Again, thanks! Bill
Hi Bill, To answer about the APIs: They are available for your use in a program without creating additional classes, they are supplied as part of Windows and your VC++ 4 compiler should let you write programs that call them. About the includes: To be honest, I'm not sure of the actual #includes needed to access them. The reason is that I take it for granted that they will be provided automatically by App Wizard (the tool provided in VC++) when I create the program skeleton. Are you familiar with using App Wizard to generate a program skeleton? This will help answer about a sample program. Best, Eric