Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!uunet!zephyr.ens.tek.com!tektronix!psueea!parsely!bucket!servio!bruce From: bruce@servio.UUCP (Bruce Schuchardt) Newsgroups: comp.windows.x Subject: Re: XDrawLine Message-ID: <278@servio.UUCP> Date: 5 Dec 89 22:23:43 GMT References: <1989Dec2.193728.2991@athena.mit.edu> Reply-To: bruce@servio.UUCP (Bruce Schuchardt) Distribution: usa Organization: Servio Logic Development Corp.; Beaverton, OR Lines: 50 In article <1989Dec2.193728.2991@athena.mit.edu> jstravis@athena.mit.edu (John S. Travis) writes: >Can anyone help me with what must be an obvious(to others) error >I am merely trying to read in some data ponts and draw lines >connecting them. The window pops up, but nothing is drawn, not even >the XDrawLines i threw in randomly throughout the program. What's the deal? >Thanks for any help! > [ deleted ] > > toplevel = XtInitialize(argv[0],"Stream",NULL,0,&argc,argv); > canvas = XtCreateManagedWidget("canvas",XwworkSpaceWidgetClass,toplevel,NULL,0); > XtRealizeWidget(toplevel); > [ deleted ] > gc = XtGetGC(canvas,GCForeground | GCLineWidth | GCBackground, &values); > > XDrawLine(XtDisplay(canvas), XtWindow(canvas),gc, 24,89,30,133); > [ deleted ] > XtMainLoop(); >} [ deleted ] I'm surprised you didn't get an Invalid Window error from the server with this code. Calling XtRealizeWidget() doesn't complete the job of getting a window up on the screen. This won't happen until some events are dispatched (e.g., in XtMainLoop()). You can draw all you want, but it won't go on the widget's window if the widget doesn't have a mapped window yet. I had a similar problem, where I wanted to create and map a widget and then do some other good stuff all in the same function. Here's what I did: /* try to get a real widget window */ while (!XtIsRealized(widget) && XtPending()) { XtNextEvent(&event); XtDispatchEvent(&event); } if (XtIsRealized(widget)) { /* do your drawing here */ } else { /* something went haywire */ } -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Bruce Schuchardt Ph: (503) 629-8383 Servio Logic bruce@servio.SLC.COM Beaverton, OR uunet!servio!bruce