GTK C - 如何编辑关闭窗口按钮的功能(右上角的X按钮)? [英] GTK C - How to edit function of close window button (the X button in the top right corner)?

查看:434
本文介绍了GTK C - 如何编辑关闭窗口按钮的功能(右上角的X按钮)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何编辑使用GTK库创建的窗口右上角的关闭按钮(或最小化/最大化按钮)。我试图删除用户摧毁这个窗口的能力,只允许顶层窗口销毁它,所以我想让右上角的X按钮(关闭窗口)只隐藏窗口而不是关闭它 - 仍然允许它在后台运行。



我对gtk有点新,并且在创建窗口和添加按钮方面经历了一些初级教程,但没有什么非常先进的。 / p>

我认为这可以通过在窗口中使用gtk_window_hide调用来代替X按钮的当前功能来完成,但我不确定在哪里使用它,因为

解决方案

在GTK中,您可以侦听小部件发出的信号。在Java等其他语言中(您可能更熟悉术语),这些语言通常称为事件。



如果发生事件,如删除小部件,则会触发相应的信号,您可以通过连接g_signal_connect等来应用该信号。



我建议您安装devhelp以获取良好的文档/联机帮助GTK。



这个小代码应该让你继续前进,我希望它能够自我解释给你。

  #include< stdio.h> 
#include< gtk / gtk.h>
#include< stdlib.h>

int
main(int argc,char ** argv)
{
GtkWidget * window;

gtk_init(& argc,& argv);

window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
g_signal_connect(window,delete_event,G_CALLBACK(gtk_window_iconify),NULL);

gtk_widget_show(window);
gtk_main();

return EXIT_SUCCESS;
}


I am wondering how to edit the "close" button (or the minimize/maximize buttons) in the top right corner of a window that was created with the GTK library. I am trying to remove the user's ability to destroy this window and only allow the top level window to destroy it so I want the X button (close window) in the top right corner to only hide the window instead of close it - still allowing it to run in the background.

I am somewhat new to gtk and I have gone through a few beginner tutorials in terms of creating windows and adding buttons but nothing very advanced.

I am assuming this can be accomplished by using a gtk_window_hide call on the window in place of the current functionality of the X button but I am not sure where to use it because the functions for the default buttons dont appear to be easily accessible.

解决方案

In GTK you listen for signals the widgets send out. In other languages like Java (in which you might be more familiar with the terminology), those are often called Events.

If an event occurs, like "deleting" the widget, there is the corresponding signal triggered, to which you might apply by connecting with g_signal_connect and the like.

I suggest you to install devhelp for a good documentation/online help for GTK.

This little code should keep you going, i hope it is self-explaining to you.

    #include <stdio.h>
    #include <gtk/gtk.h>
    #include <stdlib.h>

    int
    main (int argc, char **argv)
    {
      GtkWidget *window;

      gtk_init (&argc, &argv);

      window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
      g_signal_connect (window, "delete_event", G_CALLBACK (gtk_window_iconify), NULL);

      gtk_widget_show (window);
      gtk_main ();

      return EXIT_SUCCESS;
    }

这篇关于GTK C - 如何编辑关闭窗口按钮的功能(右上角的X按钮)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