|
发表于 2009-11-13 14:27:47
|
显示全部楼层
下面是我改的,在windows xp sp3 mingw下测试通过。- #include <gtk/gtk.h>
- static int t = 0;
- static gboolean on_threads_request( void * lpData)
- {
- gtk_widget_queue_draw( GTK_WIDGET(lpData));
- return FALSE;
- }
- static gboolean on_expose_event (GtkWidget * widget, GdkEventExpose * event, gpointer data)
- {
- //printf("%d", t);
- cairo_t *cr;
- cr = gdk_cairo_create (widget->window);
- char sztext[64] = {0};
- sprintf(sztext, "%d", t);
- cairo_move_to (cr, 10.0, 34.0);
- cairo_show_text( cr, sztext);
- cairo_destroy (cr);
- return FALSE;
- }
- void * ThreadFunc(void * lpData)
- {
- while (1)
- {
- g_usleep(500000);
- t++;
- g_print(" %d\n", t);
- gdk_threads_enter();
- gdk_threads_add_idle( on_threads_request, lpData);
- gdk_threads_leave();
- }
- return NULL;
- }
- int main (int argc, char * argv[])
- {
- if (!g_thread_supported())
- g_thread_init(NULL);
- gtk_init (&argc, &argv);
- GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
- g_signal_connect(window, "expose-event", G_CALLBACK(on_expose_event), NULL);
- g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
- gtk_widget_set_app_paintable(window, TRUE);
- gtk_widget_show(window);
- g_thread_create(ThreadFunc, window, FALSE, NULL);
-
- gdk_threads_enter();
- gtk_main();
- gdk_threads_leave();
-
- return 0;
- }
复制代码 |
|