QNX Photon: Getting Window Resources and Setting Label Resources

  1. Create a base window.
  2. Add a PtButton widget to the window, and give it a suitable name.
  3. Set its Text resource (Pt_ARG_TEXT_STRING) to Move Label.
  4. Add a PtLabel widget to the window, and give it a suitable name.
  5. Select the button widget, and go to the Callbacks control panel.
  6. Click the Activate event, and the Callback editor appears.
  7. Ensure the code button is depressed, and click on the Function name text box.
  8. 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.
  9. Go the the Application menu, and select Build + Run.
  10. Ensure the correct platform is selected, and click Generate.
  11. 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).
  12. Click Edit.
  13. In the following code sample, the changes you need to make to the generated function stub are stongly emphasised like this.
    /* Standard headers */
    #include <stdio.h>
    #include <stdlib.h>
    #include <unistd.h>
    #include <string.h>
    /* Local headers */
    #include "ablibs.h"
    #include "abimport.h"
    #include "proto.h"
    #include <Ph.h>
    MoveLabel( PtWidget_t *widget, ApInfo_t *apinfo, PtCallbackInfo_t *cbinfo )
       PhPoint_t lbl_pos;
       unsigned short *wnd_width;
       unsigned short *wnd_height;
       PtWidget_t *parent_wnd;
       /* 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 );


Home About Me
Copyright © Neil Carter

Content last updated: 2003-09-23