instance name and callbacks

I don’t mean to pound the group, but I have just a couple more quetions.

  1. How to I create Instance names from Application Code. I’ve know got my
    window drawing, but I need to name my different widgets so Ican use
    getresource and setresource.

  2. I looked at the sample on creating callbacks from application code, but I
    missed how to control the name of the callback function. I’ve got four
    different buttons and I need to create a callback for each. Any hints.

Thanks a Ton
Ben

Hi Ben,

When you create each of your widgets, I assume your using the
PtCreateWidget() function. This function returns a PtWidget_t *widget,
you can use this in the PtAddCallback() function to add a callback to
the widget.

For example:

activated( PtWidget_t *widget, void *data,
PtCallbackInfo_t info)
{
/
Add you code for what happens when button 1
is pressed */
//suppress compiler warnings concerning unused arguments.
widget = widget, data = data, info = info;

PtExit( 0 );
}

activated2( PtWidget_t *widget, void *data,
PtCallbackInfo_t info)
{
/
Add your code for what happens when button 2
is pressed */
//suppress compiler warnings concerning unused arguments.
widget = widget, data = data, info = info;

PtExit( 0 );
}
main()
{
PtArg_t args;
PtWidget_t *window, *widget, *button1, *button2;

if (PtInit(NULL) == -1)
PtExit(EXIT_FAILURE);

if ((window = PtCreateWidget(PtWindow, Pt_NO_PARENT,
0, NULL)) == NULL)
PtExit(EXIT_FAILURE);

/* Creating the first button */
PtSetArg( &args, Pt_ARG_TEXT_STRING,
“Press Me To Quit”, 0 );
button1 = PtCreateWidget( PtButton, Pt_DEFAULT_PARENT,
1, &args );

//add an activate callback to the button1.
PtAddCallback( button1, Pt_CB_ACTIVATE,
activated, NULL );
/* Creating the second button */
PtSetArg( &args, Pt_ARG_TEXT_STRING,
“Press Me Also To Quit”, 0 );
button2 = PtCreateWidget( PtButton, Pt_DEFAULT_PARENT,
1, &args );

//add an activate callback to the button2.
PtAddCallback( button2, Pt_CB_ACTIVATE,
activated2, NULL );
PtRealizeWidget( window );
PtMainLoop();
return (EXIT_SUCCESS);
}

You can have all the widget point to the same callback or create a
callback for each of the widgets separately. The widget pointer can be
used to set and get the resources of the widget. Inside the callbacks
the widget pointer that is passed to the function is the widget that the
callback is attached to.

Hope this helps
Regards
Brenda

Ben wrote:

I don’t mean to pound the group, but I have just a couple more quetions.

  1. How to I create Instance names from Application Code. I’ve know got my
    window drawing, but I need to name my different widgets so Ican use
    getresource and setresource.

  2. I looked at the sample on creating callbacks from application code, but I
    missed how to control the name of the callback function. I’ve got four
    different buttons and I need to create a callback for each. Any hints.

Thanks a Ton
Ben

Ben wrote:

I don’t mean to pound the group, but I have just a couple more quetions.

  1. How to I create Instance names from Application Code. I’ve know got my
    window drawing, but I need to name my different widgets so Ican use
    getresource and setresource.

PtCreateWidget() returns a pointer to the widget. This is what you use
to get and set resources.


  1. I looked at the sample on creating callbacks from application code, but I
    missed how to control the name of the callback function. I’ve got four
    different buttons and I need to create a callback for each. Any hints.

You can name it what you want. The third argument in the
PtAddCallback() is the name of your callback.


Regards,
Dave B.


Thanks a Ton
Ben