Jump to content

GUICtrlCreateIcon Size


regi
 Share

Recommended Posts

Hi,

I'm including an icon in in my build, but when showing it in a gui instead of being 48 x 48, it defaults to 32 x 32, is this a bug? Or am I missing something here?

Demo script and attached icon file below...

#Region
#AutoIt3Wrapper_Res_Icon_Add=I:\numbers.ico
#EndRegion
#include <GUIConstants.au3>
GUICreate(" My GUI Icons")
$icon = GUICtrlCreateIcon (@ScriptFullPath, -5, 20, 20, 48, 48)
GUISetState()
While 1
    $msg = GUIGetMsg()

    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
Wend

This however, works fine:

#include <GUIConstants.au3>
GUICreate(" My GUI Icons")
$icon = GUICtrlCreateIcon ("numbers.ico",-1, 20, 20, 48, 48)
GUISetState()
While 1
    $msg = GUIGetMsg()
    
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
Wend

Source: http://www.autoitscript.com/forum/index.php?showtopic=14606

numbers.ico

Link to comment
Share on other sites

I believe that the next beta versiuon will support larger icons. Until then 32x32 is as large as you can use.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

  • 1 month later...

I am having the same problem with the newest version of Au3. When using the included icon I only get 32x32 however if the icon is out of the exe then it gets 48x48 fine. Have we had a regression in the latest version?

Included Icon

Posted Image

External Icon

Posted Image

Edited by P5ych0Gigabyte
HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code.
Link to comment
Share on other sites

I am having the same problem with the newest version of Au3. When using the included icon I only get 32x32 however if the icon is out of the exe then it gets 48x48 fine. Have we had a regression in the latest version?

Included Icon

Posted Image

External Icon

Posted Image

Regression would imply some sort of previously done progression.
Link to comment
Share on other sites

Regression would imply some sort of previously done progression.

After looking at the exe in reshacker I can see that the icons included are 48x48 and did not get scaled down. So I am pretty sure this is a bug. I am going to file a report on trac. Submitted:Trac

Edited by P5ych0Gigabyte
HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code.
Link to comment
Share on other sites

After looking at the exe in reshacker I can see that the icons included are 48x48 and did not get scaled down. So I am pretty sure this is a bug. I am going to file a report on trac. Submitted:Trac

I just said that there has been no regression since there was no progression.

When specifying icon file as icon to use there are two modes that AutoIt works in. First one is (will split in two sub modes):

GUICtrlSetImage($ButtonTest, ".\Icon.ico", 0, 0) ; get small icon (16x16)
GUICtrlSetImage($ButtonTest, ".\Icon.ico", 0, 1) ; get normal icon (32x32)

The other is:

GUICtrlSetImage($ButtonTest, ".\Icon.ico") ; get first icon found in icon file

First mode uses ExtractIconExW to get icons and other LoadImageW.

When doing the same thing but now specifying resource as icon to use, there is only one mode. The first one; ExtractIconExW. Third case would be just repeating second one.

Why is this so I have no idea. Actually I don't know why is ExtractIconExW used at all. Probably some smart reason though. Maybe for simplicity (small/normal).

Edited by trancexx
Link to comment
Share on other sites

Anyways...getting back to the question...Here is a way.

#include <GUIConstantsEx.au3>
#Include <Constants.au3>
#include <GDIPlus.au3>
#include <WinAPI.au3>
    $Gui = GUICreate("",200,200,-1,-1)
    $gradie = GUICtrlCreatePic("", 0, 0,48, 48)
    iconbutton_1(-1, "numbers.ico", -1)

GUISetState()

While 1
sleep(20)
$msg=GUIGetMsg()
if $msg=$GUI_EVENT_CLOSE then Exit
WEnd

Func iconbutton_1($control, $sIcon = "", $iIndex = "", $size=32)
    If Not $sIcon = "" Then
        _GDIPlus_Startup()
        $hwd = GUICtrlGetHandle($control)
        $width = _WinAPI_GetClientWidth($hwd)
        $height = _WinAPI_GetClientHeight($hwd)
        $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hwd)
        $hBitmap1 = _GDIPlus_BitmapCreateFromGraphics($width, $height, $hGraphic)
        $hBitmap1 = _drawicon($hBitmap1, $width, $height, $sIcon, $iIndex,0,0)
        $hImage1 = _GDIPlus_ImageGetGraphicsContext($hBitmap1)
        $hBMP1 = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap1)
        _WinAPI_DeleteObject(GUICtrlSendMsg($control, 0x0172, 0, $hBMP1))
        _GDIPlus_GraphicsDispose($hImage1)
        _WinAPI_DeleteObject($hBMP1)
        _GDIPlus_BitmapDispose($hBitmap1)
        _GDIPlus_GraphicsDispose($hGraphic)
        _GDIPlus_Shutdown()
    EndIf
EndFunc ;==>iconbutton_1

