[Lazarus] Show a window under GTK2 in front without stealing the focus

Michael Fuchs freepascal at ypa-software.de
Mon Feb 6 13:48:12 CET 2017


Am 19.01.2017 um 15:04 schrieb zeljko:
>> Under windows this works with >> ShowWindow(MyForm.Handle, SW_SHOWNOACTIVATE); >> But how can I do
this under GTK2? > > Don't know now exactly, but
gtk_window_set_focus_on_map(Window, > False) maybe could help. Have you
looked into gtk2winapi ? eg Qt have > such flag and it can show window
without activating. > > zeljko

Hi,

thanks for your help. With gtk_window_set_focus_on_map and
gtk_window_set_accept_focusit seems to work under GTK.

   MyForm.Visible := True;
   // HACK: SW_SHOWNOACTIVATE is not implemented under GTK2, we will use
a direct GTK calls
   {$IFDEF LCLGTK2}
     GtkWindow := PGtkWindow(MyForm.Handle);
     gtk_window_set_keep_above(GtkWindow, True);
     gtk_window_set_accept_focus(GtkWindow, False);
     gtk_window_set_focus_on_map(GtkWindow, False);
     gtk_window_present(GtkWindow);
   {$ELSE}
     ShowWindow(MyForm.Handle, SW_SHOWNOACTIVATE);
   {$ENDIF}

Unfortunately I discovered that under Windows SW_SHOWNOACTIVATE does not
work as I expected. So in the end, I build a form that inherits from
THintWindow. This resolves my problem.


More information about the Lazarus mailing list