Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

disable console screen resizing #33

Closed
goblinfactory opened this issue Dec 4, 2019 · 5 comments
Closed

disable console screen resizing #33

goblinfactory opened this issue Dec 4, 2019 · 5 comments

Comments

@goblinfactory
Copy link
Owner

goblinfactory commented Dec 4, 2019

When running a console executable in windows, if you resize the console window while the app is running it totally wrecks the layout. Like below ... (this is not a bug with Konsole, it's a behavior of windows consoles, there's a checkbox setting in options, that is on by default to "wrap text on resize". ) Using platform detection it might be possible to provide a switch to lock the window from being resized. Alternatively, launch a custom console emulator? This issue goes hand in hand with issue #32 as a core requirement for Konsole to be able to be used to build commercial applications and utilities. If the speed of Konsole can be dramatically improved, then detecting resize and offering a Redraw facility similar to Winforms then becomes a realistic option.

Capture

Capture

@goblinfactory
Copy link
Owner Author

goblinfactory commented Dec 4, 2019

alternatively, see if we can simply have this value unchecked as part of the console app setting. This is new BTW and has only been added in windows 10.

@goblinfactory
Copy link
Owner Author

goblinfactory commented Dec 4, 2019

blows me away that this is not available in .net ?
https://docs.microsoft.com/en-us/windows/console/setconsolemode

BOOL WINAPI SetConsoleMode(
  _In_ HANDLE hConsoleHandle,
  _In_ DWORD  dwMode
);

Grrr, just reading more, there is an enticingly almost right setting that does text wrapping, but that's only for when text is being written, and does not impact when the screen is resized, so this does not look like it helps! hashtag redherring.

@goblinfactory
Copy link
Owner Author

Quick update : @eiredrake has confirmed in closed issue #28 that adding the following code does stop a console app from being resized; That looks like a plausible option, just need a nice .net core (.net standard) way to deliver this with the nuget package.

class Program
    {
        private const int MF_BYCOMMAND = 0x00000000;
        public const int SC_CLOSE = 0xF060;
        public const int SC_MINIMIZE = 0xF020;
        public const int SC_MAXIMIZE = 0xF030;
        public const int SC_SIZE = 0xF000;

        [DllImport("user32.dll")]
        public static extern int DeleteMenu(IntPtr hMenu, int nPosition, int wFlags);

        [DllImport("user32.dll")]
        private static extern IntPtr GetSystemMenu(IntPtr hWnd, bool bRevert);

        [DllImport("kernel32.dll", ExactSpelling = true)]
        private static extern IntPtr GetConsoleWindow();

        static void Main(string[] args)
        {
            IntPtr handle = GetConsoleWindow();
            IntPtr sysMenu = GetSystemMenu(handle, false);

            if (handle != IntPtr.Zero)
            {
                DeleteMenu(sysMenu, SC_CLOSE, MF_BYCOMMAND);
                DeleteMenu(sysMenu, SC_MINIMIZE, MF_BYCOMMAND);
                DeleteMenu(sysMenu, SC_MAXIMIZE, MF_BYCOMMAND);
                DeleteMenu(sysMenu, SC_SIZE, MF_BYCOMMAND);
            }
            Console.Read();
        }

    }

code is from : https://social.msdn.microsoft.com/Forums/vstudio/en-US/1aa43c6c-71b9-42d4-aa00-60058a85f0eb/c-console-window-disable-resize?forum=csharpgeneral

@eiredrake
Copy link

Interesting. I'll poke that now.

Yep... that prevents it from going wacky. very cool.

goblinfactory added a commit that referenced this issue Dec 4, 2019
@goblinfactory
Copy link
Owner Author

@eiredrake Just released version 4.1 which includes new method .LockConsoleResizing() on windows class. Give that a go. Closing this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants