Trying to put a BMP image on a button

This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

  • Trying to put a BMP image on a button

    Hi All,

    I'm trying to put a bmp Icon which is located as a file in flash on a button, as far as I understand I have to use the BUTTON_SetBMPEx() function with the file pointer to the *.bmp file. I'm using this function right at the beginning where all the widgets get created.

    C Source Code

    1. [...]
    2. fsStat = finit("N0:");
    3. fsStat = fmount("N0:");
    4. ptr_IconFile = fopen("N0:\\ZIcon.bmp","r"); //returns a valid ptr!
    5. [...]
    6. mainWin = WM_CreateWindow(pPara->xPosWin,pPara->yPosWin,pPara->xSizeWin,pPara->ySizeWin,WM_CF_SHOW, mainWinCallBack, 0);
    7. hZButton = BUTTON_CreateEx(120, 172, 80, 80, mainWin, WM_CF_SHOW, 0, Z_BUTTON_ID);
    8. BUTTON_SetBMPEx(hZButton, BUTTON_BI_UNPRESSED, ptr_IconFile, 0, 0);
    9. [...]


    Unfortunately it doesn't work. The Button will be displayed but bare without the bmp image.

    Any help is appreciated

    Best Regards
    Benjamin
  • Hello Benjamin,

    Please note that that the function fopen() returns a pointer to a FILE. This pointer can be used with file related functions only. I would suggest reading the whole file into a buffer and pass the pointer to the buffer to the function BUTTON_SetBMPEx(). Please note that the pointer to the BMP data has to remain valid as long as it is used by the BUTTON widget.

    Best regards,
    Adrian