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!).
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.)
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.
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.
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
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
}
}
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:
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();
}
}
}
© 2022 - 2025 — McMap. All rights reserved.