⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gtkfaq-7.html

📁 gtk是linux一款强大的夸平台的图形化开发工具
💻 HTML
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><HTML><HEAD> <META NAME="GENERATOR" CONTENT="SGML-Tools 1.0.9"> <TITLE>GTK+ FAQ: About gdk</TITLE> <LINK HREF="gtkfaq-8.html" REL=next> <LINK HREF="gtkfaq-6.html" REL=previous> <LINK HREF="gtkfaq.html#toc7" REL=contents></HEAD><BODY BGCOLOR="#FFFFFF"><A HREF="gtkfaq-8.html">Next</A><A HREF="gtkfaq-6.html">Previous</A><A HREF="gtkfaq.html#toc7">Contents</A><HR NOSHADE><H2><A NAME="s7">7. About gdk</A></H2><H2><A NAME="ss7.1">7.1 What is GDK?</A></H2><P>GDK is basically a wrapper around the standard Xlib function calls. If you areat all familiar with Xlib, a lot of the functions in GDK will require little or no getting used to. All functions are written to provide an way to access Xlib functions in an easier and slightly more intuitive manner. In addition, since GDK uses GLib (see below), it will be more portable and safer to use on multiple platforms.<P><P><H2><A NAME="ss7.2">7.2 How do I use color allocation?</A></H2><P>One of the nice things about GDK is that it's based on top of Xlib; this is also a problem, especially in the area of color management. If you want to use color in your program (drawing a rectangle or such, your code should look something like this:<BLOCKQUOTE><CODE><PRE>{  GdkColor *color;  int width, height;  GtkWidget *widget;  GdkGC *gc;  ...    /* first, create a GC to draw on */  gc = gdk_gc_new(widget->window);  /* find proper dimensions for rectangle */  gdk_window_get_size(widget->window, &amp;width, &amp;height);  /* the color we want to use */  color = (GdkColor *)malloc(sizeof(GdkColor));    /* red, green, and blue are passed values, indicating the RGB triple   * of the color we want to draw. Note that the values of the RGB components   * within the GdkColor are taken from 0 to 65535, not 0 to 255.   */  color->red = red * (65535/255);  color->green = green * (65535/255);  color->blue = blue * (65535/255);    /* the pixel value indicates the index in the colormap of the color.   * it is simply a combination of the RGB values we set earlier   */  color->pixel = (gulong)(red*65536 + green*256 + blue);  /* However, the pixel valule is only truly valid on 24-bit (TrueColor)   * displays. Therefore, this call is required so that GDK and X can   * give us the closest color available in the colormap   */  gdk_color_alloc(gtk_widget_get_colormap(widget), color);  /* set the foreground to our color */  gdk_gc_set_foreground(gc, color);    /* draw the rectangle */  gdk_draw_rectangle(widget->window, gc, 1, 0, 0, width, height);  ...}</PRE></CODE></BLOCKQUOTE><P><HR NOSHADE><A HREF="gtkfaq-8.html">Next</A><A HREF="gtkfaq-6.html">Previous</A><A HREF="gtkfaq.html#toc7">Contents</A></BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -