/*
* Copyright (C) Jcodeer Zhang 2011
*
* This application is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This application is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <
*
* 功能介绍
* 含有内置图标的按钮
* 构建命令
* gcc -g -o 011.exe 011.c `pkg-config --cflags --libs gtk+-2.0`
*/
#include
/**
*callback function of button
*@param w widget
*@param userdata
*/
void hello_proc(GtkWidget* w,gpointer userdata)
{
g_print("hello GTK\n");
}
#define WIDTH 480
#define HEIGHT 320
int main(int argc,char** argv)
{
gtk_init(&argc,&argv);
GtkWidget* main_win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_container_set_border_width(GTK_CONTAINER(main_win),5);
//创建垂直布局
GtkWidget* v = gtk_vbox_new(FALSE,5);
gtk_container_add(GTK_CONTAINER(main_win),v);
//使用内置图标创建按钮
GtkWidget* b = gtk_button_new_from_stock(GTK_STOCK_OK);
//将按钮pack到布局中
gtk_box_pack_start(GTK_BOX(v),b,FALSE,FALSE,0);
//按钮的单击事件处理
g_signal_connect(G_OBJECT(b),"clicked",G_CALLBACK(hello_proc),NULL);
g_signal_connect_swapped(G_OBJECT(main_win),"destroy",G_CALLBACK(gtk_main_quit),NULL);
//显示所有控件
gtk_widget_show_all(main_win);
gtk_main();
return 0;
}
阅读(2300) | 评论(0) | 转发(0) |