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.
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.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
Windows XP / Dev-C++ / none
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 }
"Think not but that I know these things; or think
I know them not: not therefore am I short
Of knowing what I ought."
-John Milton, Paradise Regained (1671)
"Work hard and it might happen."
-XSquared
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.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
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?