Jump to content

Recommended Posts

Posted

Hi,

is it possible to use icons larger than 32x32 pixel with buttons created with GUICtrlCreateButton()?

I'm looking for using icons NOT bitmaps...

Greets,

-supersonic.

Posted

Did you look in the "user defined functions" in the help file?

#Include <GuiButton.au3>
_GUICtrlButton_SetImage($hWnd, $sImageFile[,  $nIconId = -1[, $fLarge = False]])
Posted

Yes I did. When using "False" for $fLarge the icon is resized to 16x16.

When using "True" the icon will be 32x32.

Did you look in the "user defined functions" in the help file?

#Include <GuiButton.au3>
_GUICtrlButton_SetImage($hWnd, $sImageFile[,  $nIconId = -1[, $fLarge = False]])
Posted

I think there may be a problem in the call to _GUICtrlButton_SetImage when you specify the icon id to extract. In that function there is a call to _WinAPI_ExtractIconEx which always returns an error on an *.ico file.

Posted

Replace _WinAPI_ExtractIconEx() at _WinAPI_PrivateExtractIcon() and it works.

Func _WinAPI_PrivateExtractIcon($sIcon, $iIndex, $iWidth, $iHeight)

    Local $hIcon, $tIcon = DllStructCreate('hwnd'), $tID = DllStructCreate('hwnd')
    Local $Ret = DllCall('user32.dll', 'int', 'PrivateExtractIcons', 'str', $sIcon, 'int', $iIndex, 'int', $iWidth, 'int', $iHeight, 'ptr', DllStructGetPtr($tIcon), 'ptr', DllStructGetPtr($tID), 'int', 1, 'int', 0)

    If (@error) Or ($Ret[0] = 0) Then
        Return SetError(1, 0, 0)
    EndIf

    $hIcon = DllStructGetData($tIcon, 1)

    If ($hIcon = Ptr(0)) Or (Not IsPtr($hIcon)) Then
        Return SetError(1, 0, 0)
    EndIf
    Return $hIcon
EndFunc   ;==>_WinAPI_PrivateExtractIcon
Posted

Thanks for the reply. :-)

Please, can you give me an example how to implement this function?

Replace _WinAPI_ExtractIconEx() at _WinAPI_PrivateExtractIcon() and it works.

Func _WinAPI_PrivateExtractIcon($sIcon, $iIndex, $iWidth, $iHeight)

    Local $hIcon, $tIcon = DllStructCreate('hwnd'), $tID = DllStructCreate('hwnd')
    Local $Ret = DllCall('user32.dll', 'int', 'PrivateExtractIcons', 'str', $sIcon, 'int', $iIndex, 'int', $iWidth, 'int', $iHeight, 'ptr', DllStructGetPtr($tIcon), 'ptr', DllStructGetPtr($tID), 'int', 1, 'int', 0)

    If (@error) Or ($Ret[0] = 0) Then
        Return SetError(1, 0, 0)
    EndIf

    $hIcon = DllStructGetData($tIcon, 1)

    If ($hIcon = Ptr(0)) Or (Not IsPtr($hIcon)) Then
        Return SetError(1, 0, 0)
    EndIf
    Return $hIcon
EndFunc   ;==>_WinAPI_PrivateExtractIcon
Posted

Try this. (I have not tried it)

#Include <GUIConstantsEx.au3>
#Include <GuiButton.au3>
#Include <WindowsConstants.au3>

GUICreate("Buttons", 300, 300)
GUISetState()

$btn = GUICtrlCreateButton("Button1", 10, 10, 64, 64, $BS_ICON)
_GUICtrlButton_SetIcon($btn, @DesktopDir & "\106.ico", 0, 48, 48)

While 1
    $Msg = GUIGetMsg()
    If $Msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd

