C++ WinCon Setting Buffer Size issue

Thread Starter

TheFox

Joined Apr 29, 2009
66
I am trying to set the Windows Console's buffer's buffer size, via a simple game. However, I don't think I am going about it the right way. I am using the program just to learn about Windows programming with c++. I use VC++ 2008.

I think my issue is here:
Rich (BB code):
HANDLE BufferHandle = CreateConsoleScreenBuffer( 
GENERIC_READ | // read/write access 
GENERIC_WRITE, 
FILE_SHARE_READ | 
FILE_SHARE_WRITE, // shared 
NULL, // default security attributes 
CONSOLE_TEXTMODE_BUFFER, // must be TEXTMODE 
NULL); // reserved; must be NULL 
COORD BufferSize;
BufferSize.X = 6;
BufferSize.Y = 75;
HWND console = GetConsoleWindow();
StatusCheck = SetConsoleScreenBufferSize(BufferHandle, BufferSize);
if(StatusCheck == FALSE)
{
std::cout << "Buffer Size failed \n";
system("pause");
return -2;
}
Here is the full code:
Rich (BB code):
#include<iostream>
#define _WIN32_WINNT 0x0500
#include<windows.h>
#include<string>
#define ACTOR 'o'
struct VECTOR2
{ 
unsignedfloat X, Y;
};
class ClsPlayer
{
public:
VECTOR2 Pos;
ClsPlayer(float X = 0.0f, float Y = 0.0f)
{
Pos.X = X;
Pos.Y = Y;
}
};
void DrawScreen(VECTOR2 Location, char Actor)
{
system("cls");
for(int I = 0; I != Location.Y; ++I)
{
std::cout<< "\n";
}
for(int I = 0;I != Location.X; ++I)
{
std::cout<< " ";
}
std::cout << Actor;
}
int main()
{
ClsPlayer* Player = new ClsPlayer();
BOOL StatusCheck;
HANDLE BufferHandle = CreateConsoleScreenBuffer( 
GENERIC_READ | // read/write access 
GENERIC_WRITE, 
FILE_SHARE_READ | 
FILE_SHARE_WRITE, // shared 
NULL, // default security attributes 
CONSOLE_TEXTMODE_BUFFER, // must be TEXTMODE 
NULL); // reserved; must be NULL 
COORD BufferSize;
BufferSize.X = 6;
BufferSize.Y = 75;
HWND console = GetConsoleWindow();
//ShowWindow(console, 0);
StatusCheck = MoveWindow(console, 100,100, 500, 500, TRUE);
if(StatusCheck == FALSE)
{
std::cout<< " Window size failed\n";
system("pause");
return -1;
}
StatusCheck = SetConsoleScreenBufferSize(BufferHandle, BufferSize);
if(StatusCheck == FALSE)
{
std::cout << "Buffer Size failed \n";
system("pause");
return -2;
}
 
 
StatusCheck = SetConsoleTitle(TEXT("The o Game."));
if(StatusCheck == FALSE)
{
std::cout << "Title failed \n";
system("pause");
return -3;
}
 
while(1)
{
if (GetKeyState(VK_UP) & 0x80)
{
if(Player ->Pos.Y > 0)
{
--Player->Pos.Y;
}
}
if (GetKeyState(VK_DOWN) & 0x80)
{
++Player->Pos.Y;
}
if (GetKeyState(VK_LEFT) & 0x80)
{
if(Player->Pos.X > 0)
{
--Player->Pos.X;
}
}
if (GetKeyState(VK_RIGHT) & 0x80)
{
++Player->Pos.X;
}
 
DrawScreen(Player->Pos, ACTOR);
Sleep(25);
}
delete Player;
return 0;
}
 

 
Top