Jump to content

Button with BMP and Text


Datus
 Share

Recommended Posts

Been using Autoit for some time and used pictures as buttons, buttons as buttons with text but id like to have a button with a background picture with text.

Can someone confirm this cant be done still or example small code.

$LoadIsoPickedNo = GUICtrlCreateButton("Pick another", $AdjustW - (180 * $MultiW), $AdjustH - 35, (95 * $MultiW), 27, $BS_BITMAP)
GUICtrlSetImage($LoadIsoPickedNo, @WorkingDir & "\button.bmp")

with the above i dont see the text Pick another

spent several hours looking in help and forum which both is very good source.

i think the only sugestion ive seen is to create a bitmap with the text on it.

We live as we dream alone!

Link to comment
Share on other sites

I made this...

; Icon on Button - (made easy)
; Author - Valuater

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

$mywin = GUICreate("my gui")
$btn1 = IconButton("Help", 30, 30, 70, 32, 23)
GUISetState()

While 1
    $msg = GUIGetMsg()
    If $msg = $btn1 Then MsgBox(0,0,"You pressed the Icon Button  ", 2)
    If $msg = $GUI_EVENT_CLOSE Then Exit
WEnd

Func IconButton($BItext, $BIleft, $BItop, $BIwidth, $BIheight, $BIconNum, $BIDLL = "shell32.dll")
    GUICtrlCreateIcon($BIDLL, $BIconNum, $BIleft + 5, $BItop + (($BIheight - 16) / 2), 16, 16)
    GUICtrlSetState( -1, $GUI_DISABLE)
    $XS_btnx = GUICtrlCreateButton($BItext, $BIleft, $BItop, $BIwidth, $BIheight, $WS_CLIPSIBLINGS)
    Return $XS_btnx
EndFunc

Maybe it can help you... there are more "helpers" here

http://www.autoitscript.com/forum/index.ph...st&p=133769

8)

NEWHeader1.png

Link to comment
Share on other sites

Valuater ive seen that and yes it was handy but its for icons.

hmm

You saying save the bmp as an icon?

If so will the text go over the top of the icon?

@Datus

Text will go over the bitmap with this example, but XP is the minimum OS.

;#AutoIt3Wrapper_au3check_parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <GUIConstantsEx.au3>
#include <GuiButton.au3>
#include <GuiImageList.au3>

Opt("MustDeclareVars", 1)

_Main()

