c++windowswinapigtkgtkmm

How to move a Gtk::Window with native widows api?


Background

I am developing an application in C++ with Gtkmm 4. I am creating a Gtk::Window. Now i want to move this window to the center of the screen. In Gtkmm 3 there were methods such as Gtk::Window::set_position and Gtk::Window::move, but they were removed in Gtkmm 4. I have already worked out how to get the screen size from Gdk::Display, and calculate the position. But, i have to use platform specific API to move my window. On Linux, there is X11 and Wayland, and i know how to do it with these.

Question

How can i move a Gtk::Window to a specific position on screen with native windows API ?


Solution

  • According to this source:

    GDK exports gdk_win32_window_get_handle() as a public symbol—but its declaration is not available in a public header, so you’ll have to define it yourself:

    HGDIOBJ gdk_win32_window_get_handle (GdkWindow *window);

    It seems a <gdk/gdkwin32.h> header is also available, which makes the macro GDK_WINDOW_HWND available to simplify things a bit. An example is provided here.