Solved

Disabling the windows close icon

Posted on 1998-04-15
1
154 Views
Last Modified: 2010-04-06
Can anyone tell me how to disable the Windows close icon i.e. the X at the top right of a Window.  I also need to enable it as well.

Any help would be appreciated.

David.
0
Comment
Question by:dl090597
1 Comment
 
LVL 1

Accepted Solution

by:
extreme earned 20 total points
ID: 1361554
This function does what you want, it's in the OnClick event of a button in a form:

procedure TForm1.Button1Click(Sender: TObject);
var
  h : THandle;
  Id : word;
  i : integer;
  Info : TMenuItemInfo;
begin
  h := GetSystemMenu(Handle, False);
  for i := 0 to GetMenuItemCount (h) - 1 do
    begin
      Id := GetMenuItemId (h, i);
      if Id = SC_CLOSE
        then
        begin
          Info.cbSize := sizeof (Info);
          Info.fMask := MIIM_STATE;
          if GetMenuItemInfo (h, Id, false, Info)
            then if Info.fState = MFS_ENABLED
              then EnableMenuItem (h, Id, MF_DISABLED or MF_GRAYED)
              else EnableMenuItem (h, Id, MF_ENABLED)
        end;
    end;
end;

Every time you press the button the function changes the state of the close menu item to the opposite depending on the current state.

Hope this serves you.
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Strange behavior when a form is closed 6 57
Making delphi communicate with a c# service 16 103
Create a path if not exists 7 77
Wincontrol not (correctly) drawn 15 38
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question