Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to disable the close button of a TForm Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
28-Oct-02
Category
VCL-Forms
Language
Delphi 2.x
Views
167
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Jonas Bilinkevicius

How to disable the close button of a TForm

Answer:

Solve 1:
1   
2   procedure EnableCloseButton(const bEnable: Boolean);
3   const
4     MenuFlags: array[Boolean] of Integer = (MF_DISABLED, MF_ENABLED);
5   var
6     hSysMenu: HMENU;
7   begin
8     hSysMenu := GetSystemMenu(Handle, False);
9     if hSysMenu > 0 then
10      EnableMenuItem(hSysMenu, SC_CLOSE, MF_BYCOMMAND or MenuFlags[bEnable]);
11  end;



Solve 2:

The usual approach is to disable or enable the corresponding item in the forms 
system menu. However, that does not work for all of them. You can always trap the 
WM_SYSCOMMAND message caused by clicking on the items and not pass it on, but this 
way the border icons do not appear disabled.

12  { ... }
13  EnableMenuItem(GetSystemMenu(handle, False), SC_CLOSE, MF_BYCOMMAND or MF_GRAYED); 
        

That will disable the close box, for example.


Solve 3:

Remember that certain combinations will cause different results (ie. removing the 
system menu will also disable minimize/ maximize etc.)

14  procedure TForm1.Button1Click(Sender: TObject);
15  var
16    Style: Integer;
17  begin
18    Style := GetWindowLong(Handle, GWL_STYLE);
19    {disable minimize}
20    Style := Style - WS_MINIMIZEBOX;
21    {disable maximize}
22    Style := Style - WS_MAXIMIZEBOX;
23    {remove system menu}
24    Style := Style - WS_SYSMENU;
25    {set new style}
26    SetWindowLong(Handle, GWL_STYLE, Style);
27    {repaint the title bar}
28    RedrawWindow(Handle, nil, 0, RDW_FRAME or RDW_INVALIDATE);
29  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC