|
发表于 2009-11-16 16:30:56
|
显示全部楼层
我在xubuntu 9.04下在directfb下测试通过的,以下是我的代码。- #include <gtk/gtk.h>
- #include <stdio.h>
- #include <stdlib.h>
- static gchar *icons[9] =
- {
- "folder", "web", "mail",
- "movie", "weather", "tools",
- "tv", "phone", "note"
- };
- static gint width, height;
- static GtkWidget * btns[9];
- static GtkWidget * fixed;
- void delete_event(GtkWidget *widget, GdkEvent *event, gpointer data)
- {
- gtk_main_quit();
- }
- GtkWidget *label_box(gchar *filename, gchar *label_text)
- {
- GtkWidget *box;
- GtkWidget *label;
- GtkWidget *image = NULL;
-
- // create a box
- box = gtk_vbox_new(FALSE, 0);
- gtk_container_set_border_width(GTK_CONTAINER(box), 2);
-
- // create a image
- image = gtk_image_new_from_file(filename);
- if (!image)
- {
- printf("gtk_image_new_from_file error %s\n", filename);
- }
-
- // create a label
- label = gtk_label_new(label_text);
-
- gtk_box_pack_start(GTK_BOX(box), image, FALSE, FALSE, 3);
- gtk_box_pack_start(GTK_BOX(box), label, FALSE, FALSE, 3);
-
- gtk_widget_show(image);
- gtk_widget_show(label);
-
- return box;
- }
- void create_main_window()
- {
- GtkWidget *window;
- GtkWidget *button;
- GtkWidget *box;
- int i;
- gchar filename[30];
-
- window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
-
- g_signal_connect(G_OBJECT(window), "delete_event",
- G_CALLBACK(delete_event), NULL);
-
- GdkScreen *screen = gdk_screen_get_default();
- //gdk_display_get_pointer(gdk_display_get_default(), &screen,
- // NULL, NULL, NULL);
- width = gdk_screen_get_width(screen);
- height = gdk_screen_get_height(screen);
-
- gtk_window_set_default_size(GTK_WINDOW(window), width*9/5, height/4);
- //gtk_window_set_decorated(GTK_WINDOW(window), FALSE);
- gtk_window_move(GTK_WINDOW(window), 0, height*4/5);
- fixed = gtk_fixed_new();
-
-
- gtk_container_add(GTK_CONTAINER(window), fixed);
-
- button = gtk_button_new();
- box = label_box("tux.jpg", "tux");
- gtk_container_add(GTK_CONTAINER(button), box);
- gtk_widget_set_size_request(button, width/5, height/4);
- gtk_fixed_put(GTK_FIXED(fixed), button, 0, 0);
-
- /*
- for(i=0; i<9; i++)
- {
- sprintf(filename, "images/%s.png", icons[i]);
- button = gtk_button_new();
- btns[i] = button;
-
- box = label_box(filename, icons[i]);
- gtk_container_add(GTK_CONTAINER(button), box);
-
-
- if(i==1)
- {
- gtk_widget_set_size_request(button, width/5, height/4);
- gtk_fixed_put(GTK_FIXED(fixed), button, i*width/5, 0);
- }
- else
- {
- gtk_widget_set_size_request(button, width/5, height/5);
- gtk_fixed_put(GTK_FIXED(fixed), button, i*width/5, 20);
- }
- }
- */
- gtk_widget_show_all(window);
- }
- int main(int argc, char **argv)
- {
- gtk_init(&argc, &argv);
-
- create_main_window();
-
- gtk_main();
-
- return 0;
- }
复制代码 |
|