FireFox Posted June 9, 2011 Posted June 9, 2011 (edited) hi, I want to set the binary data of a png image to a button ctrl. Here is my script which does not work : expandcollapse popup#include <Memory.au3> #include <GDIPlus.au3> Global Const $STM_SETIMAGE = 0x0172, $BS_ICON = 0x0040 Dim $bHyperLinkIcon = "0x89504E470D0A1A0A0000000D49484452000000100000001008060000001FF3FF61000000097048597300000B1300000B1301009A9C18000000206348524D00007A25000080830000F9FF000080E9000075300000EA6000003A980000176F925FC546000002BE4944415478DA74934F6C546514C57F0F8ABE10DAF946699852482FA84C21A053F14F0193BEB03065217461883171CB9A0D0B13933E5829B268BA414713D190D060A3954242E48FAF2E6A4B4A79D3D6D0A8C84798D029C47867C0F21A6C3E17135ACDE0DD9EDC73CFBDE71ECF39C7E3BA3675B5BB387B3F2CCE3E8004D2AB5721CD4F85EDDB771EE67FCA7B4C3078F1B2FB7DE13E64005FC1B7581BA371C01B8D6BD8F5CA86B075D3EB3544CB00062F5C70E30B93A8C488180209B02320190119E0E4AFB37C1F15C2272958BEEFEDB7BAA35F6E0476DD2788C960FC56CCDF54725B3B9F56C08EF9E8AA4EA6758C67F536D94D2F0DFD4741F1CE4C6815504113453526D68186687A80E83CC0418C1AD4C48C4ECDD4A8A82BDE5BC010606D843516C5C2740E309008248AF523D457E2897BD4DE60DE8169C194043B0D71C9A02A90E4203168026A224800B4DAF5E799A64582F6D7D68724654CE62026162819ACC4C4FE40B52951644431165ED890AEAE90DE3BB368E3F8E4185F5D7AE0D4EF80E4165A0AB1ADD549AA39A4D4057" $bHyperLinkIcon &= "A0254F9E1D4175ECD1F8C4F8E0174F79EAB0B8DAF18DF56659794C89CC0D8004168DBE8D3D0D800F3B0D22B0278070E1CA2AE6DEB76AE4D5D3D1C8886B99C20D2010944710113192C9620C811E404919645AC7065D4019EE79CA3AFFFB8DBFCEABB7C773A4FFFB73FB13C95A2ABAB0BC954AD1563B853B9CBE0D779EAEBEBD9D3F1325E6A1BE59B43D401586DE49D96D4A3F70647574C0C7FE39D397FD9EDEDDCFDA83CCF0A55502D631221BDFF3700AFF4D733AE4D840F3EFDB29A85BEBECF5CD3E637991C3ECB8D3FE6C836AFE5FDA3FD4BB6013BDA3692DDD24AB6792DABCD4A7EBEBB8CF4C3C252987AF2A75D7A4D1691AAF7F148CCF5C210BBDB9B98A3855AEC4776BE98F2BC7FC7B9B7E7881B9E2853A954D8F29CE3D8479F7BF9FCC70024730F97B0E73D8E7D98F77A7B8EF0CF00EC65488957DC766E0000000049454E44AE426082" GuiCreate("") $btn=GUICtrlCreateButton("", 5, 5, 20, 20, $BS_ICON) GUICtrlSendMsg($btn, $STM_SETIMAGE, 0, Load_BMP_From_Mem($bHyperLinkIcon)) GuiSetState() While 1 Sleep(1000) WEnd Func Load_BMP_From_Mem($mem_image) ;coded by UEZ - thanks to progandy for the MemGlobalAlloc and tVARIANT lines _GDIPlus_Startup() Local $memBitmap, $len, $tMem, $hImage, $hData, $pData, $aBitmap, $aStream $memBitmap = Binary($mem_image) ;load image saved in variable (memory) and convert it to binary $len = BinaryLen($memBitmap) ;get length of image $hData = _MemGlobalAlloc($len, $GMEM_MOVEABLE) ;allocates movable memory ($GMEM_MOVEABLE = 0x0002) $pData = _MemGlobalLock($hData) ;translate the handle into a pointer $tMem = DllStructCreate("byte[" & $len & "]", $pData) ;create struct DllStructSetData($tMem, 1, $memBitmap) ;fill struct with image data _MemGlobalUnlock($hData) ;decrements the lock count associated with a memory object that was allocated with GMEM_MOVEABLE $aStream = DllCall("ole32.dll", "int", "CreateStreamOnHGlobal", "handle", $pData, "int", True, "ptr*", 0) $aBitmap = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromStream", "ptr", $aStream[3], "int*", 0) ;Creates a Bitmap object based on an IStream COM interface Local $tVARIANT = DllStructCreate("word vt;word r1;word r2;word r3;ptr data; ptr") Local $aCall = DllCall("oleaut32.dll", "long", "DispCallFunc", "ptr", $aStream[3], "dword", 8 + 8 * @AutoItX64, _ "dword", 4, "dword", 23, "dword", 0, "ptr", 0, "ptr", 0, "ptr", DllStructGetPtr($tVARIANT)) ;release memory from $hStream to avoid memory leak $tMem = 0 Return $aBitmap[2] EndFunc ;==>Load_BMP_From_Mem Thanks for your help. Br, FireFox. Edited June 10, 2011 by FireFox
UEZ Posted June 10, 2011 Posted June 10, 2011 (edited) Try this: expandcollapse popup#include <ButtonConstants.au3> #include <Memory.au3> #include <GDIPlus.au3> _GDIPlus_Startup() Global $bHyperLinkIcon = "0x89504E470D0A1A0A0000000D49484452000000100000001008060000001FF3FF61000000097048597300000B1300000B1301009A9C18000000206348524D00007A25000080830000F9FF000080E9000075300000EA6000003A980000176F925FC546000002BE4944415478DA74934F6C546514C57F0F8ABE10DAF946699852482FA84C21A053F14F0193BEB03065217461883171CB9A0D0B13933E5829B268BA414713D190D060A3954242E48FAF2E6A4B4A79D3D6D0A8C84798D029C47867C0F21A6C3E17135ACDE0DD9EDC73CFBDE71ECF39C7E3BA3675B5BB387B3F2CCE3E8004D2AB5721CD4F85EDDB771EE67FCA7B4C3078F1B2FB7DE13E64005FC1B7581BA371C01B8D6BD8F5CA86B075D3EB3544CB00062F5C70E30B93A8C488180209B02320190119E0E4AFB37C1F15C2272958BEEFEDB7BAA35F6E0476DD2788C960FC56CCDF54725B3B9F56C08EF9E8AA4EA6758C67F536D94D2F0DFD4741F1CE4C6815504113453526D68186687A80E83CC0418C1AD4C48C4ECDD4A8A82BDE5BC010606D843516C5C2740E309008248AF523D457E2897BD4DE60DE8169C194043B0D71C9A02A90E4203168026A224800B4DAF5E799A64582F6D7D68724654CE62026162819ACC4C4FE40B52951644431165ED890AEAE90DE3BB368E3F8E4185F5D7AE0D4EF80E4165A0AB1ADD549AA39A4D4057" $bHyperLinkIcon &= "A0254F9E1D4175ECD1F8C4F8E0174F79EAB0B8DAF18DF56659794C89CC0D8004168DBE8D3D0D800F3B0D22B0278070E1CA2AE6DEB76AE4D5D3D1C8886B99C20D2010944710113192C9620C811E404919645AC7065D4019EE79CA3AFFFB8DBFCEABB7C773A4FFFB73FB13C95A2ABAB0BC954AD1563B853B9CBE0D779EAEBEBD9D3F1325E6A1BE59B43D401586DE49D96D4A3F70647574C0C7FE39D397FD9EDEDDCFDA83CCF0A55502D631221BDFF3700AFF4D733AE4D840F3EFDB29A85BEBECF5CD3E637991C3ECB8D3FE6C836AFE5FDA3FD4BB6013BDA3692DDD24AB6792DABCD4A7EBEBB8CF4C3C252987AF2A75D7A4D1691AAF7F148CCF5C210BBDB9B98A3855AEC4776BE98F2BC7FC7B9B7E7881B9E2853A954D8F29CE3D8479F7BF9FCC70024730F97B0E73D8E7D98F77A7B8EF0CF00EC65488957DC766E0000000049454E44AE426082" $hGUI = GUICreate("Displays an image from memory in button control") $btn = GUICtrlCreateButton("", 175, 175, 40, 40, $BS_BITMAP) $hHBITMAP = Load_BMP_From_Mem($bHyperLinkIcon, True) _WinAPI_DeleteObject(GUICtrlSendMsg($btn, $BM_SETIMAGE, 0, $hHBITMAP)) _WinAPI_DeleteObject($hHBITMAP) _GDIPlus_Shutdown() GUISetState() While 1 $msg = GUIGetMsg() If $msg = -3 Or $msg = $btn Then ExitLoop WEnd GUIDelete($hGUI) Exit Func Load_BMP_From_Mem($mem_image, $hHBITMAP = False) ;coded by UEZ - thanks to progandy for the MemGlobalAlloc and tVARIANT lines Local $memBitmap, $len, $tMem, $hImage, $hData, $pData, $hBitmap, $aStream, $tVARIANT, $aCall, $hHBmp $memBitmap = Binary($mem_image) ;load image saved in variable (memory) and convert it to binary $len = BinaryLen($memBitmap) ;get length of image $hData = _MemGlobalAlloc($len, $GMEM_MOVEABLE) ;allocates movable memory ($GMEM_MOVEABLE = 0x0002) $pData = _MemGlobalLock($hData) ;translate the handle into a pointer $tMem = DllStructCreate("byte[" & $len & "]", $pData) ;create struct DllStructSetData($tMem, 1, $memBitmap) ;fill struct with image data _MemGlobalUnlock($hData) ;decrements the lock count associated with a memory object that was allocated with GMEM_MOVEABLE $aStream = DllCall("ole32.dll", "int", "CreateStreamOnHGlobal", "handle", $pData, "int", True, "ptr*", 0) $hBitmap = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromStream", "ptr", $aStream[3], "int*", 0) ;Creates a Bitmap object based on an IStream COM interface $hBitmap = $hBitmap[2] $tVARIANT = DllStructCreate("word vt;word r1;word r2;word r3;ptr data; ptr") $aCall = DllCall("oleaut32.dll", "long", "DispCallFunc", "ptr", $aStream[3], "dword", 8 + 8 * @AutoItX64, _ "dword", 4, "dword", 23, "dword", 0, "ptr", 0, "ptr", 0, "ptr", DllStructGetPtr($tVARIANT)) ;release memory from $hStream to avoid memory leak $tMem = 0 If $hHBITMAP Then $hHBmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap) _GDIPlus_BitmapDispose($hBitmap) Return $hHBmp EndIf Return $hBitmap EndFunc ;==>Load_BMP_From_Mem Br, UEZ Edited June 10, 2011 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!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
FireFox Posted June 10, 2011 Author Posted June 10, 2011 Try this: expandcollapse popup#include <ButtonConstants.au3> #include <Memory.au3> #include <GDIPlus.au3> _GDIPlus_Startup() Global $bHyperLinkIcon = "0x89504E470D0A1A0A0000000D49484452000000100000001008060000001FF3FF61000000097048597300000B1300000B1301009A9C18000000206348524D00007A25000080830000F9FF000080E9000075300000EA6000003A980000176F925FC546000002BE4944415478DA74934F6C546514C57F0F8ABE10DAF946699852482FA84C21A053F14F0193BEB03065217461883171CB9A0D0B13933E5829B268BA414713D190D060A3954242E48FAF2E6A4B4A79D3D6D0A8C84798D029C47867C0F21A6C3E17135ACDE0DD9EDC73CFBDE71ECF39C7E3BA3675B5BB387B3F2CCE3E8004D2AB5721CD4F85EDDB771EE67FCA7B4C3078F1B2FB7DE13E64005FC1B7581BA371C01B8D6BD8F5CA86B075D3EB3544CB00062F5C70E30B93A8C488180209B02320190119E0E4AFB37C1F15C2272958BEEFEDB7BAA35F6E0476DD2788C960FC56CCDF54725B3B9F56C08EF9E8AA4EA6758C67F536D94D2F0DFD4741F1CE4C6815504113453526D68186687A80E83CC0418C1AD4C48C4ECDD4A8A82BDE5BC010606D843516C5C2740E309008248AF523D457E2897BD4DE60DE8169C194043B0D71C9A02A90E4203168026A224800B4DAF5E799A64582F6D7D68724654CE62026162819ACC4C4FE40B52951644431165ED890AEAE90DE3BB368E3F8E4185F5D7AE0D4EF80E4165A0AB1ADD549AA39A4D4057" $bHyperLinkIcon &= "A0254F9E1D4175ECD1F8C4F8E0174F79EAB0B8DAF18DF56659794C89CC0D8004168DBE8D3D0D800F3B0D22B0278070E1CA2AE6DEB76AE4D5D3D1C8886B99C20D2010944710113192C9620C811E404919645AC7065D4019EE79CA3AFFFB8DBFCEABB7C773A4FFFB73FB13C95A2ABAB0BC954AD1563B853B9CBE0D779EAEBEBD9D3F1325E6A1BE59B43D401586DE49D96D4A3F70647574C0C7FE39D397FD9EDEDDCFDA83CCF0A55502D631221BDFF3700AFF4D733AE4D840F3EFDB29A85BEBECF5CD3E637991C3ECB8D3FE6C836AFE5FDA3FD4BB6013BDA3692DDD24AB6792DABCD4A7EBEBB8CF4C3C252987AF2A75D7A4D1691AAF7F148CCF5C210BBDB9B98A3855AEC4776BE98F2BC7FC7B9B7E7881B9E2853A954D8F29CE3D8479F7BF9FCC70024730F97B0E73D8E7D98F77A7B8EF0CF00EC65488957DC766E0000000049454E44AE426082" $hGUI = GUICreate("Displays an image from memory in button control") $btn = GUICtrlCreateButton("", 175, 175, 40, 40, $BS_BITMAP) $hHBITMAP = Load_BMP_From_Mem($bHyperLinkIcon, True) _WinAPI_DeleteObject(GUICtrlSendMsg($btn, $BM_SETIMAGE, 0, $hHBITMAP)) _WinAPI_DeleteObject($hHBITMAP) _GDIPlus_Shutdown() GUISetState() While 1 $msg = GUIGetMsg() If $msg = -3 Or $msg = $btn Then ExitLoop WEnd GUIDelete($hGUI) Exit Func Load_BMP_From_Mem($mem_image, $hHBITMAP = False) ;coded by UEZ - thanks to progandy for the MemGlobalAlloc and tVARIANT lines Local $memBitmap, $len, $tMem, $hImage, $hData, $pData, $hBitmap, $aStream, $tVARIANT, $aCall, $hHBmp $memBitmap = Binary($mem_image) ;load image saved in variable (memory) and convert it to binary $len = BinaryLen($memBitmap) ;get length of image $hData = _MemGlobalAlloc($len, $GMEM_MOVEABLE) ;allocates movable memory ($GMEM_MOVEABLE = 0x0002) $pData = _MemGlobalLock($hData) ;translate the handle into a pointer $tMem = DllStructCreate("byte[" & $len & "]", $pData) ;create struct DllStructSetData($tMem, 1, $memBitmap) ;fill struct with image data _MemGlobalUnlock($hData) ;decrements the lock count associated with a memory object that was allocated with GMEM_MOVEABLE $aStream = DllCall("ole32.dll", "int", "CreateStreamOnHGlobal", "handle", $pData, "int", True, "ptr*", 0) $hBitmap = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromStream", "ptr", $aStream[3], "int*", 0) ;Creates a Bitmap object based on an IStream COM interface $hBitmap = $hBitmap[2] $tVARIANT = DllStructCreate("word vt;word r1;word r2;word r3;ptr data; ptr") $aCall = DllCall("oleaut32.dll", "long", "DispCallFunc", "ptr", $aStream[3], "dword", 8 + 8 * @AutoItX64, _ "dword", 4, "dword", 23, "dword", 0, "ptr", 0, "ptr", 0, "ptr", DllStructGetPtr($tVARIANT)) ;release memory from $hStream to avoid memory leak $tMem = 0 If $hHBITMAP Then $hHBmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap) _GDIPlus_BitmapDispose($hBitmap) Return $hHBmp EndIf Return $hBitmap EndFunc ;==>Load_BMP_From_Mem Br, UEZ It does not work, I have also tried with a jpg image. Br, FireFox.
guinness Posted June 10, 2011 Posted June 10, 2011 (edited) It worked for me UEZ & I'm using the latest Beta. Edited June 10, 2011 by guinness 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
UEZ Posted June 10, 2011 Posted June 10, 2011 (edited) Hmm, that's strange because I can see the button with the pic in it. Win7 x64, works on both, final and beta! Can somebody else test it whether he/she can see the image within the button? Br, UEZ Edited June 10, 2011 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!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
JeromeB Posted June 10, 2011 Posted June 10, 2011 (edited) Hey, I follow FireFox on this point, it does not work for me too. edit : AutoIt v3.3.6.1, Windows XP x32 Jérôme Edited June 10, 2011 by JeromeB
guinness Posted June 10, 2011 Posted June 10, 2011 (edited) OK, tested using the latest Beta & V3.3.6.1 on Windows 7 x64 and it works. As you can see by saying "It doesn't work" is neither helpful or productive, more details about the system being used can greatly solve problems like this. Edited June 10, 2011 by guinness 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
UEZ Posted June 10, 2011 Posted June 10, 2011 (edited) It doesn't work for me means you see the button but not the picture inside the button, right?I will do some tests in my VMs now.Br,UEZ Edited June 10, 2011 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!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
UEZ Posted June 10, 2011 Posted June 10, 2011 (edited) Well, here the results from my VMs: Windows 2000 x86: NOK Windows XP x86: NOK Windows Server 2003 x86: NOK Windows Server 2008 x86: OK Windows Server 2008 R2 x64:OK Vista x64: OK Windows 7 x64: OK It seems to be a problem with OS < Vista. br, UEZ Edited June 10, 2011 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!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
FireFox Posted June 10, 2011 Author Posted June 10, 2011 Well, here the results from my VMs:Windows 2000 x86: NOKWindows XP x86: NOKWindows Server 2003 x86: NOKWindows Server 2008 x86: OKWindows Server 2008 R2 x64:OKVista x64: OKWindows 7 x64: OKIt seems to be a problem with OS < Vista.br,UEZI'm on Win XP, 32bits. I only see the button but not the picture in it :/Any other solution to make it work?Br, FireFox.
UEZ Posted June 10, 2011 Posted June 10, 2011 (edited) Try this: expandcollapse popup#include <ButtonConstants.au3> #include <Memory.au3> #include <GDIPlus.au3> #include <WindowsConstants.au3> _GDIPlus_Startup() Global $binImage = BinaryImage() $hGUI = GUICreate("Displays an image from memory in button control") $idButton = GUICtrlCreateButton("", 175, 175, 32, 32, $BS_BITMAP) $hButton = GUICtrlGetHandle($idButton) $hHBITMAP = Load_BMP_From_Mem($binImage, True) _WinAPI_DeleteObject(_SendMessage($hButton, $BM_SETIMAGE, 0, $hHBITMAP)) _WinAPI_UpdateWindow($hButton) _GDIPlus_Shutdown() GUISetState() While 1 $msg = GUIGetMsg() If $msg = -3 Or $msg = $idButton Then ExitLoop WEnd _WinAPI_DeleteObject($hHBITMAP) GUIDelete($hGUI) Exit ;====================================================================================== ; Function Name: Load_BMP_From_Mem ; Description: Loads a image which is saved as a binary string and converts it to a bitmap or hbitmap ; ; Parameters: $mem_image: the binary string which contains any valid image which is supported by GDI+ ; Optional: $hHBITMAP: if false a bitmap will be created, if true a hbitmap will be created ; ; Remark: hbitmap format is used generally for GUI internal images ; ; Requirement(s): GDIPlus.au3, Memory.au3 ; Return Value(s): Success: handle to bitmap or hbitmap, Error: 0 ; Error codes: 1: $mem_image is not a binary string ; ; Author(s): UEZ ; Additional Code: thanks to progandy for the MemGlobalAlloc and tVARIANT lines ; Version: v0.95 Build 2011-06-11 Beta ;======================================================================================= Func Load_BMP_From_Mem($mem_image, $hHBITMAP = False) If Not IsBinary($mem_image) Then Return SetError(1, 0, 0) Local $declared = True If Not $ghGDIPDll Then _GDIPlus_Startup() $declared = False EndIf Local Const $memBitmap = Binary($mem_image) ;load image saved in variable (memory) and convert it to binary Local Const $len = BinaryLen($memBitmap) ;get length of image Local Const $hData = _MemGlobalAlloc($len, $GMEM_MOVEABLE) ;allocates movable memory ($GMEM_MOVEABLE = 0x0002) Local Const $pData = _MemGlobalLock($hData) ;translate the handle into a pointer Local $tMem = DllStructCreate("byte[" & $len & "]", $pData) ;create struct DllStructSetData($tMem, 1, $memBitmap) ;fill struct with image data _MemGlobalUnlock($hData) ;decrements the lock count associated with a memory object that was allocated with GMEM_MOVEABLE Local $hStream = DllCall("ole32.dll", "int", "CreateStreamOnHGlobal", "handle", $pData, "int", True, "ptr*", 0) $hStream = $hStream[3] Local $hBitmap = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromStream", "ptr", $hStream, "int*", 0) ;Creates a Bitmap object based on an IStream COM interface $hBitmap = $hBitmap[2] Local Const $tVARIANT = DllStructCreate("word vt;word r1;word r2;word r3;ptr data; ptr") DllCall("oleaut32.dll", "long", "DispCallFunc", "ptr", $hStream, "dword", 8 + 8 * @AutoItX64, _ "dword", 4, "dword", 23, "dword", 0, "ptr", 0, "ptr", 0, "ptr", DllStructGetPtr($tVARIANT)) ;release memory from $hStream to avoid memory leak $tMem = 0 If $hHBITMAP Then Local Const $hHBmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap) _GDIPlus_BitmapDispose($hBitmap) If Not $declared Then _GDIPlus_Shutdown() Return $hHBmp EndIf If Not $declared Then _GDIPlus_Shutdown() Return $hBitmap EndFunc ;==>Load_BMP_From_Mem Func BinaryImage() Local _ $BinaryString = "0x89504E470D0A1A0A0000000D49484452000000100000001008060000001FF3FF61000000097048597300000B1300000B1301009A9C18000000206348524D00007A25000080830000F9FF000080E9000075300000EA6000003A980000176F925FC546000002BE4944415478DA74934F6C546514C57F0F8ABE10DAF946699852482FA84C21A053F14F0193BEB03065217461883171CB9A0D0B13933E5829B268BA414713D190D060A3954242E48FAF2E6A4B4A79D3D6D0A8C84798D029C47867C0F21A6C3E17135ACDE0DD9EDC73CFBDE71ECF39C7E3BA3675B5BB387B3F2CCE3E8004D2AB5721CD4F85EDDB771EE67FCA7B4C3078F1B2FB7DE13E64005FC1B7581BA371C01B8D6BD8F5CA86B075D3EB3544CB00062F5C70E30B93A8C488180209B02320190119E0E4AFB37C1F15C2272958BEEFEDB7BAA35F6E0476DD2788C960FC56CCDF54725B3B9F56C08EF9E8AA4EA6758C67F536D94D2F0DFD4741F1CE4C6815504113453526D68186687A80E83CC0418C1AD4C48C4ECDD4A8A82BDE5BC010606D843516C5C2740E309008248AF523D457E2897BD4DE60DE8169C194043B0D71C9A02A90E4203168026A224800B4DAF5E799A64582F6D7D68724654CE62026162819ACC4C4FE40B52951644431165ED890AEAE90DE3BB368E3F8E4185F5D7AE0D4EF80E4165A0AB1ADD549AA39A4D4057" $BinaryString &= "A0254F9E1D4175ECD1F8C4F8E0174F79EAB0B8DAF18DF56659794C89CC0D8004168DBE8D3D0D800F3B0D22B0278070E1CA2AE6DEB76AE4D5D3D1C8886B99C20D2010944710113192C9620C811E404919645AC7065D4019EE79CA3AFFFB8DBFCEABB7C773A4FFFB73FB13C95A2ABAB0BC954AD1563B853B9CBE0D779EAEBEBD9D3F1325E6A1BE59B43D401586DE49D96D4A3F70647574C0C7FE39D397FD9EDEDDCFDA83CCF0A55502D631221BDFF3700AFF4D733AE4D840F3EFDB29A85BEBECF5CD3E637991C3ECB8D3FE6C836AFE5FDA3FD4BB6013BDA3692DDD24AB6792DABCD4A7EBEBB8CF4C3C252987AF2A75D7A4D1691AAF7F148CCF5C210BBDB9B98A3855AEC4776BE98F2BC7FC7B9B7E7881B9E2853A954D8F29CE3D8479F7BF9FCC70024730F97B0E73D8E7D98F77A7B8EF0CF00EC65488957DC766E0000000049454E44AE426082" Return Binary($BinaryString) EndFunc It shows the image within the button but not transparent; transparency probably only on Vista+ os. Br, UEZ Edited June 12, 2011 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!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
FireFox Posted June 10, 2011 Author Posted June 10, 2011 Try this: expandcollapse popup#include <ButtonConstants.au3> #include <Memory.au3> #include <GDIPlus.au3> #include <WindowsConstants.au3> _GDIPlus_Startup() Global $binImage = BinaryImage() $hGUI = GUICreate("Displays an image from memory in button control") $idButton = GUICtrlCreateButton("", 175, 175, 32, 32, $BS_BITMAP) $hButton = GUICtrlGetHandle($idButton) $hHBITMAP = Load_BMP_From_Mem($binImage, True) _WinAPI_DeleteObject(_SendMessage($hButton, $BM_SETIMAGE, 0, $hHBITMAP)) _WinAPI_UpdateWindow($hButton) _GDIPlus_Shutdown() GUISetState() While 1 $msg = GUIGetMsg() If $msg = -3 Or $msg = $idButton Then ExitLoop WEnd _WinAPI_DeleteObject($hHBITMAP) GUIDelete($hGUI) Exit Func Load_BMP_From_Mem($mem_image, $hHBITMAP = False) ;coded by UEZ - thanks to progandy for the MemGlobalAlloc and tVARIANT lines Local $memBitmap, $len, $tMem, $hImage, $hData, $pData, $hBitmap, $hStream, $tVARIANT, $aCall, $hHBmp $memBitmap = Binary($mem_image) ;load image saved in variable (memory) and convert it to binary $len = BinaryLen($memBitmap) ;get length of image $hData = _MemGlobalAlloc($len, $GMEM_MOVEABLE) ;allocates movable memory ($GMEM_MOVEABLE = 0x0002) $pData = _MemGlobalLock($hData) ;translate the handle into a pointer $tMem = DllStructCreate("byte[" & $len & "]", $pData) ;create struct DllStructSetData($tMem, 1, $memBitmap) ;fill struct with image data _MemGlobalUnlock($hData) ;decrements the lock count associated with a memory object that was allocated with GMEM_MOVEABLE $hStream = DllCall("ole32.dll", "int", "CreateStreamOnHGlobal", "handle", $pData, "int", True, "ptr*", 0) $hStream = $hStream[3] $hBitmap = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromStream", "ptr", $hStream, "int*", 0) ;Creates a Bitmap object based on an IStream COM interface $hBitmap = $hBitmap[2] $tVARIANT = DllStructCreate("word vt;word r1;word r2;word r3;ptr data; ptr") $aCall = DllCall("oleaut32.dll", "long", "DispCallFunc", "ptr", $hStream, "dword", 8 + 8 * @AutoItX64, _ "dword", 4, "dword", 23, "dword", 0, "ptr", 0, "ptr", 0, "ptr", DllStructGetPtr($tVARIANT)) ;release memory from $hStream to avoid memory leak $tMem = 0 If $hHBITMAP Then $hHBmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap) _GDIPlus_BitmapDispose($hBitmap) Return $hHBmp EndIf Return $hBitmap EndFunc ;==>Load_BMP_From_Mem Func BinaryImage() Local _ $BinaryString = "0x89504E470D0A1A0A0000000D49484452000000100000001008060000001FF3FF61000000097048597300000B1300000B1301009A9C18000000206348524D00007A25000080830000F9FF000080E9000075300000EA6000003A980000176F925FC546000002BE4944415478DA74934F6C546514C57F0F8ABE10DAF946699852482FA84C21A053F14F0193BEB03065217461883171CB9A0D0B13933E5829B268BA414713D190D060A3954242E48FAF2E6A4B4A79D3D6D0A8C84798D029C47867C0F21A6C3E17135ACDE0DD9EDC73CFBDE71ECF39C7E3BA3675B5BB387B3F2CCE3E8004D2AB5721CD4F85EDDB771EE67FCA7B4C3078F1B2FB7DE13E64005FC1B7581BA371C01B8D6BD8F5CA86B075D3EB3544CB00062F5C70E30B93A8C488180209B02320190119E0E4AFB37C1F15C2272958BEEFEDB7BAA35F6E0476DD2788C960FC56CCDF54725B3B9F56C08EF9E8AA4EA6758C67F536D94D2F0DFD4741F1CE4C6815504113453526D68186687A80E83CC0418C1AD4C48C4ECDD4A8A82BDE5BC010606D843516C5C2740E309008248AF523D457E2897BD4DE60DE8169C194043B0D71C9A02A90E4203168026A224800B4DAF5E799A64582F6D7D68724654CE62026162819ACC4C4FE40B52951644431165ED890AEAE90DE3BB368E3F8E4185F5D7AE0D4EF80E4165A0AB1ADD549AA39A4D4057" $BinaryString &= "A0254F9E1D4175ECD1F8C4F8E0174F79EAB0B8DAF18DF56659794C89CC0D8004168DBE8D3D0D800F3B0D22B0278070E1CA2AE6DEB76AE4D5D3D1C8886B99C20D2010944710113192C9620C811E404919645AC7065D4019EE79CA3AFFFB8DBFCEABB7C773A4FFFB73FB13C95A2ABAB0BC954AD1563B853B9CBE0D779EAEBEBD9D3F1325E6A1BE59B43D401586DE49D96D4A3F70647574C0C7FE39D397FD9EDEDDCFDA83CCF0A55502D631221BDFF3700AFF4D733AE4D840F3EFDB29A85BEBECF5CD3E637991C3ECB8D3FE6C836AFE5FDA3FD4BB6013BDA3692DDD24AB6792DABCD4A7EBEBB8CF4C3C252987AF2A75D7A4D1691AAF7F148CCF5C210BBDB9B98A3855AEC4776BE98F2BC7FC7B9B7E7881B9E2853A954D8F29CE3D8479F7BF9FCC70024730F97B0E73D8E7D98F77A7B8EF0CF00EC65488957DC766E0000000049454E44AE426082" Return Binary($BinaryString) EndFunc It shows the image within the button but not transparent; transparency probably only on Vista+ os. Br, UEZ Thanks, it works Br, FireFox.
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