Console Resizing

This is a discussion on Console Resizing within the Windows Programming forums, part of the Platform Specific Boards category; I am trying to create a method in a class that will create a console window to the desired size. ...

  1. #1
    Registered User filler_bunny's Avatar
    Join Date
    Feb 2003
    Posts
    87

    Console Resizing

    I am trying to create a method in a class that will create a console window to the desired size. However I am having some serious issues with this seemingly simple task. This code below is a hash together of code from Adrianxw's site and some stuff I found here.

    This code here works exactly as expected. But the second I put this into a class and try it, it does not work (I cut and paste the code into a constructor). Also compiled this in another compiler (Visual C++) and it doesn't work. It is really frustrating me because this is a very simple peice of code. Of course the error messages returned from the functions are useless as it appears to be incorrect.
    Code:
    #include <windows.h>
    #include <iostream.h>
    
    int main()
    {
        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);
        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;
        }
    
        cin.get();
    
        return 0;
    }
    Visual C++ .net
    Windows XP profesional

  2. #2
    Registered User filler_bunny's Avatar
    Join Date
    Feb 2003
    Posts
    87
    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).
    Last edited by filler_bunny; 08-31-2003 at 05:54 AM.
    Visual C++ .net
    Windows XP profesional

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Full Screen Console
    By St0rmTroop3er in forum C++ Programming
    Replies: 1
    Last Post: 09-26-2005, 10:59 PM
  2. Resizing the Console
    By jrahhali in forum C++ Programming
    Replies: 4
    Last Post: 09-21-2005, 06:52 PM
  3. Console Functions Help
    By Artist_of_dream in forum C++ Programming
    Replies: 9
    Last Post: 12-04-2004, 03:44 AM
  4. Resizing a Borland Builder 4.0 Console
    By dalek in forum C++ Programming
    Replies: 5
    Last Post: 07-19-2003, 07:20 AM
  5. Just one Question?
    By Irish-Slasher in forum C++ Programming
    Replies: 6
    Last Post: 02-12-2002, 10:19 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21