Re: Console application's window size
From: Vincent Fatica (abuse_at_localhost)
Date: 09/01/04
- Next message: Senapathy: "Re: Console application's window size"
- Previous message: Steve Alpert: "Re: highlighting window"
- In reply to: Senapathy: "Re: Console application's window size"
- Next in thread: Senapathy: "Re: Console application's window size"
- Reply: Senapathy: "Re: Console application's window size"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 01 Sep 2004 12:41:23 -0400
Right, the standard runtime handles need to be hooked up after using
AllocConsole() or AttachConsole(). Look for a recent article by me in
comp.os.ms-windows.programmer.win32: "Re: I need console output in a
dialog-based app".
But you said your app **is** a console app. In that case there's no need to
AllocConsole(). You already have a console, and the runtime handles are
automatically set up when you start a "subsystem:console" application. Is
there some need to free the old console and alloc a new one?
--
- Vince
On Wed, 1 Sep 2004 21:34:42 +0530, "Senapathy" <senapathy.k@siemens.com>
wrote:
>Hello Vincent,
>
>Thanks for the hint. I tried the APIs that you suggested - my problem is
>that the usual C++ I/O library method cout is not working after I create
>this new console. I am posting the code that I have:
>
>int main(int argc, char* argv[])
>{
> // free old console and allocate new one
> ::FreeConsole();
> ::AllocConsole();
>
> // create new console handle
> HANDLE handle = ::CreateConsoleScreenBuffer(GENERIC_WRITE,
>FILE_SHARE_WRITE,
> NULL,
>CONSOLE_TEXTMODE_BUFFER, NULL);
>
> // set this handle as the active screen buffer
> ::SetConsoleActiveScreenBuffer(handle);
>
> SMALL_RECT srWindowRect; // hold the new window size
> COORD coordScreen; // hold the new screen buffer size
>
> // define the new console window size to be 1 less than the buffer
>size
> srWindowRect.Right = 99;
> srWindowRect.Bottom = 39;
> srWindowRect.Left = srWindowRect.Top = 0;
>
> // define the new console buffer size
> coordScreen.X = 100;
> coordScreen.Y = 40;
> ::SetConsoleScreenBufferSize(hConsole, coordScreen);
> ::SetConsoleWindowInfo(hConsole, TRUE, &srWindowRect);
>
> // try setting the std out handle to the newly created one. This
>succeeds!!!
> BOOL bSet = ::SetStdHandle(STD_OUTPUT_HANDLE, handle);
>
> // however, the lines below doesn't get printed out !!!
> printf("Hello world\n");
> cout << "cout in new buff" << endl;
>
> // however the line below gets printed out
> ::WriteConsole(handle, (void*)"Hi there", 4, &dwWritten, NULL);
>
> int i;
> cin >> i;
>
> return 0;
>}
>
>Now I find 2 funny things.
>
>1) If I _comment_out_ the FreeConsole and the AllocConsole parts and run the
>exe from a cmd prompt, the same cmd prompt gets bigger properly.
>In this, only the WriteConsole output is visible. Once I key in some
>character for the cin >> and then hit enter, the cmd prompt goes back to the
>original size and THEN the printf and the cout statements are visible!!!
>
>2) If I keep the FreeConsole and AllocConsole and run the exe, I get a NEW
>cmd prompt window. The original cmd prompt from where I launched the exe is
>waiting for the new cmd prompt to close down.
>Only the WriteConsole output is visible in the new window also.
>Once I close the new cmd prompt, the 2 lines are NOT printed even on the
>original cmd prompt.
>
>How do I get the cout statements to appear on the expanded window in the
>proper sequence?
>I am now guessing that I do not need a FreeConsole and AllocConsole
>
>Warm regards,
>Senapathy
>
>
>"Vincent Fatica" <abuse@localhost.com> wrote in message
>news:4135e29d$1@localhost...
>> In the particular example you mentioned, first make sure the console has
>> at least 40 lines of screen buffer with SetConsoleScreenBufferSize() and
>> then make the window larger with SetConsoleWindowInfo().
>>
>> Those two functions will work in the general setting, keeping in mind
>> that you can't make the window larger than the screen buffer in either
>> direction, and, if the window is smaller than the screen buffer in
>> either direction, you'll get a scroll bar in that direction.
>>
>> --
>> - Vince
>>
>> On Wed, 1 Sep 2004 20:03:04 +0530, "Senapathy" <senapathy.k@siemens.com>
>> wrote:
>>
>> >Hello,
>> >
>> >I am developing a commandline application (Console App) in W2K using VC6.
>> >I am using the regular C++ library functions like cout and cin for
>> >input/output.
>> >
>> >Now I want the window size of the resultant console exe to be more than
>the
>> >default size on the user's machine, which is 80 * 25. I want it to be
>say,
>> >100 * 40. I want this to be done from within my program itself on
>starting -
>> >and not ask the user to change the size from the console window property
>> >page.
>> >
>> >I went through the console APIs - CreateConsoleScreenBuffer and so on.
>But
>> >this seems to complicated to me.
>> >
>> >Is there any other simple way to increase the console window size?
>> >
>> >Warm regards,
>> >Senapathy
>> >
>>
>
- Next message: Senapathy: "Re: Console application's window size"
- Previous message: Steve Alpert: "Re: highlighting window"
- In reply to: Senapathy: "Re: Console application's window size"
- Next in thread: Senapathy: "Re: Console application's window size"
- Reply: Senapathy: "Re: Console application's window size"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|