QNX Photon: Displaying an Icon using a Button Command

  1. Create a base window.
  2. Add a PtLabel widget to the window, and give it a suitable name.
  3. Set its Label Type resource (Pt_ARG_LABEL_TYPE) to Pt_Image (see Pt_Image_t).
  4. Add a PtButton 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. ShowImage). 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 named after the function you named earlier.
  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 <photon/PxImage.h>
    ShowImage( PtWidget_t *widget, ApInfo_t *apinfo, PtCallbackInfo_t *cbinfo )
       PhImage_t   *myImg;
       char        myImgFlnm[20] = "PICTURE.BMP";
       /* eliminate 'unreferenced' warnings */
       widget = widget, apinfo = apinfo, cbinfo = cbinfo;
       if ((myImg = PxLoadImage( myImgFlnm, NULL)) == NULL) {
          fprintf( stderr, "Error loading image file %s\n", myImgFlnm);
          PtExit( EXIT_FAILURE );
       PtSetResource(ABW_lblMyImg, Pt_ARG_LABEL_IMAGE, myImg, 0);
       return( Pt_CONTINUE );


Home About Me
Copyright © Neil Carter

Content last updated: 2003-09-23