Making a pixmap object as a background..

Making a pixmap object as a background..

Post by ganesh.ram » Thu, 23 Oct 2003 05:32:49


Hello,

Here's my dumb program which is supposed to create a window and put a pixmap up
as it's background.

#include <stdio.h>
#include <stdlib.h>
#include <Xm/MainW.h>
#include <xpm.h>

main(int argc, char *argv[])
{
Widget main_w;
XtAppContext app;
Widget top;
int status;
Pixmap pixmap;
XpmAttributes attributes;

attributes.valuemask = 0;

/* create a simple hierarchy with a main window */
top = XtAppInitialize(&app, "Bart", NULL, 0, &argc, argv,
NULL, NULL, 0);

main_w = XmCreateMainWindow (top, "main_window", NULL, 0);

/* create a pixmap from the XPM file */
status = XpmReadFileToPixmap(XtDisplay(top), XtWindow(main_w),
"bart.xpm", &pixmap, NULL, &attributes);
if (status != XpmSuccess)
{
fprintf(stderr, "XpmError: %s\n", XpmGetErrorString(status));
exit(1);
}
else
{
XSetWindowBackgroundPixmap(XtDisplay(top), XtWindow(main_w), pixmap);
}

XtManageChild (main_w);
XtRealizeWidget (top);
XtAppMainLoop(app);
}

I can't understand why it does not work. I keep getting the following error:

X Error of failed request: BadDrawable (invalid Pixmap or Window parameter)
Major opcode of failed request: 53 (X_CreatePixmap)
Resource id in failed request: 0x0
Serial number of failed request: 99
Current serial number in output stream: 118

Any input appreciated,

Ganesh
 
 
 

Making a pixmap object as a background..

Post by Fred L. Kl » Fri, 24 Oct 2003 01:40:55


You must realize the main_w widget before you reference its window. As
your code is currently written, when you make the calls to
XpmReadFileToPixmap and XSetWindowBackgroundPixmap, XtWindow(main_w)
will return NULL since the window for that widget has not yet been
created. Place these calls AFTER XtRealize(top).
--
Fred L. Kleinschmidt
Boeing Associate Technical Fellow
Technical Architect, Common User Interface Services
M/S 2R-94 (206)544-5225