User Tools

Site Tools


Command disabled: register
displaying_20an_20icon_20on_20a_20pushbutton

Displaying an icon on a pushbutton

by Richard Russell, March 2016

The main BBC BASIC for Windows help documentation tells you how to display a BMP image on a pushbutton but not how to display an icon (ICO file) instead. The simple code below shows how to do that:

        BM_SETIMAGE = &F7
        BS_ICON = 64
        IMAGE_ICON = 1
        LR_LOADFROMFILE = 16
 
        INSTALL @lib$+"WINLIB5"
        ICOfile$ = @lib$+"..\bbchelp.ico"
 
        hButton = FN_button("", 100, 100, 96, 96, FN_setproc(PROCclick()), BS_ICON)
        SYS "LoadImage", 0, ICOfile$, IMAGE_ICON, 96, 96, LR_LOADFROMFILE TO hImage
        SYS "SendMessage", hButton, BM_SETIMAGE, IMAGE_ICON, hImage
 
        REPEAT
          WAIT 1
        UNTIL FALSE
        END
 
        DEF PROCclick(W%, L%)
        PRINT "Button clicked!"
        ENDPROC

This code is for a standalone button displayed in the main window, but can easily be adapted for a button in a dialogue box (change the SendMessage call to a SendDlgItemMessage).

You can similarly display an icon on a static control as follows:

        IMAGE_ICON = 1
        LR_LOADFROMFILE = 16
        SS_ICON = 3
        STM_SETIMAGE = 370
 
        INSTALL @lib$+"WINLIB5"
        ICOfile$ = @lib$+"..\bbchelp.ico"
 
        hButton = FN_staticbox("", 100, 100, 96, 96, 101, SS_ICON)
        SYS "LoadImage", 0, ICOfile$, IMAGE_ICON, 96, 96, LR_LOADFROMFILE TO hImage
        SYS "SendMessage", hButton, STM_SETIMAGE, IMAGE_ICON, hImage
 
        REPEAT
          WAIT 1
        UNTIL FALSE
        END
This website uses cookies for visitor traffic analysis. By using the website, you agree with storing the cookies on your computer.More information
displaying_20an_20icon_20on_20a_20pushbutton.txt · Last modified: 2018/04/15 19:15 by tbest3112