2个回答
展开全部
void enter_callback( GtkWidget *widget,
GtkWidget *entry )
{
const gchar *entry_text;
entry_text = gtk_entry_get_text (GTK_ENTRY (entry));
printf("Entry contents: %s\n", entry_text);
}
void entry_toggle_editable( GtkWidget *checkbutton,
GtkWidget *entry )
{
gtk_editable_set_editable (GTK_EDITABLE (entry),
GTK_TOGGLE_BUTTON (checkbutton)->active);
}
void entry_toggle_visibility( GtkWidget *checkbutton,
GtkWidget *entry )
{
gtk_entry_set_visibility (GTK_ENTRY (entry),
GTK_TOGGLE_BUTTON (checkbutton)->active);
}
/* 我们常见的回调函数 */
void callback( GtkWidget *widget,
gpointer data )
{
g_print ("Hello again - %s was pressed\n", (char *) data);
}
int main( int argc, char *argv[])
{
GtkWidget *window;
GtkWidget *ok;
GtkWidget *close;
GtkWidget *text_view;
GtkTextBuffer *buffer;
GtkWidget *vbox;
GtkWidget *hbox;
GtkWidget *halign;
GtkWidget *valign;
gtk_init(&argc, &argv);
//=============Build a window===========//
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
gtk_window_set_default_size(GTK_WINDOW(window), 350, 280);
gtk_window_set_title(GTK_WINDOW(window), "Labyrinth");
gtk_container_set_border_width(GTK_CONTAINER(window), 10);
g_signal_connect_swapped(G_OBJECT(window), "destroy",
G_CALLBACK(gtk_main_quit), G_OBJECT(window));
//=============Adjust layout============//
vbox = gtk_vbox_new(FALSE, 5);
valign = gtk_alignment_new(0, 1, 0, 0);
gtk_container_add(GTK_CONTAINER(vbox), valign);
gtk_container_add(GTK_CONTAINER(window), vbox);
hbox = gtk_hbox_new(TRUE, 3);
//=============Build tow button========//
ok = gtk_button_new_with_label("OK");
gtk_widget_set_size_request(ok, 70, 30);
gtk_container_add(GTK_CONTAINER(hbox), ok);
close = gtk_button_new_with_label("Close");
gtk_container_add(GTK_CONTAINER(hbox), close);
halign = gtk_alignment_new(1, 0, 0, 0);
close = gtk_button_new_from_stock (GTK_STOCK_CLOSE);
gtk_container_add(GTK_CONTAINER(halign), hbox);
gtk_box_pack_start(GTK_BOX(vbox), halign, FALSE, FALSE, 0);
g_signal_connect_swapped (G_OBJECT (close), "clicked",
G_CALLBACK (gtk_widget_destroy),
window);
GTK_WIDGET_SET_FLAGS (close, GTK_CAN_DEFAULT);
gtk_widget_grab_default (close);
gtk_widget_show (close);
//=============Build a TestView==========//
text_view=gtk_text_view_new();/*创建文本框构件*/
gtk_widget_set_size_request(text_view,200,200);
gtk_container_add(GTK_CONTAINER(window),vbox);
gtk_box_pack_start(GTK_BOX(vbox),text_view,FALSE,FALSE,0);
buffer=gtk_text_view_get_buffer(GTK_TEXT_VIEW(text_view));
gtk_widget_show(text_view);
//=============================
GtkWidget *entry;
gint tmp_pos;
entry = gtk_entry_new ();
gtk_entry_set_max_length (GTK_ENTRY (entry), 50);
g_signal_connect (G_OBJECT (entry), "OK",
G_CALLBACK (enter_callback), entry);
gtk_entry_set_text (GTK_ENTRY (entry), "hello");
tmp_pos = GTK_ENTRY (entry)->text_length;
gtk_editable_insert_text (GTK_EDITABLE (entry), " world", -1, &tmp_pos);
gtk_editable_select_region (GTK_EDITABLE (entry),
0, GTK_ENTRY (entry)->text_length);
// tmp_pos = GTK_ENTRY (entry)->text_length;
// gtk_editable_insert_text (GTK_EDITABLE (entry), " hello ", -1, &tmp_pos);
// gtk_editable_select_region (GTK_EDITABLE (entry),
// 0, GTK_ENTRY (entry)->text_length);
gtk_box_pack_start (GTK_BOX (vbox), entry, TRUE, TRUE, 0);
gtk_widget_show (entry);
gtk_widget_show_all(window);
gtk_main();
return 0;
}
GtkWidget *entry )
{
const gchar *entry_text;
entry_text = gtk_entry_get_text (GTK_ENTRY (entry));
printf("Entry contents: %s\n", entry_text);
}
void entry_toggle_editable( GtkWidget *checkbutton,
GtkWidget *entry )
{
gtk_editable_set_editable (GTK_EDITABLE (entry),
GTK_TOGGLE_BUTTON (checkbutton)->active);
}
void entry_toggle_visibility( GtkWidget *checkbutton,
GtkWidget *entry )
{
gtk_entry_set_visibility (GTK_ENTRY (entry),
GTK_TOGGLE_BUTTON (checkbutton)->active);
}
/* 我们常见的回调函数 */
void callback( GtkWidget *widget,
gpointer data )
{
g_print ("Hello again - %s was pressed\n", (char *) data);
}
int main( int argc, char *argv[])
{
GtkWidget *window;
GtkWidget *ok;
GtkWidget *close;
GtkWidget *text_view;
GtkTextBuffer *buffer;
GtkWidget *vbox;
GtkWidget *hbox;
GtkWidget *halign;
GtkWidget *valign;
gtk_init(&argc, &argv);
//=============Build a window===========//
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
gtk_window_set_default_size(GTK_WINDOW(window), 350, 280);
gtk_window_set_title(GTK_WINDOW(window), "Labyrinth");
gtk_container_set_border_width(GTK_CONTAINER(window), 10);
g_signal_connect_swapped(G_OBJECT(window), "destroy",
G_CALLBACK(gtk_main_quit), G_OBJECT(window));
//=============Adjust layout============//
vbox = gtk_vbox_new(FALSE, 5);
valign = gtk_alignment_new(0, 1, 0, 0);
gtk_container_add(GTK_CONTAINER(vbox), valign);
gtk_container_add(GTK_CONTAINER(window), vbox);
hbox = gtk_hbox_new(TRUE, 3);
//=============Build tow button========//
ok = gtk_button_new_with_label("OK");
gtk_widget_set_size_request(ok, 70, 30);
gtk_container_add(GTK_CONTAINER(hbox), ok);
close = gtk_button_new_with_label("Close");
gtk_container_add(GTK_CONTAINER(hbox), close);
halign = gtk_alignment_new(1, 0, 0, 0);
close = gtk_button_new_from_stock (GTK_STOCK_CLOSE);
gtk_container_add(GTK_CONTAINER(halign), hbox);
gtk_box_pack_start(GTK_BOX(vbox), halign, FALSE, FALSE, 0);
g_signal_connect_swapped (G_OBJECT (close), "clicked",
G_CALLBACK (gtk_widget_destroy),
window);
GTK_WIDGET_SET_FLAGS (close, GTK_CAN_DEFAULT);
gtk_widget_grab_default (close);
gtk_widget_show (close);
//=============Build a TestView==========//
text_view=gtk_text_view_new();/*创建文本框构件*/
gtk_widget_set_size_request(text_view,200,200);
gtk_container_add(GTK_CONTAINER(window),vbox);
gtk_box_pack_start(GTK_BOX(vbox),text_view,FALSE,FALSE,0);
buffer=gtk_text_view_get_buffer(GTK_TEXT_VIEW(text_view));
gtk_widget_show(text_view);
//=============================
GtkWidget *entry;
gint tmp_pos;
entry = gtk_entry_new ();
gtk_entry_set_max_length (GTK_ENTRY (entry), 50);
g_signal_connect (G_OBJECT (entry), "OK",
G_CALLBACK (enter_callback), entry);
gtk_entry_set_text (GTK_ENTRY (entry), "hello");
tmp_pos = GTK_ENTRY (entry)->text_length;
gtk_editable_insert_text (GTK_EDITABLE (entry), " world", -1, &tmp_pos);
gtk_editable_select_region (GTK_EDITABLE (entry),
0, GTK_ENTRY (entry)->text_length);
// tmp_pos = GTK_ENTRY (entry)->text_length;
// gtk_editable_insert_text (GTK_EDITABLE (entry), " hello ", -1, &tmp_pos);
// gtk_editable_select_region (GTK_EDITABLE (entry),
// 0, GTK_ENTRY (entry)->text_length);
gtk_box_pack_start (GTK_BOX (vbox), entry, TRUE, TRUE, 0);
gtk_widget_show (entry);
gtk_widget_show_all(window);
gtk_main();
return 0;
}
展开全部
Anjuta的GTK编程安装调试小记
http://hi.baidu.com/redbreast/blog/item/348e4310b90540f4c3ce7940.html
http://hi.baidu.com/redbreast/blog/item/348e4310b90540f4c3ce7940.html
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询