CodeBlocks gtk 配制
dev cpp可能是很久就没有人维护了,从2005年到现在还没有更新,下载补丁也很慢
推荐c/c++的爱好者使用CodeBlocks。跨平台的开发工具。
以windows平台为例。
1、安装
下载codeblocks-8.02mingw-setup.exe。安装不在详细描述。
2、配制gtk图形库
(1)下载gtk+-bundle_2.14.6-20081216_win32.zip工具包合集,解压缩到C:\GTK
(2)将C:\GTK\bin加入到PATH环境变量
(3)打开CodeBlocks,新建项目,选择gtk+ project,输入项目名称hello,点击next
选择gtk的安装路径比如:C:\gtk。点击next,选择编译器我使用的是gcc。点击完成
系统自动产生代码:
#include <stdlib.h>
#include <gtk/gtk.h>
static void helloWorld (GtkWidget *wid, GtkWidget *win)
{
GtkWidget *dialog = NULL;
dialog = gtk_message_dialog_new (GTK_WINDOW (win), GTK_DIALOG_MODAL, GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE, "Hello World!");
gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER);
gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_destroy (dialog);
}
int main (int argc, char *argv[])
{
GtkWidget *button = NULL;
GtkWidget *win = NULL;
GtkWidget *vbox = NULL;
/* Initialize GTK+ */
g_log_set_handler ("Gtk", G_LOG_LEVEL_WARNING, (GLogFunc) gtk_false, NULL);
gtk_init (&argc, &argv);
g_log_set_handler ("Gtk", G_LOG_LEVEL_WARNING, g_log_default_handler, NULL);
/* Create the main window */
win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_container_set_border_width (GTK_CONTAINER (win), 8);
gtk_window_set_title (GTK_WINDOW (win), "Hello World");
gtk_window_set_position (GTK_WINDOW (win), GTK_WIN_POS_CENTER);
gtk_widget_realize (win);
g_signal_connect (win, "destroy", gtk_main_quit, NULL);
/* Create a vertical box with buttons */
vbox = gtk_vbox_new (TRUE, 6);
gtk_container_add (GTK_CONTAINER (win), vbox);
button = gtk_button_new_from_stock (GTK_STOCK_DIALOG_INFO);
g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (helloWorld), (gpointer) win);
gtk_box_pack_start (GTK_BOX (vbox), button, TRUE, TRUE, 0);
button = gtk_button_new_from_stock (GTK_STOCK_CLOSE);
g_signal_connect (button, "clicked", gtk_main_quit, NULL);
gtk_box_pack_start (GTK_BOX (vbox), button, TRUE, TRUE, 0);
/* Enter the main loop */
gtk_widget_show_all (win);
gtk_main ();
return 0;
}
点击build,点击run。出现gui窗口,点击信息,出现hello,world。