Re: passing Widget variables as arguments
- From: Chris Sorenson <csoren@xxxxxxx>
- Date: Tue, 26 Jun 2007 01:14:16 -0500
Qzectb wrote:
I'm new to Motif programming and am trying to clean up and extend an
existing Motif-based program written in C.
If a variable is declared in a calling program as
Widget w ;
and I want to pass the variable to a function that includes lines like
void Test(Widget w)
{
...
w = XmCreatePulldownMenu(foo, name, NULL, 0);
...
}
so that the initialized value of w is successfully returned to the
calling program, how is this properly done? I've been assuming that w
is treated as a pointer to some kind of structure, so that the above
syntax would work as intended. Instead, I find that the contents of w
aren't surviving the trip back to the calling program.
If I embed the XmCreatePulldownMenu call "in line" in the calling
program, it works as intended, so it appears to be only an argument-
passing issue that is causing me problems.
Thanks for any advice.
That should work, provided foo is a global menubar widget and name is a
global character string. You can't see the widget on the menubar
because you haven't populated it with anything. But it's there. Try
compiling this and then look at the widget tree with editres; you'll
see it:
#include <Xm/Form.h>
#include <Xm/RowColumn.h>
#include <X11/Xmu/Editres.h>
Widget foo;
char name[] = "name";
void test(Widget);
int main(int argc, char * argv[])
{
Widget toplevel, form, w;
int ac;
Arg av[5];
XtAppContext app;
toplevel = XtAppInitialize(&app, "Test", NULL, 0,
&argc, argv, NULL, NULL, 0);
form = XtVaCreateManagedWidget("form",
xmFormWidgetClass, toplevel,
XmNheight, 100,
XmNwidth, 100,
NULL);
ac = 0;
XtSetArg(av[ac], XmNrightAttachment, XmATTACH_WIDGET); ac++;
XtSetArg(av[ac], XmNrightWidget, form); ac++;
XtSetArg(av[ac], XmNleftAttachment, XmATTACH_WIDGET); ac++;
XtSetArg(av[ac], XmNleftWidget, form); ac++;
foo = XmCreateMenuBar (form, "menu_bar", av, ac);
XtManageChild(foo);
test(w);
XtAddEventHandler ( toplevel, (EventMask) 0, True,
(XtEventHandler) _XEditResCheckMessages, NULL );
XtSetLanguageProc(NULL, NULL, NULL);
XtRealizeWidget(toplevel);
XtAppMainLoop(app);
return 0;
}
void test(Widget w)
{
w = XmCreatePulldownMenu(foo, name, NULL, 0);
}
.
- References:
- passing Widget variables as arguments
- From: Qzectb
- passing Widget variables as arguments
- Prev by Date: passing Widget variables as arguments
- Next by Date: XtUnmanageChild - intermittent crashes
- Previous by thread: passing Widget variables as arguments
- Next by thread: XtUnmanageChild - intermittent crashes
- Index(es):
Relevant Pages
|