改的楼上的
#include <gtk/gtk.h>#include <string.h>
#include <stdlib.h>
#include <stdio.h>
static gint count_temp=0;
void add(GtkWidget *widget, gpointer data)
{
char str;
count_temp++;
sprintf(str,"%d",count_temp);
str='\\0';
gtk_label_set_text(GTK_LABEL(data),str);
}
void sub(GtkWidget *widget, gpointer data)
{
char str;
count_temp--;
sprintf(str,"%d",count_temp);
str='\\0';
gtk_label_set_text(GTK_LABEL(data),str);
}
gint delete_event(GtkWidget *widget, GdkEventButton *event, gpointer data)
{
gtk_main_quit();
return FALSE;
}
int main (int argc, char *argv[])
{
GtkWidget *win;
GtkWidget *btn1,*btn2;
GtkWidget *label;
GtkWidget *box;
gtk_init(&argc,&argv);
win=gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(win),"My Second GTK Programme!");
g_signal_connect(G_OBJECT(win),"delete_event",G_CALLBACK(delete_event),NULL);
gtk_window_set_position(GTK_WINDOW(win),GTK_WIN_POS_CENTER);
// gtk_container_border_width(G_OBJECT(win),10);
label = gtk_label_new("a label");
btn1=gtk_button_new_with_label("+");
btn2=gtk_button_new_with_label("-");
box=gtk_vbox_new(TRUE,0);
gtk_box_pack_start(GTK_BOX(box),label,TRUE,FALSE,10);
gtk_box_pack_start(GTK_BOX(box),btn1,TRUE,FALSE,10);
gtk_box_pack_start(GTK_BOX(box),btn2,TRUE,FALSE,10);
gtk_container_add(GTK_CONTAINER(win),box);
//四参数分别是:信号发送源对象,连接信号名称,
//捕获信号时所需调用的函数,传给此函数的参数。
g_signal_connect(G_OBJECT(btn1),"clicked",G_CALLBACK(add),label);
g_signal_connect(G_OBJECT(btn2),"clicked",G_CALLBACK(sub),label);
gtk_widget_show_all(win);
gtk_main();
return 0;
} 额
回 zhangzaidian 的帖子
zhangzaidian:#include <gtk/gtk.h>#include <string.h>
#include <stdlib.h>
#include <stdio.h>
....... (2012-05-31 13:39) images/back.gif
str='\\0';
这个可以不写的,sprintf会自动在后面加\\0的。。 ??