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

redskull

I have success by specifiying 80 and 25 in both dwNSize and dwNCountChars, and by using STARTF_USECOUNTCHARS but *NOT* STARTF_USESIZE.

Nevermind, i just can't count
Strange women, lying in ponds, distributing swords, is no basis for a system of government

dedndave

that's why i was suggesting a shortcut to cmd.exe
with a shortcut, you can easily specify the font/pitch, number of columns, and number of lines (as well as colors   :bg )
it will work on any OS (older OS's - it may not be named cmd.exe, but it will still work)
also - you shouldn't have any "permissions" issues opening a console window
if you do, the shortcut can be customized to "run as administrator"

i am not sure how to execute the target of a shortcut, but i am sure it isn't hard
you could store it in the program folder as a .DAT file, then rename it to .LNK when needed
that will keep it from being recognized and tampered with
it won't take up a lot of space, either - lol

pcMike

dedndave: I can't use a shortcut as I need to create the process using InheritHandles=True in order to pass it a live socket.

I tried using the AttachConsole function to get the console's standard output handle, thinking I could use that to adjust it's size using SetConsoleWindowInfo, but this didn't do anything at all to the size.

      

include C:\masm32\include\masm32rt.inc
.data
small_rect      SMALL_RECT <>

hStdOut  dd 0
Console_X_size dd 80
Console_Y_size dd 50

.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

    mov eax, Console_X_size
    mov sui.dwXCountChars,eax
    mov eax, Console_Y_size
    mov sui.dwYCountChars,eax

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

    invoke Sleep,2000

    invoke AttachConsole, pi.dwProcessId
    invoke GetStdHandle, STD_OUTPUT_HANDLE
    mov hStdOut, eax
    mov small_rect.Left,0
    mov small_rect.Top,0
    mov eax,Console_X_size
    dec eax
    mov small_rect.Right,ax
    mov eax,Console_Y_size
    dec eax
    mov small_rect.Bottom,ax
    invoke SetConsoleWindowInfo,hStdOut,TRUE,ADDR small_rect
    .if EAX == 0
      print "SetConsoleWindowInfo has failed"
    .endif
   ret

main endp
end main


Edit: I see now that the SetConsoleWindowInfo proc fails.

Regards,  Mike

frktons

Mind is like a parachute. You know what to do in order to use it :-)

jj2007

An alternative route is to tweak the registry programmatically or with a *.reg file. Here is what I use to get a very wide screen with almost no margins, ideal for testbeds with a lot of output:

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Console\D:_masm32_RichMasm_richmasm.exe]
"WindowSize"=dword:002c0080
"FontSize"=dword:00120000
"FontFamily"=dword:00000036
"FontWeight"=dword:0000012c
"FaceName"="Lucida Console"
"HistoryNoDup"=dword:00000000
"ScreenBufferSize"=dword:012c0078
"WindowPosition"=dword:ffecfffd


You need to know the console window title in advance, though. The understrokes are Windows' way to circumvent backslashes.

dedndave

oh - little off topic, but i thought they used double-backslashes in registry paths

jj2007

Quote from: dedndave on June 28, 2010, 11:33:30 PM
oh - little off topic, but i thought they used double-backslashes in registry paths

In the *.reg files and the registry itself the understroke is being used for console window names. I haven't tested what you need when you write to the registry programmatically.

Slugsnack

the double backslash is only used when using a slash in a string literal. it is simply used to escape the regular backslash + the next character sort of like an escape from the regular escape sequences.

for example :
hello/next/lala

the /n would by default be converted to a 'newline'. so we put hello//next//lala

all paths in windows are a single slash, not double slash. that is not to say there is nothing that uses double ( which means quadruple ) backslash though. for example createnamedpipe :
http://msdn.microsoft.com/en-us/library/aa365150(VS.85).aspx