Gtk4获取windows窗口句柄及设置居中显示
#ifdef _MSC_VER
#include <gdk/win32/gdkwin32.h>
HWND gtk_window_get_nativehandle(GtkWidget* w)
{
return GDK_SURFACE_HWND(gtk_native_get_surface(gtk_widget_get_native(w)));
}
void gtk_window_set_position_center(GtkWidget* w)
{
RECT rc = { 0,0,0,0, };
HWND hwnd = gtk_window_get_nativehandle(w);
RECT rcwin = { 0,0,0,0, };
SystemParametersInfo(SPI_GETWORKAREA, 0, &rcwin, 0);
GetWindowRect(hwnd, &rc);
MoveWindow(hwnd, (rcwin.right - (rc.right - rc.left))/2, (rcwin.bottom - (rc.bottom - rc.top)) / 2, rc.right - rc.left, rc.bottom - rc.top, FALSE);
}
#else
#endif // _MSC_VER
调用示例:
#ifdef _MSC_VER
gtk_window_set_position_center(gtk4img->win);
#endif // _MSC_VER