linux嵌入式应用开发- ubuntu eclipse/C gtk用户界面编程


环境:ubuntu, eclipse ,c gtk

linux 环境下编程主要有两种方式:GTK  和QT


1,安装gtk 环境


sudo apt-get install build-essential 	
sudo apt-get install gnome-core-devel
sudo apt-get install pkg-config 
sudo apt-get install devhelp 
sudo apt-get install libglib2.0-doc libgtk2.0-doc

2,编写代码

#include 
/*定义回调函数hello,点击按钮时被系统自动调用*/
void main_btn_clicked(GtkWidget *widget,gpointer *data)
{
g_print("button clicked and data = %s\n",(char *)data);
voice_start(0);
}


/*定义回调函数destroy,关闭窗口时被系统自动调用*/
void main_destroy(GtkWidget *widget,gpointer *data)
{
gtk_main_quit();
}


int main_init_GUI(int value,char* argv[])
{
/*定义指向控件的指针*/
GtkWidget *window;
GtkWidget *fixed_container;
GtkWidget *complete_btn;
GtkWidget *scroll_bar;
GtkWidget *text_view;

GtkTextIter	text_iter;


/*初始化图形显示环境*/
gtk_init(&value,&argv);


/*创建窗口,并设置当关闭窗口时,要执行的回调函数*/
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
g_signal_connect(GTK_OBJECT(window),"destroy",
GTK_SIGNAL_FUNC(main_destroy),NULL);
gtk_container_border_width(GTK_CONTAINER(window),0);/*设置窗口的属性*/
gtk_window_set_title(GTK_WINDOW(window),"demo");
gtk_widget_set_size_request(window,800,480);//set window size
gtk_window_set_position(GTK_WINDOW(window),GTK_WIN_POS_CENTER);//set window  position



/*create box container*/
fixed_container=gtk_fixed_new();//gtk_vbox_new(FALSE,0);
gtk_widget_set_usize(fixed_container,800,480);//set window size

/*创建按钮,并设置当点击按钮时,要执行的回调函数*/
complete_btn = gtk_button_new_with_label("complete");
g_signal_connect(GTK_OBJECT(complete_btn),"clicked",
GTK_SIGNAL_FUNC(main_btn_clicked),"complete_btn");
gtk_widget_set_size_request(complete_btn,180,80);//set window size
gtk_fixed_put(GTK_FIXED(fixed_container),complete_btn,280,360);


scroll_bar=gtk_scrolled_window_new(NULL,NULL);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll_bar),GTK_POLICY_AUTOMATIC,GTK_POLICY_ALWAYS);
gtk_widget_set_size_request(scroll_bar,600,280);//set window size
gtk_fixed_put(GTK_FIXED(fixed_container),scroll_bar,100,50);
gtk_widget_show(scroll_bar);

/*创建text view*/
text_view = gtk_text_view_new();
gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scroll_bar),text_view);
//gtk_container_add(GTK_CONTAINER(scroll_bar),text_view);

text_buffer=gtk_text_view_get_buffer(GTK_TEXT_VIEW(text_view));
gtk_text_buffer_get_iter_at_offset(text_buffer,&text_iter,0);
gtk_text_buffer_insert(text_buffer,&text_iter,"",-1);

gtk_container_add(GTK_CONTAINER(window),fixed_container);

voice_init_engine(&callback_result,&callback_status);/*regeist the callback*/

gtk_widget_show_all(window);

/*进入消息处理循环*/
gtk_main();
return 0;
}

3,设置eclipse 环境

a, properties ->c/c++build/->setting->gcc c compiler->include

include path(-i) 添加   /usr/include/gtk-2.0      /usr/include/glib-2.0

linux嵌入式应用开发- ubuntu eclipse/C  gtk用户界面编程


b, properties ->c/c++build/->setting->gcc c compiler->miscellaneous 

Other flags 中添加  ·pkg-config --cflags gtk+-2.0·

linux嵌入式应用开发- ubuntu eclipse/C  gtk用户界面编程


c, properties ->c/c++build/->setting->GCC clinker ->miscellaneous

linker flags 后面添加 ·pkg-config --libs gtk+-2.0·

linux嵌入式应用开发- ubuntu eclipse/C  gtk用户界面编程



版权所有:


;