Win32 Line Drawing using C++

Hi Guys

Desperately need help.

I'm currently attempting to get Win32 Console Application to draw a line in the window...and for the life of me I cannot get it to work. I've poured over forums and websites galore but to no afail.

Can anyone lend a hand or does someone have an example of the code which will cause the line to be drawn in the appilcation window? All i want is help understanding How i get the code to create it. I'm not worried about colours or funky shapes, I'd even settle for a box outline which I can place stuff into.

This is all building up to a tetris clone I'm going to be working on but i'm trying to get the basics out of the way and Win32 seems like an important thing to have knowledge in.
Last edited on
Are you talking about a console-based Tetris clone?

The console does not support any graphics, so there is no way to draw an actual line like the ones which a GUI app can display. (Also see PS)

You can draw boxes using chars, but then you've got to make sure the right code page is being used (if using Ansi chars) or deal with Unicode. (This code assumes code page 437.)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// Hello World! in a Box (for Windows console)

#include <iostream>
#include <string>
using namespace std;

int main ()
{
	// Box edges and corners (all double thick line)
	// T for top, B for bottom, L for left, R for right
	const char TB = '\xCD'; // 205
	const char LR = '\xBA'; // 186
	const char TL = '\xC9'; // 201
	const char TR = '\xBB'; // 187
	const char BL = '\xC8'; // 200
	const char BR = '\xBC'; // 188

	string hello  = "Hello World!";
	string margin = "  ";
	string line(hello.length() + 2 * margin.length(), TB);

	cout << TL << line << TR << endl;
	cout << LR << margin << hello << margin << LR << endl;
	cout << BL << line << BR << endl;
	cout << endl;

	return 0;
}


╔════════════════╗
║  Hello World!  ║
╚════════════════╝

Andy

PS It is possible to make it look like a console can draw an image, etc. But than involves the use of a regular windows in front of the console. Getting this to work smoothly is prob. more trouble than coding a regular GUI app.
Last edited on
Hi Andy

thanks for the help! That has actually cleared alot up and does make sense!

As a novice then what would you recommend using if I wanted to start out in 2d graphics? what would be the easiest GUI to get to grips with?

I guess I want to be able to create solid blocks as well but as you point out above this is not something you can do in a console app.

http://www.youtube.com/watch?v=oSgj7VkZkQk&feature=relmfu

the link above is essentially what i want to achieve or atleast similar. Its the blocks that confuse me :S but I'm abit stubborn when it comes to asking.

I apprecaite your help and anyone else who wants to jump in with advice :)
Also from YouTube.com

Console Tetris
http://www.youtube.com/watch?v=5-6GRyuQzbc

C# Console Tetris Game
http://www.youtube.com/watch?v=AyMer7UEhII

I think I'm far too tainted, from working with assorted Windows technologies, to have a valid opinion on the best 2d graphics library for a novice programmer. But the name I see recommended the most often on this site is Allegro.

Allegro - A game programming library
http://alleg.sourceforge.net/

And this thread from Sept might be of interest:

Game Programming | What library should I use?
http://v2.cplusplus.com/forum/beginner/78297/

Andy
Last edited on
Topic archived. No new replies allowed.