?
Solved

Disabling the windows close icon

Posted on 1998-04-15
1
Medium Priority
?
161 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 40 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses
Course of the Month9 days, 4 hours left to enroll

765 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