Delphi

Use the AnimateWindow function

Use the AnimateWindow function The AnimateWindow function enables you to produce special effects when showing or hiding windows. procedure TForm1.Button1Click(Sender: TObject); begin Form2.BringToFront; AnimateWindow(Form2.Handle, 3000, AW_BLEND); Form2.Show; {The 3. parameter can be one or more […]

Delphi

Close a MDIChild form

Have you noticed that when you try to close a MDIChild form the form minimizes but doesn’t disappear from your Main form client area? With this tip you can learn how to really close the […]

Delphi

Scale a form manually

The first parameter of ScaleBy is the multiplier, the second the divisor. The example scale the form to 150% procedure TForm1.Button1Click(Sender: TObject); begin ScaleBy(150, 100); end;

Delphi

Make a form not resizable but moveable

Make a form not resizable but moveable private procedure WMGetMinMaxInfo(var Msg: TWMGetMinMaxInfo); message WM_GETMINMAXINFO; end; {…} implementation procedure TForm1.WMGetMinMaxInfo(var Msg: TWMGetMinMaxInfo); begin inherited; with Msg.MinMaxInfo^ do begin ptMinTrackSize.x := Form1.Width; ptMaxTrackSize.x := Form1.Width; ptMinTrackSize.y := […]

Delphi

Shade components

Shade components procedure ShadeIt(f: TForm; c: TControl; Width: Integer; Color: TColor); var rect: TRect; old: TColor; begin if (c.Visible) then begin rect := c.BoundsRect; rect.Left := rect.Left + Width; rect.Top := rect.Top + Width; rect.Right […]

Delphi

Draw a color outline around TForm

Create a message handler for the Windows Message WM_NCPAINT message. The following example paints a 1 pixel red border around the frame of the form. unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, […]

Delphi

Show hints in the Statusbar

Show hints in the Statusbar private procedure MyHint(Sender: TObject); end; implementation {….} procedure TForm1.FormCreate(Sender: TObject); begin Application.OnHint := MyHint; ShowHint := True; Button1.Hint := ‘normal yellow hint|Text in Statusbar’; Button2.Hint := ‘only yellow hint|’; Button3.Hint […]

Delphi

Make a Form semi-/ transparent

Make your forms 25%, 50% Transparent… TMyForm = class (TForm); TrackBar1: TTrackBar; //.. private FColorKey: TCOLOR; end; const // Use crKey as the transparency color. LWA_COLORKEY = 1; // Use bAlpha to determine the opacity […]

Delphi

Read data from another MDIChild form

Read data from another MDIChild form type TMDIChildForm = class(TForm) Edit1: TEdit; private { Private declarations } procedure ReadDataFromOtherMDIChildForm; end; var MDIChildForm: TMDIChildForm; implementation {$R *.DFM} uses MainForm; // Property FormStyle of this form is […]

Delphi

Check if a TMainMenu is dropped down or not

Check if a TMainMenu is dropped down or not type TForm1 = class(TForm) // … private IsMenuOpen: Boolean; procedure WMMENUSELECT(var message: TWMMENUSELECT); message WM_MENUSELECT; end; implementation procedure TForm1.WMMENUSELECT(var message: TWMMENUSELECT); begin inherited; IsMenuOpen := not […]

Delphi

Create a transparent TForm

Create a transparent TForm private { Private declarations } FullRgn, ClientRgn, CtlRgn: THandle; procedure MakeTransparent; procedure UndoTransparent; end; {…} implementation {…} procedure TForm1.MakeTransparent; var AControl: TControl; A, Margin, X, Y, CtlX, CtlY: Integer; begin Margin […]

Delphi

Correct a BiDi bug in Delphi

Correct a BiDi bug in Delphi When you set the BiDiMode in you form to bdRightToLeft, you do only HALF mirroring. Since Win98 (Hebrew/Arabic version) mirror it’s envirement completly (the Minimize, Close, Maxmize buttons are […]

Delphi

Change a Hint’s Font

When the application displays a Help Hint, it creates an instance of HintWindowClass to represent the window used for displaying the hint. Applications can customize this window by creating a descendant of THintWindow and assigning […]

Delphi

Disable a MenuItem without greying it

Disable a MenuItem without greying it procedure TForm1.Button1Click(Sender: TObject); var M: TMenu; begin M := Application.MainForm.Menu; // The first Item will be disabled EnableMenuItem(M.Handle, M.Items[0].Command, MF_BYCOMMAND or MF_DISABLED); end;

Delphi

Disable a form movement

Disable a form movement {….} private procedure WMNCHitTest(var Message: TWMNCHitTest); message WM_NCHITTEST; {….} procedure TForm1.WMNCHitTest(var Message: TWMNCHitTest); begin inherited; with Message do begin if Result = HTCAPTION then Result := HTNOWHERE; end; end;

Delphi

Determine whether a window is ‘topmost’

Determine whether a window is ‘topmost’ function IsWindowTopMost(hWindow: HWND): Boolean; begin Result := (GetWindowLong(hWindow, GWL_EXSTYLE) and WS_EX_TOPMOST) 0 end; procedure TForm1.Button1Click(Sender: TObject); begin if isWindowTopMost(FindWindow(‘notepad’, nil)) then Label1.Caption := ‘Window ist topmost’ else Label1.Caption := […]

Delphi

Show a second form with a active title bar

Show a second form with a active title bar To show a from/window with an active titlebar, send a WM_NCACTIVATE message to it. procedure TForm2.FormActivate(Sender: TObject); begin SendMessage(Application.MainForm.Handle, WM_NCACTIVATE, Boolean(True), 0); end;

Delphi

Format a MessageDlg

Format a MessageDlg procedure TForm1.Button1Click(Sender: TObject); var f: TForm; begin // Create the MessageDialog f := Dialogs.CreateMessageDialog(‘HELLOWORLD’, dialogs.mtInformation, dialogs.mbOKCancel); // Set the backcolor to blue. f.Color := clBlue; // Set textcolor to lime f.Font.Color := […]

Delphi

Tile a non-MDIframe window with a backgrund bitmap

Tile a non-MDIframe window with a backgrund bitmap type TForm1 = class(TForm) Button1: TButton; OpenDialog1: TOpenDialog; procedure Button1Click(Sender: TObject); procedure FormDestroy(Sender: TObject); private FWallpaper: TBitmap; procedure WMEraseBkGnd(var Msg: TWMEraseBkGnd); message WM_ERASEBKGND; end; var Form1: TForm1; […]

Delphi

Change the Button Captions in MessageDlg

function MyMessageDialog(const Msg: string; DlgType: TMsgDlgType; Buttons: TMsgDlgButtons; Captions: array of string): Integer; var aMsgDlg: TForm; i: Integer; dlgButton: TButton; CaptionIndex: Integer; begin { Create the Dialog } aMsgDlg := CreateMessageDialog(Msg, DlgType, Buttons); captionIndex := […]

Delphi

Create transparent menus (2000/XP)

Create transparent menus (2000/XP) var hHookID: HHOOK; // function to make the menu transparent function MakeWndTrans(Wnd: HWND; nAlpha: Integer = 10): Boolean; type TSetLayeredWindowAttributes = function(hwnd: HWND; crKey: COLORREF; bAlpha: Byte; dwFlags: Longint): Longint; stdcall; […]