Solved

Disabling the windows close icon

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

726 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