-
Notifications
You must be signed in to change notification settings - Fork 0
/
c-gtksimple.h
47 lines (37 loc) · 1.21 KB
/
c-gtksimple.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Kode sumber https://www.geeksforgeeks.org/how-to-create-gui-in-c-programming-using-gtk-toolkit/
#ifndef GTKSIMPLE
#define GTKSIMPLE
#include <gtk/gtk.h>
static int counter = 0;
void greet(GtkWidget* widget, gpointer data)
{
// printf equivalent in GTK+
g_print("Welcome to GTK\n");
g_print("%s clicked %d times\n",
(char*)data, ++counter);
}
void destroy(GtkWidget* widget, gpointer data)
{
gtk_main_quit();
}
/// parameter masukan dihapus, argc dibuat 0, argv dibuat NULL
int main_gtksimple()
{
GtkWidget* window;
GtkWidget* button;
gtk_init(0, NULL);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
g_signal_connect(window, "destroy", G_CALLBACK(destroy), NULL);
/* Let's set the border width of the window to 20.
* You may play with the value and see the
* difference. */
gtk_container_set_border_width(GTK_CONTAINER(window), 20);
button = gtk_button_new_with_label("Click Me!");
/// Mengganti GTK_OBJECT dengan G_OBJECT
g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(greet), "button");
gtk_container_add(GTK_CONTAINER(window), button);
gtk_widget_show_all(window);
gtk_main();
return 0;
}
#endif