Func _Main()
    Local $sBMPNormal = @WindowsDir & "\pchealth\helpctr\System\images\24x24\arrow_green_normal.bmp"
    Local $sBMPHot = @WindowsDir & "\pchealth\helpctr\System\images\24x24\arrow_green_mouseover.bmp"
    Local $sBMPPress = @WindowsDir & "\pchealth\helpctr\System\images\24x24\arrow_green_mousedown.bmp"
    Local $sBMPImage = @WindowsDir & "\pchealth\helpctr\System\blurbs\watermark_300x.bmp"
    Local $btn1, $btn2, $btn3, $btn4, $msg
    Local $hImagebtn1, $hImagebtn2, $hImagebtn3 ,$hImagebtn4

    ;Caveat: Minimum Operating Systems: Windows XP.

    ;Image list with multiple images will only show the images
    ;other than the 1st image when Themes are used.

    Local $hGUI = GUICreate("Button Imagelists - Minimum OS: Windows XP",400,300)
    
    GUICtrlCreatePic(@WindowsDir & "\Web\Wallpaper\Windows XP.jpg", 0, 0, 400, 300)
    GUICtrlSetState(-1, $GUI_DISABLE)
    
    ;multi state image Bitmap
    $btn1 = GUICtrlCreateButton("This Way", 30, 30, 90, 32)
    GUICtrlSetTip(-1, "Multi state bitmap imagelist")
    $hImagebtn1 = _GUIImageList_Create(24, 24, 5, 5)
    _GUIImageList_AddBitmap($hImagebtn1, $sBMPNormal);1 - Normal
    _GUIImageList_AddBitmap($hImagebtn1, $sBMPHot)   ;2 - Hot
    _GUIImageList_AddBitmap($hImagebtn1, $sBMPPress) ;3 - Pressed
    _GUIImageList_AddBitmap($hImagebtn1, $sBMPPress);4 - Disabled
    _GUIImageList_AddBitmap($hImagebtn1, $sBMPNormal);5 - Defaulted
    _GUIImageList_AddBitmap($hImagebtn1, $sBMPNormal);6 - Stylus Hot (tablet computers only)
    _GUICtrlButton_SetImageList($btn1, $hImagebtn1)

    ;single state image Bitmap
    $btn2 = GUICtrlCreateButton("This Way", 30, 70, 90, 32)
    GUICtrlSetTip(-1, "Single bitmap imagelist")
    $hImagebtn2 = _GUIImageList_Create(24, 24, 5, 3)
    _GUIImageList_AddBitmap($hImagebtn2, $sBMPNormal);1 - Normal
    _GUICtrlButton_SetImageList($btn2, $hImagebtn2)

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

    ;single state image Bitmap with overlayed text
    $btn4 = GUICtrlCreateButton("Help", 30, 160, 90, 90)
    GUICtrlSetTip(-1, "Single bitmap imagelist with overlayed text")
    GUICtrlSetFont(-1, 14, 800, -1, "Comic Sans MS") 
    $hImagebtn4 = _GUIImageList_Create(80, 80, 5, 3)
    _GUIImageList_AddBitmap($hImagebtn4, $sBMPImage)
    _GUICtrlButton_SetImageList($btn4, $hImagebtn4, 4)

    GUISetState()

    While 1
        $msg = GUIGetMsg()
        Switch $msg
            Case $GUI_EVENT_CLOSE
                Exit
            Case $btn1
            Case $btn2
                GUICtrlSetState($btn1, $GUI_DISABLE)
            Case $btn3
                GUICtrlSetState($btn1, $GUI_ENABLE)
            Case $btn4
        EndSwitch
    WEnd
EndFunc   ;==>_Main
Edited by rover

I see fascists...

Link to comment
Share on other sites

Brilliant,

Got it working with some bitmaps i had lying arround.

Cant see why i didnt see the _GUICtrlButton_SetImageList etc before.

Fairly easy concept.

Thanks again rover and im sure this thread will help many others.

We live as we dream alone!

Link to comment
Share on other sites

Brilliant,

Got it working with some bitmaps i had lying arround.

Cant see why i didnt see the _GUICtrlButton_SetImageList etc before.

Fairly easy concept.

Thanks again rover and im sure this thread will help many others.

@Datus

Thanks, glad to help

@Valuater

Thanks, It's just my own 'dog and pony show' version of the ImageList helpfile examples ;)

I see fascists...

Link to comment
Share on other sites

  • 6 months later...

so i was just about to add a background .jpg to one of my buttons , dident think it would be more than one command looked up the GUICtrlSetImage and put it in. so iv made a button & set the image simple but nooo it dont work ? but it says quite clearly in the help

GUICtrlSetImage

Sets the bitmap or icon image to use for a control.

&

If used on a Button control the image will be displayed on the button.

but having found this thread im wondering how this command was used before all the _UDF's were added cos this command has been there for a long time ? ?

and why is it that you can use it to add a background to some controls but not others ie buttons ?

Just wondering cos your responses are lot of lines of script & messing about changing .jpg's to Icons just to put a background .jpg to a button.

Cheers all.

p.s also noticed a problem with this solution my post

Edited by JackDinn

Thx all,Jack Dinn.

 

JD's Auto Internet Speed Tester

JD's Clip Catch (With Screen Shot Helper)

Projects :- AutoIt - My projects

My software never has bugs. It just develops random features. :-D

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...