The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: Mark Jones on May 20, 2005, 04:36:56 PM

Title: How to make console apps default maximized?
Post by: Mark Jones on May 20, 2005, 04:36:56 PM
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. :)
Title: Re: How to make console apps default maximized?
Post by: Jeff on May 20, 2005, 05:39:56 PM
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.  :)
Title: Re: How to make console apps default maximized?
Post by: Mark Jones on May 20, 2005, 05:51:16 PM
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)".
Title: Re: How to make console apps default maximized?
Post by: farrier on May 21, 2005, 02:46:07 AM
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
Title: Re: How to make console apps default maximized?
Post by: GregL on May 21, 2005, 03:16:28 AM
Console Functions
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/console_functions.asp

Specifically SetConsoleWindowInfo and SetConsoleScreenBufferSize
Title: Re: How to make console apps default maximized?
Post by: rwalt on May 21, 2005, 04:06:02 AM
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

Title: Re: How to make console apps default maximized?
Post by: Vortex on May 21, 2005, 08:32:32 AM
rwalt,

Thanks for the trick, it works :U
Title: Re: How to make console apps default maximized?
Post by: Mark Jones on May 22, 2005, 11:39:03 PM
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.
Title: Re: How to make console apps default maximized?
Post by: GregL on May 23, 2005, 02:13:57 AM
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
 
Title: Re: How to make console apps default maximized?
Post by: AeroASM on May 23, 2005, 07:06:44 AM
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?).
Title: Re: How to make console apps default maximized?
Post by: MichaelW on May 23, 2005, 09:46:56 AM
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]
Title: Re: How to make console apps default maximized?
Post by: pbrennick on May 23, 2005, 11:21:19 AM
Michael,
Is _kernel32.inc and _kernel32.lib a special version of that library?  In any case, GetConsoleWindow can't be found without them.

Paul
Title: Re: How to make console apps default maximized?
Post by: GregL on May 23, 2005, 08:45:39 PM
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.
Title: Re: How to make console apps default maximized?
Post by: MichaelW on May 23, 2005, 08:50:30 PM
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]
Title: Re: How to make console apps default maximized?
Post by: Mark Jones on May 23, 2005, 09:44:27 PM
Awesome, thanks you guys!!  :U :bg :clap: :dance:
Title: Re: How to make console apps default maximized?
Post by: rwalt on May 24, 2005, 04:15:04 AM
Quote from: Mark Jones on May 22, 2005, 11:39:03 PM
Indeed, nice trick, rwalt, thanks. :) That does the same thing as ALT+ENTER... is that literally what it is doing?.

Yes, it is a virtual ALT+ENTER keyboard event. A second call to the procedure will drop it back to a window.
Title: Re: How to make console apps default maximized?
Post by: pbrennick on May 24, 2005, 11:06:43 AM
Hi Michael,
I don't see anything strange going on with the code tags.  Are you still having a problem?

Paul
Title: Re: How to make console apps default maximized?
Post by: MichaelW on May 24, 2005, 06:54:59 PM
Hi Paul,

Yes I am. I started a new topic.

http://www.masmforum.com/simple/index.php?topic=1742.0