Recent

Author Topic: Console Application Full Screen?  (Read 11927 times)

nobodyknowsme

  • Full Member
  • ***
  • Posts: 114
Console Application Full Screen?
« on: December 04, 2014, 05:39:40 pm »
I looked it up and tried this code but it wont work.

http://wiki.freepascal.org/Application_full_screen_mode

Code: [Select]
unit Unit1;
 
{$mode objfpc}{$H+}
 
interface
 
uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
  Menus;
 
type
 
  { TForm1 }
 
  TForm1 = class(TForm)
    procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
  private
  public
    OriginalBounds: TRect;
    OriginalWindowState: TWindowState;
    ScreenBounds: TRect;
    procedure SwitchFullScreen;
  end;
 
var
  Form1: TForm1;
 
implementation
 
{$R *.lfm}
 
{ TForm1 }
 
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState
  );
const
  KeyF11 = 122;
begin
  if Key = KeyF11 then SwitchFullScreen;
end;
 
procedure TForm1.SwitchFullScreen;
begin
  if BorderStyle <> bsNone then begin
    // To full screen
    OriginalWindowState := WindowState;
    OriginalBounds := BoundsRect;
 
    BorderStyle := bsNone;
    ScreenBounds := Screen.MonitorFromWindow(Handle).BoundsRect;
    with ScreenBounds do
      SetBounds(Left, Top, Right - Left, Bottom - Top) ;
  end else begin
    // From full screen
    {$IFDEF MSWINDOWS}
    BorderStyle := bsSizeable;
    {$ENDIF}     
    if OriginalWindowState = wsMaximized then
      WindowState := wsMaximized
    else
      with OriginalBounds do
        SetBounds(Left, Top, Right - Left, Bottom - Top) ;
    {$IFDEF LINUX}
    BorderStyle := bsSizeable;
    {$ENDIF} 
  end;
end;
 
end.

How would I start a console application in full screen?

Never

  • Sr. Member
  • ****
  • Posts: 409
  • OS:Win7 64bit / Lazarus 1.4
Re: Console Application Full Screen?
« Reply #1 on: December 04, 2014, 06:32:28 pm »
what is the OS that you are trying to achive this goal?
The code you are refering is not about a console app
Νέπε Λάζαρε λάγγεψων οξωκά ο φίλοσ'ς αραεύσε

nobodyknowsme

  • Full Member
  • ***
  • Posts: 114
Re: Console Application Full Screen?
« Reply #2 on: December 04, 2014, 09:04:45 pm »
Windows :)

Never

  • Sr. Member
  • ****
  • Posts: 409
  • OS:Win7 64bit / Lazarus 1.4
Re: Console Application Full Screen?
« Reply #3 on: December 04, 2014, 09:13:14 pm »
version?
Νέπε Λάζαρε λάγγεψων οξωκά ο φίλοσ'ς αραεύσε

nobodyknowsme

  • Full Member
  • ***
  • Posts: 114
Re: Console Application Full Screen?
« Reply #4 on: December 08, 2014, 05:47:07 pm »
Windows 7. Is there any way to make the console open in full screen?

Leledumbo

  • Hero Member
  • *****
  • Posts: 8836
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Console Application Full Screen?
« Reply #5 on: December 08, 2014, 06:24:47 pm »
Windows 7. Is there any way to make the console open in full screen?
No, Windows 7 no longer allows it, not even in Vista AFAIR. XP is the last Windows version supporting fullscreen console apps.

Never

  • Sr. Member
  • ****
  • Posts: 409
  • OS:Win7 64bit / Lazarus 1.4
Re: Console Application Full Screen?
« Reply #6 on: December 08, 2014, 07:58:00 pm »
you can do this via registry key HCU/Console--->ScreenBufferSize
to confirm what beeing said open cmd
right click on title bar
go properties
go tab layout
at the right there is a groupbox named  [ ScreenBufferSize ]
Set the value of the Width property from 80 to 900
Set the value of the Height property from 300 to 900 or 1000 or 1200 any big number will do
click ok
press maximize
there is a registry class to help you change these values with code
you can also export the registry key and execut it when ever you want the values changed and just delete the new key to restore the default values
 *do not alter your default properties*
Νέπε Λάζαρε λάγγεψων οξωκά ο φίλοσ'ς αραεύσε

nobodyknowsme

  • Full Member
  • ***
  • Posts: 114
Re: Console Application Full Screen?
« Reply #7 on: December 08, 2014, 08:43:36 pm »
If I give this game to someone else (its an exe) will they have to chnage the buffer on their PC?

Never

  • Sr. Member
  • ****
  • Posts: 409
  • OS:Win7 64bit / Lazarus 1.4
Re: Console Application Full Screen?
« Reply #8 on: December 08, 2014, 11:10:25 pm »
yes if win version is lower than vista as Leledumbo mention

Edit*** the correct is
yes if win version is NOT lower than vista as Leledumbo mention
« Last Edit: December 09, 2014, 08:24:13 am by Never »
Νέπε Λάζαρε λάγγεψων οξωκά ο φίλοσ'ς αραεύσε

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: Console Application Full Screen?
« Reply #9 on: December 09, 2014, 12:00:56 am »
This works for Windows XP:
Code: [Select]
uses
..., Windows;
...
//not found in Windows unit
function GetConsoleWindow: HWND; stdcall; external 'Kernel32.dll';
function SetConsoleDisplayMode(hConsoleOutput: Handle; dwFlags: DWORD; lpNewScreenBufferDimensions: PCOORD): BOOL; stdcall; external 'Kernel32.dll';

const
  CONSOLE_FULLSCREEN_MODE = 1;
...
  SetConsoleDisplayMode(GetStdHandle(STD_OUTPUT_HANDLE), CONSOLE_FULLSCREEN_MODE, nil);

nobodyknowsme

  • Full Member
  • ***
  • Posts: 114
Re: Console Application Full Screen?
« Reply #10 on: December 09, 2014, 08:54:12 pm »
whats with uses, ...? The dots?

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: Console Application Full Screen?
« Reply #11 on: December 09, 2014, 09:56:15 pm »
whats with uses, ...? The dots?

They mean:
1-Make sure to add Windows to your uses section.
2-Make sure to import SetConsoleDisplayMode from Kernel32.dll directly because it is not imported in Windows unit. (GetConsoleWindow is not needed here, so you can forget about it).
3-Make sure to add CONSOLE_FULLSCREEN_MODE to your constants.
4-Finally, when you need to switch to full screen mode on WinXP, call SetConsoleDisplayMode.

Never

  • Sr. Member
  • ****
  • Posts: 409
  • OS:Win7 64bit / Lazarus 1.4
Re: Console Application Full Screen?
« Reply #12 on: February 07, 2015, 09:13:52 pm »
recently had a request to refactor several portions of an old app
 had to solve this issue also for win7
so this is what worked for me maybe will be useful for someone else
Code: [Select]
uses
  sysutils,
   Forms, Interfaces,
  windows,
  {$IFDEF UNIX}{$IFDEF UseCThreads}
  cthreads,
  {$ENDIF}{$ENDIF}
  Classes   ................

......................
......................
procedure proc_DoMaximizeConsole;
var   loc_Out:HANDLE;
      loc_Handle: THandle;
      loc_MaxSize:COORD;
      loc_NewDisplay:TSmallRect;
begin
  loc_Handle:=FindWindow(nil, pchar(Application.ExeName));
  loc_Out:=GetStdHandle(STD_OUTPUT_HANDLE);
  loc_MaxSize:=GetLargestConsoleWindowSize(loc_Out);
  SetConsoleScreenBufferSize(loc_Out, loc_MaxSize);
   with loc_NewDisplay do begin
     Right:=loc_MaxSize.X;
     Bottom:=loc_MaxSize.Y;
   end;
   SetConsoleWindowInfo(loc_Out, True, loc_NewDisplay);
   ShowWindow(loc_Handle, SW_MAXIMIZE);
   ReadLn;
end;     
begin

   proc_DoMaximizeConsole;
.......................
.......................

end. 


Νέπε Λάζαρε λάγγεψων οξωκά ο φίλοσ'ς αραεύσε

 

TinyPortal © 2005-2018