Is there a way to get a program to draw a line between two points?
Any simple tutorials on the web would be very useful.
Printable View
Is there a way to get a program to draw a line between two points?
Any simple tutorials on the web would be very useful.
here's one - wether or not this is what you are looking for
http://www.cprogramming.com/tutorial/tut3.html
Anyone else?
Well you could start with which OS / Compiler / graphics library you're using.
Windows XP / Dev-C++ / none
So far I have this:
http://www.adrianxw.dk/SoftwareSite/...Consoles3.html
Here's a little example using LineTo (must use windows 2000 or later):
Code:#define _WIN32_WINNT 0x0500 //specifies the windows version is windows 2000 (to use GetConsoleWindow)
#include <windows.h>
#include <iostream>
int main()
{
HWND hwnd = GetConsoleWindow();
if (!hwnd)
std::cout<<"Error getting console window handle!";
HPEN hPen = CreatePen(PS_SOLID,5,RGB(255,255,255)); //create a solid white pen of width 5
HDC hdc = GetDC(hwnd); //get the device context
SelectObject(hdc,hPen); //select white pen
MoveToEx(hdc,0,0,NULL); //move to 0,0
LineTo(hdc,100,100); //draw from 0,0 to 100,100
ReleaseDC(hwnd,hdc); //release the device context
DeleteObject(hPen); //delete the pen
}
When tryign to compile that i get:
implicit declaration of function `int GetConsoleWindow(...)'
initialization to `HWND__ *' from `int' lacks a cast
What do those errors mean?
> implicit declaration of function `int GetConsoleWindow(...)'
Either you spelt it wrong, or you're not including the correct header files.
Well I just copied that code into a new source file.
Go to the menu...
File>new>project>windows application>
Type in a name for your file. Then copy and paste your code in there.
Does it need to be put in with all the stuff about making a window?
No try jawib's code on its own.
Why doesn't it work then?