Setting the location of the console window

Gday all

I have had a bit of experience prior in Turbo Pascal and Java (Both several years ago) and I am looking to start getting back into programming for a bit of (irritating) fun.

I have spent ages searching around and running through tutorials and I am slowly starting to feel confident with the basics.
One thing I am struggling with is manipulation of the console. I am using Dev-C++ on windows vista and have just completed the tutorials on http://www.adrianxw.dk/SoftwareSite/index.html which i found quite helpful.

In trying to get my head around console manipulation I have been working through the below code (using the code provided from the above resource)
What I cannot work out how to do is to set the position of the window to the top left of the monitor - I have seen several ways to do it but none work with what I have done
(eg. http://msdn.microsoft.com/en-us/library/ms633534.aspx and http://www.codeguru.com/forum/showthread.php?t=159314 )

I am SURE there was a very basic way to do it with the default window that I was messing around with a few days ago but I cant find it...

Any help would be greatly appreciated!

(I tried MoveWindow(hOut, 1, 1, 80, 80, TRUE); but no luck with using hOut as the handle?)


#include <windows.h>
#include <iostream>
using namespace std;

int main()
{
HANDLE hOut;
CONSOLE_SCREEN_BUFFER_INFO SBInfo;
COORD NewSBSize;
SMALL_RECT DisplayArea = {0, 0, 0, 0};
int x;
int y;
hOut = GetStdHandle(STD_OUTPUT_HANDLE);

GetConsoleScreenBufferInfo(hOut,
&SBInfo);

NewSBSize.X = 175; //SET BUFFER
NewSBSize.Y = 65;
SetConsoleScreenBufferSize(hOut, NewSBSize);
x = SBInfo.srWindow.Right;
y = SBInfo.srWindow.Bottom;
DisplayArea.Top = 0;
DisplayArea.Left = 0;
DisplayArea.Bottom = 64; //SET WINDOW
DisplayArea.Right = 174;
SetConsoleWindowInfo(hOut,
TRUE,
&DisplayArea);
system("PAUSE");
GetConsoleScreenBufferInfo(hOut,
&SBInfo);

cout << "Maximum X : " << SBInfo.dwMaximumWindowSize.X << endl;
cout << "Maximum Y : " << SBInfo.dwMaximumWindowSize.Y << endl;
system("PAUSE");
return 0;
}
closed account (S6k9GNh0)
http://msdn.microsoft.com/en-us/library/ms687089%28v=VS.85%29.aspx

Out of honesty though, why would you need to do such a thing? I think it would be more flexible and productive to make something that emulates a console to give more freedom...
I am trying to make the window and buffer bigger because I am trying to recreate a little game I made on turbo pascal ... Little bloke running around fighting stuff, castle in the middle etc.

Code for that is below (Again, modified from other tutorials out there - this is all basic concept stuff that i will put together)

The reason I want to make the window bigger is so you can run around a bigger area (rather than just the 80x60 or whatever the basic small window is normally)

If you can point me in the direction of something more useful, I will be very appreciative (haha assuming it has sufficient tutorials to get me started!)

Code for moving around


#include <conio.h>
#include <stdio.h>
#include <windows.h>

#define ARROW_UP 0x48
#define ARROW_LEFT 0x4B
#define ARROW_RIGHT 0x4D
#define ARROW_DOWN 0x50
#define ARROW_NONE 0x00
#define ESC_KEY 0x1B

unsigned char getArrow();

void gotoxy(int x,int y)
{
COORD coord = {x-1,y-1};
SetConsoleCursorPosition( GetStdHandle(STD_OUTPUT_HANDLE),coord);
}

int main() {
int symb;
int pos_row = 1, pos_col = 1;
int offset_row = 0, offset_col = 0;
unsigned char arrow;
gotoxy(pos_col, pos_row);
putchar(254);
while ((arrow = getArrow()) != ESC_KEY) {
if (arrow != ARROW_NONE) {
switch(arrow) {
case ARROW_UP:
offset_row = -1;
symb = 24;
break;
case ARROW_LEFT:
offset_col = -1;
symb = 27;
break;
case ARROW_RIGHT:
offset_col = 1;
symb = 26;
break;
case ARROW_DOWN:
offset_row = 1;
symb = 25;
break;
}
gotoxy(pos_col, pos_row);
putchar(32);
pos_row += offset_row;
pos_col += offset_col;
if (pos_row < 1) { pos_row = 1; }
if (pos_row > 25) { pos_row = 25; }
if (pos_col < 1) { pos_col = 1; }
if (pos_col > 80) { pos_col = 80; }
gotoxy(pos_col, pos_row);
putchar(symb);
offset_row = 0; offset_col = 0;
}

}

return 0;
}

unsigned char getArrow() {
if (kbhit()) {
//we only want to get here if a key has been pressed...
unsigned char ch = getch();
if (ch == 0x00) {
//first char is a zero so lets look at the next char....
ch = getch();
switch(ch) {
case ARROW_UP:
return ch;
case ARROW_LEFT:
return ch;
case ARROW_RIGHT:
return ch;
case ARROW_DOWN:
return ch;
default:
return ARROW_NONE;
}
}
return ch;
}
return ARROW_NONE;
}
Topic archived. No new replies allowed.