Drawing Lines

This is a discussion on Drawing Lines within the C++ Programming forums, part of the General Programming Boards category; Hi there. I'm new to the forum so go easy on me. I've tried researching this but don't seem to ...

  1. #1
    Registered User
    Join Date
    Dec 2007
    Posts
    3

    Drawing Lines

    Hi there. I'm new to the forum so go easy on me.

    I've tried researching this but don't seem to be able to find an (appropiate) answer.

    I want to write a program that will ask the user for x and y (coordinate) values and draw a line between these values.

    I've posted on another forum but didn't really get anywhere. Long story.

    I downloaded MS Visual C++ 9.0 Express Edition recently and was using that, but was told (the other forum) that I'd need the MFC which it doesn't have. I also have Visual C++ 6.0 from a few years back. With this I am able to create a Windows based program and manipulate the toolbars to produce my own commands and dialog boxes.

    However, no where on the web can I find code (that works!) to display a line. Actually show the line. Not as some websites show, a series of x's across the screen. Kind of a very basic CAD program.

    Can this be done in C++. I suppose that is really my first question.
    My second? If not, what should I be using.
    Thanks for your time.
    Alan.

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    You'll want to use these function:
    http://msdn2.microsoft.com/en-us/library/ms534260.aspx

    Or possibly, sometimes, these will be useful:
    http://msdn2.microsoft.com/en-us/library/ms535178.aspx

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Dec 2007
    Posts
    3
    Eh wow that was quick. Ok I had a look there and that seems to be what I want to do. I've been looking on the net for about a week. I can't believe I couldn't find that. So will they work on either of the C++('s) that I have or should I stick to one in particular.

    Thanks again for the swift reply
    Alan

  4. #4
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,171
    LineTo and MoveToEx should be the only ones you need I think. I haven't really messed that so I don't know 100%. Anyway, those are GDI, so you don't need MFC. They'll work fine in VC9 Express.

  5. #5
    Registered User
    Join Date
    Dec 2007
    Posts
    3
    Thank you kindly. I'll have a go at that and post again next week when I've pulled more hair out.

    Alan.

  6. #6
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398
    Can this be done in C++. I suppose that is really my first question.
    My second? If not, what should I be using.
    You can do this with Microsoft Visual C++, because it includes GUI/graphics libraries. (There are no graphics in ANSI/ISO Standard C++.)

    In order to use the Win32 library with Visual C++ Express, you need to download the Platform SDK. Click here for more info.

    I'll have a go at that and post again next week when I've pulled more hair out.
    The Windows graphics functions generally require you to create a Window first which requires a fair amount of overhead code. Once you have about 80 lines of Windows overhead code to create a GUI Window, it's fairly easy to make simple graphic shapes.

    Windows and graphics are "advanced topics", and you should understand Standard C++ before you attempt to use a graphics library. When you are ready for Windows programming, here is a Windows Tutorial.
    Last edited by DougDbug; 12-04-2007 at 01:49 PM.

  7. #7
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by DougDbug View Post
    You can do this with Microsoft Visual C++, because it includes GUI/graphics libraries. (There are no graphics in ANSI/ISO Standard C++.)
    I agree that there are no graphics definitions in any standard of C++. But from what you write, it makes it sound like the GUI/graphics libraries in Windows are somehow requiring that you use Visual Studio, whilst in fact any compiler that can generate Win32 compatible code can use those libraries. There may be some slightly modifications needed to some header files [this is normally done by the compile producer, by supplying suitable copies of the header files].

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. drawing basic lines....
    By 1dayprogrammer in forum C++ Programming
    Replies: 10
    Last Post: 02-23-2008, 03:07 PM
  2. drawing lines
    By makveli in forum A Brief History of Cprogramming.com
    Replies: 12
    Last Post: 11-11-2003, 02:22 AM
  3. Drawing lines
    By Punkture in forum C Programming
    Replies: 2
    Last Post: 05-05-2003, 05:30 PM
  4. Drawing lines and ellipses with DirectDraw
    By Hunter2 in forum Game Programming
    Replies: 9
    Last Post: 01-08-2003, 12:25 PM
  5. drawing lines
    By bluehead in forum C++ Programming
    Replies: 1
    Last Post: 11-23-2001, 12:22 PM

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