红联Linux门户
Linux帮助

关于GTK+的问题,高手请进!!!

发布时间:2007-09-19 14:30:09来源:红联作者:Linux85fan
#include
GtkWidget *create_list(void)
{
GtkWidget *scrolled;
GtkWidget *list;
GtkWidget *list_item;
int i;
char buffer[16];
scrolled=gtk_scrolled_window_new(NULL,NULL);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled),GTK_POLICY_AUTOMATIC,GTK_POLICY_AUTOMATIC);
list=gtk_list_new();
gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolled),list);
gtk_widget_show(list);
for(i=1;i<10;i++)
{
sprintf(buffer,"Message #%d ",i);
list_item=gtk_list_item_new_with_label(buffer);
gtk_container_add(GTK_CONTAINER(list),list_item);
gtk_widget_show(list_item);
}
return scrolled;
}
void realize_text(GtkWidget *text,gpointer data)
{
gtk_text_freeze(GTK_TEXT(text));
gtk_text_insert(GTK_TEXT(text),NULL,&text->style->black,NULL,
"From:pathfinder@nasa.gov\n"
"To:mom@nasa.gov\n"
"Subject:Made it!\n"
"\n"
"we just got in this morning.The weather has been\n"
"great - clear but cold,and there are lots of fun sights.\n"
"Sojurner says hi.see you soon.\n"
"-Path\n", -1);
gtk_text_thaw(GTK_TEXT(text));
}
GtkWidget * create_text(void )
{
GtkWidget *table;
GtkWidget *hscrollbar;
GtkWidget *vscrollbar;
GtkText *text;
GtkAdjustment *hadj,*vadj;
table=gtk_table_new(2,2,FALSE);
vadj=gtk_adjustment_new(5,1,15,2,5,5);
hadj=gtk_adjustment_new(5,1,15,2,5,5);
text=gtk_text_new(NULL,NULL);
gtk_table_attach(GTK_TABLE(table),text,0,1,0,1,GTK_FILL|GTK_EXPAND,GTK_FILL|GTK_EXPAND|GTK_SHRINK,0,0);
//gtk_text_set_adjustments(text,hadj,vadj);
gtk_widget_show(text);
//hadj=gtk_text_get_hadjustment(GTK_TEXT(text));
hscrollbar=gtk_hscrollbar_new(GTK_TEXT(text)->hadj);
gtk_table_attach(GTK_TABLE(table),hscrollbar,1,2,0,1,GTK_FILL|GTK_EXPAND,GTK_FILL,0,0);
gtk_widget_show(hscrollbar);
//vadj=gtk_text_get_vadjustment(GTK_TEXT(text));
vscrollbar=gtk_vscrollbar_new(GTK_TEXT(text)->vadj);
gtk_table_attach(GTK_TABLE(table),vscrollbar,0,1,1,2,GTK_FILL,GTK_FILL|GTK_EXPAND|GTK_SHRINK,0,0);
gtk_widget_show(vscrollbar);
gtk_signal_connect(GTK_OBJECT(text),"realize",GTK_SIGNAL_FUNC(realize_text),NULL);
return table;
}
int main(int argc,char *argv[])
{
GtkWidget *window;
GtkWidget *vpaned;
GtkWidget *list;
GtkWidget *text;
gtk_init(&argc,&argv);
window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_container_set_border_width(GTK_CONTAINER(window),10);
gtk_signal_connect(GTK_OBJECT(window),"destroy",GTK_SIGNAL_FUNC(gtk_main_quit),NULL);
gtk_window_set_title(GTK_WINDOW(window),"Paned Windows");
gtk_widget_set_usize(window,450,400);
vpaned=gtk_vpaned_new();
gtk_container_add(GTK_CONTAINER(window),vpaned);
//gtk_paned_set_handle_size(GTK_PANED(vpaned),10);
gtk_paned_set_gutter_size(GTK_PANED(vpaned),15);
gtk_widget_show(vpaned);
list=create_list();
gtk_paned_add1(GTK_PANED(vpaned),list);
gtk_widget_show(list);
text=create_text();
gtk_paned_add2(GTK_PANED(vpaned),text);
gtk_widget_show(text);
gtk_widget_show(window);
gtk_main();
return 0;


}

我用的:gcc -o gtktext gtktext.c `pkg-config --cflags --libs gtk+-2.0`

编译时说GTK_TEXTf未定义。这是怎么回事啊??
文章评论

共有 0 条评论