Console screen size

This is a discussion on Console screen size within the C++ Programming forums, part of the General Programming Boards category; Is there a way to make the console window bigger at compile-time? I can't keep it in it's normal window ...

  1. #1
    Registered User
    Join Date
    Jul 2002
    Posts
    94

    Console screen size

    Is there a way to make the console window bigger at compile-time? I can't keep it in it's normal window because the screen contents take up more room than that, and in fullscreen, that annoying cursor is all over the place, even when i kill it! So actually, is there a way to A: totally get rid of the cursor, even in fullscreen, or B: make the console window bigger. Any help would of course be appreciated.

    Brendan
    Draco dormiens nunquam titillandus

  2. #2
    Registered User fletch's Avatar
    Join Date
    Jul 2002
    Posts
    176
    Providing that you don't mind the Windows dependency, here's what I use to hide the cursor
    Code:
    void SetCursorSize(const DWORD CursorSize)
    {
    	HANDLE	ConsoleHandle;
    	CONSOLE_CURSOR_INFO	CCI;
    
    	ConsoleHandle = GetStdHandle(STD_OUTPUT_HANDLE);
    	GetConsoleCursorInfo(ConsoleHandle, &CCI);
    	
    	if (CursorSize == 0)
    		CCI.bVisible = false;
    	else
    	{
    		CCI.dwSize = CursorSize;
    		CCI.bVisible = true;
    	}
    
    	SetConsoleCursorInfo(ConsoleHandle, &CCI);
    }
    This will set the size of the cursor to CursorSize (a percentage of the font size, eg 100 is a full block cursor). A cursor size of zero will hide the cursor.
    Last edited by fletch; 08-18-2002 at 04:30 PM.
    "Logic is the art of going wrong with confidence."
    Morris Kline

  3. #3
    Registered User fletch's Avatar
    Join Date
    Jul 2002
    Posts
    176
    Again, depending on your tolerance for Windows dependency...

    To force the window into full screen, use keybd_event to simulate pressing alt-enter.

    Use SetConsoleScreenBufferSize to adjust the window size (columns x rows).
    "Logic is the art of going wrong with confidence."
    Morris Kline

  4. #4
    Registered User
    Join Date
    Jul 2002
    Posts
    94
    Woohoo!!! I was able to solve my problem. See, the game is meant to be run in full screen, but it always showed that little underscore everywhere when in fullscreen, so this is what I did: I just used gotoxy(0,0) after every action so the stupid thing was never visible. That's what I meant by cursor, lol. Thanks, everyone!

    Brendan
    Draco dormiens nunquam titillandus

  5. #5
    BMJ
    BMJ is offline
    Banal internet user BMJ's Avatar
    Join Date
    Aug 2002
    Location
    Chicagoland
    Posts
    1,380
    Originally posted by harry_p
    I just used gotoxy(0,0) after every action so the stupid thing was never visible.
    Yikes! I don't think that it's a good idea to "hide" the cursor by moving it after every action... just use a simple function (which is Windows-dependent, like fletch said) similar to this...
    Code:
    void HideCursor()
    {
    	CONSOLE_CURSOR_INFO lpCursor;	
    	lpCursor.bVisible = 0;
    	lpCursor.dwSize = 20;
    	SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE),&lpCursor);
    }
    Then the cursor is gone for good... and if you look at the code I think you can figure out pretty quickly how to make a "RestoreCursor" function

  6. #6
    BMJ
    BMJ is offline
    Banal internet user BMJ's Avatar
    Join Date
    Aug 2002
    Location
    Chicagoland
    Posts
    1,380

    Re: Console screen size

    Originally posted by harry_p
    B: make the console window bigger.
    You can set the console screen size to 80 columns by 50 rows (rather than 25) with this code:
    Code:
    COORD SIZE_COORD = { 80, 50 };
    	SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE),SIZE_COORD);
    And if you're using DOS:
    Code:
    system("mode co80 50");
    Last edited by BMJ; 08-19-2002 at 11:09 AM.

  7. #7
    Registered User
    Join Date
    Jul 2002
    Posts
    94
    No, you misunderstood. I'm not talking about the actual cursor. For me, anyways, there are 2: the block one that is controlled by the mouse which I already know how to get rid of, and a little underscore "_" one that follows my animating objects around the screen. So, before and after I animate the object, I just send it to 0,0 where it's not visible and it's been working.

    Brendan
    Draco dormiens nunquam titillandus

  8. #8
    Registered User fletch's Avatar
    Join Date
    Jul 2002
    Posts
    176
    and a little underscore "_" one that follows my animating objects around the screen
    I'm pretty sure that is the cursor. Have you at least tried mine or BMJ's code to see if it helps?
    "Logic is the art of going wrong with confidence."
    Morris Kline

  9. #9
    Registered User
    Join Date
    Jul 2002
    Posts
    94
    Yes, I've tried both, and all they succeed in doing is getting rid of the block cursor that's controlled the mouse. The "_" one is still there. I've solved this already, thanks guys.

    Brendan
    Draco dormiens nunquam titillandus

  10. #10
    Registered User
    Join Date
    Jul 2002
    Posts
    94
    You know I feel exceedingly stupid now! My little gotoxy(0,0) trick wasn't, uh, very effective. The function to set the cursor size was, however, thanks fletch()! The other function works to get rid of the block cursor. Thanks!

    Brendan
    Draco dormiens nunquam titillandus

  11. #11
    Registered User
    Join Date
    Sep 2008
    Posts
    28
    I know this is an old post, but this code should help anyone that has this issue.

    I have the following code that works:
    Code:
    void gotoxy(int x , int y)
    {
    /******************************* gotoxy ***************************************
        takes cursor to x and y coordinates
        
        PRE : x and y coordinates.  y will be minus from current y coordinate of 
    			the cursor.
        POST: returns nothing.  moves cursor to x and y coordinates  
    *******************************************************************************/
        HANDLE hConsoleOutput;
        COORD dwCursorPosition;
        CONSOLE_SCREEN_BUFFER_INFO  ConsoleInfo;
        
        _flushall();
        hConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE);
        GetConsoleScreenBufferInfo(hConsoleOutput, &ConsoleInfo);
        dwCursorPosition.X = x;
        dwCursorPosition.Y = ConsoleInfo.dwCursorPosition.Y - y;  
        SetConsoleCursorPosition (hConsoleOutput, dwCursorPosition);
    } /* gotoxy */ 
    
    void showCursor(int bShow)
    {
    /******************************* showCursor ***********************************
        shows/hides the curser by TRUE/FALSE.
           
        PRE : bShow - TRUE/FALSE
        POST: Returns nothing.
    *******************************************************************************/ 
        int nSize = 25; 	//The nSize = the cursor height, optional parameter, by default 25. Size range: 1 - 100
    	CONSOLE_CURSOR_INFO CurInfo;
    	
    	//Define the cursor size
    	if (nSize <= 0) nSize = 1;
    	if (nSize > 100) nSize = 100;
    	CurInfo.dwSize = nSize;
    	CurInfo.bVisible = bShow;           //Define the visibility of the cursor
    	SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE),&CurInfo);  //Set parameters
    } /* showCursor */
    
    void setScreenSize(int x, int y)
    {
    /**************** setScreenSize *******************************
        changes screen to full.
           
        PRE : x  - left/right width.
              y  - up/down length.
        POST: Returns nothing.
    ***************************************************************/ 
        HANDLE hConsoleOutput;
        COORD coord;
        CONSOLE_SCREEN_BUFFER_INFO  ConsoleInfo;
        HWND console = GetConsoleWindow();
    
        hConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE);
        GetConsoleScreenBufferInfo(hConsoleOutput, &ConsoleInfo);
        coord.X = x;
        coord.Y = y;
        SetConsoleScreenBufferSize(hConsoleOutput, coord);
    
        MoveWindow(console, 20, 20, SCREEN_WIDTH, SCREEN_HEIGHT, TRUE);
    } /* setScreenSize */
    SCREEN_WIDTH and SCREEN_HEIGHT are custom #defines. I've set those to 1200 and 600

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Colour and Screen Size
    By djlethal in forum C Programming
    Replies: 1
    Last Post: 11-24-2006, 09:29 PM
  2. Error with a vector
    By Tropicalia in forum C++ Programming
    Replies: 20
    Last Post: 09-28-2006, 08:45 PM
  3. How can I change the screen size?
    By Queatrix in forum C++ Programming
    Replies: 5
    Last Post: 09-11-2005, 12:49 PM
  4. Console Screen Mode
    By GaPe in forum Windows Programming
    Replies: 9
    Last Post: 02-09-2003, 12:39 PM
  5. Console Screen Buffer
    By GaPe in forum Windows Programming
    Replies: 0
    Last Post: 02-06-2003, 05:15 AM

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