QNX Photon: Getting Window Resources and Setting Label
- Create a base window.
- Add a
PtButton widget to the window, and give it a suitable
- Set its Text resource (Pt_ARG_TEXT_STRING)
to Move Label.
- Add a
PtLabel widget to the window, and give it a suitable
- Select the button widget, and go to the
Callbacks control panel.
- Click the
Activate event, and the Callback editor appears.
- Ensure the code button is depressed, and click on the
Function name text box.
- Enter a suitable name for the function (e.g. MoveLabel). The
function needn't exist yet, appbuilder will create the file and
the function stub for you.
- Go the the Application menu, and select Build + Run.
- Ensure the correct platform is selected, and click
- In the list of module files, select the module containing the
function you named earlier (the file probably has the same name
as the function).
- Click Edit.
- In the following code sample, the changes you need to make to
the generated function stub are stongly emphasised like
/* Standard headers */
/* Local headers */
MoveLabel( PtWidget_t *widget, ApInfo_t *apinfo, PtCallbackInfo_t *cbinfo )
unsigned short *wnd_width;
unsigned short *wnd_height;
/* eliminate 'unreferenced' warnings */
widget = widget, apinfo = apinfo, cbinfo = cbinfo;
/* Specifying a position outside the window's area does not generate an error.
But the widget will not be visible. */
parent_wnd = PtGetParent(widget, PtWindow);
PtGetResource( parent_wnd, Pt_ARG_WIDTH, &wnd_width, 0);
PtGetResource( parent_wnd, Pt_ARG_HEIGHT, &wnd_height, 0);
lbl_pos.x = (int) *wnd_width / 2;
lbl_pos.y = (int) *wnd_height / 2;
PtSetResource( ABW_lbl1, Pt_ARG_POS, &lbl_pos, 0);
return( Pt_CONTINUE );
- First, we need a pointer to the window that contains the
label and button. This is achieved with the function
PtGetParent. The second parameter to this function (PtWindow)
is the type of widget that we are looking for; Photon will keep
searching higher in the ancestry until it finds the widget that
matches the given type.
- Next, we obtain the width (Pt_ARG_WIDTH)
and height (Pt_ARG_HEIGHT)
of the window with the
PtGetResource function. Note that this function takes the
address of the variable where we will store this value, so we
need the address operator (&)
- Once we have the window's height and width, we find the
middle point, which is where we will place the label.
- The position of a widget is held in the
Pt_ARG_POS resource, which is a struct. The
PtSetResource function requires a pointer to the structure
containing the new value, so it is a call-by-reference, using the
Content last updated: 2003-09-23