Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!uunet!lll-winken!decwrl!sgi!shinobu!odin!krypton!gavin From: gavin@krypton.sgi.com (Gavin A. Bell) Newsgroups: comp.sys.sgi Subject: Re: Saving a file with a dialog box Keywords: 4Sight gl, launch, confirm, inform Message-ID: <3581@odin.SGI.COM> Date: 5 Feb 90 19:13:03 GMT References: <3569@odin.SGI.COM> Sender: news@odin.SGI.COM Lines: 63 >In article elkins@topaz.rutgers.edu (George Elkins) writes: >>How does one create such a dialog box with buttons and a text field in >>4Sight using the GL/DGL interface? Well, I thought up this little hack just two or three weeks ago, so I can't guarantee that it is perfect yet. However, it is a very good starting point. Let me give you the code, then explain what exactly it is doing: --------- code follows -------- /* * s is the string the user's response will be put into * len_s is the length of s (so we won't overflow it) * m is the message prompt */ void GetInputFromUser(char *s, int len_s, const char *m) { char launchline[300]; FILE *fp; sprintf(launchline, "launch -h echo -m \"%s\"", m); if ((fp = popen(launchline, "r")) != NULL) { fgets(s, len_s, fp); pclose(fp); /* Strip off trailing newline */ if (s[0] != '\0' && s[strlen(s)-1] == '\n') { s[strlen(s)-1] = '\0'; } } else s[0] = '\0'; } ----------- end of code ---------- This code uses the 'launch' command to do all of the dirty work. It launches an 'echo' command, which will just echo back whatever the user types, which is sent back to the program through the magic of popen(). Good things about this code: It is short and easy. The launch command allows you to edit the field in lots of ways, including using Copy/Paste and the mouse. Bad things about this code: The program will ignore all events while the prompter is up; if the user moves either window, an ugly display is likely to result. This won't work unless the user is on the graphics console (an OK assumption if this is a graphics program that requires mouse/keyboard input). This won't work with the Distributed Graphics Library. The 'launch' command is in version 3.2 of the OS; I don't know if it was around before then. You might also want to check out the 'confirm' and 'inform' commands... --gavin