急…關於gtk讀檔的問題

开发基于GTK+或QT的应用程序
回复
chloejing
帖子: 6
注册时间: 2011-03-17 17:15
送出感谢: 0
接收感谢: 0

急…關於gtk讀檔的問題

#1

帖子 chloejing » 2011-03-25 15:00

#include <gtk/gtk.h>
#include <stdlib.h>
#include <iostream>
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <windows.h>

using namespace std;

GtkWidget* window;
char tag[10];
int x,y,number;
gboolean expose_event_callback(GtkWidget *widget,
GdkEventExpose *event,
gpointer data) {

GdkGC *gc = widget->style->fg_gc[GTK_WIDGET_STATE(widget)];
GdkDrawable *drawable = widget->window;
GdkColor color;


FILE* fptr=fopen("logfile","r");
while(fscanf(fptr,"%s ",tag)!=-1){
if(strcmp(tag,"Round")==0){

fscanf(fptr,"%d",&x);

getch();

}
else if(strcmp(tag,"car")==0){
fscanf(fptr,"%d at (%d,%d)",&number,&x,&y);
gdk_draw_pixbuf(drawable, gc, gdk_pixbuf_new_from_file("car-right.jpg", NULL)
, 0, 0, 100*x,100*y, -1, -1,GDK_RGB_DITHER_NORMAL, 0, 0);
}
else if(strcmp(tag,"scooter")==0){
fscanf(fptr,"%d at (%d,%d)",&number,&x,&y);
gdk_draw_pixbuf(drawable, gc, gdk_pixbuf_new_from_file("scooter.jpg", NULL)
, 0, 0, 10*x, 10*y, -1, -1, GDK_RGB_DITHER_NORMAL, 0, 0);


}

}
return TRUE;
}

int main(int argc, char *argv[]) {
GtkWidget *scrolledWindow;
GtkWidget *drawing_area;
GdkColor color;
GdkGC *gc;
GdkDrawable *drawable;
GtkWidget *image;

gtk_init(&argc, &argv);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "Intersection");
g_signal_connect(GTK_OBJECT(window), "destroy",G_CALLBACK(gtk_main_quit), NULL);
gtk_widget_realize(window);

scrolledWindow = gtk_scrolled_window_new(NULL, NULL);
gtk_container_add(GTK_CONTAINER(window),scrolledWindow);
gtk_widget_show(scrolledWindow);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledWindow),GTK_POLICY_AUTOMATIC,GTK_POLICY_AUTOMATIC);


drawing_area = gtk_drawing_area_new();
gtk_widget_set_size_request(drawing_area,2000, 2000);
g_signal_connect(GTK_OBJECT(drawing_area), "expose_event",G_CALLBACK(expose_event_callback), NULL);
gtk_container_add(GTK_CONTAINER(window), drawing_area);

gdk_color_parse("#000000", &color);
gtk_widget_modify_bg(GTK_WIDGET(drawing_area), GTK_STATE_NORMAL, &color);
gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolledWindow),drawing_area);

gtk_widget_show_all(window);


gtk_main();


return 0;
}


我讀一個logfile,讀到round這一行的時候,顯示出來
可是現在我一讀,就全部顯示出來了,不知那裡有出錯,請各位大俠幫幫忙…
FILE* fptr=fopen("logfile","r");
while(fscanf(fptr,"%s ",tag)!=-1){
if(strcmp(tag,"Round")==0){

fscanf(fptr,"%d",&x);

getch();

}
chloejing
帖子: 6
注册时间: 2011-03-17 17:15
送出感谢: 0
接收感谢: 0

Re: 急…關於gtk讀檔的問題

#2

帖子 chloejing » 2011-03-25 15:02

我是想一個round,一個round 的顯示出來
不是一次全部都出來
我用c++跑是ok的,可是用gtk就不行…
請幫幫小的…
回复

回到 “GTK+和QT”