ChrisN Posted December 26, 2011 Posted December 26, 2011 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") EndFuncdefault.ico
ChrisN Posted December 27, 2011 Author Posted December 27, 2011 Yashied's Icons.au3 UDF works fine. Is this an AutoIt bug? (AutoIt 3.3.8.0)
ChrisN Posted December 27, 2011 Author Posted December 27, 2011 GUICtrlSetGraphic works only on Graphic controls, not Icon controls
ChrisN Posted December 27, 2011 Author Posted December 27, 2011 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
Robjong Posted December 27, 2011 Posted December 27, 2011 Hi, I have the same behavior you described, AutoIt 3.3.6.1 (Release) 3.3.7.23 (Beta), not sure why...
ChrisN Posted December 27, 2011 Author Posted December 27, 2011 Found another thread describing the same problem.
Zedna Posted May 27, 2013 Posted May 27, 2013 (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 May 27, 2013 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now