Thread: Setting Console Size

  1. #1
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273

    Setting Console Size

    Hi all,

    I'm looking for an alternative to using 'system ( "mode con:cols=50 lines=30" );' (those numbers don't have to be static, obviously), (looking for an alternative against the possibility that someone hacks into my computer, and makes a mode.bat file which does bad bad things to my computer!), to set the size (buffer and regular), of my console screen, so I turned to adrianxw, of course, and got lots of examples from here. When I saw the one about setting the screen buffer size, I thought it was great, but it says that the SetConsoleScreenBufferSize() function can't make the window any smaller, which is one of the possibilities I would like to cover. Can anyone suggest how I may go about making it smaller. Is there another function I should look into?

    I've tried searching Google (albeit quickly), and anything I saw regarding the above problem was a warning about the function, and error checking - ie: if ( var < 0 ) cout<< "Cannot decrease size"; else blah blah ...

    Ta very much.

  2. #2
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,820
    Woop?

  3. #3
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273
    Thanks prog-bman!! That's where I got all my info to date. The problem is he says - "If you try to make the screen buffer smaller than the window size, the call will fail.", using the SetConsoleScreenBufferSize function. I'm wondering if there's another function out there which can decrease, as well as increase the size.

    I think I've twigged it ... if I first change the window size, and then change the buffer will it work?

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    http://msdn.microsoft.com/library/de..._winevents.asp
    Do you get EVENT_CONSOLE_LAYOUT when it's resized?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273
    No, Salem. Thanks for the link, I'm reading it at the moment. I'm basically using the code as the adrian guy put it up. I'll post my functions in a few mins when I finish them.

    EDIT - Here are the functions -
    Code:
    Note, Error checking to come for these.
    void ChangeScreenSize ( COORD NewSize )
    {
    	HANDLE                     hOut        = GetStdHandle( STD_OUTPUT_HANDLE );
    	SMALL_RECT                 DisplayArea = { 0, 0, 0, 0 };
    	CONSOLE_SCREEN_BUFFER_INFO SBInfo;
    
    
    	GetConsoleScreenBufferInfo( hOut, &SBInfo );
    
    	DisplayArea.Bottom = NewSize.Y;
    	DisplayArea.Right  = NewSize.X;
    
    	SetConsoleWindowInfo( hOut, true, &DisplayArea );
    }
    
    void ChangeBuffSize ( COORD NewSize )
    {
    	SetConsoleScreenBufferSize( GetStdHandle( STD_OUTPUT_HANDLE ), NewSize );
    }
    If I use them individually, they are ok, but in conjunction with eachother they don't seem to work. It seems ChangeBuffSize only increases, and ChangeScreenSize only decreases...
    Last edited by twomers; 08-20-2006 at 03:42 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Memory leaks problem in C -- Help please
    By Amely in forum C Programming
    Replies: 14
    Last Post: 05-21-2008, 11:16 AM
  2. Defining the size of the console...
    By twomers in forum C++ Programming
    Replies: 1
    Last Post: 12-21-2005, 11:35 AM
  3. Increasing the console size
    By Punkture in forum Windows Programming
    Replies: 3
    Last Post: 05-08-2003, 06:29 PM
  4. Console Size
    By Punkture in forum C Programming
    Replies: 2
    Last Post: 05-08-2003, 05:25 PM
  5. Replies: 11
    Last Post: 03-25-2003, 05:13 PM