Sign in to follow this  
Followers 0
motionman95

Icons/Images in buttons?

18 posts in this topic

Is it possible to do this (put images in buttons?):

Posted Image

I've searched, but I haven't found anything.

Thanks in advance!


Share this post


Link to post
Share on other sites



Here is an example: http://www.autoitscript.com/forum/index.ph...st&p=572734

You can add bitmaps and Icons to the imagelist.


*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites

Is there a Vista compatible solution?


Share this post


Link to post
Share on other sites

This should work with Vista, too i think. Just the images used in the example aren't there.


*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites

Thanks, ProgAndy. Is there a way to make the background of the bitmap transparent?


Share this post


Link to post
Share on other sites

Bump ^_^


Share this post


Link to post
Share on other sites

@motionman95, don't bump unless there is no reply for 24 hours.

The only way I know of to have transparencies would be to use gdi+ to use a png


Giggity

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

You can add the Bitmap masked ^_^

_GUIImageList_AddBitmap if you have the mask as bitmap or

_GUIImageList_AddMasked if you want to specify the transcolor

-> I wrote an extra func, so you can specify the path:

; #FUNCTION# ====================================================================================================================
; Name...........: _GUIImageList_AddBitmapMasked
; Description ...: Adds a bitmap to an image list, generating a mask from the specified color
; Syntax.........: _GUIImageList_AddBitmapMasked($hWnd, $sImage, $iMask)
; Parameters ....: $hWnd        - Handle to the control
;                  $sImage      - Path to the bitmap that contains the image
;                  $iMask       - Color used to generate the mask. Each pixel of this color in the specified bitmap is changed to
;                  +black, and the corresponding bit in the mask is set to 1.
; Return values .: Success      - The index of the image
;                  Failrue      - -1
; Author ........: Paul Campbell (PaulIA), Prog@ndy
; Modified.......: 
; Remarks .......:
; Related .......: _GUIImageList_AddMasked
; Link ..........;
; Example .......; Yes
; ===============================================================================================================================
Func _GUIImageList_AddBitmapMasked($hWnd, $sImage, $iMask = 0)
    Local $hImage, $hMask = 0, $aSize, $iResult

    $aSize = _GUIImageList_GetIconSize($hWnd)
    $hImage = _WinAPI_LoadImage(0, $sImage, $__IMAGELISTCONSTANT_IMAGE_BITMAP, $aSize[0], $aSize[1], $__IMAGELISTCONSTANT_LR_LOADFROMFILE)
    If $hImage = 0 Then Return SetError(_WinAPI_GetLastError(), 1, -1)

    $iResult = _GUIImageList_AddMasked($hWnd, $hImage, $iMask)
    _WinAPI_DeleteObject($hImage)

    Return $iResult
EndFunc   ;==>_GUIImageList_AddBitmapMasked

With this function, you can specif the color wich will become transparent. (only if you add Option 1 to your imagelist, e.g. _GUIImageList_Create(24, 24,5, 1))

//Edit: i think, the $iMask should be COLORREF (BGR not RGB)

Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites

@motionman95, don't bump unless there is no reply for 24 hours.

...

Only 21 h 14 min passed. I don't know, that's close. ...Ahhh, shot him!

@ProgAndy, yes BGR.


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

$Remove_Button = GUICtrlCreateButton("Delete Item", 8, 192, 73, 25)
$hImagebtn3 = _GUIImageList_Create(16, 16, 5, 1)
_GUIImageList_AddBitmapMasked($Remove_Button,  "C:\Documents and Settings\Owner\My Documents\Autoit Applications\Forms\RockboxFNTConverter\button_icons\delete.bmp", 0x000000)
_GUICtrlButton_SetImageList($Remove_Button, $hImagebtn3)

I tried this...but all I got was blank patch inside my button. ^_^ What am I doing wrong?


Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Strange, this works for me on XP:

