【发布时间】:2014-05-31 10:11:25
【问题描述】:
/* Draw_Red_Line.c */
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <stdio.h>
#include <stdlib.h>
Window Win;
Display *Dsp;
GC Gc;
XGCValues Gc_Values;
XEvent Event;
Colormap Color_Map;
XColor Screen_RGB, Exact_RGB;
unsigned int Win_Size;
int main (void)
{
/* Set window size */
Win_Size = 625;
/* Open a connection to the X server that controls a display */
Dsp = XOpenDisplay(NULL);
/* Create an unmapped subwindow of root window */
Win = XCreateWindow(Dsp, XDefaultRootWindow(Dsp), 0, 0, Win_Size, Win_Size, 0,
XDefaultDepth(Dsp, 0), InputOutput, CopyFromParent, 0, 0);
/* Map the window on the screen */
XMapWindow(Dsp, Win);
/* Wait until the window appears */
do
XNextEvent(Dsp, &Event);
while
(Event.type != MapNotify);
/* Draw a red line */
Color_Map = DefaultColormap(Dsp, DefaultScreen(Dsp));
XAllocNamedColor(Dsp, Color_Map, "Red", &Screen_RGB, &Exact_RGB);
Gc_Values.foreground = Screen_RGB.pixel;
Gc_Values.line_width = 1;
Gc = XCreateGC(Dsp, Win, GCForeground | GCLineWidth, &Gc_Values);
XDrawLine (Dsp, Win, Gc, 0, 0, 624, 624);
XFlush(Dsp);
/* Exit */
fprintf(stdout, "Exit the process");
return EXIT_SUCCESS;
}
我尝试在(Gnome-)终端中编译并运行它:
EXECUTABLENAME="Draw_Red_Line"
gcc "$EXECUTABLENAME.c" -o "$EXECUTABLENAME" -std=c99 -Wall -lX11
./"$EXECUTABLENAME"
GCC 不会报告任何警告和错误。无论背景如何,红线都没有出现,甚至消息字符串“退出进程”也没有打印到标准输出(运行脚本的终端)。为什么?
【问题讨论】: