#include <stdio.h>
#include <stdlib.h>
#include <Xm/Xm.h>
#include <xpm.h>

main(int argc, char **argv)
{
  XtSetLanguageProc(NULL, NULL, NULL);
  
  XtAppContext app;
  Widget topLevel;
  
  topLevel = 
    XtVaAppInitialize(&app, "IconDemo", NULL, 0, &argc, argv, 
		      NULL, 
		      XmNwidth, 100,
		      XmNheight, 100,
		      XmNiconic, True,
		      NULL);
  
    
  // Set icon pixmap
  if (argc != 2)
  {
    fprintf(stderr, "usage: %s <xpm file>\n", argv[0]);
    exit(1);
  }
  
  char *filename = argv[1];
  
  XpmAttributes xpmAttributes;

  xpmAttributes.closeness = 40000;
  xpmAttributes.valuemask = XpmSize | XpmCloseness;
  
  Pixmap iconPixmap, mask;

  int status;
  
  if ((status = XpmReadFileToPixmap(XtDisplay(topLevel),
				    DefaultRootWindow(XtDisplay(topLevel)),
				    filename,
				    &iconPixmap,
				    &mask,
				    &xpmAttributes)) == XpmSuccess)
  {
    fprintf(stderr, "XpmReadFileToPixmap SUCCEEDED\n");
    XtVaSetValues(topLevel,
		  XmNiconPixmap, iconPixmap,
		  NULL);

  }
  else
    fprintf(stderr, "XpmReadFileToPixmap FAILED; status = %d\n", status);

  
  XtRealizeWidget(topLevel);
  XtAppMainLoop(app);
}









