Modify ↓
Opened 14 years ago
Closed 13 years ago
#2075 closed Bug (Fixed)
GUICtrlSetImage changes icon position on resizable window
| Reported by: | ChrisN | Owned by: | Jon |
|---|---|---|---|
| Milestone: | 3.3.9.13 | Component: | AutoIt |
| Version: | 3.3.8.0 | Severity: | None |
| Keywords: | icon | Cc: |
Description
When a window is resized & the icon control is moved from its original position, updating it with GUICtrlUpdateImage moves it to its original position again.
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.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")
EndFunc
Attachments (0)
Change History (3)
comment:1 by , 14 years ago
| Summary: | GUICtrlUpdateImage changes icon position on resizable window → GUICtrlSetImage changes icon position on resizable window |
|---|
comment:2 by , 13 years ago
comment:3 by , 13 years ago
| Milestone: | → 3.3.9.13 |
|---|---|
| Owner: | set to |
| Resolution: | → Fixed |
| Status: | new → closed |
Fixed by revision [8175] in version: 3.3.9.13
Note:
See TracTickets
for help on using tickets.

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:
posted also in original topic on the forum
#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