Jump to content

Problem with button text and button image

Recommended Posts


I created a Gui and there are 3 buttons, but if I set an image button, the button name disappears. How can I do?



#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <file.au3>
#include <WindowsConstants.au3>

$Form1 = GUICreate("Form1", 322, 287, 318, 109)
GuiCtrlCreatePic("C:\Documents and Settings\UserXP\Documenti\Downloads\sfondo.bmp",0,0,330,290)

$Button1 = GUICtrlCreateButton("Leggi login e password", 120, 16, 89, 33, BitOR($BS_DEFPUSHBUTTON,$BS_BITMAP))
GUICtrlSetImage(-1, "C:\Documents and Settings\UserXP\Documenti\Downloads\fire.bmp", -1)

$Button2 = GUICtrlCreateButton("Inserimento account", 120, 88, 89, 33, BitOR($BS_DEFPUSHBUTTON,$BS_BITMAP))
GUICtrlSetImage(-1, "C:\Documents and Settings\UserXP\Documenti\Downloads\fire.bmp", -1)

$Button3 = GUICtrlCreateButton("Button3", 120, 152, 89, 33, BitOR($BS_DEFPUSHBUTTON,$BS_BITMAP))
GUICtrlSetImage(-1, "C:\Documents and Settings\UserXP\Documenti\Downloads\fire.bmp", -1)



Share this post

Link to post
Share on other sites


To get text and images on a button you need to use ImageLists like this:

#include <GUIConstantsEx.au3>
#include <GuiButton.au3>
#include <GuiImageList.au3>

;Caveat: Minimum Operating Systems: Windows XP
;In XP, Multiple image list will only show images other than the 1st when Themes are used.

$hGUI = GUICreate("Button Imagelists - Minimum OS: Windows XP", 500, 400)

$cLabel = GUICtrlCreateLabel("", 150, 30, 300, 300)

$sMsg = "The 'Changer' button shows what can be done." & @CRLF
$sMsg &= "It displays 'Normal', but 'Hot' when under the cursor," & @CRLF
$sMsg &= "Pressed when pressed, Disabled when disabled," & @CRLF
$sMsg &= "and when it has focus it switches between Focus and Stylus."
GUICtrlSetData($cLabel, $sMsg)

;multi state image Bitmap
$cButton_1 = GUICtrlCreateButton("Changer", 30, 30, 90, 32)
GUICtrlSetTip(-1, "Multi state bitmap imagelist")
$hImageBtn_1 = _GUIImageList_Create(24, 24, 5, 5)
_GUIImageList_AddIcon($hImageBtn_1, "shell32.dll", 27, True)  ;1 - Normal
_GUIImageList_AddIcon($hImageBtn_1, "shell32.dll", 77, True)  ;2 - Hot (ie cursor over)
_GUIImageList_AddIcon($hImageBtn_1, "shell32.dll", 144, True) ;3 - Pressed
_GUIImageList_AddIcon($hImageBtn_1, "shell32.dll", 109, True) ;4 - Disabled
_GUIImageList_AddIcon($hImageBtn_1, "shell32.dll", 130, True) ;5 - Focus button (switches between 5 & 6 in Vista)
_GUIImageList_AddIcon($hImageBtn_1, "shell32.dll", 154, True) ;6 - Stylus Hot (tablet computers only)
_GUICtrlButton_SetImageList($cButton_1, $hImageBtn_1)

;single state image Bitmap
$cButton_2 = GUICtrlCreateButton("Disable", 30, 70, 90, 32)
GUICtrlSetTip(-1, "Single bitmap imagelist")
$hImageBtn_2 = _GUIImageList_Create(24, 24, 5, 3)
_GUIImageList_AddIcon($hImageBtn_2, "shell32.dll", 131, True)
_GUICtrlButton_SetImageList($cButton_2, $hImageBtn_2)

;single state image Icon
$cButton_3 = GUICtrlCreateButton("Unlock", 30, 110, 90, 40)
GUICtrlSetTip(-1, "Single icon imagelist")
$hImageBtn_3 = _GUIImageList_Create(32, 32, 5, 3)
_GUIImageList_AddIcon($hImageBtn_3, "shell32.dll", 47, True)
_GUICtrlButton_SetImageList($cButton_3, $hImageBtn_3)

;single state image Bitmap with overlay text
$cButton_4 = GUICtrlCreateButton("Help", 30, 160, 90, 90)
GUICtrlSetTip(-1, "Single bitmap imagelist with overlayed text")
GUICtrlSetFont(-1, 14, 800, -1, "Comic Sans MS")
$hImageBtn_4 = _GUIImageList_Create(80, 80, 5, 3)
_GUIImageList_AddIcon($hImageBtn_4, "shell32.dll", 116, True)
_GUICtrlButton_SetImageList($cButton_4, $hImageBtn_4, 4)


While 1
    $sMsg = GUIGetMsg()
    Switch $sMsg

        Case $GUI_EVENT_CLOSE
        Case $cButton_2
            GUICtrlSetState($cButton_1, $GUI_DISABLE)
        Case $cButton_3
            GUICtrlSetState($cButton_1, $GUI_ENABLE)

The icon values are correct for Win7 - you may get some funny icons if you use another OS. And you can always use your own images by using _GUIImageList_AddBitmap and setting the path to the image.


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:


ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...