GTK 消息框

http://blog.csdn.net/blackboyofsnp/archive/2008/11/24/3364378.aspx
 
#include <gtk/gtk.h>

 gint count = 1;

 // 按下按钮时弹出响应框
 void on_button_clicked (GtkWidget *button, gpointer userdata)
 {
      GtkWidget* dialog;
      gchar buff[50];
      sprintf(buff, "counter: %d", count);
      dialog = gtk_message_dialog_new(
             NULL,
             GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
             GTK_MESSAGE_INFO,
             GTK_BUTTONS_OK,
             buff);
      gtk_dialog_run(GTK_DIALOG(dialog));
      gtk_widget_destroy(dialog);
      // g_print在WINDOWS不起作用
      //g_print("Hello, this is a GTK test.");
      //g_print("%d/n", (gint)userdata);
      //g_print("%d/n", count);
      count = count + 1;
 }

 int main(int argc,char *argv[])
 {
     GtkWidget *window;
     GtkWidget *button;
     gtk_init(&argc,&argv);
     window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
     
     g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), &window);
     gtk_window_set_title(GTK_WINDOW(window), "Hello GTK");
     gtk_window_set_default_size(GTK_WINDOW(window), 500, 100);
     gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
     gtk_container_set_border_width(GTK_CONTAINER(window), 40);
     button = gtk_button_new_with_label("Press to show a string on the terminal");
     g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(on_button_clicked), (gpointer)count);
     gtk_container_add(GTK_CONTAINER(window), button);
     gtk_widget_show(button);
     gtk_widget_show(window);
     gtk_main();
     return FALSE;
 }

你可能感兴趣的:(GTK 消息框)