Solved

Disabling the windows close icon

Posted on 1998-04-15
1
152 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

708 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now