Jean Alysson
Jean Alysson

Reputation: 21

How to avoid the focus on Delphi application?

I need develop an application (Delphi) that never receive the focus, I use the DLL to display the video on second monitor (I found in Torrys Delphi - Dr.SAGURA Media Player v.1.0) that receive the focus every time play the video, how avoid this ?
I try :

procedure TForm.WMActivate(var Msg: TWMActivate);  
begin  
  WA_ACTIVE :
  begin  
    Msg.Result := 0;// cancel focus  
  end;  
end;

Unsuccessful !

Thanks Jean Alysson

Upvotes: 2

Views: 1043

Answers (2)

Zoë Peterson
Zoë Peterson

Reputation: 13312

  • In your project DPR set Application.MainFormOnTaskBar := False.
  • Override the form's OnShow and OnActivate events and add this to both of them: ShowWindow(Application.Handle, SW_HIDE);
  • Override your form's CreateParams procedure and add WS_EX_NOACTIVATE to Params.ExStyle.

The first two items hide the application from the taskbar and the Alt+Tab list and the last keeps it from gaining focus when it's shown and when clicking on it.

Upvotes: 3

Daniel Luyo
Daniel Luyo

Reputation: 1336

What's the intention behind not be focusable? You want to avoid the user from closing/minimize/maximize the window? Maybe your need can be acomplished understanding the real problem.

Maybe having a sevice instead of a regular application can make the trick.

Upvotes: 0

Related Questions