Forum > General

How to hide window buttons (Minimize, Maximize and Close) in a Windows app

(1/5) > >>

Libra07:
Hi! I need to change the title of the window and hide the buttons (Minimize, Maximize and Close) on the top right corner in a small windows console application.
The users constantly close the running application or resize the window and want to prevent this.
This is not a Lazarus GUI App, only a Windows console App. So I can't set this in Lazarus window properties at Object Inspector.
And we don't need it to be platform independent, it's enough if it runs on Windows.

I made a small program to present this. This small application runs only in Windows, so this use the "Windows" unit and operating with Windows API functions.
I can save the original title, and I can update it, and restore the original value. But I don't know, how can I hide/show the buttons.
Can anyone help me with this?


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---PROGRAM Window_Title_And_Buttons;Uses Windows;Var Original_Window_Title : ShortString; Function Get_Console_Title:ShortString;Var GGet_Title,    SGet_Title  : ShortString;    LX          : Longint;Begin  GETConsoleTitle(@GGet_Title[1],255);   SGet_Title:='';  LX:=1;  While GGet_Title[LX]<>#0 Do  Begin    SGet_Title:=SGet_Title+GGet_Title[LX];    Inc(LX);  End;   Get_Console_Title:=SGet_Title;End; Procedure Set_Console_Title(CTitle:ShortString);Begin  SETConsoleTitle(@CTitle[1]);End; Begin  Writeln('Press ENTER to update Window Title...');  ReadLn;   Original_Window_Title:=Get_Console_Title;  Set_Console_Title('Demo program...'#0);   Writeln('Press ENTER to restore original Window Title...');  ReadLn;   Set_Console_Title(Original_Window_Title+#0);   Writeln('Press ENTER to Exit...');  ReadLn;End. 
Here are the Windows Console API functions, but I can't find the right one:
https://learn.microsoft.com/en-us/windows/console/console-functions

tr_escape:
By the way I am trying to ChatGPT so I asked it and answer is:

Me:How to hide window button of the console/cmd screen in lazarus/fpc

GPT: It is not possible to hide the window buttons on a console or command prompt screen in Lazarus/Free Pascal. The console or command prompt is a separate application from your Lazarus/Free Pascal program, and it does not provide any methods or properties that allow you to manipulate the appearance of its window.

In general, you cannot control the appearance of the console or command prompt window from a Lazarus/Free Pascal program. The only way to hide the window buttons would be to use the operating system's window management functions to manipulate the console or command prompt window directly, but this is not possible using Lazarus/Free Pascal alone.

If you want to hide the window buttons on a form in your Lazarus/Free Pascal program, you can use the BorderStyle property of the TForm object, as I described in my previous response. This property allows you to control the type of border and buttons that are displayed on the form, including the option to hide the buttons completely. However, this will only affect the form within your Lazarus/Free Pascal program, and it will not affect the console or command prompt window.

tr_escape:
But I think :

https://learn.microsoft.com/en-us/windows/console/getconsolewindow

You can take handle of the current console window

tr_escape:
After some chat by ChatGPT I remember some functions of the Windows :)

So of course winApi gives a lot of option that I just tried another way...



--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program consolewin; uses  Windows; var   handle: THANDLE;  Wnd: HWND;  // Handle to the window  Style: longint;  // Window style attributes  Title: array[0..255] of char;  // Buffer to store the console title begin  handle := Windows.GetConsoleWindow();  if handle <> 0 then  begin    GetConsoleTitle(Title, Length(Title));    WriteLn(Title);    // Get the handle to the window you want to hide the buttons for    Wnd := FindWindow('consolewin', Title);     // Get the current window style attributes    Style := GetWindowLong(handle, GWL_STYLE);     // Modify the window style to hide the buttons    Style := Style and not (WS_SYSMENU or WS_MINIMIZEBOX or WS_MAXIMIZEBOX);     // Set the modified window style attributes    // SetWindowLong(Wnd, GWL_STYLE, Style);     // Set the modified window style attributes    SetWindowLong(handle, GWL_STYLE, Style);   end;  ReadLn;end. 

GetMem:
@tr_escape

Very nice! I almost posted something similar, then I saw your reply. As a side note you can still close the application with Alt + F4.

Navigation

[0] Message Index

[#] Next page

Go to full version