我正在使用 Xlib 编写应用程序。我这样设置窗口的前景:
XSetForeground (dpy, gc, WhitePixel (dpy, scr));
但现在我需要将绘图颜色更改为其他颜色,我首先想这样做:
void update_window (Display* d, Window w, GC gc, Colormap cmap)
{
XWindowAttributes winatt;
XColor bcolor;
char bar_color[] = "#4E4E4E";
XGetWindowAttributes (d, w, &winatt);
XParseColor(d, cmap, bar_color, &bcolor);
XAllocColor(d, cmap, &bcolor);
// Draws the menu bar.
XFillRectangle (d, w, gc, 0, 0, winatt.width, 30);
XFreeColormap (d, cmap);
}
但这不起作用。那么 XParseColor 和 XAllocColor 做了什么?我是否需要再次使用 XSetForeground 来更改颜色?