Path: utzoo!attcan!utgpu!watmath!iuvax!rutgers!bellcore!dana From: dana@dino.bellcore.com (Dana A. Chee) Newsgroups: comp.windows.x Subject: Re: Simple programming quiz Message-ID: Date: 15 Jun 89 10:37:23 GMT References: <29675@ucbvax.BERKELEY.EDU> Sender: news@bellcore.bellcore.com Organization: Bellcore, Morristown, NJ USA Lines: 78 In-reply-to: elf@gilan.Berkeley.EDU's message of 14 Jun 89 21:45:10 GMT In article <29675@ucbvax.BERKELEY.EDU> elf@gilan.Berkeley.EDU (Marc Singer) writes: Why does this apparently simple X program not work? ---------------------- /* test.c */ #include static char szLabel[] = "Hi there."; main() { Display *display; Window xwnd; XSetWindowAttributes attrib; XGCValues xgcv; GC gc; char ch; display = XOpenDisplay(0); attrib.background_pixel = WhilePixel(display, 0); attrib.border_pixel = BlackPixel(display, 0); xwnd = XCreateWindow(display, RootWindow(display, 0), 10, 10, 500, 40, 2, CopyFromParent, InputOutput, CopyFromParent, CWBackPixel | CWBorderPixel | CWEventMask, &attrib); What's the event mask (attrib.event_mask = ?), since you set the flags saying you were going to set it? (for problem below, you need at least attrib.event_mask = Expose;) XMapWindow(display, xwnd); XFlush(display); Great, now wait for an expose event that says your window has been mapped. Until that comes, you are drawing on the window before it is being mapped and your strings and lines are going directly into the bit bucket. Add the following line (and define "Event event" above) XNextEvent(display, &event); /* xgcv.foreground = BlackPixel(display, 0); */ /* xgcv.function = GXinvert; */ /* xgcv.plane_mask = AllPlanes; */ /* gc = XCreateGC(display, xwnd, GCForeground | GCFunction | GCPlaneMask, &xgcv); */ gc = XCreateGC(display, xwnd, 0, 0); XDrawString(display, xwnd, gc, 10, 10, szLabel, strlen(szLabel)); XDrawLine(display, xwnd, gc, 0, 0, 500, 40); /* XFillRectangle(display, xwnd, gc, 0, 0, 1000, 1000); */ XFlush(display); ch = getchar(); } /* main */ ------------------ I know that some of the attributes for the window and the GC are redundant. And I have tried specifying the visual and depth of the XCreateWindow explicitly. Still, why do I not get anything other than a background in the window? Marc Singer "When fullness is taken from fullness, fullness still remains." Invocation of the Isha Upanishad The great "Drawing in an unmapped window" error strikes again. -- Dana Chee Bellcore MRE 2Q-250 (201) 829-4488 dana@bellcore.com