K8chel0fen Posted April 10, 2015 Share Posted April 10, 2015 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? Link to comment Share on other sites More sharing options...
Kyan Posted April 10, 2015 Share Posted April 10, 2015 Usually _SendMessage is used, but there's a size difference between using _SendMessage and just GUICtrlCreateIcon #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 Link to comment Share on other sites More sharing options...
guinness Posted April 11, 2015 Share Posted April 11, 2015 There is also a native version too. UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _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 parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
K8chel0fen Posted April 11, 2015 Author Share Posted April 11, 2015 (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 April 11, 2015 by K8chel0fen Link to comment Share on other sites More sharing options...
guinness Posted April 11, 2015 Share Posted April 11, 2015 GUICtrlSendMsg UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _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 parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now