Win11 - How to start console app in non-tabbed window from Windows Explorer lazarus / 21-General ---------------------------------------------------------------------- dculp · 2025-04-16 13:40 When I start my console app in Win10 from its File Explorer, the resulting console window doesn't have tabs. (See 1st image.) The result is the same if I start my app in Win11 from a 32bit file manager (Q-dir or FreeCommander). This is the desired situation so that the correct size of the console window can be set from within my app. If I start my console app in Win11 from its File Explorer, the resulting console window has tabs. The console window isn't sized to the required size and so some of the framework at the bottom of the UI is cut off. (See 2nd image.) Dragging the window boundary to increase the window height doesn't restore the framework and the UI may become unusable. A partial solution is to start my app from a batch file that calls wt.exe (windows terminal). However, wt.exe isn't included with Win10 so it must be downloaded from the Microsoft Store. I want to avoid this for the Win10 user. Alternately, a non-tabbed cmd window could be started with admin privileges and my app could be started from there without using File Explorer. However, the end user might not have admin privileges and this extra step is not preferred. Also, the end user's natural inclination is to start the app from File Explorer. Hence, is there a way to start my console app from Win11 File Explorer in a non-tabbed window so that the UI will be correct? (Also, please let me know if perhaps there are any better forums to ask this question.) Thanks, Don C. Lazarus 3.8 (rev lazarus_3_8) FPC 3.2.2 i386-win32-win32/win64 ---------------------------------------------------------------------- PascalDragon · 2025-04-18 13:20 Quote from: dculp on April 16, 2025, 03:40:52 pmHence, is there a way to start my console app from Win11 File Explorer in a non-tabbed window so that the UI will be correct? Windows 11 changed the default terminal emulator from cmd.exe to Terminal. The application itself has no control what kind of terminal emulator will be used. I don't know if this default can be changed, but you definitely only can do this for yourself and not enforce it upon potential users of your software (in case this is relevant for your software). ---------------------------------------------------------------------- paule32 · 2025-04-18 15:07 this will be done with a Batch File: - open editor - type in: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   cmd.exe /C  dir  pause - save as foo.bat in your directory. - open Explorer:  Win-Key + E - navigate to the Path of foo.bat - double click foo.bat - voila:  A command windows will be open without tabs. ---------------------------------------------------------------------- dseligo · 2025-04-18 16:01 Quote from: paule32 on April 18, 2025, 05:07:32 pm- voila:  A command windows will be open without tabs. On my Windows 11 it still opens command window with tab. ---------------------------------------------------------------------- paule32 · 2025-04-18 16:15 you could use win32api AllocConsole to make your own Command Line Interface ---------------------------------------------------------------------- Remy Lebeau · 2025-04-18 17:55 You really should not be messing with the console window to begin with.  You don't own that window. It is not even running in your process.  If you need a customized UI, you should make your own. ---------------------------------------------------------------------- dculp · 2025-04-18 18:21 Quote from: Remy Lebeau on April 18, 2025, 07:55:21 pmYou really should not be messing with the console window to begin with.  You don't own that window. It is not even running in your process.  If you need a customized UI, you should make your own. The app is for clients. I want to supply it to them and have it run without them having to fiddle with other processes. This was fine in Win10 where the size of the cmd.exe console window could be set from within the app. (As I mentioned, for Win11 the UI doesn't display correctly with the default console window. Manually resizing the console window after the app has loaded doesn't help.) I'm currently setting up a batch file that will query the Windows version. (See discussion https://forum.lazarus.freepascal.org/index.php/topic,70722.0.html) If Win11 then the batch file will start wt.exe (Windows Terminal) which allows setting the window size and other parameters. If Win10 or earlier then it will it will just load the non-tabbed cmd.exe. This works OK but I'm still open to other suggestions. (Windows Terminal "is available in all versions of Windows 11 and versions of Windows 10 22H2 after the installation of the May 23, 2023 update". See https://learn.microsoft.com/en- us/windows/terminal/install ) Batch file possibly not quite finalized - Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i @ECHO OFFCLS SETLOCALREM See https://www.jamesparker.dev/what-is-the- setlocal-command-in-batch-files/REM SET commands must be outside "IF EXIST" block. SET App_title="CARD (Computer Aided Resonator Design)"SET App=CARD_.exe SET CMD_Windows11=%USERPROFILE%\AppData\Loca l\Microsoft\WindowsApps\wt.exeSET CMD_Windows11_path=%USERPROFILE%\App Data\Local\Microsoft\WindowsApps\SET CMD_window=%WINDIR%\System32\cmd.exe SET CRT_columns=83   REM 12/Apr/2025 - minimum for App is 83; can be larger SET CRT_rows=45   REM 12/Apr/2025 - minimum for App is 45; can be larger SET Position_X=10SET Position_Y=1 IF EXIST %App% (   Find_Windows_version;      REM Returned exitcode (ERRORLEVEL) corresponds to the Windows version   IF ERRORLEVEL 11 (      REM Win11 or higher      IF EXIST %CMD_Windows11% (         call %CMD_Windows11% --size %CRT_columns%,%CRT_rows% --pos Position_X,Position_Y --title CARD --suppressApplicationTitle -d . %CMD_window% /k %App%            REM Multi-tabbed console with title bar; dragging window does not distort UI            REM https://learn.microsoft.com/en- us/windows/terminal/command-line-arguments?tabs=windows            REM    ==> Using command line arguments for Windows Terminal            REM "-d ." flag opens wt.exe in current directory. See https://endjin.com/blog/2020/05/5-tips-for-an-awesome-windows- terminal-experience#open-the-terminal-at-the-current-directory          REM --size option must come before flag options       REM - Other console window options -REM         call %CMD_Windows11% --maximized --title CARD --suppressApplicationTitle -d . %CMD_window% /k %App%          REM Full screen with title bar; multi-tabbed console; dragging window may distort UI REM         call %CMD_Windows11% --fullscreen --title CARD --suppressApplicationTitle -d . %CMD_window% /k %App%          REM No title bar or tabs; window will start on default monitor and can't be dragged REM         call %CMD_Windows11% --focus --title CARD --suppressApplicationTitle -d . %CMD_window% /k %App%          GOTO END      ) ELSE (         cls         ECHO *** ERROR ***         ECHO Can't find %CMD_Windows11%.         ECHO This file is required in order to create the proper command window in Windows 11.         ECHO This file can be downloaded from the Microsoft Store -         ECHO    "https://apps.microsoft.com/detail/9n0dx20hk701?hl=en-US&gl=US"       ECHO For more information see -         ECHO    "https://learn.microsoft.com/en-us/windows/terminal/install"          ECHO.         PAUSE         )    ) ELSE (      call %CMD_window% /k %App%         REM Win10 or lower that don't have multi-tabbed cmd so can set window dims in App      ) ) ELSE (   cls   ECHO *** ERROR *** ECHO Can't find %App% in the current folder.   PAUSE   ) :END ENDLOCAL :: PAUSEexit ---------------------------------------------------------------------- dculp · 2025-04-18 19:04 Quote from: paule32 on April 18, 2025, 05:07:32 pmthis will be done with a Batch File: - open editor - type in: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   cmd.exe /C  dir  pause - save as foo.bat in your directory. - open Explorer:  Win-Key + E - navigate to the Path of foo.bat - double click foo.bat - voila:  A command windows will be open without tabs. Still has tabs when started from file managers Windows Explorer (64bit) and FreeCommander (32bit). However, no tabs when started from file manager Q-Dir (32bit). Curious. ---------------------------------------------------------------------- dculp · 2025-04-18 22:21 Quote from: paule32 on April 18, 2025, 06:15:47 pmyou could use win32api AllocConsole to make your own Command Line Interface I grabbed the following but it still opens cmd with tabs. Maybe this needs additional coding? Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program Get_console_window_10a;// https://forum.lazarus.freepascal.org/index.p hp/topic,12234.15.html uses   Windows; function GetConsoleWindow(): HWND; stdcall; external 'kernel32.dll' name 'GetConsoleWindow'; var   hMenuHandle: HMENU;begin   AllocConsole();    hMenuHandle := GetSystemMenu(GetConsoleWindow(), FALSE);//   DeleteMenu(hMenuHandle, SC_CLOSE, MF_BYCOMMAND);//   SetConsoleTitle('MyApp');//   DrawMenuBar(GetConsoleWindow());    // do something more here   writeln('OK');   readln;    FreeConsole();end.