Path: utzoo!mnetor!uunet!lll-winken!lll-lcc!rutgers!ucla-cs!zen!ucbvax!hplabs!hp-pcd!hpcvlo!julie From: julie@hpcvlo.HP.COM (Julie Skeen) Newsgroups: comp.windows.x Subject: Re: Xr11 Example Programs (fixes) Message-ID: <3940061@hpcvlo.HP.COM> Date: 28 Dec 87 22:20:48 GMT References: <3940058@hpcvlo.HP.COM> Organization: Hewlett-Packard Co., Corvallis, OR, USA Lines: 136 /* * add a Message Box to Hello World */ #include #include #include /* * fill a structure to define a Title Bar */ xrTitleBarInfo titleBarInfo = { 0, /* windowId */ {0,0,0,0}, /* editor rectangle */ XrVISIBLE | XrSENSITIVE, /* editor state */ -1, -1, /* editor colors; use defaults */ NULL, /* editor font; use defaults */ "Hello World", /* Title name */ NULL, /* gadget1; unused */ NULL /* gadget2; unused */ }; xrWindowData windowData; xrEditor * t_bar; xrEvent messageEvent; xrMsgBoxInfo msgInfo; INT8 * myButtons[] = {"Ready", "Not Ready"}; main() { Display * display; int screen; Window windowId; XSetWindowAttributes wAttrs; /* Open the display specified by the environment variable DISPLAY */ if ((display = XOpenDisplay(0)) == NULL) { printf ("Cannot open display: %s\n", getenv("DISPLAY")); exit (1); } screen = DefaultScreen(display); /* Initialize Xrlib */ if (XrInit (display, screen, NULL) == FALSE) { printf ("Could not initialize Xrlib\n"); exit (1); } /* Create a window and put it on the display */ windowId = XCreateSimpleWindow (display, RootWindow(display, screen), 50, 50, 400, 200, 3, BlackPixel(display, screen), WhitePixel(display, screen)); wAttrs.override_redirect = TRUE; XChangeWindowAttributes (display, windowId, CWOverrideRedirect, &wAttrs); XMapWindow (display, windowId); /* Associate this window with Xrlib functionality */ XrSetRect (&windowData.windowRect, 50, 50, 400, 200); windowData.foreTile = BlackPixmap; windowData.backTile = WhitePixmap; XrInput (windowId, MSG_ADDWINDOW, &windowData); /* Draw the Title Bar */ titleBarInfo.editorWindowId = windowId; t_bar = XrTitleBar (NULL, MSG_NEW, &titleBarInfo); /* 1. Select the type of input for the window. */ XSelectInput (display, windowId, ButtonPressMask | ButtonReleaseMask | KeyPressMask); /* 2. Put up a message box. */ msgInfo.messageOrigin.x = 50; msgInfo.messageOrigin.y = 50; msgInfo.relativeTo = windowId; msgInfo.messageText = "Are you ready?"; msgInfo.messageButtons = myButtons; msgInfo.numButtons = 2; /* * Put up a message box; upon return, examine value1: * value1 == 1, iff the user selected the 'not ready' button. * value1 == 0, iff the user hit a key or selected the 'ready' button. * value1 == -1, if the message box times out. */ do { XrMessageBox (&msgInfo, MSG_EDIT, &messageEvent); } while (messageEvent.value1 != 0); /* 3. Redraw the Title Bar. */ XrTitleBar (t_bar, MSG_REDRAW, XrREDRAW_ALL); /* Write hello world message to the window */ XSetForeground (display, xrEditorGC1, BlackPixel(display, screen)); XDrawString (display, windowId, xrEditorGC1, 100, 80, "Hello World", 11); /* Send all those instructions to the X window server to process */ XFlush (display); /* Sleep, close the display, and then exit */ sleep (5); XCloseDisplay (display); }