Func _drawicon($bitmap, $width, $height, $ico, $ind,$hpos,$hvpos)
    $hbmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($bitmap)
    $hIcon = _WinAPI_SHExtractIcons($ico, $ind, 48, 48)
    $hDC = _WinAPI_GetDC(0)
    $hBackDC = _WinAPI_CreateCompatibleDC($hDC)
    $hBackSv = _WinAPI_SelectObject($hBackDC, $hbmp)
    If $hIcon <> 0 Then _WinAPI_DrawIconEx($hBackDC,$hpos, $hvpos, $hIcon, 0, 0, 0, 0, $DI_NORMAL)
    $bitmap = _GDIPlus_BitmapCreateFromHBITMAP($hbmp)
    _WinAPI_DeleteObject($hbmp)
    _WinAPI_SelectObject($hBackDC, $hBackSv)
    _WinAPI_DeleteDC($hBackDC)
    _WinAPI_ReleaseDC(0, $hDC)
    _WinAPI_DestroyIcon($hIcon)
    Return $bitmap
    Return
EndFunc ;==>_drawicon

Func _WinAPI_SHExtractIcons($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 ($Ret[0] = 0) Or ($Ret[5] = Ptr(0)) Then
        Return SetError(1, 0, 0)
    EndIf
    Return $Ret[5]
EndFunc ;==>_WinAPI_SHExtractIcons
Link to comment
Share on other sites

Anyways...getting back to the question...Here is a way.

Thanks for the workaround. I'm gonna give that a try and see how it turns out. The thing is its for a gpl project. Are you OK with me using that code?

HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code.
Link to comment
Share on other sites

of course....

So how would I get this to draw on a button. Something like the following.

#include <GUIConstantsEx.au3>
#Include <Constants.au3>
#include <GDIPlus.au3>
#include <WinAPI.au3>

    $Gui = GUICreate("",200,200,-1,-1)
    $gradie = GUICtrlCreateButton("", 0, 0,48, 48)
    iconbutton_1(-1, "go.ico", -1)

GUISetState()

While 1
sleep(20)
$msg=GUIGetMsg()
if $msg=$GUI_EVENT_CLOSE then Exit
WEnd

Func iconbutton_1($control, $sIcon = "", $iIndex = "", $size=32)
    If Not $sIcon = "" Then
        _GDIPlus_Startup()
        $hwd = GUICtrlGetHandle($control)
        $width = _WinAPI_GetClientWidth($hwd)
        $height = _WinAPI_GetClientHeight($hwd)
        $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hwd)
        $hBitmap1 = _GDIPlus_BitmapCreateFromGraphics($width, $height, $hGraphic)
        $hBitmap1 = _drawicon($hBitmap1, $width, $height, $sIcon, $iIndex,0,0)
        $hImage1 = _GDIPlus_ImageGetGraphicsContext($hBitmap1)
        $hBMP1 = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap1)
        _WinAPI_DeleteObject(GUICtrlSendMsg($control, 0x0172, 0, $hBMP1))
        _GDIPlus_GraphicsDispose($hImage1)
        _WinAPI_DeleteObject($hBMP1)
        _GDIPlus_BitmapDispose($hBitmap1)
        _GDIPlus_GraphicsDispose($hGraphic)
        _GDIPlus_Shutdown()
    EndIf
EndFunc ;==>iconbutton_1

Func _drawicon($bitmap, $width, $height, $ico, $ind,$hpos,$hvpos)
    $hbmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($bitmap)
    $hIcon = _WinAPI_SHExtractIcons($ico, $ind, 48, 48)
    $hDC = _WinAPI_GetDC(0)
    $hBackDC = _WinAPI_CreateCompatibleDC($hDC)
    $hBackSv = _WinAPI_SelectObject($hBackDC, $hbmp)
    If $hIcon <> 0 Then _WinAPI_DrawIconEx($hBackDC,$hpos, $hvpos, $hIcon, 0, 0, 0, 0, $DI_NORMAL)
    $bitmap = _GDIPlus_BitmapCreateFromHBITMAP($hbmp)
    _WinAPI_DeleteObject($hbmp)
    _WinAPI_SelectObject($hBackDC, $hBackSv)
    _WinAPI_DeleteDC($hBackDC)
    _WinAPI_ReleaseDC(0, $hDC)
    _WinAPI_DestroyIcon($hIcon)
    Return $bitmap
    Return
EndFunc ;==>_drawicon

Func _WinAPI_SHExtractIcons($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 ($Ret[0] = 0) Or ($Ret[5] = Ptr(0)) Then
        Return SetError(1, 0, 0)
    EndIf
    Return $Ret[5]
EndFunc ;==>_WinAPI_SHExtractIcons
Edited by P5ych0Gigabyte
HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code.
Link to comment
Share on other sites

Okay...different example

#include <GDIPlus.au3>
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WINAPI.au3>
_GDIPlus_Startup()
Global $Image1 = _GDIPlus_ImageLoadFromFile("sb.png")
   $width=_GDIPlus_ImageGetWidth($Image1)
   $height=_GDIPlus_ImageGetHeight($Image1)
Global Const $AC_SRC_ALPHA = 1
$GUI = GUICreate("Example",$width,$height,-1,-1,$WS_POPUP)
$pic=GUICtrlCreateButton("",0,0,$width,$height)
GUISetState()
Global $Graphic = _GDIPlus_GraphicsCreateFromHWND(GUICtrlGetHandle($pic))
_GDIPlus_GraphicsDrawImageRect($Graphic, $Image1,0,0,$width,$height)
    
While 1
    $MSG = GUIGetMsg()
    Switch $MSG
        Case -3
            Quit()
    EndSwitch
WEnd

Func Quit()
    _GDIPlus_ImageDispose($Image1)
    _GDIPlus_GraphicsDispose($Graphic)
    _GDIPlus_Shutdown()
    Exit
EndFunc
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...