Can i still use GDK_WINDOW_HWND macro in Gtkmm4?

Hi, guys !
I am developing an application with Gtkmm 4, and since Gtk::Window::move has been removed, i want to use native Windows API for that purpose when compiling on Windows. According to another topic here i can use gdk_win32_window_get_handle to get the HWND of a Gtk::Window. I would like to know if that’s still possible, and if the macro GDK_WINDOW_HWND is still available, too. I doubt, because GDK_WINDOW_HWND is declared in the header gdk/gdkwin32.h, and i cannot find this header in the source git repository (not in my installation either, because i am on linux). Does this header still exist, and can it safely be used in future or will it be removed soon ?

Yes, it’s still there, albeit under a different name: GDK_SURFACE_HWND().

See here for reference:

As far as i can see, these headers are written in C, but i am developing in C++ using Gtkmm. Which header have i got to include in C++ in order to use the macro ?

It looks like Gtkmm does not wrap any of the GDK platform-specific functions, so you have to rely on the C API.

Here’s a sample code (untested):

#include <gtkmm.h>
#include <gdk/gdkwin32.h>
#include <windows.h>

HWND get_window_hwnd(const Gtk::Window& window) {
  return GDK_SURFACE_HWND(window.get_surface()->gobj());

but can i use c headers in c++ code without causing lots of syntax errors ?

Yes, you can include GTK headers in C++ code. As a general rule it’s a good idea to include the GTK headers as extern “C”:

extern "C" {
#include <gdk/gdkwin32.h>

Even though I never had any problem whatsoever by doing without extern “C”.

Note the various headers should already use G_{BEGIN,END}_DECLS which handle that for you

1 Like

Ah, great! Didn’t know that. Thanks!

Thanks, you helped me a lot !

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.