Like Tree2Likes
  • 1 Post By VirtualAce
  • 1 Post By Elysia

changing console window

This is a discussion on changing console window within the C++ Programming forums, part of the General Programming Boards category; Is it possible to change the size, position, background colour, foreground colour of the default console window that the first ...

  1. #1
    Registered User
    Join Date
    Jan 2011
    Posts
    96

    changing console window

    Is it possible to change the size, position, background colour, foreground colour of the default console window that the first programs I am currently exploring use?

  2. #2
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,866
    Programatically? Yes via the windows API. However this isn't necessarily something you want to focus to much on when just learning how to program. adrianxw has decent tutorials on console programming, however like I said not really something you want to focus on. Additionally, for GUI programming in C++, the suggested course is QT, however you really need to learn more C++ before diving into that.
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

  3. #3
    Registered User
    Join Date
    Jan 2011
    Posts
    96
    Thanks for the advice Andrew and I realise it is sound; but it is infuriating having to do everything in a 7 x 3 window - I assume then that I cannot somehow change it from within Code::Blocks?

  4. #4
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,866
    Quote Originally Posted by JayCee++ View Post
    Thanks for the advice Andrew and I realise it is sound; but it is infuriating having to do everything in a 7 x 3 window - I assume then that I cannot somehow change it from within Code::Blocks?
    Oh, I think I see what you are saying. Just compile your code and then run it from the command prompt, this will give you the windows "dos window" which you can change the size of just like any other window. As for C::B I am not sure, perhaps there is some settings you can adjust. I am sure someone knows around here, also you can check your help file for C::B.
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

  5. #5
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,490
    Quote Originally Posted by JayCee++ View Post
    Thanks for the advice Andrew and I realise it is sound; but it is infuriating having to do everything in a 7 x 3 window - I assume then that I cannot somehow change it from within Code::Blocks?
    If you mean, the console window, I think you can change the size manually at runtime... (I tried on my computer...and it worked..)
    Manasij Mukherjee | gcc-4.8.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



  6. #6
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,866
    Yes, I just looked through our Setting up C::B tutorial and it looks like once you hit F9 it spawns the standard windows console window. Which you can just grab the corner of and drag to resize.
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

  7. #7
    Registered User
    Join Date
    Jan 2011
    Posts
    96
    You can indeed change the height of the console window by dragging but not the width.

    Googling found the following which when run gives you a console window listing the colours available.

    Code:
    #include <iostream>
    #include <cstdlib>
    
    using namespace std;
    
    int main()
    {
    system ("TITLE Color Program");
    system ("Color )G");
    return 0;
    }
    If you change "Color )G" to eg "Color f1" you get blue text on a white background, so until I am ready to start GUI programming that will do most of what I want.

  8. #8
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,866
    Quote Originally Posted by JayCee++ View Post
    If you change "Color )G" to eg "Color f1" you get blue text on a white background, so until I am ready to start GUI programming that will do most of what I want.
    Did you look at adrian's tutorials? If you want to do this, you might as well do it the right way. Click on that link I gave you and read through his console programming section; that will show you how to do what you want.
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

  9. #9
    Registered User
    Join Date
    Jan 2011
    Posts
    96
    Sorry Andrew, I obviously misunderstood your first comments- I assumed you meant that changing colours etc couldn't be done except by getting into programming with Windows API - had another look and will study Adrian's tutorials closely later today.

  10. #10
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,586
    Besides the tutorial you can also check out the Windows SDK documentation for console functions. There are a whole host of functions related solely to the console.

    In the SDK index type in AllocConsole and from there you should be able to find a link to all of the console related functions.
    AndrewHunter likes this.

  11. #11
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by JayCee++ View Post
    Thanks for the advice Andrew and I realise it is sound; but it is infuriating having to do everything in a 7 x 3 window - I assume then that I cannot somehow change it from within Code::Blocks?
    Actually you are working on a visual representation of the old DOS 25 x 80 screen... In CMD.EXE they've added buffering so you can scroll back but it's still a Command Line Interface, intended to deliberately emulate DOS.

    If you want GUI style windows... use Windows... theForger's Win32 API Tutorial

  12. #12
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by manasij7479 View Post
    If you mean, the console window, I think you can change the size manually at runtime... (I tried on my computer...and it worked..)
    That depends on the Windows version... Prior to Vista you could even go full screen with it. On Vista and Win7 you can only make it taller or shorter.

  13. #13
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,172
    Quote Originally Posted by CommonTater View Post
    Actually you are working on a visual representation of the old DOS 25 x 80 screen... In CMD.EXE they've added buffering so you can scroll back but it's still a Command Line Interface, intended to deliberately emulate DOS.

    If you want GUI style windows... use Windows... theForger's Win32 API Tutorial
    ...Qt...
    manasij7479 likes this.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.
    For information on how to enable C++11 on your compiler, look here.
    よく聞くがいい!私は天才だからね! ^_^

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 01-13-2011, 08:46 PM
  2. Changing the window frame styles causes the window to disappear
    By sethjackson in forum Windows Programming
    Replies: 2
    Last Post: 08-12-2010, 04:43 PM
  3. SDL Window opening with Console Window
    By carrotcake1029 in forum Windows Programming
    Replies: 2
    Last Post: 12-23-2008, 02:32 PM
  4. Changing the Console text back to black
    By Unregistered in forum C++ Programming
    Replies: 11
    Last Post: 07-12-2002, 08:11 AM

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