Jump to content

set binary png image to button ctrl


Recommended Posts

hi,

I want to set the binary data of a png image to a button ctrl.

Here is my script which does not work :

#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 by FireFox
Link to comment
Share on other sites

Try this:

#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 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

Try this:

#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.

Link to comment
Share on other sites

It worked for me UEZ & I'm using the latest Beta.

Edited 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 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: 22/04/2018

Link to comment
Share on other sites

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 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

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 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 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: 22/04/2018

Link to comment
Share on other sites

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 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

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 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

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

I'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.

Link to comment
Share on other sites

Try this:

#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 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

Try this:

#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 :huh2:

Br, FireFox.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...