Path: utzoo!attcan!uunet!husc6!bloom-beacon!ATHENA.MIT.EDU!kit From: kit@ATHENA.MIT.EDU (Chris D. Peterson) Newsgroups: comp.windows.x Subject: Re: How do I draw on a widget? Message-ID: <8812162153.AA16365@DORA.MIT.EDU> Date: 16 Dec 88 21:53:43 GMT References: <10461@umn-cs.CS.UMN.EDU> Sender: daemon@bloom-beacon.MIT.EDU Organization: The Internet Lines: 61 In reply to: randy@umn-cs.arpa (Randy Orrison) message of 16 December. The most likely cause of your problem is that you are trying to draw in a widget that does not have a window associated with it. Only widgets that have been realized have real X windows associated with them. A call to XtIsRealized() may be appropriate. When I just want a plain window to draw into I usually just instanciate a core widget, class is widgetClass. In order for this to work you must understand X events. References: Xlib Manual Chapter 8 and Xt Manual Chapter 7. Example: NOTE: Rattled off here, has NOT been tested, but I hope you will get the general idea. main(argc, argv) int argc; char ** argv; { Widget foo, bar; Arg arglist[10]; Cardinal num_args; static void DrawProc(); bar = XtInitialize( NULL, "foo_bar", NULL, 0, &argc, argv); num_args = 0; XtSetArg(arglist[num_args], XtNwidth, 100); num_args++; XtSetArg(arglist[num_args], XtNheight, 100); num_args++; foo = XtCreateManagedWidget( "window", bar, widgetClass, arglist, num_args); XtAddEventHandler(foo, ExposureMask, FALSE, DrawProc, NULL); XtRealizeWidget(bar); XtMainLoop(); } static void DrawProc(w, junk, event) Widget w; caddr_t junk; XEvent *event; { /* Insert drawing code here, make sure to check the count in the * exposure structure, or you may draw the graphics multiple times * on every exposure. */ } Chris D. Peterson MIT X Consortium / Project Athena Net: kit@athena.mit.edu Phone: (617) 253 - 1326 USMail: MIT - Room E40-342C 77 Massachusetts Ave. Cambridge, MA 02139