News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

How to make console apps default maximized?

Started by Mark Jones, May 20, 2005, 04:36:56 PM

Previous topic - Next topic

Mark Jones

I've tried:


Start:
    invoke GetModuleHandle,eax
    mov hWnd,eax
    invoke ShowWindow,hWnd,WS_MAXIMIZE   ; does not work
    invoke ShowWindow,hWnd,SW_MAXIMIZE   ; does not work
    invoke Main
    invoke ExitProcess,0


Thanks. :)
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

Jeff

console apps... windows XP?

when you say maximized, do you mean fullscreen for have the window be as large as it can?

to get it fullscreen, run your console app (or cmd.exe), go to the properties window (right click on the taskbar icon or upper-left corner), check the fullscreen radio button under the options tab and hit ok.  it will ask you to save the settings for all future windows or just the current.  make your choice.

however, i wouldnt recommend fullscreen since, well, its fullscreen so you cant see other open windows and the text is smaller than usual.  to get the maximum possible size: go to the properrties window again, go to the layout tab, with these settings:
Screen Buffer Size (how many characters can be displayed (scrollable))
Width 80 (i recommend not touching this)
Height 300 (any number will do)
Window Size (how many characters can be visible at a time)
Width 80 (i recommend not touching this)
Height 300 (initially, windows will automatically adjust this number)
Window Position (in pixels from the top left corner of the screen)
(clear "let system position window")
Left 0 (or however far you want it from the side)
Top 0

then ok, save? and so on.  :)

Mark Jones

Thanks Jeff, yes windows XP. By fullscreen I meant what happens when the "maximize" button is clicked. In my case, the window enlarges to about half the size of the screen width and docks at 0,0. I assumed that sending it a windows message would do the trick, but I guess not? The result from invoke ShowWindow,hWnd,WS_MAXIMIZE is "ERROR_INVALID_WINDOW_HANDLE (00000578)".
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

farrier

Mark Jones,

Using an "old-fashioned" technique:  start using a batch file and include--before invoking your program--the following line:

Mode con lines=25

hth,

farrier
It is a GOOD day to code!
Some assembly required!
ASM me!
With every mistake, we must surely be learning. (George...Bush)

GregL


rwalt

I have seen a trick that uses an USER32.DLL procedure, it should be something like this..


.386
.model flat,stdcall
option casemap:none

include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc

includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib

.code
start:
call FullScreenConsole
invoke Sleep,10000
invoke ExitProcess,0

FullScreenConsole proc
  invoke keybd_event,VK_MENU,38h,0,0
  invoke keybd_event,VK_RETURN,1Ch,0,0
  invoke keybd_event,VK_RETURN,1Ch,KEYEVENTF_KEYUP,0
  invoke keybd_event,VK_MENU,38h,KEYEVENTF_KEYUP,0
  ret
FullScreenConsole endp

end start


Vortex


Mark Jones

Indeed, nice trick, rwalt, thanks. :) That does the same thing as ALT+ENTER... is that literally what it is doing?

Thanks Greg, the invoke SetConsoleDisplayMode,hWnd,CONSOLE_FULLSCREEN_MODE looks like it would be a safe bet, but the call is not prototyped nor is the static defined - it looks like an XP-only API. So to manually size the console window I tried


.data
bigcoords COORD<100,80>
.code
    invoke GetModuleHandle,eax
    mov hWnd,eax
    invoke SetConsoleScreenBufferSize,hWnd,offset bigcoords


but nothing happens. Perhaps my syntax is wrong or the issues has something to do with access rights? In the fine print MSDN says the handle to the console screen buffer must have the GENERIC_READ access right.
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

GregL

Mark,

The Screen Buffer and the Console Window are two different things. They both can be sized. Set the Screen Buffer size first and then set the Console Window size with SetConsoleWindowInfo. Here is a good tutorial on that, it's for C, but you can get the underlying principles from it. Part 6 deals with the sizing of the console window.

http://www.adrianxw.dk/SoftwareSite/Consoles/Consoles1.html
 

AeroASM

I think that the reason nothing seems to be working is that you are doing hWnd = GetModuleHandle which is wrong. The get the window handle of the console window you need to do something else (AllocConsole?).

MichaelW

This is a modification of an app I posted somewhere here previously.

; ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    .486                       ; create 32 bit code
    .model flat, stdcall       ; 32 bit memory model
    option casemap :none       ; case sensitive

    include \masm32\include\windows.inc
    include \masm32\include\masm32.inc
    include \masm32\include\user32.inc
    include \masm32\include\_kernel32.inc
    includelib \masm32\lib\masm32.lib
    includelib \masm32\lib\user32.lib
    includelib \masm32\lib\_kernel32.lib
    include \masm32\macros\macros.asm
; ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    .data     
      hConsoleOutput  dd 0
      max_coord       COORD <>
      small_rect      SMALL_RECT <>
      csbi            CONSOLE_SCREEN_BUFFER_INFO <>
    .code
; ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
start:
; ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    invoke GetStdHandle,STD_OUTPUT_HANDLE
    mov   hConsoleOutput,eax

    invoke GetConsoleScreenBufferInfo,hConsoleOutput,ADDR csbi
    print chr$("console screen buffer rows = ")
    movzx eax,csbi.dwSize.y
    print ustr$(eax)
    print chr$(13,10,"console screen buffer cols = ")
    movzx eax,csbi.dwSize.x
    print ustr$(eax)
    print chr$(13,10,13,10,"console window left = ")
    movzx eax,csbi.srWindow.Left
    print ustr$(eax)
    print chr$(13,10,"console window top = ")
    movzx eax,csbi.srWindow.Top
    print ustr$(eax)
    print chr$(13,10,"console window right = ")
    movzx eax,csbi.srWindow.Right
    print ustr$(eax)
    print chr$(13,10,"console window bottom = ")
    movzx eax,csbi.srWindow.Bottom
    print ustr$(eax)   

    invoke GetLargestConsoleWindowSize,hConsoleOutput
    mov   max_coord,eax
    print chr$(13,10,13,10,"largest console window rows = ")
    movzx eax,max_coord.y
    print ustr$(eax)
    print chr$(13,10,"largest console window cols = ")
    movzx eax,max_coord.x
    print ustr$(eax)

    mov   ax,csbi.dwSize.y
    shl   eax,16
    mov   ax,max_coord.x
    invoke SetConsoleScreenBufferSize,hConsoleOutput,eax
   
    invoke GetConsoleScreenBufferInfo,hConsoleOutput,ADDR csbi
    print chr$(13,10,13,10,"console screen buffer rows = ")
    movzx eax,csbi.dwSize.y
    print ustr$(eax)
    print chr$(13,10,"console screen buffer cols = ")
    movzx eax,csbi.dwSize.x
    print ustr$(eax)

    mov   eax,input(13,10,13,10,"Press enter to continue...")

    mov small_rect.Left,0
    mov small_rect.Top,0
    mov ax,max_coord.x
    dec ax
    mov small_rect.Right,ax
    mov ax,max_coord.y
    dec ax
    mov small_rect.Bottom,ax
    invoke SetConsoleWindowInfo,hConsoleOutput,TRUE,ADDR small_rect

    invoke GetConsoleScreenBufferInfo,hConsoleOutput,ADDR csbi
    print chr$(13,10,"console window left = ")
    movzx eax,csbi.srWindow.Left
    print ustr$(eax)
    print chr$(13,10,"console window top = ")
    movzx eax,csbi.srWindow.Top
    print ustr$(eax)
    print chr$(13,10,"console window right = ")
    movzx eax,csbi.srWindow.Right
    print ustr$(eax)
    print chr$(13,10,"console window bottom = ")
    movzx eax,csbi.srWindow.Bottom
    print ustr$(eax)

    mov   eax,input(13,10,13,10,"Press enter to continue...")

    print chr$(13,10,"GetModuleHandle: ")
    invoke GetModuleHandle,NULL
    print uhex$(eax)
    print chr$(13,10)   

    call GetConsoleWindow
    mov   ebx,eax

    print chr$("GetConsoleWindow: ")
    print uhex$(ebx)   

    ;invoke ShowWindow,ebx,WS_MAXIMIZE   ; does not work
    invoke ShowWindow,ebx,SW_MAXIMIZE

    invoke GetConsoleScreenBufferInfo,hConsoleOutput,ADDR csbi
    print chr$(13,10,13,10,"console window left = ")
    movzx eax,csbi.srWindow.Left
    print ustr$(eax)
    print chr$(13,10,"console window top = ")
    movzx eax,csbi.srWindow.Top
    print ustr$(eax)
    print chr$(13,10,"console window right = ")
    movzx eax,csbi.srWindow.Right
    print ustr$(eax)
    print chr$(13,10,"console window bottom = ")
    movzx eax,csbi.srWindow.Bottom
    print ustr$(eax)

    mov   eax,input(13,10,13,10,"Press enter to exit...")
    exit
; ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
end start




[attachment deleted by admin]
eschew obfuscation

pbrennick

Michael,
Is _kernel32.inc and _kernel32.lib a special version of that library?  In any case, GetConsoleWindow can't be found without them.

Paul

GregL

According to MSDN the GetConsoleWindow function is in kernel32.dll. For some reason it's not in the MASM32 kernel32.lib nor is the PROTO in kernel32.inc. It is supported in Windows 2000 and Windows XP.

MichaelW

Hi Paul,

Thanks for spotting this. I couldn't find the original post and I had forgotten about the change I made to the library. The attachment contains a modified include file and a batch file to build the new library.

BTW, what happened to the code tags? They don't seem to work correctly.


[attachment deleted by admin]
eschew obfuscation

Mark Jones

Awesome, thanks you guys!!  :U :bg :clap: :dance:
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08