Visual C++

Started by
12 comments, last by pulpfist 16 years, 3 months ago
I was wondering and I have seen some options that add back grounds to my consol projects. An option to drawbg(); = (Draw Back Ground) or some thing like that. and maybe some options to create boxes. and even with a shadow. I'm new at this so please bear with me. Joe
Advertisement
In the old days there was a dos library where you could define boxes or areas on the console window and add text and colors to them. I remember trying it once a long time ago using Borlands compiler tools.

Is this what you are thinking about?
If it is, I don't think that library is available anymore. At least not unless you have a old Borland compiler installed.

If all you want to do is to change the background color you can take a look at these functions

There is a function among the console functions called SetConsoleScreenBufferInfoEx that I suspect could be used to define *boxes* but it is only available on Windows Vista.

There is a library called PDCurses that can do a lot of stuff. I managed to compile it using Visual C++ and the demos that follow the code works. However, as soon as I try to write a little test myself nothing happens, so I can't really recommend it yet lol.
Besides, compiling and installing it is not all that easy.

[Edited by - pulpfist on January 7, 2008 7:34:57 AM]
Quote:Original post by pulpfist
In the old days there was a dos library where you could define boxes or areas on the console window and add text and colors to them. I remember trying it once a long time ago using Borlands compiler tools.

Is this what you are thinking about?
If it is, I don't think that library is available anymore. At least not unless you have a old Borland compiler installed.

If all you want to do is to change the background color you can take a look at these functions

There is a function among the console functions called SetConsoleScreenBufferInfoEx that I suspect could be used to define *boxes* but it is only available on Windows Vista.

There is a library called PDCurses that can do a lot of stuff. I managed to compile it using Visual C++ and the demos that follow the code works. However, as soon as I try to write a little test myself nothing happens, so I can't really recommend it yet lol.
Besides, compiling and installing it is not all that easy.


In Visual C++ I been teaching my self Consol applications just to learn the code. I thought maybe that I could create my own back grounds using some of the ideas I got from other dos related programs.

How ever I don't know what they were using or how they did it. Programing in pascal back then was hard. And today I can create a option like "DrawBox(x1,y1,x2,y2,bg,fg)" in pascal. Al it does is draws a box using ascii codes that draw lines a round the borders.

All I'm trying to do is customize my program so that the menus look better with back ground graphics. If that what you want to call them..

and as for colors. Remember you help me with that last week. and thanks

At this time I'm just trying to under stand what a library does.






Quote:
In Visual C++ I been teaching my self Consol applications just to learn the code. I thought maybe that I could create my own back grounds using some of the ideas I got from other dos related programs.

The Windows XP console is very different from the DOS console even if it looks the same.
To make a long story short, console applictions under windows can not access OS and hardware memory directly the way dos applications could.
Therefore a lot of the functions from dos does not work anymore.

Quote:
How ever I don't know what they were using or how they did it. Programing in pascal back then was hard. And today I can create a option like "DrawBox(x1,y1,x2,y2,bg,fg)" in pascal. Al it does is draws a box using ascii codes that draw lines a round the borders.

They were probably using the dos functions that does not work anymore.
An exception is Borlands old compiler tools, like turbo pascal and turbo c++.
In Visual C++ that stuff won't work.

Quote:
All I'm trying to do is customize my program so that the menus look better with back ground graphics. If that what you want to call them..

I assume that you mean boxes with shadow effects and colors here. Real graphics like bitmaps can not be drawn in a console no matter what.
The best way to do that these days is to use PDCurses. I can give you info on how to make PDCurses work in Visual C++ if you want.

Quote:
At this time I'm just trying to under stand what a library does.

A library is basically pre-compiled source code that you can link with your program. A library contains normal source code like classes and functions.
Once you have linked such a library to your program, you can use the classes and functions from the library in your own code.
You are using libraries all the time, maybe without knowing it. For example when you say #include <windows.h> in your program, you are linking to a library.
You can also write and compile your own libraries with Visual C++.
Quote:Original post by bigjoe11a
I was wondering and I have seen some options that add back grounds to my consol projects.

An option to drawbg(); = (Draw Back Ground) or some thing like that. and maybe some options to create boxes. and even with a shadow. I'm new at this so please bear with me.

Joe


Sorry; do you have a question?

Quote:Original post by pulpfist
Quote:
In Visual C++ I been teaching my self Consol applications just to learn the code. I thought maybe that I could create my own back grounds using some of the ideas I got from other dos related programs.

The Windows XP console is very different from the DOS console even if it looks the same.
To make a long story short, console applictions under windows can not access OS and hardware memory directly the way dos applications could.
Therefore a lot of the functions from dos does not work anymore.

Quote:
How ever I don't know what they were using or how they did it. Programing in pascal back then was hard. And today I can create a option like "DrawBox(x1,y1,x2,y2,bg,fg)" in pascal. Al it does is draws a box using ascii codes that draw lines a round the borders.

They were probably using the dos functions that does not work anymore.
An exception is Borlands old compiler tools, like turbo pascal and turbo c++.
In Visual C++ that stuff won't work.

Quote:
All I'm trying to do is customize my program so that the menus look better with back ground graphics. If that what you want to call them..

I assume that you mean boxes with shadow effects and colors here. Real graphics like bitmaps can not be drawn in a console no matter what.
The best way to do that these days is to use PDCurses. I can give you info on how to make PDCurses work in Visual C++ if you want.

Quote:
At this time I'm just trying to under stand what a library does.

A library is basically pre-compiled source code that you can link with your program. A library contains normal source code like classes and functions.
Once you have linked such a library to your program, you can use the classes and functions from the library in your own code.
You are using libraries all the time, maybe without knowing it. For example when you say #include <windows.h> in your program, you are linking to a library.
You can also write and compile your own libraries with Visual C++.


Sorry I couldn't get back to you sooner. Any way Yes. Any information you can get for me about PDCurses. Please Let me Know

Joe


Quote:
Sorry I couldn't get back to you sooner. Any way Yes. Any information you can get for me about PDCurses. Please Let me Know

No worries =)
I decided to write a little tutorial on getting PDCurses up and running on Visual C++. After all there is quite a few text RPG hobbyist around here who might find it useful.

Here is how I got started with PDCurses in Visual C++.
It could come in handy later on if the question arises.
Note that there might be other ways to compile the source, and there might be pre-compiled versions available online. I just couldn't find any useful ones myself.


COMPILING PDCURSES USING VISUAL C++



1. Download NMake15.exe
Double-clicking on this file will create two new files, NMAKE.EXE and NMAKE.ERR.
Copy both these files to the C:\Windows\System32 folder.

2. Download the pdcurs33.zip (Or a later version)
Place this file somewhere you can find it (For the remainder of this tutorial I'll pretend it is located at C:\Temp), and unzip it.

3. Open a console. (Start -> Run, and type cmd)
Execute the vcvarsall.bat script in the console.
On my system this script is located at: "C:\Program files\Microsoft Visual Studio 9.0\VC\vcvarsall.bat"
The folder names could be slightly different on other systems of course.
This will set up the environment variables necessary to locate the Visual C++ compiler tools in the current console.

4. From inside the console, navigate to the win32 folder in the pdcurses source.
On my system: C:\Temp\pdcurs33\win32

5. Compile the library using the command: nmake.exe -f vcwin32.mak all

With some luck the library will be compiled and the demo programs will show up in the current folder.
You can execute the demo programs to get an idea of what PDCurses is all about.

The files of interest to us is panel.lib, pdcurses.lib located in the win32 folder, and curses.h, curspriv.h, panel.h, term.h located in the pdcurs33 folder.

Create the following folders on your system: C:\pdcurses\include and C:\pdcurses\lib, and copy the lib files mentioned earlier to the lib folder and the h files to the include folder.



SETTING UP THE PDCURSES LIBRARY IN VISUAL C++



Start Visual C++.
From the menus, go to: Tools -> Options -> Projects and Solutions -> VC++ Directories.
At the upper right corner there will be a drop-down list. Select 'Include files' in this list, and add the C:\pdcurses\include folder to the list below.
Now, select 'Library files' in the drop-down list and add the C:\pdcurses\lib folder to the list below.
This configuration step is system-wide and needs to be done only once.

At this point Visual C++ is set up to find and use the pdcurses library so we are ready to give it a test.
Create a new console project and add the following code:

#include <curses.h>#pragma comment(lib, "pdcurses.lib")int main(void) {	WINDOW *mainWindow = initscr();	noecho();	cbreak();	nodelay(mainWindow, TRUE);   	wrefresh(mainWindow);   	WINDOW *helloWindow = newwin(12, 25, 5, 5);	box(helloWindow, ACS_VLINE, ACS_HLINE);   	curs_set(0);	while(1) 	{		int ch = getch();		if(ch == 27) 	  			break;            				mvwprintw(helloWindow, 5, 6, "Hello world!");   		wrefresh(helloWindow);   	}	endwin();   	return 0;}


One last thing to do:
Right-click the project in the Solution Explorer and go to Properties -> Configuration properties -> C/C++ -> Code generation,
and make sure the option Runtime Library is set to Multi-threaded (/MT)

Compile and run the program. If everything works as expected you can exit by pressing escape.
For a detailed description of the PDCurses API see PDCurses User's Guide



Cheers

[Edited by - pulpfist on January 8, 2008 1:02:24 PM]
6. Compile the library using the command: nmake.exe -f vcwin32.mak all

When trying to compile the vcwin32.mak file I got this error

vcwin32.mak(all) : fatal error U1088 : invalid separtor '::' on inference rule stop

Yea I get that error if I don't execute the vcvarsall.bat script first.
You are using Visual C++ 2008 express right?

Write this line in the console ( including the " ):
"C:\Program files\Microsoft Visual Studio 9.0\VC\vcvarsall.bat"
and press enter.

(If the hard disk where you have Visual C++ installed is called something else than C: you must change that. Also, if you use Visual C++ 2005 express the 9.0 should be 8.0)

Now the nmake command should work
By the way, installing perl doesn't seem to be necessary. I have perl installed anyway but if you don't want it you should be able to skip installing perl as described in step 1 and just place the two nmake files in a folder visible on your path variable. Like C:\Windows\System32.
Sorry about that.

This topic is closed to new replies.

Advertisement