当前位置: 技术问答>linux和unix
怎么用Linux 下的C/C++开发一个窗口,人人有分!
来源: 互联网 发布时间:2015-01-05
本文导语: 怎么用Linux 下的C/C++开发一个窗口,然在中间显示出一句“Hello world!” 不是控制台的。是像windows那样的一个窗口,并要用SDK式的! | #include void hello( GtkWidget *widget, gpoin...
怎么用Linux 下的C/C++开发一个窗口,然在中间显示出一句“Hello world!”
不是控制台的。是像windows那样的一个窗口,并要用SDK式的!
不是控制台的。是像windows那样的一个窗口,并要用SDK式的!
|
#include
void hello( GtkWidget *widget,
gpointer data )
{
g_print ("Hello Worldn");
}
gint delete_event( GtkWidget *widget,
GdkEvent *event,
gpointer data )
{
g_print ("delete event occurredn");
return TRUE;
}
void destroy( GtkWidget *widget,
gpointer data )
{
gtk_main_quit ();
}
int main( int argc,
char *argv[] )
{
gtk_init (&argc, &argv);
/* create a new window */
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
g_signal_connect (G_OBJECT (window), "delete_event",
G_CALLBACK (delete_event), NULL);
g_signal_connect (G_OBJECT (window), "destroy",
G_CALLBACK (destroy), NULL);
gtk_container_set_border_width (GTK_CONTAINER (window), 10);
/* Creates a new button with the label "Hello World". */
button = gtk_button_new_with_label ("Hello World");
g_signal_connect (G_OBJECT (button), "clicked",
G_CALLBACK (hello), NULL);
g_signal_connect_swapped (G_OBJECT (button), "clicked",
G_CALLBACK (gtk_widget_destroy),
G_OBJECT (window));
gtk_container_add (GTK_CONTAINER (window), button);
gtk_widget_show (button);
gtk_widget_show (window);
gtk_main ();
return 0;
}
编译命令:
gcc -Wall -g helloworld.c -o helloworld `pkg-config --cflags --libs gtk+-2.0`
void hello( GtkWidget *widget,
gpointer data )
{
g_print ("Hello Worldn");
}
gint delete_event( GtkWidget *widget,
GdkEvent *event,
gpointer data )
{
g_print ("delete event occurredn");
return TRUE;
}
void destroy( GtkWidget *widget,
gpointer data )
{
gtk_main_quit ();
}
int main( int argc,
char *argv[] )
{
gtk_init (&argc, &argv);
/* create a new window */
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
g_signal_connect (G_OBJECT (window), "delete_event",
G_CALLBACK (delete_event), NULL);
g_signal_connect (G_OBJECT (window), "destroy",
G_CALLBACK (destroy), NULL);
gtk_container_set_border_width (GTK_CONTAINER (window), 10);
/* Creates a new button with the label "Hello World". */
button = gtk_button_new_with_label ("Hello World");
g_signal_connect (G_OBJECT (button), "clicked",
G_CALLBACK (hello), NULL);
g_signal_connect_swapped (G_OBJECT (button), "clicked",
G_CALLBACK (gtk_widget_destroy),
G_OBJECT (window));
gtk_container_add (GTK_CONTAINER (window), button);
gtk_widget_show (button);
gtk_widget_show (window);
gtk_main ();
return 0;
}
编译命令:
gcc -Wall -g helloworld.c -o helloworld `pkg-config --cflags --libs gtk+-2.0`
|
up
|
qt
|
用QT亚、
|
对啊,用QT很方便的,现在已经是3.1.0版了,可以用他自带的QT-designer把对话框画好再进行程序设计。就跟vc下的资源编辑一样方便。
|
Klyix 啦~~
:)
:)