Jump to content

Icons/Images in buttons?


Recommended Posts

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

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

Link to comment
Share on other sites

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

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • 1 year later...

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?

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

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

Link to comment
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?
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...