Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1720256
  • 博文数量: 171
  • 博客积分: 11553
  • 博客等级: 上将
  • 技术积分: 3986
  • 用 户 组: 普通用户
  • 注册时间: 2006-05-25 20:28
文章分类

全部博文(171)

文章存档

2012年(2)

2011年(70)

2010年(9)

2009年(14)

2008年(76)

分类: C/C++

2011-09-25 21:37:04

/*
 * 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 012.exe 012.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)
{
}

#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_widget_set_size_request(main_win,WIDTH,HEIGHT);
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_with_label("Relief Normal");
//设置按钮样式
gtk_button_set_relief(GTK_BUTTON(b),GTK_RELIEF_NORMAL);
//将按钮加入到布局中
gtk_box_pack_start(GTK_BOX(v),b,FALSE,FALSE,0);
//为按钮加入单击事件响应函数
g_signal_connect(G_OBJECT(b),"clicked",G_CALLBACK(hello_proc),NULL);

    //创建按钮
b = gtk_button_new_with_label("Relief Half");
//设置按钮的样式
gtk_button_set_relief(GTK_BUTTON(b),GTK_RELIEF_HALF);
//将按钮加入到布局中
gtk_box_pack_start(GTK_BOX(v),b,FALSE,FALSE,0);
//添加事件处理函数
g_signal_connect(G_OBJECT(b),"clicked",G_CALLBACK(hello_proc),NULL);

    //创建按钮
b = gtk_button_new_with_label("Relief None");
//设置按钮样式
gtk_button_set_relief(GTK_BUTTON(b),GTK_RELIEF_NONE);
//将按钮加入到布局中
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;
}

阅读(3534) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~