C# full screen console?
Asked Answered
S

6

15

I have seen that Windows can switch to the very basic console interface when updating the video drivers and I have also seen programs like Borland C++ doing this.
I'd really like to know how to make this with a console application in C# (or VB.NET if you prefer), and I don't mind using P/Invoke's (and I bet I must!).

Surely answered 12/12, 2010 at 18:2 Comment(8)
If the application should be full screen, I'd consider creating a windows application instead of a console application. Unless you have requirements that say it must be a console application, there really is no reason not to go with a window.Desorb
Yes, well I am going to use a full screen form with a console-like control.Surely
My approach works fine how do you say it's not working?Capsular
Try it on Windows Vista or Windows Seven. PLUS I was looking for a method to do this with my console alone.Surely
You can examine the way CYGWIN is doing the things. I use minty and its console is windowed, and has a maximize which takes the whole screen.Damoiselle
The C# System.Console codebase doesn't even provide a wrapper to fullscreen functionality, so Vercas is correct: P/Invoke's are a must.Steinman
By the way: There still are no solution to the question. Providing custom console widget for an apllication is a solution but how to do that? Are there any opensource libraries implementing that?Cacography
@JakubJagiełło I was looking for a custom console host just a few days ago... More precisely, I am looking into providing window size and other such parameters reliably. I did not find anything helpful.Surely
R
6

In older versions of Windows you could put any console into full screen with Alt-Enter (if I remember correctly).

With the introduction of the Desktop Window Manager and full screen composition via the GPU in Vista that full screen console window function was removed.

