Jump to content
Alexander Halser

Firemonkey form not included in "Also snap to screen"

Recommended Posts

When pressing the Windows key plus the right or left arrow key simultaneously, the window is moved to fill the right or left half of the screen, respectively. This works for FMX forms as well, out of the box. At least with D11, not sure about older FMX versions.

 

However, when you release the Win key, Windows usually offers (if enabled in global settings) a list of windows to fill the other half of the screen. And this is the issue I am wondering about:

  • A VCL form is shown in this "also snap..." list.
  • An FMX form is not shown.

 

I assume that either a param in CreateParams is responsible for this behavior, or a Windows message needs to be handled to enable it (which is implemented in VCL but not in FMX for Windows). Does anyone know what causes the FMX window to be hidden and how to overcome it?

 

snap-vcl.png

snap-fmx.png

Share this post


Link to post

Partial answer: in VCL the behavior is triggered by MainFormOnTaskbar := true;

 

More detailed answer: it is the param WS_EX_APPWINDOW in the window GWL_EXSTYLE that makes the window appear (automatically set by MainFormOnTaskbar).


In FMX, the main form can be made visible in the selection list by setting the form's (Windows) window handle manually:
 

procedure TForm1.Button1Click(Sender: TObject);
var
  WND: HWND;
begin
  wnd := FmxHandleToHWND(self.handle);
  SetWindowLong(wnd, GWL_EXSTYLE, GetWindowLong(wnd, GWL_EXSTYLE) or WS_EX_APPWINDOW);

  //now the form is visible in the "Also snap..." list
end;

 

New question: Any known downside or side effects due to this modification?

  • Like 1

Share this post


Link to post
5 minutes ago, Alexander Halser said:

Any known downside or side effects due to this modification?

You should do this only for Windows environments. So be shure to wrap that in appropriate $IFDEFs in case you develop multi platform (what FMX is designed for).

Share this post


Link to post
1 minute ago, Sherlock said:

You should do this only for Windows environments. So be shure to wrap that in appropriate $IFDEFs in case you develop multi platform (what FMX is designed for).

Sure.

Winapi.Windows.pas and SetWindowLong would be difficult to compile anyway for MacOS, iOS and Android 😉

 

Are there any other negative side effects known?

Share this post


Link to post
3 hours ago, Alexander Halser said:

Are there any other negative side effects known?

Not that I am aware of.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×