Title: Non Focusable Window - Create a Delphi Form that can Not be Activated
As explained in the A more powerful Delphi Form article, when Delphi creates a form, the Create method calls the CreteWindowEx API function to crete the actual window.
Before executing the CreteWindowEx, the CreateParams method is called - CreateParams allows you to change the default style of a window when it is created to suit your particular needs.
WS_EX_NOACTIVATE - Always Inactive Form
The ExStyle field of the Params paramater specifies the extended window style of the window being created.
A flag named WS_EX_NOACTIVATE can be used to create a window (form) that does not become the foreground window when the user clicks it. Also, the system does not bring this window to the foreground when the user minimizes or closes the foreground window.
To create a non activatable form, override the CreateParams method as:
procedure TMainForm.CreateParams(var Params: TCreateParams) ;
//const WS_EX_NOACTIVATE = $8000000;
begin
inherited;
Params.ExStyle := Params.ExStyle + WS_EX_NOACTIVATE;
end;
Note: you can click buttons on such a form, you can set the focus to an edit control on a form - BUT when you start typing the text you type will not go into the edit control - as the form does NOT have the focus!
An example where you would use this form feature is an application like Screen Ruler.