Mega Code Archive

 
Categories / Delphi / Forms
 

Creating a collapsable form

Title: Creating a "collapsable" form Question: Have you ever wondered how to make forms in the style of the MacOS? This article shows you how to make forms that collapse to just the caption and then expand again when you doubleclick on the caption bar Answer: The answer to this problem involves overriding the WM_NCLBUTTONDBLCLK message and detecting where the message has been sent from. The way to do this (i you want to override other messages as well) is to override the WndProc procedure. unit Unit1; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs; type TForm1 = class(TForm) private { Private declarations } OldHeight: Integer; procedure ZipUpForm; public { Public declarations } { Override the WndProc procedure } { If you don't need to override any more messages you can simply use procedure CollapseForm(var Message: TMessage); message WM_NCLBUTTONDBLCLK } procedure WndProc(var Message: TMessage); override; end; var Form1: TForm1; implementation {$R *.DFM} {capture the WM_NCLBUTTONDBLCLK message} procedure TForm1.WndProc(var Message: TMessage); begin if Message.Msg = WM_NCLBUTTONDBLCLK then begin if Message.wParam = htCaption then ZipUpForm; end else inherited WndProc(message); end; {Procedure for zipping and unzipping the form} procedure TForm1.ZipUpForm; begin if Height = 27 then Height := OldHeight else begin OldHeight := Height; Height := 27; end; end; { Use this procedure if you don't need to override any other messages } { procedure TForm1.CollapseForm(var Message: TMessage); begin if Message.Msg = WM_NCLBUTTONDBLCLK then begin if Message.wParam = htCaption then ZipUpForm; end else inherited WndProc(message); end; } end. You can detect clicks on other non client parts of the form. The values that the wParam can be are: HTBORDER In the border of a window that does not have a sizing border HTBOTTOM In the lower horizontal border of a window HTBOTTOMLEFT In the lower-left corner of a window border HTBOTTOMRIGHT In the lower-right corner of a window border HTCAPTION In a title bar HTCLIENT In a client area HTERROR On the screen background or on a dividing line between windows (same as HTNOWHERE, except that the a beep will be produced for the HTERROR hittest HTGROWBOX In a size box (same as HTSIZE) HTHSCROLL In a horizontal scroll bar HTLEFT In the left border of a window HTMENU In a menu HTNOWHERE On the screen background or on a dividing line between windows HTREDUCE In a Minimize button HTRIGHT In the right border of a window HTSIZE In a size box (same as HTGROWBOX) HTSYSMENU In a System menu or in a Close button in a child window HTTOP In the upper horizontal border of a window HTTOPLEFT In the upper-left corner of a window border HTTOPRIGHT In the upper right corner of a window border HTTRANSPARENT In a window currently covered by another window HTVSCROLL In the vertical scroll bar HTZOOM In a Maximize button