JohnOne Posted April 9, 2014 Share Posted April 9, 2014 (edited) Cant for the life of me figure out why a click on my makeshift button does not register. If the image is loaded from file it registers just fine. (the base64 string is just a png image) Can anyone see my mistake/omission? (Please excuse the terrible state of code, just threw it together to test funcs found around the forum. expandcollapse popup;#include <Array.au3> ;#include <ButtonConstants.au3> #include <GDIPlus.au3> #include <GUIConstantsEx.au3> ;#include <MsgBoxConstants.au3> #include <StaticConstants.au3> #include <WinAPIEx.au3> #include <Memory.au3> _GDIPlus_Startup() Local $Base64String $Base64String &= 'iVBORw0KGgoAAAANSUhEUgAAADwAAAAtCAMAAADFqPh+AAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAAAYNQTFRFAAAK/fnu7+vj1dPPxMPOq6usp6enm5ucpaWk6+jg6ebfn5+glZWYf36ESklkJiYzHR0pBQUPAAAJGxsnJiYxi4uPr6+w4d7Ze3qFFxckSUl2W1u9ZWXGbGzncXHvXl69ray2RERlcHDtExMf9fHoTExrSkmIaGjhdHTmkZHeoKDlqqrrsLDtiYnao6Oi+vbskJCUOjprZ2fXwcHsISEu+fXrSEiauLjvTEy9V1fAnJzjr6/sl5fgUFC+pqbooaGhQkKqZWXNQkK1MzOWRUW4c3PKe3vSMzOdNzdz0M7PhISJJCQwNTWGMTGqjo3VLi6q//vw5OHcyMfPKyuolJPPCgoUIyOeJSWgc3PD29nVHh6YnZ3FGBiUHByWMTGkERGPExORIiKbCQmJDAyLFRWTAABpBgaGAAB2AABkPz9nAAB/AABwAABdAABRAAB6AABHDQ0XAABFFRUmAAA3AAAyAAA9AABWAAAvAABSAAAtAAAnEBAaAAAhAAAbAAAVAAARAAAKMwwy/wAAAAF0Uk5TAEDm2GYAAAABYktHRACIBR1IAAAACXBIWXMAAABIAAAASABGyWs+AAADUklEQVRIx5XW61/SUBgH8DHGNmEbm8BpA4zVFC8FAoENyzBCUzFFS0uNt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J0RVh0Y29tbWVudAAiQ3JlYXRlZCB3aXRoIENoaW1wbHkuY29tIiIEkkgAAAAldEVYdGRhdGU6Y3JlYXRlADIwMTQtMDQtMDlUMDc6MDM6NDgt' $Base64String &= 'MDQ6MDBqEUZ/AAAAJXRFWHRkYXRlOm1vZGlmeQAyMDE0LTA0LTA5VDA3OjAzOjQ4LTA0OjAwG0z+wwAAAABJRU5ErkJggg==' Local $bString = Binary(_Base64Decode($Base64String)) $hHBITMAP = Load_BMP_From_Mem($bString, True) $hImage = _GDIPlus_BitmapCreateFromHBITMAP($hHBITMAP) Local $iH = _GDIPlus_ImageGetHeight($hImage) Local $iW = _GDIPlus_ImageGetWidth($hImage) Global Const $hGUI = GUICreate("Test", 300, 200), $STM_SETIMAGE = 0x0172, $IMAGE_BITMAP = 0 GUISetBkColor(0xfffbf0) Global Const $iPic = GUICtrlCreatePic("", 10, 10, $iW, $iH, $SS_BITMAP) ;Global Const $hImage = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\image_633781.png") ;Global Const $hHBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage) _WinAPI_DeleteObject(GUICtrlSendMsg($iPic, $STM_SETIMAGE, $IMAGE_BITMAP, $hHBITMAP)) GUISetState() Do Switch GUIGetMsg() Case $GUI_EVENT_CLOSE _Exit() Case $iPic MsgBox(0, "Test", "Button was pressed") EndSwitch Until False Func _Exit() _WinAPI_DeleteObject($hHBITMAP) _GDIPlus_ImageDispose($hImage) _GDIPlus_Shutdown() GUIDelete() Exit EndFunc ;==>_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 ;Code below was generated by: 'File to Base64 String' Code Generator v1.12 Build 2013-03-25 Func _Base64Decode($sB64String) Local $struct = DllStructCreate("int") Local $a_Call = DllCall("Crypt32.dll", "int", "CryptStringToBinary", "str", $sB64String, "int", 0, "int", 1, "ptr", 0, "ptr", DllStructGetPtr($struct, 1), "ptr", 0, "ptr", 0) If @error Or Not $a_Call[0] Then Return SetError(1, 0, "") Local $a = DllStructCreate("byte[" & DllStructGetData($struct, 1) & "]") $a_Call = DllCall("Crypt32.dll", "int", "CryptStringToBinary", "str", $sB64String, "int", 0, "int", 1, "ptr", DllStructGetPtr($a), "ptr", DllStructGetPtr($struct, 1), "ptr", 0, "ptr", 0) If @error Or Not $a_Call[0] Then Return SetError(2, 0, "") Return DllStructGetData($a, 1) EndFunc ;==>_Base64Decode Edited April 9, 2014 by JohnOne AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Solution UEZ Posted April 9, 2014 Solution Share Posted April 9, 2014 Try this John: expandcollapse popup#include <GDIPlus.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WinAPIEx.au3> #include <Memory.au3> _GDIPlus_Startup() Local $Base64String $Base64String &= 'iVBORw0KGgoAAAANSUhEUgAAADwAAAAtCAMAAADFqPh+AAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAAAYNQTFRFAAAK/fnu7+vj1dPPxMPOq6usp6enm5ucpaWk6+jg6ebfn5+glZWYf36ESklkJiYzHR0pBQUPAAAJGxsnJiYxi4uPr6+w4d7Ze3qFFxckSUl2W1u9ZWXGbGzncXHvXl69ray2RERlcHDtExMf9fHoTExrSkmIaGjhdHTmkZHeoKDlqqrrsLDtiYnao6Oi+vbskJCUOjprZ2fXwcHsISEu+fXrSEiauLjvTEy9V1fAnJzjr6/sl5fgUFC+pqbooaGhQkKqZWXNQkK1MzOWRUW4c3P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Y0WScEE0xNZ/P6+VL++qJ1XjPCEMo7iXul78Mi3SRMJNty/bsxyZtT+t46KfwYFtWiSLDdbtV/mGmS6vuc8fil8yFK+IClLy9a9XNTkj8Oq9+hXdJXHxL1VH9eylLdCseCztcTrwrSELndkqw1q3i3194iOLn1X2QBQ/odY+NK/h8XQgKdvO5VLNe+sK3NsfjAgDDvYrlL2zgSPdD1Z074aUuDC6C67u4AiSL9ywa66NJPBmrL8kw1fL9v0GywPDoykyhgkKCuaOaPKYa+ooDxNKTNYdgULfjTjb8j9tJ+gWYBCizGuB3EgxlMgIwyAZIAWE6A2p0znj3jyuzp1s+e/wA7MayZVXjA0AAAACJ0RVh0Y29tbWVudAAiQ3JlYXRlZCB3aXRoIENoaW1wbHkuY29tIiIEkkgAAAAldEVYdGRhdGU6Y3JlYXRlADIwMTQtMDQtMDlUMDc6MDM6NDgt' $Base64String &= 'MDQ6MDBqEUZ/AAAAJXRFWHRkYXRlOm1vZGlmeQAyMDE0LTA0LTA5VDA3OjAzOjQ4LTA0OjAwG0z+wwAAAABJRU5ErkJggg==' $hHBITMAP = _GDIPlus_BitmapCreateFromMemory(Binary(_Base64Decode($Base64String)), True) $aDim = _WinAPI_BitmapGetDim($hHBITMAP) Local $iH = $aDim[0] Local $iW = $aDim[1] Global Const $hGUI = GUICreate("Test", 300, 200), $STM_SETIMAGE = 0x0172 GUISetBkColor(0xfffbf0) Global Const $iPic = GUICtrlCreatePic("", 10, 10, $iW, $iH) _WinAPI_DeleteObject(GUICtrlSendMsg($iPic, $STM_SETIMAGE, $IMAGE_BITMAP, $hHBITMAP)) GUISetState() Do Switch GUIGetMsg() Case $GUI_EVENT_CLOSE _Exit() Case $iPic MsgBox(0, "Test", "Button was pressed") EndSwitch Until False Func _Exit() _WinAPI_DeleteObject($hHBITMAP) _GDIPlus_Shutdown() GUIDelete() Exit EndFunc ;==>_Exit Func _WinAPI_BitmapGetDim($hHBitmap) Local $tDim = DllStructCreate($tagBITMAP) DllCall("gdi32.dll", "int", "GetObject", "int", $hHBitmap, "int", DllStructGetSize($tDim), "struct*", $tDim) If @error Then Return SetError(1, 0, 0) Local $aDim[2] = [$tDim.bmWidth, $tDim.bmHeight] Return $aDim EndFunc Func _Base64Decode($sB64String) Local $struct = DllStructCreate("int") Local $a_Call = DllCall("Crypt32.dll", "int", "CryptStringToBinary", "str", $sB64String, "int", 0, "int", 1, "ptr", 0, "ptr", DllStructGetPtr($struct, 1), "ptr", 0, "ptr", 0) If @error Or Not $a_Call[0] Then Return SetError(1, 0, "") Local $a = DllStructCreate("byte[" & DllStructGetData($struct, 1) & "]") $a_Call = DllCall("Crypt32.dll", "int", "CryptStringToBinary", "str", $sB64String, "int", 0, "int", 1, "ptr", DllStructGetPtr($a), "ptr", DllStructGetPtr($struct, 1), "ptr", 0, "ptr", 0) If @error Or Not $a_Call[0] Then Return SetError(2, 0, "") Return DllStructGetData($a, 1) EndFunc ;==>_Base64Decode Br, UEZ JohnOne 1 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...
JohnOne Posted April 9, 2014 Author Share Posted April 9, 2014 Nice one! Works a treat. Thanks UEZ. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. 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