我将使用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来更改颜色?