Results 1 to 12 of 12

Thread: Visual C console output question

  1. #1
    New Romantic
    Join Date
    Nov 2002
    Posts
    5,830

    Visual C console output question

    I've got a command line program that spits out a lot of data.

    I'd like to run it in a way where I can view that data in a window much larger than the standard 80 x 25 character window.

    Preferably, I'd like to do this in as few steps as possible, after making a change to my program.

    There are many ways I can do it, given a few steps (Pipe to a text file and open that. Run from a command line window I resize myself. Output to the VC debug window and resize that).

    But my preference is to be looking at my code, tweak a couple things, press F5, and see the output in a big fat debug window - one keystroke removed (F5) from my last code edit.

    Is it possible to change the size of the DOS window that VC opens by default?

  2. #2
    New Romantic
    Join Date
    Jul 2005
    Location
    Calgary
    Posts
    9,911
    There's a function for changing the size of a console window:
    Code:
    #define WIN32
    #include <windows.h>
    
    int main()
    {
       COORD x;
    
       x.X = 132;
       x.Y = 43;
    
       SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE), x);
    
       return 0;
    }
    Though it doesn't seem to automatically maximize the window, giving you a window the same physical size but with scrollbars, so you'd have to manually maximize it (I can't see a simple way to do so via the console API).

    Edit: It looks like the Y size should include however much scrollback you want, too.

  3. #3
    Account closed World's End Supernova
    Join Date
    Apr 2003
    Location
    Toronto, Ontario
    Posts
    15,264
    You can't resize the dos window, because there's no 'window' in DOS. The command line is text only, in/out. All window operations would have to be handled by yourself.

  4. #4
    Social Worker
    Join Date
    Jan 2003
    Location
    Ontario, Canada
    Posts
    2,664
    mode co80!
    :b

    edit: hmm, that's not the one I'm thinking of... it's been so long!

  5. #5
    New Romantic
    Join Date
    Nov 2002
    Posts
    5,830
    Stupid me.

    If I just run my program, and, while it's open, modify the properties of the console window, I'm prompted to save those properties for future windows with the same title. Basically, I can set the window large and save it that way for future sessions. No need to call the Windows Console API. Cool!

  6. #6
    Account closed World's End Supernova
    Join Date
    Apr 2003
    Location
    Toronto, Ontario
    Posts
    15,264
    Quote Originally Posted by Phil_Stein
    Stupid me.

    If I just run my program, and, while it's open, modify the properties of the console window, I'm prompted to save those properties for future windows with the same title. Basically, I can set the window large and save it that way for future sessions. No need to call the Windows Console API. Cool!

    Is that a global change? Or one local to your project? Because if it's a global change to all console windows, you, sir, are being one of those programmer assholes who hijack's other people's settings!

    edit: Wait, you meant you were doing this via the window itself, and not programmatically. Ignore me!

  7. #7
    Account closed World's End Supernova
    Join Date
    Jun 2002
    Location
    Aurora
    Posts
    15,922
    You probably could also write a GUI program that programmatically opens a console window with the desired size, then directs all output into that window.

    But if you do that you might as well create a GUI program with a simple text box. :)

  8. #8
    Account closed New Romantic
    Join Date
    Jul 2003
    Location
    smrt
    Posts
    7,948
    or pipe std out to notepad.

  9. #9
    Broad Band
    Join Date
    Feb 2004
    Location
    Boston area
    Posts
    252
    Quote Originally Posted by bago
    or pipe std out to notepad.
    Is that possible? I can't get that to work. This works:

    mycmd > blah.txt && notepad blah.txt

    'Course, then you're stuck in notepad.

  10. #10
    New Romantic
    Join Date
    Nov 2002
    Posts
    5,830
    Is there a way to play tricks with the console output - to get it to appear in different colors, flashing, etc.?

    I don't really want to delve into a whole console API, if possible. But perhaps there is a CTRL key sequence I can use in my output to do this kind of stuff.

    Is this possible?

  11. #11
    New Romantic
    Join Date
    Jul 2005
    Location
    Calgary
    Posts
    9,911
    ANSI codes might still work. Failing that, there is indeed a console API.

  12. #12
    New Romantic
    Join Date
    Nov 2003
    Location
    Seattle and Charlotte
    Posts
    6,293
    http://msdn2.microsoft.com/en-us/library/ms686047.aspx
    Code:
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), color);

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •