GCC配置路径:
运行路径配置:
GTK配置路径:
参数:
$(FileName) -w -o $(FileNameNoExt).exe -II:\Study\rupengc\gtk\include -II:\Study\rupengc\gtk\include\gtk-3.0 -II:\Study\rupengc\gtk\include\cairo -II:\Study\rupengc\gtk\include\gdk -II:\Study\rupengc\gtk\include\glib-2.0 -II:\Study\rupengc\gtk\lib\glib-2.0\include -II:\Study\rupengc\gtk\include\pango-1.0 -II:\Study\rupengc\gtk\include\atk-1.0 -II:\Study\rupengc\gtk\include\gdk-pixbuf-2.0 -LI:\Study\rupengc\gtk\lib -lgtk-win32-3.0 -lgobject-2.0 -lglib-2.0 -lgdk-win32-3.0 -lgdk_pixbuf-2.0 -lcairo -mwindows
Code:
#include<stdio.h> #include<gtk/gtk.h> //引入GTK文件 int main() { gtk_init(NULL,NULL); //初始化GTK环境 GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL); //创建一个窗口 gtk_window_set_title(window,"丁小未"); //设置窗口标题 g_signal_connect(window,"destroy",gtk_main_quit,NULL); // gtk_widget_show(window); //显示窗口 gtk_main(); // return 0; }
效果:
GTK继承关系:
Widget控件:
void gtk_widget_show(widget):显示。int整数
void gtk_widget_hide(widget):隐藏
void gtk_widget_set_sensitive(widget, sensitive):禁用。boolean(布尔类型)只有true(真/是)、false(假/否)两个值。
void gtk_widget_set_size_request(int widget,int width, int height) 设置“建议的”大小
void gtk_widget_destroy(widget)销毁
gtk_window_set_resizable(window, resizable);设置是否可以缩放。
gtk_window_set_position(window, GTK_WIN_POS_CENTER_ALWAYS)显示在屏幕正中间
void gtk_window_maximize(window)最大化
void gtk_container_add(container, widget):从container继承。比如可以将子控件widget添加到window中,window中只能有一个子控件。
Code:
//输入框(GtkEntry)
//GtkEntry *entry1 = gtk_entry_new(); //创建一个输入框
//gtk_container_add(window,entry1); //添加到窗口
//gtk_widget_show(entry1); //显示出来
//添加按钮(GtkButton)
//GtkButton * btn1 = gtk_button_new();
//gtk_button_set_label(btn1,"点我呀");
//gtk_container_add(window,btn1);
//gtk_widget_show(btn1);
//添加标签(GtkLabel)
GtkLabel * label1 = gtk_label_new("姓名:");
gtk_container_add(window,label1);
gtk_widget_show(label1);
容器控件:(window控件只能容纳一个子控件,能加入多个子控件的控件)
Code:
//GtkBox(容器)控件 #include<stdio.h> #include<gtk/gtk.h> //引入GTK文件 int main() { gtk_init(NULL,NULL); //初始化GTK环境 GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL); //创建一个窗口 gtk_window_set_position(window,GTK_WIN_POS_CENTER_ALWAYS);//设置窗口居中 gtk_window_set_title(window,"丁小未"); //设置窗口标题 g_signal_connect(window,"destroy",gtk_main_quit,NULL); // gtk_widget_show(window); //显示窗口 GtkBox *box1 = gtk_box_new(GTK_ORIENTATION_VERTICAL,0); GtkButton * btn1 = gtk_button_new(); gtk_button_set_label(btn1,"小清新"); gtk_box_pack_start(box1,btn1,FALSE,FALSE,0); gtk_widget_show(btn1); GtkButton * btn2 = gtk_button_new(); gtk_button_set_label(btn2,"小屌丝"); gtk_box_pack_start(box1,btn2,FALSE,FALSE,0); gtk_widget_show(btn2); GtkEntry *entry1 = gtk_entry_new(); //创建一个输入框 gtk_box_pack_start(box1,entry1,FALSE,FALSE,0); gtk_widget_show(entry1); //显示出来 gtk_widget_show(box1); gtk_container_add(window,box1); gtk_main(); return 0; }
效果: