Modify

Opened 13 years ago

Closed 11 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

Forum thread: http://www.autoitscript.com/forum/topic/136001-problem-with-icon-position-when-using-guictrlsetimage/page__view__findpost__p__949740

Attachments (0)

Change History (3)

comment:1 Changed 13 years ago by Jpm

  • Summary changed from GUICtrlUpdateImage changes icon position on resizable window to GUICtrlSetImage changes icon position on resizable window

comment:2 Changed 11 years ago by Zedna

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

comment:3 Changed 11 years ago by Jon

  • Milestone set to 3.3.9.13
  • Owner set to Jon
  • Resolution set to Fixed
  • Status changed from new to closed

Fixed by revision [8175] in version: 3.3.9.13

Guidelines for posting comments:

  • You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
  • In-depth discussions should take place on the forum.

For more information see the full version of the ticket guidelines here.

Add Comment

Modify Ticket

Action
as closed The owner will remain Jon.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.