Code:
#include <windows.h>
#include <iostream.h>
class CScreen
{
private:
public:
CScreen(void);
};
CScreen::CScreen(void)
{
// Stuff would normally go here...
}
//---------------------------------------------------------------------------
int main(void)
{
CScreen *scr = new CScreen;
HANDLE hOut;
CONSOLE_SCREEN_BUFFER_INFO SBInfo;
COORD NewSBSize;
int Status;
hOut = GetStdHandle(STD_OUTPUT_HANDLE);
NewSBSize.X = (short)90;
NewSBSize.Y = (short)31;
Status = SetConsoleScreenBufferSize(hOut, NewSBSize);
GetConsoleScreenBufferInfo(hOut, &SBInfo);
if (Status == 0)
{
Status = GetLastError();
cout << "Buffer: Failed! Error: " << Status << endl;
}
SMALL_RECT DisplayArea;
DisplayArea.Bottom = 30;
DisplayArea.Right = 89;
Status = SetConsoleWindowInfo(hOut, TRUE, &DisplayArea);
if (Status == 0)
{
Status = GetLastError();
cout << "Screen: Failed! Error: " << Status << endl;
}
cout << "Maximum X : " << SBInfo.dwMaximumWindowSize.X << endl;
cout << "Maximum Y : " << SBInfo.dwMaximumWindowSize.Y << endl;
cin.get();
return 0;
}
OKay, this is really bizzare. Just the act of creating a class and instantiating it prevents this from working! The above code kind of works as I am allocating memory for the class (for some reason it the console function calls work but the resize does not work in the X direction).
If I were to create the object on the stack, the console resize does not work (the SetConsoleWindowInfo() call fails). If I create the object on the heap (as above), it seems to work (i.e. no errors), but the console does resize correctly in the X direction. This makes not sense whatsoever as the class is completely unrelated to the rest of the code!
It of course does not work under MSVC++ at all (having made appropriate changes to the includes etc).