Go Back  DVD Talk Forum > General Discussions > Tech Talk
Reload this Page >

Need simple C++ routine to plot lines to display

Tech Talk Discuss PC Hardware, Software, Internet and Other Technology

Need simple C++ routine to plot lines to display

Old 02-01-04, 04:02 PM
  #1  
Member
Thread Starter
 
Join Date: Dec 2000
Posts: 100
Likes: 0
Received 0 Likes on 0 Posts
Need simple C++ routine to plot lines to display

For a home project (using my PC as a logic analyzer) I need a simple C++ routine that will allow me to plot lines on the display. I will be running Windows XP. Anyone know where I can find one? Most of what I find on the net are too complex. Thanks!
Old 02-02-04, 05:03 PM
  #2  
DVD Talk Legend
 
Join Date: Oct 1999
Location: |-|@><0r [email protected]|)
Posts: 17,214
Likes: 0
Received 0 Likes on 0 Posts
Like everything in Windows... it's not that simple.

You need to use one of several programming interfaces for drawing graphics. The two that I know of, which should be built into Windows, are GDI and DirectDraw. GDI is undoubtedly easier to learn and implement than DirectDraw (part of the DirectX suite), so I'd recommend that.

Here's a rough description of how GDI works:

Your application runs in a window, right? Every time the window is redrawn (when it's first created, when you move it, when you maximize it, etc.), your application is sent a Paint event, so you can just throw some code into the OnPaint() event handler. That procedure will get run whenever the window gets repainted, but you can make it run more frequently - e.g., create a timer function that triggers periodically (e.g., every 1/10th of a second) and raises an event, which forces a refresh. (You do this by calling InvalidateRect() and specifying the rectangular surface of your application window.)

Here's how OnPaint() works. When this event is triggered, your application is sent an object called a "drawing context" - it's an interface for drawing within your window. You can call all kinds of functions on that drawing context - LineTo() draws a line, DrawRect() draws a rectangle, Point() draws pixels, DrawEllipse() draws circles and ellipses, etc. You just specify the coordinates of the shapes that you're drawing. There are text functions, too.

These shapes, etc. are drawn with the current brush and pen objects of the drawing context. As you may imagine, the pen is used for fine drawing (lines, the borders of shapes, etc.), and the brush is used for filling areas (the interior of a filled ellipse, etc.) You can switch the colors used for these shapes just by "selecting" a brush or pen into the drawing context. Now, where do you get tehse pens and brushes? Windows provides a bunch of stock pens and brushes - BLACK_PEN and BLACK_BRUSH, I think, are stock objects - and you can create pens and brushes with functions like CreatePen(RGB value for color) and CreateBrush(Brush pattern type, RGB value for color).

Any Windows book on the planet will have tons of explanations and sample code for using GDI, and hundreds of websites should, too.

Good luck!

- David Stein
Old 02-03-04, 02:34 PM
  #3  
DVD Talk Platinum Edition
 
Join Date: Oct 1999
Location: South Surrey, BC
Posts: 3,990
Likes: 0
Received 0 Likes on 0 Posts
This last week, I ported a simple line-drawn UNIX game to Win32. If you're interested, I can send you the source.
Old 02-06-04, 08:57 PM
  #4  
Member
Thread Starter
 
Join Date: Dec 2000
Posts: 100
Likes: 0
Received 0 Likes on 0 Posts
Thanks, David and DivxGuy, for the help. I have picked up a copy of Borland C++ Version 4.5, and am making good progress.

Again, thanks!

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Thread Tools
Search this Thread

Archive - Advertising - Cookie Policy - Privacy Statement - Terms of Service - Do Not Sell My Personal Information

Copyright 2018 MH Sub I, LLC dba Internet Brands. All rights reserved. Use of this site indicates your consent to the Terms of Use.