How to create a Console window that is 80x25 characters in size?

Started by pcMike, June 28, 2010, 07:05:07 AM

Previous topic - Next topic

pcMike

I can't find a way to use CreateProcess to create a new Console window with a specific size such as 80x25 characters.

The STARTUPINFO structure includes these options:
dwXCountChars
If dwFlags specifies STARTF_USECOUNTCHARS, if a new console window is created in a console process, this member specifies the screen buffer width, in character columns. Otherwise, this member is ignored.

dwYCountChars
If dwFlags specifies STARTF_USECOUNTCHARS, if a new console window is created in a console process, this member specifies the screen buffer height, in character rows. Otherwise, this member is ignored.

But these are only used to set the buffer size (i.e: the scrollable number of columns or lines, not the console screen size.

The only way I found to do it is to use dwXsize and dwYsize to set the screen size to a specific number of pixles, but this only works right if there is a known font size. If I assume the font size is 8x12 for example, then I can set the screensize to 8*80 by 12*25 to get a 80-by-25 character consiole size. But the problem with this is I don't have any way to set the font size of the Console process I create, and I can't find any way to find the default console font size.

Is it possible?



include C:\masm32\include\masm32rt.inc
.code
main proc
LOCAL sui:STARTUPINFO
LOCAL pi:PROCESS_INFORMATION

   invoke memfill,ADDR sui,SIZEOF sui,0 ; Fill STARTUPINFO
   mov sui.cb,SIZEOF sui  
   mov sui.dwFlags, STARTF_USECOUNTCHARS Or STARTF_USESIZE

   mov sui.dwXSize,80*8    ; Assume current font is 8x12
   mov sui.dwYSize,25*12

   mov sui.dwXCountChars,80
   mov sui.dwYCountChars,25

   fn CreateProcess,0,"cmd.exe",0,0,0,CREATE_NEW_CONSOLE,0,0,ADDR sui,ADDR pi
   ret

main endp
end main


Regards,  Mike
Edit: I ment to say the STARTUPINFO structure, not PROCESSINFO

box

http://msdn.microsoft.com/en-us/library/ms682073%28v=VS.85%29.aspx

You could do something like:


    invoke AttachConsole, pi.dwProcessId
    invoke GetStdHandle, STD_OUTPUT_HANDLE
    mov hStdOut, eax
    invoke GetCurrentConsoleFont, hStdOut, FALSE, pConsoleFontInfo
    GetConsoleFontSize, hStdOut, pConsoleFontInfo.nFont


and then resize the window

I don't think windows.inc has CONSOLE_FONT_INFO, you might have to define it


What are you trying to accomplish? Why don't you build a console application?

ecube

you should take special care of parsing out the directory path of the process you want to run, then setting that as the lpCurrentDirectory for CreateProcess,otherwise the newly created processes default directory is that of the calling process, which is easy way to make programs crash that are dependant on dlls etc in their original directory.

Neil

If you build a Console application it has a default size of 80 X 25

dedndave

you could create a shortcut to cmd.exe and execute that  :P

Queue

If you insist on launching your own command interpreter, shouldn't you read the COMSPEC environment variable rather than executing cmd.exe? I mean, cmd.exe makes some sense as a fallback if COMSPEC is invalid for some weird reason...

Queue

dedndave

that sounds like trouble, too - you have no guarantee of how a user-specified command interpreter will behave
(not that the MS command interpreter is well-behaved, either - lol)
if you open a linux-style interpreter and start trying windows/DOS-style commands, for example

i think there is a much better soultion all the way around
that would be to create your own gui-application that has an 80x25 text display area (edit box, maybe)
much better to talk to - much easier to predict
it won't execute DOS commands - that's probably ok
you can do whatever you like without a console window

ecube

someone already did what dave's talking about on here, I know I posted in the thread but I can't seem to find it. He made a beautiful GUI thing that displayed like console text in nice color, it wasn't finished but was nice.

redskull

Startup Info for consoles is in character cells, is it not?

QuoteWhen a process uses CreateProcess, it can specify a STARTUPINFO structure, whose members control the characteristics of the first new console (if any) created for the child process. The STARTUPINFO structure specified in the call to CreateProcess affects a console created if the CREATE_NEW_CONSOLE flag is specified. It also affects a console created if the child process subsequently uses AllocConsole. The following console characteristics can be specified:


Size of the new console window, in character cells
Location of the new console window, in screen pixel coordinates
Size of the new console's screen buffer, in character cells
Text and background color attributes of the new console's screen buffer
Display name for the title bar of the new console's window
Strange women, lying in ponds, distributing swords, is no basis for a system of government

TmX

Quote from: E^cube on June 28, 2010, 11:52:06 AM
someone already did what dave's talking about on here, I know I posted in the thread but I can't seem to find it. He made a beautiful GUI thing that displayed like console text in nice color, it wasn't finished but was nice.

This one?
http://www.masm32.com/board/index.php?topic=11970.0

ecube

Yup, IDK how you managed to find it, but nice work TmX  :U you must be like a surgeon with that search box.

dedndave

yes - i thought of that one too - but couldn't think of a good search term - lol
around the same time, SlugSnack was playing with piping - if you put the two threads together, you had a nice app   :bg
(hyper-threading ?   :P )

dedndave

Mike (Slugsnack) has some code sitting on this page
9dt.zwit.org
and, if you read through the thread that TmX found, there is more info
let me see if i can find Mike's thread....

here it is
http://www.masm32.com/board/index.php?topic=11945.0

pcMike

Thanks for all the suggestions guys!

Box:  I will give that a try.

Neil: The console will not be cmd.exe, that was just an example to see the results. My application is a telnet server that will open a console window to pass the telnet users each to their own console application (a seperate bulletin board system program), and I want to allow the console size to be user-definable, so they can choose either 80x25 or 80x50.

E_Cube:  A console-like GUI would not work for my application.

RedSkull:  I reviewed the STARTUPINFO structure, and found that only the COUNTCHARACTERS are defined in character cells, the other members including dwXsize and dwYsize can only be specified in pixels.

Regards,  Mike

pcMike

hmm the GetCurrentConsoleFont process is only for XP and above, and I want my app to be able to support Win 2000 as well. :-(
I'm taking another look at the STARTUPINFO structure but I don't see any way of defining the size of the Console window in character cells.

Regards,  Mike