Solved

Disabling the windows close icon

Posted on 1998-04-15
1
158 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

696 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