Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create a Window in Unix?

Status
Not open for further replies.

Wolfie7873

Technical User
Jan 15, 2004
94
US
There's an interesting app that I can from our server, it tells you which of a list of people are currently logged on and in what lab. What I want to do is write a small utility that will create a separate window to display the results of the app. It doesn't need any menus, just a simple small window that can call the program that already exists on the server and display the results (refreshing ever so often) and return control to the main window. Any suggestions? I'm relatively skilled in C++, but I don't know how to create new windows or any of that in Unix - I know that in WIN32 it's pretty much a nightmare. Any suggestions?
 
Lots of ways of doing this depending on what is available. If you have XWindows, you can set the DISPLAY to the relevant machine and then pop up a window on it.

There is a script utility for windowing kornshell which you could use as a prototype. These are basically Motif primitives in a scripting environment. Once you've figured out what you want, you can convert it to C/C++. Seems a roundabout way of doing things but wrestling with Motif when nobody around knows about it is something else.

Alternatively, there is a drag and drop thing on Sun for designing forms in CDE. It may be available on other platforms now.

You could also get the latest version of QT for a graphical interface.
 
XWindows is available how to I do what you suggested with DISPLAY, etc?

Thanks
 
Say you have two terminals called happy and grumpy. For happy to display a console on grumpy, on a terminal window in happy, you type

DISPLAY=grumpy:0.0
export DISPLAY
xterm &

This will pop up a display on grumpy which is actually running on happy. Now the programming bit. Look up lesstif or motif. There are quite a few user groups and some of them have tutorials on getting started etc. The hello world looks something like
Code:
#include <Xm/PushB.h>
void pushed (Widget w, XtPointer clientdata, XtPointer calldata)
{
   printf ("Ouch\n");
}

main (int argc, char* argv[])
{
   Widget topl, butn;
   XtAppContext app;
   XmString     lab;

   XtSetLanguageProc (NULL, NULL, NULL, NULL);
   topl = XtVaAppInitialize (&app, "Hello", NULL, 0, &argc, argv, NULL, NULL);
   lab  = XmStringCreateLocalized ("Press me");
   butn = XtVaCreateManagedWidget (
      "pushb",
      xmPushButtonWidgetClass, topl,
      XmNlabelString, lab,
      NULL);
   XmStringFree (lab);
   XtAddCallback (butn, XmNactivateCallback, pushed, NULL);
   XtRealizeWidget (topl);
   XtAppMainLoop (app);

   return 0;
}
You have to build it with something like

cc -O -o filename filename.c -lXm -lXt -lX11

The order of the libraries is important because the same calls exist in libXm and libXt and the libXm ones override the libXt ones. I spent half a day trying to figure this out when an MS-Windows developer changed the order because he didn't know it mattered.

You can run this program with DISPLAY set to any terminal and it will pop up on that workstation. The fonts etc are controlled by a text file in a directory called C (if you do not have LANG defined). They are not built into the code. If you want a MS-Windows type dialog editor, there are some about. On Sun, there is some equivalent of XDesigner in the CDE toolkit. It may be the same on HP but I don't know about AIX. Unlike MS, these are hierarchical and the Widgets (controls) will grow/shrink to the size of the text.
Resources are controlled by a files in 13 different places. It searches them in a specified order before starting the program. These are pure text files.

The thing to remember about X-Windows is that it isn't like MS-Windows. Treat all calls like PostMessage: not like SendMessage. i.e. the system does not hang around until you finish: it returns straight away. The events are handled by the callbacks.

Other graphical alternatives are the more ancient XView or the more modern CDE (similar to KDE).

If you wish to delve any deeper, you will need the O'Reilly reference books. Basically Vol1 & 2 for Xlib, Vol4A for Xt Toolkit and 6A and 6B for Motif. Some of these are also available for download with info about the newer controls.

Have fun.

For more info and possibly tutorials, there is the OpenMotif group and possibly lesstif.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top