[Lazarus] GtkWidget questions

SteveG steveg at nevets.com.au
Fri Sep 12 17:02:53 CEST 2008

Thanks for your answer here Mattias -

GetActiveWindow does seem to be just what I need to be able to create my 
own code from - but I cant get it to work :(
I have extracted the function and placed in a new app - causes exception 
at gtk_is_window

Are Gtk windows the same as Gdk windows ? - 'get_toplevels' returns 
gdkwindows, but using as gtkwindow ?

uses gtk2, glib, gdk;

function GetActiveWindow :integer;
  TopList, List: PGList;
  Widget: PGTKWidget;
  Window: PGTKWindow;
  Result := 0;

  TopList := glib.pglist(gdk_window_get_toplevels);
  List := TopList;

  while List <> nil do begin
    if (List^.Data <> nil) then begin
      gdk_window_get_user_data(PGDKWindow(List^.Data), Pgpointer(@Window));

// --------FAILS AT NEXT LINE //

      if gtk_is_window(Window) then begin
        Widget := Window^.focus_widget;
        if Widget=nil then Widget:=PGtkWidget(Window);
        if (Widget <> nil) and gtk_widget_has_focus(Widget) then begin
          Result := 1;//PtrUInt(GetMainWidget(PGtkWidget(Window)));
    list := g_list_next(list);
  if TopList <> nil then g_list_free(TopList);

Mattias Gärtner wrote:
> Zitat von SteveG <steveg at nevets.com.au>:
>> Need some pointers on the way Laz/fpc handle gtkwidgets if possible.
>> I am attempting (as a test) to get and then set the size and position of
>> a Laz form using Gtk / Gdk - (not necessary I know, just leading to
>> further things)
> See in gtk intf:
> procedure SetWindowSizeAndPosition

More information about the Lazarus mailing list