Forms

Prevent window from resizing

Posted in Forms

You should trap WM_GETMINMAXINFO message. In your form's class declaration put this:

  procedure WMGetMinMaxInfo(var Msg: TWMGetMinMaxInfo);
    message WM_GETMINMAXINFO;

and in the implementation section:


procedure TYourForm.WMGetMinMaxInfo(var Msg: TWMGetMinMaxInfo);
begin
  inherited;
  with Msg.MinMaxInfo^ do
  begin
    ptMinTrackSize.Y:=200;
    ptMaxTrackSize.Y:=400;
  end;
end;

Min all Internet Explorer windows

Posted in Forms

Send WM_SYSCOMMAND to all Internet Explorer window. Use FindWindow function to find all IE windows.

procedure TForm1.Button1Click(Sender: TObject);
var
  IExplorer, Prev: THandle;
begin
  Prev:=0;
  IExplorer:=FindWindow('IEFrame', nil);
  while (IExplorer<>0) and (IExplorer<>Prev) do
  begin
    SendMessage(IExplorer,WM_SYSCOMMAND,SC_MINIMIZE,0);
    Prev:=IExplorer;
    IExplorer:=FindWindow('IEFrame',nil);
  end;
end; 

Move form by client area

Posted in Forms

If you want, that user can move your form by client area, then use WM_NCHITTEST handler to achieve this cool effect: In the Forms private declarations add this

  procedure WMNCHitTest(var Msg: TWMNCHitTest);

    message WM_NCHITTEST;

Create handler for this message with this code:


procedure TForm1.WMNCHitTest(var Msg: TWMNCHitTest);
begin
 DefaultHandler(Msg);
 if Msg.Result=HTCLIENT then
   Msg.Result:=HTCAPTION;
end;

Related chapters
    Graphics

Related topics
    Draw transparent text on canvas

For more
    Win32 programmer's referenc

Minimize non-main forms

Posted in Forms

Use this text in project file. This example shows how to minimize non-main form in the running application.

program Project1;

uses
  Forms,
  Windows,
  Messages,
  SysUtils,
  Classes,
  Graphics,
  Controls,
  Dialogs,
  Unit1 in 'Unit1.pas' {Form1},
  Unit2 in 'Unit2.pas' {Form2};
{$R *.RES}

begin
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  Application.CreateForm(TForm2, Form2);
  Form2.Show;
  SendMessage(Form2.Handle,WM_SYSCOMMAND,SC_MINIMIZE,0);
  Application.Run;
end.

Limit the count of MDIChild form

Posted in Forms

The count of the MDIChild forms can be looked in the MDIChildCount property. In this example you can open 10 MDIChild forms only. Don't forget to remove line Application.CreateForm(TForm2, Form2) from project file and line var Form2: TForm2 from unit2.pas file.

procedure TForm1.New1Click(Sender: TObject);
var
  ChildForm: TForm2;
begin
  if MDIChildCount