CoMPi74 3 Posted July 11, 2023 (edited) Is there a way to create a kind of custom form (or custom form descendant) which would be completely transparent for all mouse and keyboard activities. More precisely, I need a custom form (or other control) to show a message which will disappear after a certain amount of time. Edited July 11, 2023 by CoMPi74 Share this post Link to post
KodeZwerg 54 Posted July 11, 2023 (edited) How about - Design a form - make it borderless - put a Panel on (alClient) - put a Timer on - create OnShow event to activate timer - in Timer event simple call "Close" from your calling Form - create an event that does - "Form.Panel.Caption := 'My Text';" - "Form.Timer.Interval := 1234;" - "Form.Show;" In theory it does what you wanted, adjust what I forgot to mention. Edited July 11, 2023 by KodeZwerg Share this post Link to post
Uwe Raabe 2059 Posted July 11, 2023 That would still miss the 44 minutes ago, CoMPi74 said: completely transparent for all mouse and keyboard activities To achieve that add a message handler like this: procedure WMNCHitTest(var Message: TWMNCHitTest); message WM_NCHITTEST; ... procedure TMyTransparentForm.WMNCHitTest(var Message: TWMNCHitTest); begin Message.Result := HTTRANSPARENT; end; Share this post Link to post
CoMPi74 3 Posted July 11, 2023 6 minutes ago, KodeZwerg said: How about - Design a form - make it borderless - put a Panel on (alClient) - put a Timer on - create OnShow event to activate timer - in Timer event simple call "Close" from your calling Form - create an event that does - "Form.Panel.Caption := 'My Text';" - "Form.Timer.Interval := 1234;" - "Form.Show;" In theory it does what you wanted, adjust what I forgot to mention. @KodeZwerg I did not test it but I am afraid such a form can be activated (gets focus) when clicked. I want to avoid such behaviour. Share this post Link to post
PeterBelow 238 Posted July 11, 2023 1 hour ago, CoMPi74 said: Is there a way to create a kind of custom form (or custom form descendant) which would be completely transparent for all mouse and keyboard activities. More precisely, I need a custom form (or other control) to show a message which will disappear after a certain amount of time. Try the form in the attached archive. To use it add the form unit to the uses clause of your form and add a call like procedure TForm2.Button1Click(Sender: TObject); begin TTransparentMsgForm.ShowMessage( 'This is a test message.', 30, self); end; Examples.zip Share this post Link to post
KodeZwerg 54 Posted July 11, 2023 24 minutes ago, CoMPi74 said: @KodeZwerg I did not test it but I am afraid such a form can be activated (gets focus) when clicked. I want to avoid such behaviour. You can do this to prevent that the second form get a focus: ... protected procedure ActiveFormChanged(Sender: TObject); ... procedure TForm1.ActiveFormChanged(Sender: TObject); begin if not (csDestroying in ComponentState) then if ActiveControl <> nil then ActiveControl.SetFocus end; procedure TForm1.FormCreate(Sender: TObject); begin Screen.OnActiveFormChange := ActiveFormChanged; end; Share this post Link to post
CoMPi74 3 Posted July 11, 2023 6 minutes ago, Uwe Raabe said: That would still miss the To achieve that add a message handler like this: procedure WMNCHitTest(var Message: TWMNCHitTest); message WM_NCHITTEST; ... procedure TMyTransparentForm.WMNCHitTest(var Message: TWMNCHitTest); begin Message.Result := HTTRANSPARENT; end; @Uwe Raabe I can not believe it. Is it really so simple? No way 🙂 Share this post Link to post
Remy Lebeau 1403 Posted July 11, 2023 (edited) 4 hours ago, CoMPi74 said: I am afraid such a form can be activated (gets focus) when clicked. I want to avoid such behaviour. Override the Form's CreateParams() method to enable the WS_EX_NOACTIVATE extended style: procedure CreateParams(var Params: TCreateParams); override; ... procedure TMyForm.CreateParams(var Params: TCreateParams); begin inherited; Params.WindowClass.ExStyle := Params.WindowClass.ExStyle or WS_EX_NOACTIVATE; end; Edited July 11, 2023 by Remy Lebeau Share this post Link to post
KodeZwerg 54 Posted July 11, 2023 37 minutes ago, Remy Lebeau said: Override the Form's CreateParams() method to enable the WS_EX_NOACTIVATE extended style: procedure CreateParams(var Params: TCreateParams); override; ... procedure TMyForm.CreateParams(var Params: TCreateParams); begin inherited; Params.WindowClass.ExStyle := Params.WindowClass.ExStyle or WS_EX_NOACTIVATE; end; Is this not just for the purpose that at generation it will not get focus? I mean, the generated form can still be clicked and it get focus, or? Share this post Link to post
Uwe Raabe 2059 Posted July 11, 2023 The docs say for WS_EX_NOACTIVATE: Quote A top-level window created with this style does not become the foreground window when the user clicks it. The system does not bring this window to the foreground when the user minimizes or closes the foreground window. Share this post Link to post