A Line

This is a discussion on A Line within the C++ Programming forums, part of the General Programming Boards category; Is there a way to get a program to draw a line between two points? Any simple tutorials on the ...

  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    545

    A Line

    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.

  2. #2
    Registered User CorvusVita's Avatar
    Join Date
    Apr 2006
    Location
    Yorkshire
    Posts
    5
    here's one - wether or not this is what you are looking for

    http://www.cprogramming.com/tutorial/tut3.html

  3. #3
    Registered User
    Join Date
    Nov 2005
    Posts
    545
    Anyone else?

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,484
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Registered User
    Join Date
    Nov 2005
    Posts
    545
    Windows XP / Dev-C++ / none

  6. #6
    Registered User
    Join Date
    Nov 2005
    Posts
    545

  7. #7
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    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

  8. #8
    Registered User
    Join Date
    Nov 2005
    Posts
    545
    When tryign to compile that i get:

    implicit declaration of function `int GetConsoleWindow(...)'

    initialization to `HWND__ *' from `int' lacks a cast

  9. #9
    Registered User
    Join Date
    Nov 2005
    Posts
    545
    What do those errors mean?

  10. #10
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,484
    > 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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  11. #11
    Registered User
    Join Date
    Nov 2005
    Posts
    545
    Well I just copied that code into a new source file.

  12. #12
    Super Moderater.
    Join Date
    Jan 2005
    Posts
    374
    Go to the menu...


    File>new>project>windows application>

    Type in a name for your file. Then copy and paste your code in there.

  13. #13
    Registered User
    Join Date
    Nov 2005
    Posts
    545
    Does it need to be put in with all the stuff about making a window?

  14. #14
    Super Moderater.
    Join Date
    Jan 2005
    Posts
    374
    No try jawib's code on its own.

  15. #15
    Registered User
    Join Date
    Nov 2005
    Posts
    545
    Why doesn't it work then?

Page 1 of 3 123 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to do encryption in C
    By sankarv in forum C Programming
    Replies: 33
    Last Post: 12-28-2010, 10:01 AM
  2. Reading a file line by line
    By Raskalnikov in forum C Programming
    Replies: 8
    Last Post: 03-18-2009, 11:44 PM
  3. Pointer and Polymorphism help.
    By Skyy in forum C++ Programming
    Replies: 29
    Last Post: 12-18-2008, 08:17 PM
  4. Printing Length of Input and the Limited Input
    By dnguyen1022 in forum C Programming
    Replies: 33
    Last Post: 11-29-2008, 03:13 PM
  5. Finding carriage returns (\c) in a line
    By JizJizJiz in forum C++ Programming
    Replies: 37
    Last Post: 07-19-2006, 05:44 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21