【问题标题】:Change Xlib window background color with C++使用 C++ 更改 Xlib 窗口背景颜色
【发布时间】:2013-01-05 21:17:29
【问题描述】:

这是 Linux。我创建了一个窗口,我想将其背景颜色更改为绿色。这就是我的代码的样子:

Window xwin = XCreateSimpleWindow(dis, 
                                  DefaultRootWindow(dis), 
                                  0, 0, 
                                  500, 300, 
                                  0,
                                  WhitePixel(dis, 0),
                                  WhitePixel(dis, 0));
GC gc = XCreateGC(dis, xwin, 0, NULL);
XColor color;
Colormap colormap;
char green[] = "#00FF00";

colormap = DefaultColormap(dis, 0);
XParseColor(dis, colormap, green, &color);
XAllocColor(dis, colormap, &color);

XSetBackground(dis, gc, color.pixel);

XMapWindow(dis, xwin);
XFlush(dis);

我看到的窗口是白色的。是否可以使用 X11 在 Linux 中更改窗口背景颜色?谢谢!

【问题讨论】:

    标签: colors background window x11 xlib


    【解决方案1】:

    如果你只想要一个绿色的背景,XCreateSimpleWindow 的最后一个参数就是背景颜色,所以 ...

      XColor color;
      Colormap colormap;
      char green[] = "#00FF00";
    
      colormap = DefaultColormap(dis, 0);
      XParseColor(dis, colormap, green, &color);
      XAllocColor(dis, colormap, &color);
    
    
      Window xwin = XCreateSimpleWindow(dis, 
                       DefaultRootWindow(dis), 
                       0, 0, 
                       500, 300, 
                       0,
                       WhitePixel(dis, 0),
                       color.pixel);
    
    XMapWindow(dis, xwin);
    XFlush(dis);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-10-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-25
      • 1970-01-01
      相关资源
      最近更新 更多