Jump to content

Problems with Autoit using wrong resolution for embeded icons


Homes32
 Share

Recommended Posts

Greetings.

I am having problems with Autoit using the always using 32x32 icon size for my buttons regardless of the higher resolution icons when using the #AutoIt3Wrapper_Res_Icon_Add= directive along with GUICtrlSetImage.

According to the Help documentation

If used on a Button control the image will be displayed on the button. Images can also be set for Checkbox controls as long as the $BS_PUSHLIKE style is used. In both case the $BS_ICON or $BS_BITMAP styles are needed to select the type of the picture used. The first icon resolution will be used in a multi icon resolution file. I.E. if a 128x128 is the first resolution and the control is 64x64 the image will be truncated

this is not the case for me when using embedded icons. regardless of the 1st resolution in a milti icon file, even if the icon is 64x64 and not a multi-resolution file it always sets the icon size to 32x32.

to be clear. there is no problems with the icon itself. I have used several different icons from different sources, as well as standalone single resolution files. Also when looking at the compiled .exe with a resource editor all icon resolutions show up fine and are in the correct order (ie. 64x64, 48x48, 32x32, etc.)

on another note: linking to the icon file directly (not embedding the icon) work's fine and Autoit behaves correctly and picks the highest resolution image. I am only having problems with icons embedded in the compiled exe.

I have tested this with Autoit Stable 3.3.0.0 and the last couple of beta versions with the same results.

I have attached the following code and and an Icon for those wishing to investigate this issue.

thank you.

-Homes32

#AutoIt3Wrapper_Res_Icon_Add=Shutdown.ico

; Includes
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

; GUI
$Form1_1 = GUICreate("Shutdown", 316, 203, -1, -1, BitOR($WS_POPUP,$DS_SETFOREGROUND), BitOR($WS_EX_TOPMOST,$WS_EX_WINDOWEDGE))

; Shutdown Button
$BTN_Shutdown = GUICtrlCreateButton("BTN_Shutdown", 120, 56, 75, 75, $BS_ICON)
GUICtrlSetImage(-1, @ScriptFullPath, -5)
; comment out the above line and
; uncomment the following line to use direct link instead of embedded icon.
;GUICtrlSetImage(-1, "Shutdown.ico", -1)

GUISetState(@SW_SHOW)

; Main Loop
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg

        Case $GUI_EVENT_CLOSE
            Exit

        Case $BTN_Shutdown
            Exit

    EndSwitch
WEnd
Link to comment
Share on other sites

Seems like there is a description ambiguity. If it doesn't work for you, you can specify the preferred size using _WinAPI_LoadImage:

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_Res_Icon_Add=Shutdown.ico
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

; Includes
#include <ButtonConstants.au3>
#include <Constants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>

; GUI
$Form1_1 = GUICreate("Shutdown", 316, 203, -1, -1, BitOR($WS_POPUP,$DS_SETFOREGROUND), BitOR($WS_EX_TOPMOST,$WS_EX_WINDOWEDGE))

; Shutdown Button
$BTN_Shutdown = GUICtrlCreateButton("BTN_Shutdown", 120, 56, 75, 75, $BS_ICON)
;~ GUICtrlSetImage(-1, @ScriptFullPath, -5, 3)
; comment out the above line and
; uncomment the following line to use direct link instead of embedded icon.
;GUICtrlSetImage(-1, "Shutdown.ico", -1)

$hIcon = _WinAPI_LoadImage(_WinAPI_GetModuleHandle(0), 201, $IMAGE_ICON, 0, 0, 0)

GUICtrlSendMsg(-1, 247, 1, $hIcon) ; BM_SETIMAGE = 247, 1 = IMAGE_ICON
GUISetState()

; Main Loop
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg

        Case $GUI_EVENT_CLOSE
            ExitLoop

        Case $BTN_Shutdown
            ExitLoop

    EndSwitch
WEnd

If $hIcon Then _WinAPI_DestroyIcon($hIcon)

If you specify $LR_DEFAULTSIZE the system loads the icon sized as the default system icons size.

Edited by Authenticity
Link to comment
Share on other sites

Seems like there is a description ambiguity. If it doesn't work for you, you can specify the preferred size using _WinAPI_LoadImage:

*Code Removed to make reading easier*

If you specify $LR_DEFAULTSIZE the system loads the icon sized as the default system icons size.

ahh. I see. as far as I can tell I wasn't defining $LR_DEFAULTSIZE anywhere and wasn't including <Constants.au3> so is this ambiguity unique to me or is this a common issue/bug?

the _WinAPI_LoadImage method is working very well for me. ;) Thank you very much for taking the time to help me figure this out.

-Homes32

Link to comment
Share on other sites

one more question:

when using the following code to try to set an embedded icon to an Icon control the icon will not show up. Am I not allowed to use GUICtrlSendMsg() with STM_SETIMAGE constant (172)? or do I have something wrong with my code?

; Directives
#NoTrayIcon
#AutoIt3Wrapper_Res_Icon_Add=Resources\Ico\Warning.ico


; Includes
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Constants.au3> ; defines $IMAGE_ICON
#include <WinAPI.au3>

;**********************************************************************
; Resources Loading
;**********************************************************************
$hWarningIcon = _WinAPI_LoadImage(_WinAPI_GetModuleHandle(0), 201, $IMAGE_ICON, 48, 48, 0)


;**********************************************************************
; GUI Warning
;**********************************************************************
$FRM_Warning = GUICreate("Starting Program..", 368, 128, -1, -1, BitOR($WS_CAPTION,$WS_POPUP,$WS_BORDER,$WS_CLIPSIBLINGS,$DS_SETFOREGROUND), BitOR($WS_EX_TOPMOST,$WS_EX_WINDOWEDGE))
GUISetBkColor(0xFFFFFF)
$WarningIcon = GUICtrlCreateIcon("", -1, 8, 16, 48, 48)
GUICtrlSendMsg($WarningIcon, 172, 1, $hWarningIcon) ; STM_SETIMAGE = 172 1 = IMAGE_ICON
;GUICtrlSetImage(-1, @ScriptFullPath, -5)
$LBL_Warning = GUICtrlCreateLabel("Warning!", 72, 16, 63, 20)
GUICtrlSetFont(-1, 10, 800, 0, "Tahoma")
$Label1 = GUICtrlCreateLabel("Do not run any other programs while running this program.", 72, 40, 284, 17)
$Label2 = GUICtrlCreateLabel("Failure to obey this warning could cause unwanted", 72, 56, 243, 17)
$Label3 = GUICtrlCreateLabel("problems with your envoronment.", 72, 72, 176, 17)
$BTN_Ok = GUICtrlCreateButton("Ok", 280, 96, 75, 25)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            If $hWarningIcon Then _WinAPI_DestroyIcon($hWarningIcon)
            Exit
        Case $BTN_Ok
            GUIDelete($FRM_Warning)
            If $hWarningIcon Then _WinAPI_DestroyIcon($hWarningIcon)
            Exit ; for debug only
    EndSwitch
WEnd

thank you in advance.

-homes32

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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