当前位置: 技术问答>linux和unix
gtk编程求助?谢谢!
来源: 互联网 发布时间:2015-06-21
本文导语: 程序是想改窗口的背景色和画几个不同颜色的矩形,颜色是用color1赋值的 程序编译可以通过但有警告,且还画出的矩形是一个颜色,这是怎么回事。 谢谢! #include #include #include GtkWidget *window; GdkColormap *colormap...
程序是想改窗口的背景色和画几个不同颜色的矩形,颜色是用color1赋值的
程序编译可以通过但有警告,且还画出的矩形是一个颜色,这是怎么回事。
谢谢!
#include
#include
#include
GtkWidget *window;
GdkColormap *colormap;
GdkColor color;
GdkGC *gc;
void mbg(){
if(gdk_colormap_alloc_color(colormap,&color,FALSE,TRUE)){
gdk_window_set_background(window->window, &color);
}
}
void draw(){
GdkColor color1;
gc=gdk_gc_new(window->window);
color1.red=0x0000;
color1.blue=0x0000;
color1.green=0x0000;
if(gdk_colormap_alloc_color(colormap,&color,FALSE,TRUE))
gdk_rgb_gc_set_foreground(gc,&color1);
gdk_draw_rectangle(window->window,gc,FALSE,25,50,450,200);
color1.red=0xffff;
color1.blue=0x0000;
color1.green=0x0000;
if(gdk_colormap_alloc_color(colormap,&color,FALSE,TRUE))
gdk_rgb_gc_set_foreground(gc,&color1);
gdk_draw_rectangle(window->window,gc,FALSE,30,55,450,200);
color1.red=0x0000;
color1.blue=0x0000;
color1.green=0x0000;
if(gdk_colormap_alloc_color(colormap,&color,FALSE,TRUE))
gdk_rgb_gc_set_foreground(gc,&color1);
gdk_draw_rectangle(window->window,gc,FALSE,25,270,260,100);
color1.red=0x0000;
color1.blue=0xffff;
color1.green=0x0000;
if(gdk_colormap_alloc_color(colormap,&color,FALSE,TRUE))
gdk_rgb_gc_set_foreground(gc,&color1);
gdk_draw_rectangle(window->window,gc,FALSE,30,275,260,100);
color1.red=0x0000;
color1.blue=0x0000;
color1.green=0x0000;
if(gdk_colormap_alloc_color(colormap,&color,FALSE,TRUE))
gdk_rgb_gc_set_foreground(gc,&color1);
gdk_draw_rectangle(window->window,gc,FALSE,300,270,175,100);
color1.red=0xffff;
color1.blue=0x0000;
color1.green=0x0000;
if(gdk_colormap_alloc_color(colormap,&color,FALSE,TRUE))
gdk_rgb_gc_set_foreground(gc,&color1);
gdk_draw_rectangle(window->window,gc,FALSE,305,275,175,100);
}
int main(int argc, char *argv[]){
gtk_init(&argc,&argv);
window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
gint width=500;
gint height=400;
gtk_widget_set_usize(window,width,height);
color.red=0;
color.blue=0;
color.green=0;
colormap=gtk_widget_get_colormap(window);
gtk_signal_connect(GTK_OBJECT(window),"event",GTK_SIGNAL_FUNC(mbg),(gpointer)window);
gtk_signal_connect(GTK_OBJECT(window),"event",GTK_SIGNAL_FUNC(draw),(gpointer)window);
gtk_widget_show(window);
gtk_main();
return 0;
}
程序编译可以通过但有警告,且还画出的矩形是一个颜色,这是怎么回事。
谢谢!
#include
#include
#include
GtkWidget *window;
GdkColormap *colormap;
GdkColor color;
GdkGC *gc;
void mbg(){
if(gdk_colormap_alloc_color(colormap,&color,FALSE,TRUE)){
gdk_window_set_background(window->window, &color);
}
}
void draw(){
GdkColor color1;
gc=gdk_gc_new(window->window);
color1.red=0x0000;
color1.blue=0x0000;
color1.green=0x0000;
if(gdk_colormap_alloc_color(colormap,&color,FALSE,TRUE))
gdk_rgb_gc_set_foreground(gc,&color1);
gdk_draw_rectangle(window->window,gc,FALSE,25,50,450,200);
color1.red=0xffff;
color1.blue=0x0000;
color1.green=0x0000;
if(gdk_colormap_alloc_color(colormap,&color,FALSE,TRUE))
gdk_rgb_gc_set_foreground(gc,&color1);
gdk_draw_rectangle(window->window,gc,FALSE,30,55,450,200);
color1.red=0x0000;
color1.blue=0x0000;
color1.green=0x0000;
if(gdk_colormap_alloc_color(colormap,&color,FALSE,TRUE))
gdk_rgb_gc_set_foreground(gc,&color1);
gdk_draw_rectangle(window->window,gc,FALSE,25,270,260,100);
color1.red=0x0000;
color1.blue=0xffff;
color1.green=0x0000;
if(gdk_colormap_alloc_color(colormap,&color,FALSE,TRUE))
gdk_rgb_gc_set_foreground(gc,&color1);
gdk_draw_rectangle(window->window,gc,FALSE,30,275,260,100);
color1.red=0x0000;
color1.blue=0x0000;
color1.green=0x0000;
if(gdk_colormap_alloc_color(colormap,&color,FALSE,TRUE))
gdk_rgb_gc_set_foreground(gc,&color1);
gdk_draw_rectangle(window->window,gc,FALSE,300,270,175,100);
color1.red=0xffff;
color1.blue=0x0000;
color1.green=0x0000;
if(gdk_colormap_alloc_color(colormap,&color,FALSE,TRUE))
gdk_rgb_gc_set_foreground(gc,&color1);
gdk_draw_rectangle(window->window,gc,FALSE,305,275,175,100);
}
int main(int argc, char *argv[]){
gtk_init(&argc,&argv);
window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
gint width=500;
gint height=400;
gtk_widget_set_usize(window,width,height);
color.red=0;
color.blue=0;
color.green=0;
colormap=gtk_widget_get_colormap(window);
gtk_signal_connect(GTK_OBJECT(window),"event",GTK_SIGNAL_FUNC(mbg),(gpointer)window);
gtk_signal_connect(GTK_OBJECT(window),"event",GTK_SIGNAL_FUNC(draw),(gpointer)window);
gtk_widget_show(window);
gtk_main();
return 0;
}
|
if(gdk_colormap_alloc_color(colormap,&color,FALSE,TRUE))
怎么是color,应该是color1把
怎么是color,应该是color1把