Jump to content

Recommended Posts

Posted

When I resize my gui, and update my icon with GuiCtrlSetImage(), the icon goes back to the original location until I resize my gui again. Anyone else have this problem

Example code:

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 185, 139, 192, 148, BitOR($GUI_SS_DEFAULT_GUI,$WS_SIZEBOX,$WS_THICKFRAME))
$Icon1 = GUICtrlCreateIcon(@ScriptDir & "\default.ico", -1, 16, 88, 32, 32)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT+$GUI_DOCKBOTTOM+$GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
AdlibRegister("updateicon")
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
  Case $GUI_EVENT_CLOSE
   Exit
EndSwitch
WEnd
Func updateicon()
GUICtrlSetImage($Icon1, @ScriptDir & "\default.ico")
EndFunc

default.ico

Posted

Actually _SetIcon() from Icons.au3 doesn't work like GuiCtrlSetImage() because it doesn't return 0 if I try to set an icon from a .exe file with none in, and my program depends on it :)

  • 1 year later...
Posted (edited)

It's really bug in GUICtrlSetImage()

Note: Original bug is better visible when you resize window.

Here is simple workaround for this long lasting not fixed bug:

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

$Form1 = GUICreate("Form1", 185, 139, 192, 148, BitOR($GUI_SS_DEFAULT_GUI, $WS_SIZEBOX, $WS_THICKFRAME))
$Icon1 = GUICtrlCreateIcon(@ScriptDir & "\default.ico", -1, 16, 88, 32, 32)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKBOTTOM + $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT)
GUISetState(@SW_SHOW)

AdlibRegister("updateicon")

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func updateicon()
;~  GUICtrlSetImage($Icon1, @ScriptDir & "\default.ico") ; bug
    GUICtrlSetIcon($Icon1, @ScriptDir & "\default.ico", 0) ; workaround
EndFunc

Func GUICtrlSetIcon($id_ctrl, $filename, $icon_index)
    $hCtrl = GUICtrlGetHandle($id_ctrl)
    $hIcon = _WinAPI_ShellExtractIcon($filename, $icon_index, 32, 32)
    _WinAPI_DestroyIcon(_SendMessage($hCtrl, 0x0172, 1, $hIcon)) ; $STM_SETIMAGE, $IMAGE_ICON
EndFunc

Func _WinAPI_ShellExtractIcon($sIcon, $iIndex, $iWidth, $iHeight)
    Local $Ret = DllCall('shell32.dll', 'int', 'SHExtractIconsW', 'wstr', $sIcon, 'int', $iIndex, 'int', $iWidth, 'int', $iHeight, 'ptr*', 0, 'ptr*', 0, 'int', 1, 'int', 0)
    If (@error) Or (Not $Ret[0]) Or (Not $Ret[5]) Then Return SetError(1, 0, 0)
    Return $Ret[5]
EndFunc

This workaround posted also in Trac (ticket #2075).

http://www.autoitscript.com/trac/autoit/ticket/2075

Edited by Zedna

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