Func _GUICtrlButton_SetIcon($hWnd, $sIcon, $iIndex, $iWidth, $iHeight)
    If Not IsHWnd($hWnd) Then
        $hWnd = GUICtrlGetHandle($hWnd)
        If $hWnd = 0 Then
            Return False
        EndIf
    EndIf
    Local $hIcon = _WinAPI_PrivateExtractIcon($sIcon, $iIndex, $iWidth, $iHeight)
    If @error Then
        Return False
    EndIf
    Local $hPrev = _SendMessage($hWnd, 0xF7, 1, $hIcon)
    If $hPrev Then
        If Not _WinAPI_DeleteObject($hPrev) Then
            _WinAPI_DestroyIcon($hPrev)
        EndIf
    EndIf
    _WinAPI_UpdateWindow($hWnd)
    Return True
EndFunc   ;==>_GUICtrlButton_SetIcon

Func _WinAPI_PrivateExtractIcon($sIcon, $iIndex, $iWidth, $iHeight)
    Local $hIcon, $tIcon = DllStructCreate('hwnd'), $tID = DllStructCreate('hwnd')
    Local $Ret = DllCall('user32.dll', 'int', 'PrivateExtractIcons', 'str', $sIcon, 'int', $iIndex, 'int', $iWidth, 'int', $iHeight, 'ptr', DllStructGetPtr($tIcon), 'ptr', DllStructGetPtr($tID), 'int', 1, 'int', 0)
    If (@error) Or ($Ret[0] = 0) Then
        Return SetError(1, 0, 0)
    EndIf
    $hIcon = DllStructGetData($tIcon, 1)
    If ($hIcon = Ptr(0)) Or (Not IsPtr($hIcon)) Then
        Return SetError(1, 0, 0)
    EndIf
    Return $hIcon
EndFunc   ;==>_WinAPI_PrivateExtractIcon
Posted

It work's! :-) Thank you soo much!

Try this. (I have not tried it)

#Include <GUIConstantsEx.au3>
#Include <GuiButton.au3>
#Include <WindowsConstants.au3>

GUICreate("Buttons", 300, 300)
GUISetState()

$btn = GUICtrlCreateButton("Button1", 10, 10, 64, 64, $BS_ICON)
_GUICtrlButton_SetIcon($btn, @DesktopDir & "\106.ico", 0, 48, 48)

While 1
    $Msg = GUIGetMsg()
    If $Msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd

Func _GUICtrlButton_SetIcon($hWnd, $sIcon, $iIndex, $iWidth, $iHeight)
    If Not IsHWnd($hWnd) Then
        $hWnd = GUICtrlGetHandle($hWnd)
        If $hWnd = 0 Then
            Return False
        EndIf
    EndIf
    Local $hIcon = _WinAPI_PrivateExtractIcon($sIcon, $iIndex, $iWidth, $iHeight)
    If @error Then
        Return False
    EndIf
    Local $hPrev = _SendMessage($hWnd, 0xF7, 1, $hIcon)
    If $hPrev Then
        If Not _WinAPI_DeleteObject($hPrev) Then
            _WinAPI_DestroyIcon($hPrev)
        EndIf
    EndIf
    _WinAPI_UpdateWindow($hWnd)
    Return True
EndFunc   ;==>_GUICtrlButton_SetIcon

Func _WinAPI_PrivateExtractIcon($sIcon, $iIndex, $iWidth, $iHeight)
    Local $hIcon, $tIcon = DllStructCreate('hwnd'), $tID = DllStructCreate('hwnd')
    Local $Ret = DllCall('user32.dll', 'int', 'PrivateExtractIcons', 'str', $sIcon, 'int', $iIndex, 'int', $iWidth, 'int', $iHeight, 'ptr', DllStructGetPtr($tIcon), 'ptr', DllStructGetPtr($tID), 'int', 1, 'int', 0)
    If (@error) Or ($Ret[0] = 0) Then
        Return SetError(1, 0, 0)
    EndIf
    $hIcon = DllStructGetData($tIcon, 1)
    If ($hIcon = Ptr(0)) Or (Not IsPtr($hIcon)) Then
        Return SetError(1, 0, 0)
    EndIf
    Return $hIcon
EndFunc   ;==>_WinAPI_PrivateExtractIcon

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
  • Recently Browsing   0 members

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