Articles   Members Online: 3
-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 functionality of sizing a form at runtime 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 All Versions
Views
60
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Jonas Bilinkevicius

How to disable the functionality of sizing a form at runtime

Answer:

In some cases, developers would want to create a regular window (Form) in Delphi 
that contains some of the characteristics of a dialog box. For example, they do not 
want to allow their users to resize the form at runtime due to user interface 
design issues.

The following example demonstrates a way of handling the Windows message 
"WM_GetMinMaxInfo" which allows the developer to restrict the size of windows 
(forms) at runtime to a specific value. In this case, it will be used to disable 
the functionality of sizing the window (form) at runtime.

1   unit getminmax;
2   
3   interface
4   
5   uses
6     Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
7   
8   type
9     TForm1 = class(TForm)
10  
11    private
12      { Private declarations }
13      procedure WMGetMinMaxInfo(var Msg: TWMGetMinMaxInfo); message WM_GETMINMAXINFO;
14      procedure WMInitMenuPopup(var Msg: TWMInitMenuPopup); message WM_INITMENUPOPUP;
15      procedure WMNCHitTest(var Msg: TWMNCHitTest); message WM_NCHitTest;
16    public
17      { Public declarations }
18    end;
19  
20  var
21    Form1: TForm1;
22  
23  implementation
24  
25  {$R *.DFM}
26  
27  procedure TForm1.WMGetMinMaxInfo(var Msg: TWMGetMinMaxInfo);
28  begin
29    inherited;
30    with Msg.MinMaxInfo^ do
31    begin
32      ptMinTrackSize.x := form1.width;
33      ptMaxTrackSize.x := form1.width;
34      ptMinTrackSize.y := form1.height;
35      ptMaxTrackSize.y := form1.height;
36    end;
37  end;
38  
39  procedure TForm1.WMInitMenuPopup(var Msg: TWMInitMenuPopup);
40  begin
41    inherited;
42    if Msg.SystemMenu then
43      EnableMenuItem(Msg.MenuPopup, SC_SIZE, MF_BYCOMMAND or MF_GRAYED)
44  end;
45  
46  procedure TForm1.WMNCHitTest(var Msg: TWMNCHitTest);
47  begin
48    inherited;
49    with Msg do
50      if Result in [HTLEFT, HTRIGHT, HTBOTTOM, HTBOTTOMRIGHT,
51        HTBOTTOMLEFT, HTTOP, HTTOPRIGHT, HTTOPLEFT] then
52        Result := HTNOWHERE
53  end;
54  end.


A message handler for the windows message "WM_GetMinMaxInfo" in the code above was used to set the minimum and maximum TrackSize of the window to equal the width and height of the form at design time. That was actually enough to disable the resizing of the window (form), but the example went on to handle another couple of messages just to make the application look professional. The first message was the "WMInitMenuPopup" and that was to gray out the size option from the System Menu so that the application does not give the impression that this functionality is available. The second message was the "WMNCHitTest" and that was used to disable the change of the cursor icon whenever the mouse goes over one of the borders of the window (form) for the same reason which is not to give the impression that the resizing functionality is available.

			
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