自学真是太痛苦了
Linux编程技术详解 是个半吊子
关键的地方就没了
害我自己找半天 没有网络真不行阿
g_signal_connect(GTK_COMBO(combol)->entry,
"changed",GTK_SIGNAL_FUNC(combo_changed),
(gpointer)combol);
还有我想解决回调函数只能传一个参数的问题
我用了结构体来装多个参数 总是出错 打击
只好使用全局变量解决了
以下是我的例子
/***************************************************************************
* Copyright (C) 2008 by zuopai
cand300k@163.com
组合框构件
***************************************************************************/
#include <gtk-2.0/gtk/gtk.h>
GtkWidget *wnd;
GtkWidget *fixed;
GtkWidget *btn;
GtkWidget *label;
GtkWidget *combol;
GList *list=NULL;
void combo_changed(GtkCombo *combl,gpointer data)
{
//char *var;
//GtkWidget *label1;
gtk_label_set_text(GTK_LABEL(label),gtk_entry_get_text(GTK_ENTRY(((GtkCombo*)combol)->entry)));
//(GtkWidget *)data.label;
//label1=(combo_label*)data;
}
gint release_resource(GtkWidget *widget,GdkEvent *event ,gpointer data)
{
gtk_main_quit();
return FALSE;
}
int main(int argc, char *argv[])
{
gtk_init(&argc,&argv);
wnd=gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(wnd),"固定容器构件");
gtk_window_set_policy(GTK_WINDOW(wnd), FALSE, FALSE, TRUE);
gtk_container_set_border_width(GTK_CONTAINER(wnd),10);
fixed=gtk_fixed_new();
gtk_container_add(GTK_CONTAINER(wnd),fixed);
combol=gtk_combo_new();
gtk_fixed_put(GTK_FIXED(fixed),combol,5,20);
list=g_list_append(list,"first item");
list=g_list_append(list,"2 item");
list=g_list_append(list,"3 item");
list=g_list_append(list,"3 item");
gtk_combo_set_popdown_strings(GTK_COMBO(combol),list);
label=gtk_label_new("");
gtk_label_set_text(GTK_LABEL(label),gtk_entry_get_text(GTK_ENTRY(((GtkCombo*)combol)->entry)));
gtk_fixed_put(GTK_FIXED(fixed),label,400,30);
btn=gtk_button_new_with_label("Quit");
gtk_fixed_put(GTK_FIXED(fixed),btn,550,200);
gtk_widget_set_size_request(GTK_WIDGET(btn),100,40);
g_signal_connect(G_OBJECT(btn),"clicked",G_CALLBACK(release_resource),NULL);
g_signal_connect(GTK_COMBO(combol)->entry,"changed",GTK_SIGNAL_FUNC(combo_changed),(gpointer)combol);
gtk_widget_show_all(wnd);
gtk_main();
return 0;
}
Linux编程技术详解 是个半吊子
关键的地方就没了
害我自己找半天 没有网络真不行阿
g_signal_connect(GTK_COMBO(combol)->entry,
"changed",GTK_SIGNAL_FUNC(combo_changed),
(gpointer)combol);
还有我想解决回调函数只能传一个参数的问题
我用了结构体来装多个参数 总是出错 打击
只好使用全局变量解决了
以下是我的例子
/***************************************************************************
* Copyright (C) 2008 by zuopai
cand300k@163.com
组合框构件
***************************************************************************/
#include <gtk-2.0/gtk/gtk.h>
GtkWidget *wnd;
GtkWidget *fixed;
GtkWidget *btn;
GtkWidget *label;
GtkWidget *combol;
GList *list=NULL;
void combo_changed(GtkCombo *combl,gpointer data)
{
//char *var;
//GtkWidget *label1;
gtk_label_set_text(GTK_LABEL(label),gtk_entry_get_text(GTK_ENTRY(((GtkCombo*)combol)->entry)));
//(GtkWidget *)data.label;
//label1=(combo_label*)data;
}
gint release_resource(GtkWidget *widget,GdkEvent *event ,gpointer data)
{
gtk_main_quit();
return FALSE;
}
int main(int argc, char *argv[])
{
gtk_init(&argc,&argv);
wnd=gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(wnd),"固定容器构件");
gtk_window_set_policy(GTK_WINDOW(wnd), FALSE, FALSE, TRUE);
gtk_container_set_border_width(GTK_CONTAINER(wnd),10);
fixed=gtk_fixed_new();
gtk_container_add(GTK_CONTAINER(wnd),fixed);
combol=gtk_combo_new();
gtk_fixed_put(GTK_FIXED(fixed),combol,5,20);
list=g_list_append(list,"first item");
list=g_list_append(list,"2 item");
list=g_list_append(list,"3 item");
list=g_list_append(list,"3 item");
gtk_combo_set_popdown_strings(GTK_COMBO(combol),list);
label=gtk_label_new("");
gtk_label_set_text(GTK_LABEL(label),gtk_entry_get_text(GTK_ENTRY(((GtkCombo*)combol)->entry)));
gtk_fixed_put(GTK_FIXED(fixed),label,400,30);
btn=gtk_button_new_with_label("Quit");
gtk_fixed_put(GTK_FIXED(fixed),btn,550,200);
gtk_widget_set_size_request(GTK_WIDGET(btn),100,40);
g_signal_connect(G_OBJECT(btn),"clicked",G_CALLBACK(release_resource),NULL);
g_signal_connect(GTK_COMBO(combol)->entry,"changed",GTK_SIGNAL_FUNC(combo_changed),(gpointer)combol);
gtk_widget_show_all(wnd);
gtk_main();
return 0;
}