GtkAboutDialog
GtkAboutDialog — Display information about an application
👁 📖 官方学习网站
#include <gtk/gtk.h>
static GtkWidget *create_window(const gint, const gint);
void button_clicked_cb(GtkWindow *window)
{
if (!GTK_IS_WINDOW(window))
{
g_print("参数错误\n");
return;
}
GtkWidget *aboutDialog;
/// *** AboutDialog
aboutDialog = gtk_about_dialog_new();
/// *** 设置主次窗口
gtk_window_set_transient_for(GTK_WINDOW(aboutDialog), window);
/// *** 设置显示的程序名
gtk_about_dialog_set_program_name(GTK_ABOUT_DIALOG(aboutDialog), "AboutDialog");
/// *** 设置程序版本
gtk_about_dialog_set_version(GTK_ABOUT_DIALOG(aboutDialog), "1.0.0");
/// *** 版权
gtk_about_dialog_set_copyright(GTK_ABOUT_DIALOG(aboutDialog), "my Copyright");
/// ***
gtk_about_dialog_set_comments(GTK_ABOUT_DIALOG(aboutDialog), "Here you can put a Set of comments");
/// ***
gtk_about_dialog_set_license(GTK_ABOUT_DIALOG(aboutDialog), "This is the part where you need to set your license information");
gtk_widget_show_all(aboutDialog);
}
int main(int argc, char *argv[])
{
gtk_init(&argc, &argv);
GtkWidget *window;
GtkWidget *button;
/// *** Create a Window
window = create_window(400, 500);
/// *** Create a button
button = gtk_button_new_with_mnemonic("_Open the app about dialog");
g_object_set(button,
"margin", 50,
"parent", window,
NULL);
g_signal_connect_swapped(button, "clicked", G_CALLBACK(button_clicked_cb), window);
gtk_widget_show_all(window);
gtk_main();
}
static GtkWidget *create_window(const gint w, const gint h)
{
GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
gtk_window_set_default_size(GTK_WINDOW(window), w, h);
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
gtk_window_set_title(GTK_WINDOW(window), "Hello GTK3");
gtk_container_set_border_width(GTK_CONTAINER(window), 50);
return window;
}
- 运行效果