The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: QvasiModo on February 09, 2006, 07:55:57 PM

Title: Full screen consoles?
Post by: QvasiModo on February 09, 2006, 07:55:57 PM
A quick question, how do I programatically set a console in full screen mode? I've been looking at the console functions at MSDN, but found nothing of interest there.
Title: Re: Full screen consoles?
Post by: QvasiModo on February 09, 2006, 08:01:08 PM
Mhm, this turned up at Google:

http://www.sunlightd.com/Windows/FAQ.html#ConsoleFullScreen

QuoteCan I make a console window start up full screen programmatically?

No. There is currently no documented way to switch between windowed and full-screen mode in console applications.

I guess I'll have to try sending Alt+Enter to the console window. :(
Title: Re: Full screen consoles?
Post by: farrier on February 09, 2006, 09:27:53 PM
QvasiModo,

If you can launch from a batch file, try this line before launching your program:

mode con lines=25
MyProgramName


hth,

farrier
Title: Re: Full screen consoles?
Post by: Casper on February 09, 2006, 09:34:23 PM
It does not work on XP using cmd or command

Casper.
Title: Re: Full screen consoles?
Post by: MichaelW on February 09, 2006, 10:49:21 PM
This works under Windows 2000:

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    include \masm32\include\masm32rt.inc

    CONSOLE_FULLSCREEN_MODE EQU 1
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    .data
       pSetConsoleDisplayMode dd 0
       coord                  COORD <>
       x81                    db 81 dup ('x'),0
    .code
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
start:
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    invoke GetModuleHandle,chr$("kernel32.dll")
    invoke GetProcAddress,eax,chr$("SetConsoleScreenBufferInfoEx")
    print ustr$(eax),13,10
   
    invoke GetModuleHandle,chr$("kernel32.dll")
    invoke GetProcAddress,eax,chr$("SetConsoleDisplayMode")
    mov   pSetConsoleDisplayMode, eax
    push  OFFSET coord       
    push  CONSOLE_FULLSCREEN_MODE
    invoke GetStdHandle,STD_OUTPUT_HANDLE
    push  eax
    call  pSetConsoleDisplayMode

    movzx eax, coord.x
    print ustr$(eax),"x"
    movzx eax, coord.y
    print ustr$(eax),13,10

    print ADDR x81,13,10
    mov   ebx, 4
    REPEAT 45
      inc   ebx
      print ustr$(ebx),13,10
    ENDM
   
    inkey "Press any key to exit..."
    exit
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
end start


Per  this MSDN page (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/setconsoledisplaymode.asp) SetConsoleDisplayMode requires Windows XP or later. Perhaps it was simply undocumented for previous versions of Windows. I don't have any way to test under Windows 9x.

EDIT:

I screwed up on the code and passed the COORD value instead of the address. I have now corrected the problem and added some other details. On my system (running Windows 2000) the return value for coord.x is 65404, the return value for coord.y is 18, and the size of the screen in characters is 80x50. So I don't know whether there is a problem with the documentation, or the version of kernel32.dll on my system.

There is also a new function  SetConsoleScreenBufferInfoEx (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/setconsolescreenbufferinfoex.asp) which is not present in the version of kernel32.dll on my system.

Title: Re: Full screen consoles?
Post by: farrier on February 09, 2006, 11:37:55 PM
Casper,

If your post was directed at my post:
From a batch file, it does!  You usually have to set the Properties to set the app to run in a Maximized window.

MichaelW shows the better way, originally in:

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

farrier
Title: Re: Full screen consoles?
Post by: Mincho Georgiev on February 09, 2006, 11:46:54 PM
Yes, requires Windows XP or later, and maybe will be a good idea to be added as regular WinAPI ,not a underground one like now:



[attachment deleted by admin]
Title: Re: Full screen consoles?
Post by: Mincho Georgiev on February 09, 2006, 11:48:31 PM
I'm sorry Michael, i didn't saw what you've posted already  :'(
Title: Re: Full screen consoles?
Post by: P1 on February 10, 2006, 01:33:01 AM
You can also change the mode by setting the proper values in the registry ( Done before starting your app. ), so that the default mode is FullScreen and 80X25.

Regards,  P1  :8)
Title: Re: Full screen consoles?
Post by: zooba on February 10, 2006, 01:34:36 AM
It's generally a bad idea in UI terms to force the user to forfeit their entire screen to your program - hence the PIF option and the Alt-Enter shortcut. However, no rule is unbreakable if your reasoning is good enough :U :bg
Title: Re: Full screen consoles?
Post by: MichaelW on February 10, 2006, 01:54:09 AM
Quote from: farrier on February 09, 2006, 11:37:55 PM
MichaelW shows the better way, originally in:

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

The app I posted in that topic maximizes the console window (or at least that is what it does on my system).

Title: Re: Full screen consoles?
Post by: QvasiModo on February 10, 2006, 05:33:29 PM
Wow, tons of info, thanks a lot guys! :U

I also asked a friend about this and he gave me this link:
http://www.gametutorials.com/forum/topic.asp?ARCHIVE=true&TOPIC_ID=11870

This line does the trick:
SendMessage( hWndConsole, WM_SYSKEYDOWN, VK_RETURN, 0x20000000 );

Still the SetConsoleDisplayMode method is the best, I'll check out if it existed in NT as well as 2K.