Jump to content

Displaying large icons from *.exe files!


Yashied
 Share

Recommended Posts

If you have problems displaying large size (eg 128x128) icons from the *.exe files, take a look at _DrawIcon function which I use instead GUICtrlCreateIcon. :)

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

#region Examle

GUICreate('Test', 176, 88)
GUICtrlCreateIcon('C:\WINDOWS\explorer.exe', 0, 108, 20, 48, 48)
_DrawIcon('C:\WINDOWS\explorer.exe', 0, 20, 20, 48, 48)
GUISetState()

do
    Sleep(10)
until GUIGetMsg() = $GUI_EVENT_CLOSE

#endregion Example

func _DrawIcon($sIcon, $iIndex, $iLeft, $iTop, $iWidth, $iHeight, $iStyle = -1, $iExStyle = -1)
    
    const $STM_SETIMAGE = 0x0172
    
    local $iIcon, $hIcon, $tIcon, $tID
    local $bError = false


    $tIcon = DllStructCreate('hwnd')
    $tID = DllStructCreate('hwnd')
    DllCall('user32.dll', 'int', 'PrivateExtractIcons', 'str', $sIcon, 'int', $iIndex, 'int', $iWidth, 'int', $iHeight, 'ptr', DllStructGetPtr($tIcon), 'ptr', DllStructGetPtr($tID), 'int', 1, 'int', 0)
    if @error then
        $bError = 1
    endif
    $hIcon = DllStructGetData($tIcon, 1)
    $tIcon = 0
    $tID = 0
    
    if ($bError) or (not IsPtr($hIcon)) then
        return SetError(1, 0, 0)
    endif
    
    $iIcon = GUICtrlCreateIcon('', 0, $iLeft, $iTop, $iWidth, $iHeight, $iStyle, $iExStyle)
    if $iIcon > 0 then
        GUICtrlSendMsg($iIcon, $STM_SETIMAGE, $IMAGE_ICON, _WinAPI_CopyIcon($hIcon))
    endif
    
    _WinAPI_DeleteObject($hIcon)
    
    return SetError(0, 0, $iIcon)
endfunc; _DrawIcon
Link to comment
Share on other sites

Should this not be in Example Scripts as it is not a request for support.


Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Link to comment
Share on other sites

If you have problems displaying large size (eg 128x128) icons from the *.exe files, take a look at _DrawIcon function which I use instead GUICtrlCreateIcon. :)

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

#region Examle

GUICreate('Test', 176, 88)
GUICtrlCreateIcon('C:\WINDOWS\explorer.exe', 0, 108, 20, 48, 48)
_DrawIcon('C:\WINDOWS\explorer.exe', 0, 20, 20, 48, 48)
GUISetState()

do
    Sleep(10)
until GUIGetMsg() = $GUI_EVENT_CLOSE

#endregion Example

func _DrawIcon($sIcon, $iIndex, $iLeft, $iTop, $iWidth, $iHeight, $iStyle = -1, $iExStyle = -1)
    
    const $STM_SETIMAGE = 0x0172
    
    local $iIcon, $hIcon, $tIcon, $tID
    local $bError = false


    $tIcon = DllStructCreate('hwnd')
    $tID = DllStructCreate('hwnd')
    DllCall('user32.dll', 'int', 'PrivateExtractIcons', 'str', $sIcon, 'int', $iIndex, 'int', $iWidth, 'int', $iHeight, 'ptr', DllStructGetPtr($tIcon), 'ptr', DllStructGetPtr($tID), 'int', 1, 'int', 0)
    if @error then
        $bError = 1
    endif
    $hIcon = DllStructGetData($tIcon, 1)
    $tIcon = 0
    $tID = 0
    
    if ($bError) or (not IsPtr($hIcon)) then
        return SetError(1, 0, 0)
    endif
    
    $iIcon = GUICtrlCreateIcon('', 0, $iLeft, $iTop, $iWidth, $iHeight, $iStyle, $iExStyle)
    if $iIcon > 0 then
        GUICtrlSendMsg($iIcon, $STM_SETIMAGE, $IMAGE_ICON, _WinAPI_CopyIcon($hIcon))
    endif
    
    _WinAPI_DeleteObject($hIcon)
    
    return SetError(0, 0, $iIcon)
endfunc; _DrawIcon
Thanks for that post Yashied!

(When you have enough posts I think you should put it in example scripts.)

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Nice work with the _DrawCombineBkIcon also, Yashied.

I am not seeing a benefit (display qualitywise) to your _DrawIcon Function using this code. Any thoughts?

local $iconsrcexe = "C:\WINDOWS\explorer.exe"
GUICreate(@scriptname, 1000, 500)
local $sz, $left = 0
For $sz = 16 to 256 step 16
      GUICtrlCreateIcon($iconsrcexe, 0, $left, 10, 80, $sz, $sz)
      _DrawIcon($iconsrcexe, 0, $left, 300, 80, $sz, $sz)
      $left += 80
Next;$sz
GUISetState()
do
    Sleep(10)
until GUIGetMsg() = $GUI_EVENT_CLOSE
Link to comment
Share on other sites

Nice work with the _DrawCombineBkIcon also, Yashied.

I am not seeing a benefit (display qualitywise) to your _DrawIcon Function using this code. Any thoughts?

local $iconsrcexe = "C:\WINDOWS\explorer.exe"
GUICreate(@scriptname, 1000, 500)
local $sz, $left = 0
For $sz = 16 to 256 step 16
      GUICtrlCreateIcon($iconsrcexe, 0, $left, 10, 80, $sz, $sz)
      _DrawIcon($iconsrcexe, 0, $left, 300, 80, $sz, $sz)
      $left += 80
Next;$sz
GUISetState()
do
    Sleep(10)
until GUIGetMsg() = $GUI_EVENT_CLOSE
DaRam, look more closely at the title of function! :)

_DrawIcon($sIcon, $iIndex, $iLeft, $iTop, $iWidth, $iHeight, $iStyle = -1, $iExStyle = -1)

local $iconsrcexe = "C:\WINDOWS\explorer.exe"
GUICreate(@scriptname, 1000, 500)
local $sz, $left = 0
For $sz = 16 to 256 step 16
      GUICtrlCreateIcon($iconsrcexe, 0, $left, 10, $sz, $sz)
      _DrawIcon($iconsrcexe, 0, $left, 300, $sz, $sz)
      $left += 80
Next;$sz
GUISetState()
do
    Sleep(10)
until GUIGetMsg() = $GUI_EVENT_CLOSE

Moreover, it is assumed that the icon size exists in the specified file.

In any case, look at my screenshort.

Edited by Yashied
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...