(When updating the graphics driver the graphics subsystem is being reset, what you see isn't a console window, but the graphics card default startup into text mode.)

Repel answered 12/12, 2010 at 18:13 Comment(9)
Thanks, this is the most complete (can I say that?) answer of all!Surely
Alt+Enter still works on console windows in Windows 10.Fash
@MatheusRocha, in my Win10, ALT-Enter performs a maximize but not a full screen.Multivocal
@Multivocal Some config might be preventing full screen windows. By default (tested on a brand new updated installation of Win10) Alt+Enter makes the console window full screen. Have you searched around about any configs or registry keys that might have control over this behaviour?Fash
@MatheusRocha try doing an alt-tab: the console window stays the same: it is maximised without a title bar. In older Windows there was a screen mode change to text and alt-tab away out restore the console window. Based on the question (graphics card switching to text mode) what happens today is not the old "full screen text mode".Repel
Additionally: Windows Terminal is so much more functional for command line purposes I really don't understand why anyone would want the old console windows...Repel
@Repel It certainly isn't the same, but the asker just wants to replicate the "full screen console" appearance AFAIK.Fash
@Repel The asker doesn't wanna use the Cmd nor the terminal, he wants to replicate that behaviour in C#. C# console applications use the native console window, same as the command prompt.Fash
@Repel Just to clarify: It uses the native console window ENCAPSULATED by managed code. But it's still the native console window under the hood.Fash
K
3

Windows 7 does not support Full Screen console applications. On XP you can use SetConsoleDisplayMode, you will need to P/Invoke to this, but it is relatively simple. I know on win 7 x64 this function will fail with error 120 This function is not spported on this system

To get the console handle you can use some of the code from this answer.

Kneedeep answered 12/12, 2010 at 18:17 Comment(2)
On CMD (x86, Windows 7) I get an error that the device driver does not support this.Surely
@Vercas: Actually, it is device driver dependent. The support or lack thereof is in the OS code, not the driver, but different OS code paths get used for legacy display drivers (support is present) vs WDDM (no support for full-screen).Fourlegged
C
1

You can right click on your console, click properties, and in option pan, set it to Full Screen. you can save this changes to be persist.

Capsular answered 12/12, 2010 at 18:19 Comment(6)
Is this still available on Windows 7 (and Vista)?Desorb
@Hans Unfortunately, that is true in this case.Surely
@Jason Down, I have XP sp3, I didn't know about Seven, @Vercas, @Hans Passant, It works carefully in XP, and because you can set it to be persist, It's useful for stand alone applications, because there is no need to do for each running of a program, you will do it after installation.Capsular
@Vercas, just be care full, you should set the Console of .net frame work, not usual command prompt, goto install folder of framework and find it.Capsular
@Saeed It doesn't work on Windows Vista and Windows Seven, so this is a dead cause.Surely
Also not present in Win 11, so definitely a dead causeDarwinism
F
1

Do you mean unloading the GUI altogether, or changing screen resolution, like when you install a new device driver and windows goes to 800x600/8bpp, instead of your normal resolution? I cant help if you want a full screen console, but if you are trying to change your screen resolution, etc, take a look at http://www.c-sharpcorner.com/UploadFile/GemingLeader/display-settings08262009094802AM/display-settings.aspx

Fungoid answered 12/12, 2010 at 18:21 Comment(1)
Uh... This is the answer to another question of mine.Surely
S
1

Perhaps my implementation here may help. Note that this will not work on windows systems lacking text-mode driver support.

using System;
using System.IO;
using System.Collections.Generic; //for dictionary
using System.Runtime.InteropServices; //for P/Invoke DLLImport

class App
{

        /// <summary>
        /// Contains native methods imported as unmanaged code.
        /// </summary>
        internal static class DllImports
        {
            [StructLayout(LayoutKind.Sequential)]
            public struct COORD
            {

                public short X;
                public short Y;
                public COORD(short x, short y) { 
                    this.X = x;
                    this.Y = y;
                }

            }
            [DllImport("kernel32.dll")]
            public static extern IntPtr GetStdHandle(int handle);
            [DllImport("kernel32.dll", SetLastError = true)]
            public static extern bool SetConsoleDisplayMode(
                IntPtr ConsoleOutput
                ,uint Flags
                ,out COORD NewScreenBufferDimensions
                );
        }
        /// Main App's Entry point
        public static void Main (string[] args)
        {
            IntPtr hConsole = DllImports.GetStdHandle(-11);   // get console handle
            DllImports.COORD xy = new DllImports.COORD(100,100);
            DllImports.SetConsoleDisplayMode(hConsole, 1, out xy); // set the console to fullscreen
            //SetConsoleDisplayMode(hConsole, 2);   // set the console to windowed

        }
}
Steinman answered 18/9, 2012 at 8:18 Comment(0)
P
0

good but wrong question duo to the lack of deep understanding the concept of a "console" in a generic fashion

1- why the question is wrong?


assume a tty:
enter image description here
if you want to change the size of a console app window from the code which is responsible for the program of that console app, it is similar that you want to write outside of the paper which is in the tty device!!
in other words, a console in your computer is like a virtual paper for the program you write in c# (or...), if for example the maximum width of your console window is 1000px you can change your console maximum available width, maximum to n where n<=1000 (e.g.: in windows console you can use Console.BufferWidth property for this) but you can not change the width of the window which is responsible for showing the console to you from your console app program (instead of using .Net libraries which are for changing windows properties in your console app) cause actually that is non sence!
so the right question is:

how to change the size of the window which is responsible to monitor a console application?

2- now what is workaround?


2-1- logical and robust way: use .Net UI Automation for this, you can get the process of your console app (e.g. with Process.GetCurrentProcess()), get the AutomationElement from your process, put it into a WindowPattern and finally you can perform a method like yourTarget.SetWindowVisualState(WindowVisualState.Maximized) or anything you want on it
2-2- hacky and not robust way: use below code:

using System;  
using System.Collections.Generic;  
using System.Linq;  
using System.Text;  
using System.IO;  
using System.Diagnostics;  
using System.Runtime.InteropServices;  
namespace Consolefullscreen  
{  
   class Program  
   {  
      [DllImport("kernel32.dll", ExactSpelling = true)]  
      private static extern IntPtr GetConsoleWindow();  
      private static IntPtr ThisConsole = GetConsoleWindow();  
      [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]  
      private static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);  
      private const int HIDE = 0;  
      private const int MAXIMIZE = 3;  
      private const int MINIMIZE = 6;  
      private const int RESTORE = 9;  
      static void Main(string[] args)  
      {  
         Console.SetWindowSize(Console.LargestWindowWidth, Console.LargestWindowHeight);  
         ShowWindow(ThisConsole, MAXIMIZE);  
         Console.ReadLine();  
      }  
   }  
}  
Photoelectron answered 12/6, 2022 at 23:9 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.