Quantcast
Channel: AutoIt v3 - General Help and Support
Viewing all articles
Browse latest Browse all 12506

Cannot set a PNG to a button

$
0
0
Hey, I don't know what is happening but It doesn't displays the PNG inside the button ctrl
AutoIt         
#include <GDIPlus.au3> #include <Memory.au3> #include <WindowsConstants.au3> #NoTrayIcon Global Const $STM_SETIMAGE = 0x0172, $BM_SETIMAGE = 0xF7, $BS_BITMAP = 0x0080 Global $bico = "0x89504E470D0A1A0A0000000D49484452000000100000001008060000001FF3FF61000000017352474200AECE1CE" & _         "90000000467414D410000B18F0BFC6105000000E249444154384F9D93B11183300C45198559E8E92929188B9E31684241E58" & _         "CC0064E1A5AC74F67F9841B82B9D321E4AF6759C84D533CE7798ED1D668A1306263A9CFDF71B18DE634E9388ED0759D18BE81" & _         "A1692FA094EC976509FBBE8B185F01F33C4B8C35E2D1F717083BDB84699A42DFF719804F4C8109E2A48A7466A1ABE0EEAD554" & _         "A4F6CC3741776DC5E5BF8F8AF18BE5684C6F46305204DE29C2AD264E7DE01530895A141AB8D1540593209246A5C21A58EDC47" & _         "8061182E9B6500E5D0D97F8F80D61E214F5D6D1319DDFADF9866A17E9012807B503FCA06527799ECCD7A7A9D7F919E81F9F48" & _         "210970000000049454E44AE426082" _GDIPlus_Startup() $Form1 = GUICreate("Example", 300, 200, -1, -1, BitOR($WS_THICKFRAME,$WS_SYSMENU)) $btn = GUICtrlCreateButton("",130,70,32,32,$BS_BITMAP) $hButton = GUICtrlGetHandle($btn) $hHBITMAP = Load_BMP_From_Mem($bico, True) _WinAPI_DeleteObject(_SendMessage($hButton, $BM_SETIMAGE, 0, $hHBITMAP)) _WinAPI_UpdateWindow($hButton) _GDIPlus_Shutdown() GUISetState()     While 1     $nMsg = GUIGetMsg()     Switch $nMsg         Case -3             GUIDelete()             _WinAPI_DeleteObject($hHBITMAP)             Exit     EndSwitch WEnd ;====================================================================================== ; 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 $__g_hGDIPDll 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($__g_hGDIPDll, "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
I guess this worked before :s

Viewing all articles
Browse latest Browse all 12506

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>