Get the instance pointer for a widget in a given module


#include <Ap.h>

PtWidget_t *ApGetWidgetPtr( PtWidget_t *link_instance,
                            int wgt_name );


The link instance of the module that you want to search for the widget.
The ABN_ name of the widget that you want to find. PhAB automatically generates these name values for you when you generate your code.




ApGetWidgetPtr() is used to obtain the widget's instance pointer within the specified link_instance. For most modules, PhAB generates manifests that let you access the widgets within the module directly, provided only one instance of the module exists at a time.

Note: You can also use AbGetABW() to get the widget instance pointer more efficiently, though AbGetABW() does not work when there are multiple instances of the widget's window module.

Because window modules allow you to have multiple instances you can't always use the direct access manifests; the manifest will only be valid for the last instance of the window. For windows, you may need either to save the link_instance pointer when creating the window, or to use this function to find the correct link_instance for the callback.

Once you determine the module link instance, you'll need to extract the widget pointer from it.


A pointer to the widget within the module link_instance, or NULL if it wasn't found.


PtArg_t        args[1];

mywindow_callback( PtWidget_t *widget, ... )
    PtWidget_t   *window;

    /* from which window did this come? */
    if ( window = ApGetInstance( widget ) ) {
        /* set the widget selected to red */
        PtSetArg( &args[0], Pt_ARG_FILL_COLOR,
                  Pg_RED, 0 );
            ApGetWidgetPtr( window, ABN_mywidget ),
            1, args );

    return( Pt_CONTINUE );

Note: If you compare this example with the one for ApGetInstance(), you'll notice a subtle difference. This example modifies a specific widget identified by ABN_mywidget, while the other example modifies any widget affected by the callback.



Interrupt handler No
Signal handler No
Thread No

See also:

AbGetABW(), ApGetInstance()

Handling multiple instances of a window in the Working with Code chapter of the Photon Programmer's Guide