smashly Posted August 25, 2009 Share Posted August 25, 2009 (edited) Hi,Edit Again: I used GetBitmapBits instead of _WinAPI_GetDIBits() to retrieve the dib bits.Tried it in XP x86, Tried it in Win7 x64 using x64 & x86 autoit.And it works ok for me.... Excuse the crude code below..But I was curious on how to create a .ico file from a HICONThis was my untidy attempt..lol expandcollapse popup#include <GDIPlus.au3> #include <WinAPI.au3> Opt("MustDeclareVars", 1) Global $sRegPath, $sImagePath, $hImage, $hIcon ; Get the path of the image $sRegPath = "HKLM\SOFTWARE\AutoIt v3\AutoIt" If StringInStr("X64IA64", @OSArch) Then $sRegPath = StringReplace($sRegPath, "SOFTWARE", "SOFTWARE\Wow6432Node") $sImagePath = RegRead($sRegPath, "InstallDir") & "\Examples\GUI\logo4.gif" ; Start GDIPlus _GDIPlus_Startup() ; Load image $hImage = _GDIPlus_ImageLoadFromFile($sImagePath) ; Create a HICON from the image, ; Before doing this you should really scale your image to an icon size! ; But I just wanted to show that it works..lol $hIcon = _GDIPlus_BitmapCreateHICONFromBitmap($hImage) ;Clean up and shutdown GDIPlus _GDIPlus_ImageDispose($hImage) _GDIPlus_Shutdown() ; Create an ico file from the image _CreateIconFileFromHICON($hIcon, @ScriptDir & "\NewAutoit.ico") ; Destroy the HICON now I've finished with it. _WinAPI_DestroyIcon($hIcon) Func _CreateIconFileFromHICON($hIcon, $sOutIcon) Local $aInfo, $sIco, $sBmp, $hCDC, $tBI, $tBits, $iSz, $sBD, $FO ; Start of single Icon Header 3 x 2 bytes = 6 bytes: 0000 Reserved / 0100 Icon / 0100 Numer of icons, total length will be 22 bytes for a single icon when finished $sIco = "0x000001000100" ; Start of the Bitmap data header 1 x 4bytes: length of the header will be 40 bytes when finished. Will be appended to the end of the icon header when finished $sBmp = "28000000" ; Get info about the HICON, this is mainly to get the pointers to the Color/Mask bitmaps data $aInfo = _WinAPI_GetIconInfo($hIcon) ; Create a memory Compatable DC $hCDC = _WinAPI_CreateCompatibleDC(0) ; Create a BITMAPINFO Struct to store the Bitmap Info, it needs to be inilialized by setting the struct size. $tBI = DllStructCreate($tagBITMAPINFO) DllStructSetData($tBI, "Size", DllStructGetSize($tBI)) ; Pass a bitmap data pointer to the BITMAPINFO struct so we can recieve the details of the color bitmap data, we use it to write the headers _WinAPI_GetDIBits($hCDC, $aInfo[5], 0, 0, 0, DllStructGetPtr($tBI), 0) ; Now we have some the basic info to add to the Icon & Bitmap header so we'll add that to the headers. $sIco &= Hex(DllStructGetData($tBI, "Width"), 2) & Hex(DllStructGetData($tBI, "Height"), 2) & "00000100" & _RB(Hex(DllStructGetData($tBI, "BitCount"), 4)) $sBmp &= _RB(Hex(DllStructGetData($tBI, "Width"))) & _RB(Hex(DllStructGetData($tBI, "Height") * 2)) & "0100" & _RB(Hex(DllStructGetData($tBI, "BitCount"), 4)) & "00000000" ; Get the size of the Bitmap data from the BITMAPINFO Struct, we'll use this in the headers further on. $iSz = DllStructGetData($tBI, "SizeImage") ; Create a struct to store the Bitmap data Bits of the first bitmap, reset the BITMAPINFO struct $tBits = DllStructCreate("byte[" & DllStructGetData($tBI, "SizeImage") & "]") ; Get the color bitmap dib bits into the $tBits struct. DllCall('gdi32.dll', 'int', 'GetBitmapBits', 'ptr', $aInfo[5], 'int', $iSz, 'ptr', DllStructGetPtr($tBits)) ; Get GetBitmapBits returns Bottom to Top dib, so I turn it to Top to Bottom dib ;) ; ATM I'm only assuming that GetBitmapBits returns a Bottom to Top dib, maybe the bitmap bits you use could be Top Down already?. For $i = DllStructGetData($tBI, "SizeImage") + 1 To 0 Step -(DllStructGetData($tBI, "SizeImage") / DllStructGetData($tBI, "Height")) $sBD &= StringTrimLeft(BinaryMid(DllStructGetData($tBits, 1), $i, (DllStructGetData($tBI, "SizeImage") / DllStructGetData($tBI, "Height"))), 2) Next ;Clear the BITMAPINFO & $tBits Struct as we'll use the same variables again for the mask bitmap data $tBits = 0 $tBI = 0 ; Create a BITMAPINFO Struct to store the Bitmap Info again, it needs to be inilialized by setting the struct size. $tBI = DllStructCreate($tagBITMAPINFO) DllStructSetData($tBI, "Size", DllStructGetSize($tBI)) ; Pass a bitmap data pointer to the BITMAPINFO struct so we can recieve the details of the bitmask bitmap data _WinAPI_GetDIBits($hCDC, $aInfo[4], 0, 0, 0, DllStructGetPtr($tBI), 0) ; We've finished with the Compatable DC, delete it. _WinAPI_DeleteDC($hCDC) ; Add the size of the of the color + bitmask bitmap data as we need this for both the Icon & Bitmap header $iSz += DllStructGetData($tBI, "SizeImage") ; combine the bitmap data size with the bitmap header, I'm padding the rest of the 40 byte bitmap header with 0's., that's the Bitmap header done $sBmp &= _RB(Hex($iSz)) & "00000000000000000000000000000000" ; Now add the size of the Bitmap data + bitmap header size and combine the icon header together with the bitmap header and color bitmap data $sIco &= _RB(Hex($iSz + 40)) & _RB(Hex("22")) & $sBmp & $sBD ; Create a struct to store the Bitmap dib Bits of the mask bitmap $tBits = DllStructCreate("byte[" & DllStructGetData($tBI, "SizeImage") & "]") ; Get the mask bitmap dib bits into the $tBits struct. DllCall('gdi32.dll', 'int', 'GetBitmapBits', 'ptr', $aInfo[4], 'int', DllStructGetData($tBI, "SizeImage"), 'ptr', DllStructGetPtr($tBits)) ; Get GetBitmapBits returns Bottom to Top dib, so I turn it to a Top to Bottom dib and append the mask bitmap data to the icon For $i = DllStructGetData($tBI, "SizeImage") + 1 To 0 Step -(DllStructGetData($tBI, "SizeImage") / DllStructGetData($tBI, "Height")) $sIco &= StringTrimLeft(BinaryMid(DllStructGetData($tBits, 1), $i, (DllStructGetData($tBI, "SizeImage") / DllStructGetData($tBI, "Height"))), 2) Next ; Write the icon to a file. $FO = FileOpen($sOutIcon, 18) FileWrite($sOutIcon, Binary($sIco)) FileClose($FO) ; Clear the structs $tBits = 0 $tBI = 0 EndFunc ;==>_CreateIconFileFromHICON ; Reverse Byte String Func _RB($sByte) Local $aX = StringRegExp($sByte, "(.{2})", 3), $sX = '' For $i = UBound($aX) - 1 To 0 Step -1 $sX &= $aX[$i] Next Return $sX EndFunc ;==>_RB Func _GDIPlus_BitmapCreateHICONFromBitmap($hBitmap) Local $hIcon $hIcon = DllCall($ghGDIPDll, "int", "GdipCreateHICONFromBitmap", "hwnd", $hBitmap, "int*", 0) If @error Then Return SetError(@error, 0, -1) Return SetError($hIcon[0], 0, $hIcon[2]) EndFunc ;==>_GDIPlus_BitmapCreateHICONFromBitmapIf a user is wanting to use an already prepared 256x256 png then this function is not for you as your icon size will be huge..Your better off writing the icon header and append the the png strait after the header, no get dib bits and your icon will only be 22bytes larger then the png. Cheers Edited August 26, 2009 by smashly Link to comment Share on other sites More sharing options...
UEZ Posted August 25, 2009 Share Posted August 25, 2009 (edited) AutoIt is crashing when I execute the script >_<Probably this line _WinAPI_GetDIBits($hCDC, $aInfo[5], 0, DLLStructGetData($tBI, "Height"), DllStructGetPtr($tBits), DllStructGetPtr($tBI), 0) in function Func _CreateIconFileFromHICON($hIcon, $sOutIcon) is causing the crash!?!I'm using Vista x32 and AutoIt v3.3.0.0 / AutoIt v3.3.1.1 Beta.UEZ Edited August 25, 2009 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...
Yashied Posted August 25, 2009 Share Posted August 25, 2009 For me too. My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More... Link to comment Share on other sites More sharing options...
smashly Posted August 25, 2009 Author Share Posted August 25, 2009 (edited) Sorry but I can't see why your getting crash.. I'm using Win7 x64 / AutoIt v3.3.0.0 / AutoIt v3.3.1.1 Beta. This is the output I get in scite console when the script is run>"C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /beta /ErrorStdOut /in "C:\AutoIt\IcoFileFromHICON\IcoFromHicon.au3" /autoit3dir "C:\Program Files (x86)\AutoIt3\beta" /UserParams +>21:11:57 Starting AutoIt3Wrapper v.2.0.0.1 Environment(Language:0409 Keyboard:00000409 OS:WIN_VISTA/ CPU:X64 OS:X64) >Running AU3Check (1.54.16.0) from:C:\Program Files (x86)\AutoIt3\beta +>21:11:57 AU3Check ended.rc:0 >Running:(3.3.1.1):C:\Program Files (x86)\AutoIt3\beta\autoit3_x64.exe "C:\AutoIt\IcoFileFromHICON\IcoFromHicon.au3" +>21:11:57 AutoIT3.exe ended.rc:0 +>21:11:58 AutoIt3Wrapper Finished >Exit code: 0 Time: 1.854 I'll have a look at it on a x86 platform when I get a chance.. PS. that return is using the code copied from the first post. Edit: had a look at the code under x86.. Seems to be the _WinAPI_ReleaseDC(0,$hDC) has to moved to the end of the function. Updated first post.. Edited August 25, 2009 by smashly Link to comment Share on other sites More sharing options...
UEZ Posted August 25, 2009 Share Posted August 25, 2009 Ok, I tested it on my vm (environment: Win2k3 Standard x64 SP2):>"C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /prod /ErrorStdOut /in "E:\AU3\Test01.au3" /autoit3dir "C:\Program Files\AutoIt3" /UserParams +>13:29:19 Starting AutoIt3Wrapper v.2.0.0.0 Environment(Language:0409 Keyboard:00000407 OS:WIN_2003/Service Pack 2 CPU:X64)>Running AU3Check (1.54.14.0) from:C:\Program Files (x86)\AutoIt3+>13:29:19 AU3Check ended.rc:0>Running:(3.3.0.0):C:\Program Files (x86)\AutoIt3\autoit3.exe "E:\AU3\Test01.au3" !>13:29:22 AutoIT3.exe ended.rc:-1073741819+>13:29:23 AutoIt3Wrapper Finished>Exit code: -1073741819 Time: 4.947UEZ 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...
smashly Posted August 25, 2009 Author Share Posted August 25, 2009 Ok, I tested it on my vm (environment: Win2k3 Standard x64 SP2): >"C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /prod /ErrorStdOut /in "E:\AU3\Test01.au3" /autoit3dir "C:\Program Files\AutoIt3" /UserParams +>13:29:19 Starting AutoIt3Wrapper v.2.0.0.0 Environment(Language:0409 Keyboard:00000407 OS:WIN_2003/Service Pack 2 CPU:X64) >Running AU3Check (1.54.14.0) from:C:\Program Files (x86)\AutoIt3 +>13:29:19 AU3Check ended.rc:0 >Running:(3.3.0.0):C:\Program Files (x86)\AutoIt3\autoit3.exe "E:\AU3\Test01.au3" !>13:29:22 AutoIT3.exe ended.rc:-1073741819 +>13:29:23 AutoIt3Wrapper Finished >Exit code: -1073741819 Time: 4.947 UEZ Did you try it with updated first post? It works for me now x86 or x64 autoit 3.3.0.0 or beta 3.3.1.1 ... Have you tried it under x64 autoit? Cause your return tells me x86 autoit was used, but it still shouldn't matter.. >Running:(3.3.0.0):C:\Program Files (x86)\AutoIt3\autoit3.exe "E:\AU3\Test01.au3" Link to comment Share on other sites More sharing options...
UEZ Posted August 25, 2009 Share Posted August 25, 2009 Mmmhhhh, strange >_<:when I add #AutoIt3Wrapper_UseX64=y, compile it and run the exe afterwards then it creates the NewAutoIt.ico (no em during the compilation)!But when I start the script by F5 it gives me following error:>"C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /prod /ErrorStdOut /in "E:\AU3\Test01.au3" /autoit3dir "C:\Program Files\AutoIt3" /UserParams +>14:10:16 Starting AutoIt3Wrapper v.2.0.0.0 Environment(Language:0409 Keyboard:00000407 OS:WIN_2003/Service Pack 2 CPU:X64)>Running AU3Check (1.54.14.0) from:C:\Program Files (x86)\AutoIt3+>14:10:16 AU3Check ended.rc:0>Running:(3.3.0.0):C:\Program Files (x86)\AutoIt3\autoit3.exe "E:\AU3\Test01.au3" E:\AU3\Test01.au3 (95) : ==> Variable used without being declared.:_WinAPI_GetDIBits($hCDC, $aInfo[4], 0, DLLStructGetData($tBI, "Height"), DllStructGetPtr($tBits), DllStructGetPtr($tBI), 0)_WinAPI_GetDIBits(^ ERROR->14:10:16 AutoIT3.exe ended.rc:1+>14:10:18 AutoIt3Wrapper Finished>Exit code: 1 Time: 2.096When I move the line Local $aInfo, $sIco, $sBmp, $hDC, $hCDC, $tBI, $tBits, $iSz, $sBD and start it by pressing F5 it shows the em in my previous post (!>14:18:02 AutoIT3.exe ended.rc:-1073741819)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...
smashly Posted August 26, 2009 Author Share Posted August 26, 2009 Updated first post.. Hopefully x86 users will get some joy.. fingers crossed..lol Changed the method to get the dib bits, should work on x86 and x64 AutoIt/OS. Strange that x86 Autoit on x86 OS fails the 2nd call to _WinAPI_GetDIBits() to retrieve the dib bits.. By all rights it should work.. I thought it may be a memory prob with the ptr for the tBits struct.. but it's not. But no matter what I tried the 2nd call _WinAPI_GetDIBits() to retrieve the dib bits fails with an autoit crash on x86 Autoit/OS. I also thought that maybe the image I was passing was not in the correct format or the Compatible DC part is wrong.. But if that was the case the it would fail on the 1st pass when when filling the BITMAPINFO struct I must be missing or doing something wrong when passing the ptr.. Yet it succeeds on x64 AutoIt/OS fine.. >_< Oh well, live and learn... Link to comment Share on other sites More sharing options...
UEZ Posted August 26, 2009 Share Posted August 26, 2009 It's working now on my system >_< 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...
Yashied Posted August 26, 2009 Share Posted August 26, 2009 Works for me too. Thanks. My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More... Link to comment Share on other sites More sharing options...
Iuli Posted August 27, 2009 Share Posted August 27, 2009 Very useful >_< Thanks for code. [size="2"]SFXMaker[/size] - The most complete switchless installer creator software[indent][/indent] Link to comment Share on other sites More sharing options...
nend Posted January 7, 2013 Share Posted January 7, 2013 (edited) I Like this example very much, but with autoit 3.3.8.1. it wont work anymore, does anybody know how to fix it. This piece of code is just to difficult for me. I Know It's a long time ago this example. Edited January 7, 2013 by nend Link to comment Share on other sites More sharing options...
guinness Posted January 7, 2013 Share Posted January 7, 2013 Why doesn't it work exactly. Note: I haven't downloaded or tested as I don't feel like doing all the leg work. 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...
nend Posted January 7, 2013 Share Posted January 7, 2013 Hoi Guinness,It's make a ico but the ico is corupted (not showing the picture).With a older version of autoit it was working perfectly.It won't give any error.I wish I can debug this my self but the code is "way over my head".Why doesn't it work exactly.Note: I haven't downloaded or tested as I don't feel like doing all the leg work. Link to comment Share on other sites More sharing options...
UEZ Posted January 7, 2013 Share Posted January 7, 2013 (edited) The problem is probably the Hex() function which is different now compared to previous versions. Br, UEZ Edited January 7, 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...
nend Posted January 7, 2013 Share Posted January 7, 2013 Thanks UEZ,I will look into this.The problem is probably the Hex() function which is different now compared to previous versions.Br,UEZ Link to comment Share on other sites More sharing options...
UEZ Posted January 7, 2013 Share Posted January 7, 2013 Try this: expandcollapse popup;http://www.autoitscript.com/forum/index.php?showtopic=101305 #include <GDIPlus.au3> #include <WinAPI.au3> Opt("MustDeclareVars", 1) Global $sRegPath, $sImagePath, $hImage, $hIcon ; Get the path of the image $sRegPath = "HKLM\SOFTWARE\AutoIt v3\AutoIt" If StringInStr("X64IA64", @OSArch) Then $sRegPath = StringReplace($sRegPath, "SOFTWARE", "SOFTWARE\Wow6432Node") $sImagePath = RegRead($sRegPath, "InstallDir") & "\Examples\GUI\logo4.gif" ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $sImagePath = ' & $sImagePath & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console ; Start GDIPlus _GDIPlus_Startup() ; Load image $hImage = _GDIPlus_ImageLoadFromFile($sImagePath) ; Create a HICON from the image, ; Before doing this you should really scale your image to an icon size! ; But I just wanted to show that it works..lol $hIcon = _GDIPlus_BitmapCreateHICONFromBitmap($hImage) ;Clean up and shutdown GDIPlus _GDIPlus_ImageDispose($hImage) _GDIPlus_Shutdown() If FileExists(@ScriptDir & "\HICON to ICO.ico") Then FileDelete(@ScriptDir & "\HICON to ICO.ico") ; Create an ico file from the image _CreateIconFileFromHICON($hIcon, @ScriptDir & "\HICON to ICO.ico") ; Destroy the HICON now I've finished with it. _WinAPI_DestroyIcon($hIcon) Func _CreateIconFileFromHICON($hIcon, $sOutIcon) Local $aInfo, $sIco, $sBmp, $hCDC, $tBI, $tBits, $iSz, $sBD, $FO ; Start of single Icon Header 3 x 2 bytes = 6 bytes: 0000 Reserved / 0100 Icon / 0100 Numer of icons, total length will be 22 bytes for a single icon when finished $sIco = "0x000001000100" ; Start of the Bitmap data header 1 x 4bytes: length of the header will be 40 bytes when finished. Will be appended to the end of the icon header when finished $sBmp = "28000000" ; Get info about the HICON, this is mainly to get the pointers to the Color/Mask bitmaps data $aInfo = _WinAPI_GetIconInfo($hIcon) ; Create a memory Compatable DC $hCDC = _WinAPI_CreateCompatibleDC(0) ; Create a BITMAPINFO Struct to store the Bitmap Info, it needs to be inilialized by setting the struct size. $tBI = DllStructCreate($tagBITMAPINFO) DllStructSetData($tBI, "Size", DllStructGetSize($tBI)) ; Pass a bitmap data pointer to the BITMAPINFO struct so we can recieve the details of the color bitmap data, we use it to write the headers _WinAPI_GetDIBits($hCDC, $aInfo[5], 0, 0, 0, DllStructGetPtr($tBI), 0) ; Now we have some the basic info to add to the Icon & Bitmap header so we'll add that to the headers. $sIco &= Hex(DllStructGetData($tBI, "Width"), 2) & Hex(DllStructGetData($tBI, "Height"), 2) & "00000100" & _RB(Hex(DllStructGetData($tBI, "BitCount"), 4)) $sBmp &= _RB(Hex(DllStructGetData($tBI, "Width"), 8)) & _RB(Hex(DllStructGetData($tBI, "Height") * 2, 8)) & "0100" & _RB(Hex(DllStructGetData($tBI, "BitCount"), 4)) & "00000000" ; Get the size of the Bitmap data from the BITMAPINFO Struct, we'll use this in the headers further on. $iSz = DllStructGetData($tBI, "SizeImage") ; Create a struct to store the Bitmap data Bits of the first bitmap, reset the BITMAPINFO struct $tBits = DllStructCreate("byte[" & DllStructGetData($tBI, "SizeImage") & "]") ; Get the color bitmap dib bits into the $tBits struct. DllCall('gdi32.dll', 'int', 'GetBitmapBits', 'ptr', $aInfo[5], 'int', $iSz, 'ptr', DllStructGetPtr($tBits)) ; Get GetBitmapBits returns Bottom to Top dib, so I turn it to Top to Bottom dib ;) ; ATM I'm only assuming that GetBitmapBits returns a Bottom to Top dib, maybe the bitmap bits you use could be Top Down already?. For $i = DllStructGetData($tBI, "SizeImage") + 1 To 0 Step -(DllStructGetData($tBI, "SizeImage") / DllStructGetData($tBI, "Height")) $sBD &= StringTrimLeft(BinaryMid(DllStructGetData($tBits, 1), $i, (DllStructGetData($tBI, "SizeImage") / DllStructGetData($tBI, "Height"))), 2) Next ;Clear the BITMAPINFO & $tBits Struct as we'll use the same variables again for the mask bitmap data $tBits = 0 $tBI = 0 ; Create a BITMAPINFO Struct to store the Bitmap Info again, it needs to be inilialized by setting the struct size. $tBI = DllStructCreate($tagBITMAPINFO) DllStructSetData($tBI, "Size", DllStructGetSize($tBI)) ; Pass a bitmap data pointer to the BITMAPINFO struct so we can recieve the details of the bitmask bitmap data _WinAPI_GetDIBits($hCDC, $aInfo[4], 0, 0, 0, DllStructGetPtr($tBI), 0) ; We've finished with the Compatable DC, delete it. _WinAPI_DeleteDC($hCDC) ; Add the size of the of the color + bitmask bitmap data as we need this for both the Icon & Bitmap header $iSz += DllStructGetData($tBI, "SizeImage") ; combine the bitmap data size with the bitmap header, I'm padding the rest of the 40 byte bitmap header with 0's., that's the Bitmap header done $sBmp &= _RB(Hex($iSz, 8)) & "00000000000000000000000000000000" ; Now add the size of the Bitmap data + bitmap header size and combine the icon header together with the bitmap header and color bitmap data $sIco &= _RB(Hex($iSz + 40, 8)) & _RB(Hex("22", 8)) & $sBmp & $sBD ; Create a struct to store the Bitmap dib Bits of the mask bitmap $tBits = DllStructCreate("byte[" & DllStructGetData($tBI, "SizeImage") & "]") ; Get the mask bitmap dib bits into the $tBits struct. DllCall('gdi32.dll', 'int', 'GetBitmapBits', 'ptr', $aInfo[4], 'int', DllStructGetData($tBI, "SizeImage"), 'ptr', DllStructGetPtr($tBits)) ; Get GetBitmapBits returns Bottom to Top dib, so I turn it to a Top to Bottom dib and append the mask bitmap data to the icon For $i = DllStructGetData($tBI, "SizeImage") + 1 To 0 Step -(DllStructGetData($tBI, "SizeImage") / DllStructGetData($tBI, "Height")) $sIco &= StringTrimLeft(BinaryMid(DllStructGetData($tBits, 1), $i, (DllStructGetData($tBI, "SizeImage") / DllStructGetData($tBI, "Height"))), 2) Next ; Write the icon to a file. $FO = FileOpen($sOutIcon, 18) FileWrite($sOutIcon, Binary($sIco)) FileClose($FO) ; Clear the structs $tBits = 0 $tBI = 0 EndFunc ;==>_CreateIconFileFromHICON Func _GDIPlus_BitmapCreateHICONFromBitmap($hBitmap) Local $hIcon $hIcon = DllCall($ghGDIPDll, "int", "GdipCreateHICONFromBitmap", "hwnd", $hBitmap, "int*", 0) If @error Then Return SetError(@error, 0, -1) Return SetError($hIcon[0], 0, $hIcon[2]) EndFunc ;==>_GDIPlus_BitmapCreateHICONFromBitmap ; Reverse Byte String Func _RB($sByte) Local $aX = StringRegExp($sByte, "(.{2})", 3), $sX = '' For $i = UBound($aX) - 1 To 0 Step -1 $sX &= $aX[$i] Next Return $sX EndFunc ;==>_RB It works for me using 3.3.8.1 and Win7 x64. Br, 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...
ptrex Posted January 7, 2013 Share Posted January 7, 2013 @UEZ The file is created 47 Kb large, but can't be opened ? Win 7 X64 3.3.8.0 Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New Link to comment Share on other sites More sharing options...
nend Posted January 7, 2013 Share Posted January 7, 2013 Thanks UEZ!!! Ik works perfectly. Link to comment Share on other sites More sharing options...
ptrex Posted January 7, 2013 Share Posted January 7, 2013 @nend Which program are you using to open it ? Because using IrFanView doesn't like it ! "Invalid or unsupported ICO file" rgds ptrex Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New 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