がんばって英語で書くブログ
英語勉強中なので、ブログも英語で書こうかと。
スポンサーサイト
上記の広告は1ヶ月以上更新のないブログに表示されています。
新しい記事を書く事で広告が消せます。

GTK+ studying11
This is GTK+ memo. using label and fork(), pipe().


#include <gtk/gtk.h>

#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/wait.h>

static gchar *get_uname(void)
{
int fd[2];

pid_t pid;
char buf[256];
gchar *p = NULL;

memset(buf, 0, sizeof(buf));

pipe(fd);

if ((pid = fork()) == -1)
perror("fork()");

if (pid == 0) { /* chiled */
dup2(fd[1], 1);

close(fd[0]);
close(fd[1]);

execl("/bin/uname", "uname", "-sr", NULL);
_exit(0);
} else {
close(fd[1]);

read(fd[0], &buf, sizeof(buf) - 1);
p = g_strdup(buf);
}

return p;
}

static gboolean button_clicked(GtkWidget *widget,
gpointer data)
{
GtkWidget *label = (GtkWidget *) data;
gchar *p = get_uname();

gtk_label_set_text(GTK_LABEL(label), p);
g_free(p);

return FALSE;
}

static GtkWidget *create_button(void *data)
{
GtkWidget *button;

button = gtk_button_new_with_label("ok");
g_signal_connect(G_OBJECT(button), "clicked",
G_CALLBACK(button_clicked), data);

return button;
}

void create_window(void)
{
GtkWidget *window;
GtkWidget *vbox1;
GtkWidget *vbox2;
GtkWidget *button;
GtkWidget *separator;
GtkWidget *label;

window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "label test");

gtk_container_set_border_width(GTK_CONTAINER(window), 5);
g_signal_connect(G_OBJECT(window), "destroy",
G_CALLBACK(gtk_main_quit), NULL);

vbox1 = gtk_vbox_new(FALSE,0);
vbox2 = gtk_vbox_new(FALSE, 0);

label = gtk_label_new("default text");

gtk_box_pack_start(GTK_BOX(vbox1), label, TRUE, TRUE, 0);
gtk_widget_set_size_request(GTK_WIDGET(label), 180, 200);

gtk_widget_show(label);

gtk_container_add(GTK_CONTAINER(window), vbox1);
gtk_widget_show(vbox1);

separator = gtk_hseparator_new();
gtk_box_pack_start(GTK_BOX(vbox1), separator, FALSE, TRUE, 0);
gtk_widget_show(separator);

button = create_button(label);
gtk_box_pack_start(GTK_BOX(vbox2), button, TRUE, TRUE, 0);
gtk_widget_show(button);

gtk_container_add(GTK_CONTAINER(vbox1), vbox2);
gtk_widget_show(vbox2);

gtk_widget_show(window);

}

int main(int argc, char **argv)
{
gtk_init(&argc, &argv);

create_window();

gtk_main();

return 0;
}


スポンサーサイト

テーマ:英語日記 - ジャンル:学問・文化・芸術

travel
over seas? no. go to space!!
Amex sent a catalogue to me. then I found that you could go to space if you got 22,000,000 points.(1 point is 100Yen)

That really awesome, don't you think?
if I ware f*cking rich, I'd go there:-)


awesome day
Today was beautiful day, wasn't it!
yesterday we had strong raining. it was crap:-(
although today was awesome. we could see blue sky!
I wish every day is like today during winter time.

テーマ:英語日記 - ジャンル:学問・文化・芸術

trip log2
I reckon that my 2nd best place would be the Mirror Lakes. there is close to the Milford Sound. maybe about 40 min by car.
there is small place not so big. even so, there is really beautiful! I took some picture there are like guide book's picture:-) becouse of place!
if you want to go to the south island, I'll recommend there!


テーマ:英語日記 - ジャンル:学問・文化・芸術

think about...
I think about travel plan and job now.

I graduate from English school about one month later.

then I'm going to travel around NZ and move down to south island.

so now my travel plan is travel and fruit picking(2 weeks travel, 3 weeks job or etc).

I sent application form for IRD number today.
(if you want to get a job, you need IRD number)

maybe few days later I get IRD number :-)


テーマ:英語日記 - ジャンル:学問・文化・芸術



上記広告は1ヶ月以上更新のないブログに表示されています。新しい記事を書くことで広告を消せます。