K8chel0fen

extract icon from .exe and draw it

5 posts in this topic

I'm new to AutoIt. So thanks for any help. Is there a simple way to extract an icon from an .exe file and then draw it in my main window?

This is the code so far (out of the greater context and broken down to the main problem)

#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <WinAPIShellEx.au3>
#include <WinAPI.au3>

Global Const $iGlobalWindowWidth = 840
Global Const $iGlobalWindowHeigth = 525

Global Const $cWhite = 0xFFFFFF

Local $hGlobalWindow = GUICreate ( "Test", $iGlobalWindowWidth, $iGlobalWindowHeigth)
GUISetBkColor ( $cWhite )

$hIcon = _WinAPI_ShellExtractIcon(@systemdir & "\notepad.exe" , 0, 32, 32)
$hDC = _WinAPI_GetDC( $hGlobalWindow )
_WinAPI_DrawIconEx($hDC, 100, 100, $hIcon, 20, 20)    ; That function doesn't work like I want.

GUISetState ( @SW_SHOW, $hGlobalWindow )

While 1
    Switch GUIGetMsg()
    Case $GUI_EVENT_CLOSE
            _Exit()
    EndSwitch
WEnd

Func _Exit()
    _WinAPI_ReleaseDC($hGlobalWindow, $hDC)
    _WinAPI_DestroyIcon($hIcon)
    Exit
EndFunc   ;==>_Exit

In the end I want to extract the largest icon with the highest resolution out of the exe and draw it 20 x 20 pixel in something with a handle return. GuiCtrlCreateIcon would have been great because of its simple structure but if there's something similar I won't bother. I found nothing yet so perhaps someone had a similar problem in the past and can help me out?

Share this post


Link to post
Share on other sites



Usually _SendMessage is used, but there's a size difference between using _SendMessage and just GUICtrlCreateIcon  :guitar: 
 

#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <WinAPIShellEx.au3>
#include <WinAPI.au3>
 
Global Const $iGlobalWindowWidth = 840,  $STM_SETIMAGE = 0x0172
Global Const $iGlobalWindowHeigth = 525
 
Global Const $cWhite = 0xFFFFFF
 
Local $hGlobalWindow = GUICreate ( "Test", $iGlobalWindowWidth, $iGlobalWindowHeigth)
GUISetBkColor ( $cWhite )
 
;$hAIcon = _WinAPI_ShellExtractIcon(@systemdir & "\notepad.exe" , 0, 32, 32)
;$hDC = _WinAPI_GetDC( $hGlobalWindow )
$idIcon = GUICtrlCreateIcon(@systemdir & "\notepad.exe", 0, 50, 50, 20, 20)
$hIcon = GUICtrlGetHandle(-1)
;_WinAPI_DrawIconEx($hDC, 100, 100, $hIcon, 20, 20)    ; That function doesn't work like I want.
;_SendMessage($hIcon, $STM_SETIMAGE, 1,$hAIcon)
GUISetState ( @SW_SHOW, $hGlobalWindow )
 
While 1
    Switch GUIGetMsg()
    Case $GUI_EVENT_CLOSE
            _Exit()
    EndSwitch
WEnd
 
Func _Exit()
    ;_WinAPI_ReleaseDC($hGlobalWindow, $hDC)
    ;_WinAPI_DestroyIcon($hAIcon)
    Exit
EndFunc   ;==>_Exit

Heroes, there is no such thing

One day I'll discover what IE.au3 has of special for so many users using it.
C'mon there's InetRead and WinHTTP, way better
happy.png

Share this post


Link to post
Share on other sites

There is also a native version too.


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

I tested the code from Kyan and it's working fine. When I adjust the sizes like this

$hAIcon = _WinAPI_ShellExtractIcon(@systemdir & "\notepad.exe" , 0, 20, 20)

$idIcon = GUICtrlCreateIcon("", 0, 50, 50, 20, 20)

there's no difference. Thanks so far. The only thing is I wished I had more control over the choice which Icon should be extracted and not always the first one. The largest with the best quality or the smallest with best quality etc.

@guinness: Which is the native version?

Edited by K8chel0fen

Share this post


Link to post
Share on other sites

_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
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