guinness Posted October 13, 2013 Share Posted October 13, 2013 As you can see the final image is quite frankly awful! Does anyone have a better approach. You will need the latest AutoIt beta v3.3.9.6+ #include <GDIPlus.au3> #include <WinAPIEx.au3> Example() Func Example() _GDIPlus_Startup() Local $sFilePath = @AutoItExe Local $tFILEINFO = DllStructCreate($tagSHFILEINFO) _WinAPI_ShellGetFileInfo($sFilePath, BitOR($SHGFI_ICON, $SHGFI_LARGEICON), 0, $tFILEINFO) Local $hIcon = DllStructGetData($tFILEINFO, 'hIcon') _GDIPlus_ImageSaveToFile(_GDIPlus_CreateBitmapFromHICON($hIcon), 'Example.png') _WinAPI_DestroyIcon($hIcon) _GDIPlus_Shutdown() EndFunc ;==>Example Func _GDIPlus_CreateBitmapFromHICON($hImage) Local $aResult = DllCall($ghGDIPDll, "int", "GdipCreateBitmapFromHICON", "ptr", $hImage, "int*", 0) If @error Then Return SetError(@error, @extended, 0) If $aResult[0] Then Return SetError(10, $aResult[0], 0) Return $aResult[2] EndFunc ;==>_GDIPlus_CreateBitmapFromHICON 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...
FireFox Posted October 13, 2013 Share Posted October 13, 2013 Hi,;replace _GDIPlus_ImageSaveToFile(_GDIPlus_CreateBitmapFromHICON($hIcon), 'Example.png') ;by _WinAPI_SaveHICONToFile("Example.png", $hIcon, True)Br, FireFox. Link to comment Share on other sites More sharing options...
Solution UEZ Posted October 13, 2013 Solution Share Posted October 13, 2013 (edited) You have to extend the _GDIPlus_CreateBitmapFromHICON() function a little bit expandcollapse popup#include <GDIPlus.au3> #include <WinAPIEx.au3> Example() Func Example() _GDIPlus_Startup() Local $sFilePath = @AutoItExe, $hHBmp Local $tFILEINFO = DllStructCreate($tagSHFILEINFO) _WinAPI_ShellGetFileInfo($sFilePath, BitOR($SHGFI_ICON, $SHGFI_LARGEICON), 0, $tFILEINFO) Local $hIcon = DllStructGetData($tFILEINFO, "hIcon") _GDIPlus_ImageSaveToFile(_GDIPlus_CreateBitmapFromHICONEx($hIcon, 32, 32, $hHBmp), "Example.png") _WinAPI_DestroyIcon($hIcon) _WinAPI_DeleteObject($hHBmp) _GDIPlus_Shutdown() EndFunc ;==>Example Func _GDIPlus_CreateBitmapFromHICONEx($hIcon, $iWidth, $iHeight, ByRef $hHBmp) Local $tBITMAPINFO = DllStructCreate("dword Size;long Width;long Height;word Planes;word BitCount;dword Compression;dword SizeImage;long XPelsPerMeter;long YPelsPerMeter;dword ClrUsed;dword ClrImportant;dword RGBQuad") DllStructSetData($tBITMAPINFO, "Size", DllStructGetSize($tBITMAPINFO) - 4) DllStructSetData($tBITMAPINFO, "Width", $iWidth) DllStructSetData($tBITMAPINFO, "Height", -$iHeight) DllStructSetData($tBITMAPINFO, "Planes", 1) DllStructSetData($tBITMAPINFO, "BitCount", 32) DllStructSetData($tBITMAPINFO, "Compression", 0) DllStructSetData($tBITMAPINFO, "SizeImage", 0) Local $hDC = _WinAPI_CreateCompatibleDC(0) Local $aRet = DllCall("gdi32.dll", "ptr", "CreateDIBSection", "hwnd", 0, "ptr", DllStructGetPtr($tBITMAPINFO), "uint", 0, "ptr*", 0, "ptr", 0, "dword", 0) Local $pBits = $aRet[4] $hHBmp = $aRet[0] Local $hOrig = _WinAPI_SelectObject($hDC, $hHBmp) _WinAPI_DrawIconEx($hDC, 0, 0, $hIcon, $iWidth, $iHeight) $aRet = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iWidth, "int", $iHeight, "int", $iWidth * 4, "int", 0x26200A, "ptr", $pBits, "int*", 0) Local $hBitmap = $aRet[6] _WinAPI_SelectObject($hDC, $hOrig) _WinAPI_DeleteDC($hDC) Return $hBitmap EndFunc ;==>_GDIPlus_CreateBitmapFromHICONEx Br,UEZ Edited October 13, 2013 by UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
guinness Posted October 14, 2013 Author Share Posted October 14, 2013 Thanks FireFox, though for some reason there was an issue with the BITMAP header when I open in IfranView. Rendered fine though in WIndows Picture Viewer. Thanks UEZ. That works perfectly. I guessed I was a little off with the knowledge of GDI! 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...
UEZ Posted October 14, 2013 Share Posted October 14, 2013 (edited) Btw,Eukalyptus wrote also something similar as the function above which should be added to the beta GDIPlus.au3 UDF. expandcollapse popup; #FUNCTION# ==================================================================================================================== ; Name...........: _GDIPlus_BitmapCreateFromHICON32 ; Description ...: Creates a Bitmap object based on a 32bit icon ; Syntax.........: _GDIPlus_BitmapCreateFromHICON32($hIcon) ; Parameters ....: $hIcon - Handle to a 32bit icon ; Return values .: Success - Returns a handle to a new Bitmap object ; Failure - 0 ; Author ........: Eukalyptus ; Modified.......: ; Remarks .......: After you are done with the object, call _GDIPlus_ImageDispose to release the object resources ; Related .......: _GDIPlus_ImageDispose, _WinAPI_ShellExtractIcon ; Link ..........; @@MsdnLink@@ GdipCreateBitmapFromHICON ; Example .......; Yes ; =============================================================================================================================== Func _GDIPlus_BitmapCreateFromHICON32($hIcon) Local $tSIZE = _WinAPI_GetIconDimension($hIcon) Local $iWidth = DllStructGetData($tSIZE, 'X') Local $iHeight = DllStructGetData($tSIZE, 'Y') If $iWidth <= 0 Or $iHeight <= 0 Then Return SetError(10, -1, 0) Local $tBITMAPINFO = DllStructCreate("dword Size;long Width;long Height;word Planes;word BitCount;dword Compression;dword SizeImage;long XPelsPerMeter;long YPelsPerMeter;dword ClrUsed;dword ClrImportant;dword RGBQuad") DllStructSetData($tBITMAPINFO, 'Size', DllStructGetSize($tBITMAPINFO) - 4) DllStructSetData($tBITMAPINFO, 'Width', $iWidth) DllStructSetData($tBITMAPINFO, 'Height', -$iHeight) DllStructSetData($tBITMAPINFO, 'Planes', 1) DllStructSetData($tBITMAPINFO, 'BitCount', 32) DllStructSetData($tBITMAPINFO, 'Compression', 0) DllStructSetData($tBITMAPINFO, 'SizeImage', 0) Local $hDC = _WinAPI_CreateCompatibleDC(0) Local $pBits Local $hBmp = _WinAPI_CreateDIBSection(0, $tBITMAPINFO, 0, $pBits) Local $hOrig = _WinAPI_SelectObject($hDC, $hBmp) _WinAPI_DrawIconEx($hDC, 0, 0, $hIcon, $iWidth, $iHeight) Local $hBitmapIcon = _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight, $GDIP_PXF32ARGB, $iWidth * 4, $pBits) Local $hBitmap = _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight) Local $hContext = _GDIPlus_ImageGetGraphicsContext($hBitmap) _GDIPlus_GraphicsDrawImage($hContext, $hBitmapIcon, 0, 0) _GDIPlus_GraphicsDispose($hContext) _GDIPlus_BitmapDispose($hBitmapIcon) _WinAPI_SelectObject($hDC, $hOrig) _WinAPI_DeleteDC($hDC) _WinAPI_DeleteObject($hBmp) Return $hBitmap EndFunc ;==>_GDIPlus_BitmapCreateFromHICON32This is a good example for the cooparation between GDI and GDI+!Br,UEZ Edited October 14, 2013 by UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
guinness Posted October 14, 2013 Author Share Posted October 14, 2013 Thanks. Will most likely use this. 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