;#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 = @ScriptDir&"\test.bmp"

    Local $btn1
    Local $hImagebtn1
    Local $msg, $hGUI

    ;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.

    $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_AddBitmapMasked($hImagebtn1, $sBMPNormal,0xFFFFFF);1 - Normal
    _GUICtrlButton_SetImageList($btn1, $hImagebtn1)


    GUISetState()

    While 1
        $msg = GUIGetMsg()
        Switch $msg
            Case $GUI_EVENT_CLOSE
                Exit
        EndSwitch
    WEnd
EndFunc   ;==>_Main

; #FUNCTION# ====================================================================================================================
; Name...........: _GUIImageList_AddBitmapMasked
; Description ...: Adds a bitmap to an image list, generating a mask from the specified color
; Syntax.........: _GUIImageList_AddBitmapMasked($hWnd, $sImage, $iMask)
; Parameters ....: $hWnd        - Handle to the control
;                  $sImage      - Path to the bitmap that contains the image
;                  $iMask       - Color used to generate the mask. Each pixel of this color in the specified bitmap is changed to
;                  +black, and the corresponding bit in the mask is set to 1.
; Return values .: Success      - The index of the image
;                  Failrue      - -1
; Author ........: Paul Campbell (PaulIA), Prog@ndy
; Modified.......:
; Remarks .......:
; Related .......: _GUIImageList_AddMasked
; Link ..........;
; Example .......; Yes
; ===============================================================================================================================
Func _GUIImageList_AddBitmapMasked($hWnd, $sImage, $iMask = 0)
    Local $hImage, $hMask = 0, $aSize, $iResult

    $aSize = _GUIImageList_GetIconSize($hWnd)
    $hImage = _WinAPI_LoadImage(0, $sImage, $__IMAGELISTCONSTANT_IMAGE_BITMAP, $aSize[0], $aSize[1], $__IMAGELISTCONSTANT_LR_LOADFROMFILE)
    If $hImage = 0 Then Return SetError(_WinAPI_GetLastError(), 1, -1)

    $iResult = _GUIImageList_AddMasked($hWnd, $hImage, $iMask)
    _WinAPI_DeleteObject($hImage)

    Return $iResult
EndFunc   ;==>_GUIImageList_AddBitmapMasked

//Edit: Do you have 64bit? Maybe there are some structs not created properly for 64bit OS ...

Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites

Old thread, I know - but if someone could help me out again...I'd be really grateful. I've been searching the forums, but all I've found are ways to use PNGs as buttons - but not inside a button. ProgAndy's function has been working great, but now I need to use a transparent icon inside my button, and BMP files aren't up to par. Is there anyway to add PNG support?


Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

Old thread, I know - but if someone could help me out again...I'd be really grateful. I've been searching the forums, but all I've found are ways to use PNGs as buttons - but not inside a button. ProgAndy's function has been working great, but now I need to use a transparent icon inside my button, and BMP files aren't up to par. Is there anyway to add PNG support?

not to oversimplify, but if you can use a png as a button, and you can set the size of the other button, and make both buttons do the same thing, how would your user know that the png is not just an image on the button?

***edit***

i mean of course if you positioned the png button on top of the button that it's supposed to look like it's a graphic on... just in case that wasn't clear...

Edited by cameronsdad

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

not to oversimplify, but if you can use a png as a button, and you can set the size of the other button, and make both buttons do the same thing, how would your user know that the png is not just an image on the button?

***edit***

i mean of course if you positioned the png button on top of the button that it's supposed to look like it's a graphic on... just in case that wasn't clear...

...

I think my brain just exploded.


Share this post


Link to post
Share on other sites

...

I think my brain just exploded.

you're welcome i think?

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

not to oversimplify, but if you can use a png as a button, and you can set the size of the other button, and make both buttons do the same thing, how would your user know that the png is not just an image on the button?

***edit***

i mean of course if you positioned the png button on top of the button that it's supposed to look like it's a graphic on... just in case that wasn't clear...

So you're saying I could just position a PNG over a button control?

Share this post


Link to post
Share on other sites

Never mind, I solved the PNG problem, but with ProgAndy's code is there any way to center the image inside the button?


Share this post


Link to post
Share on other sites

Gah, I'm an idiot. I went through about 50 functions before I realized it was in a function I was already using. >.<


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
Sign in to follow this  
Followers 0