Jump to content

Set image string directly to Control


ProgAndy
 Share

Recommended Posts

Zedna asked me to post this Script in Example-Forum. This Script uses some GDI(Plus)-functions to set image directly to Control., so you can provide them in Script code, when no Transparency is required.

Update: This code is outdated and has memory leaks. Please go to for updated functions.

#include <GUIConstants.au3>
#include "BinaryImage.au3"

#region - GUI Create
GUICreate('Image from Stream smile.gif',200,80,-1,-1,$WS_CAPTION+$WS_SYSMENU)
;#~ Start image Creation
$picbox = GUICtrlCreatePic("", 10,10,64,63)
GUICtrlSetCursor(-1,0)
$LOGO = _LOGOBin()
_SetImageBinaryToCtrl($picbox,$LOGO)
;#~ end image Creation
GUICtrlCreateLabel("www.progandy.de.tt",80,20)
$zedna = GUICtrlCreateLabel("Zedna on autoitscript.com",80,40)
GUICtrlSetCursor(-1,0)

GUISetState()
#endregion


#region - GUI SelectLoop
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
        Case $msg = $picbox
            ShellExecute("www.progandy.de.tt")
        Case $msg = $zedna
            ShellExecute("http://www.autoitscript.com/forum/index.php?showuser=6483")
    EndSelect
WEnd
#endregion
Func _LOGOBin()
    Local $FileName = "0xFFD8FFE000104A46494600010101006000600000FFE1001645786966000049492A0008000000000000000000FFDB004300080606070605080707070909080A"
   $FileName &= "0C140D0C0B0B0C1912130F141D1A1F1E1D1A1C1C20242E2720222C231C1C2837292C30313434341F27393D38323C2E333432FFDB0043010909090C0B0C180D0D"
   $FileName &= "1832211C213232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232FFC0001108003F0040"
   $FileName &= "03012200021101031101FFC4001F0000010501010101010100000000000000000102030405060708090A0BFFC400B5100002010303020403050504040000017D"
   $FileName &= "01020300041105122131410613516107227114328191A1082342B1C11552D1F02433627282090A161718191A25262728292A3435363738393A43444546474849"
   $FileName &= "4A535455565758595A636465666768696A737475767778797A838485868788898A92939495969798999AA2A3A4A5A6A7A8A9AAB2B3B4B5B6B7B8B9BAC2C3C4C5"
   $FileName &= "C6C7C8C9CAD2D3D4D5D6D7D8D9DAE1E2E3E4E5E6E7E8E9EAF1F2F3F4F5F6F7F8F9FAFFC4001F0100030101010101010101010000000000000102030405060708"
   $FileName &= "090A0BFFC400B51100020102040403040705040400010277000102031104052131061241510761711322328108144291A1B1C109233352F0156272D10A162434"
   $FileName &= "E125F11718191A262728292A35363738393A434445464748494A535455565758595A636465666768696A737475767778797A82838485868788898A9293949596"
   $FileName &= "9798999AA2A3A4A5A6A7A8A9AAB2B3B4B5B6B7B8B9BAC2C3C4C5C6C7C8C9CAD2D3D4D5D6D7D8D9DAE2E3E4E5E6E7E8E9EAF2F3F4F5F6F7F8F9FAFFDA000C0301"
   $FileName &= "0002110311003F00F78DDC64D729ABF8BFEC17DF678EDE699B04E2242C703D80F7AE9657DB1393D00AE37C29FE97E30D62F32D886148978E097624FE5B17F3AF"
   $FileName &= "0B30E7AF8B8616326935776FC0EFC2538724EACD5D4509FF0009CCFF00F40CBFFF00C077FF000A07C418609116EE196DF79C2F9CA5371F6CF5AED26B88EDE332"
   $FileName &= "CD2A471AFDE791B007E2698925BDEDBEE4314F04808C821D5877E7A1A1E4CD7C35A57F52BEB343AD1D3D59574CD6ADB5240617539E7835A7BABCF759D363F0CE"
   $FileName &= "B3697DA78F2ED2EA429242B9DA8FD723B007D3B62B7B53F14DB68ED6AB7322A89D495C9C1E3AFF003ACE19855C1D4950C4FBD6D9ADC2AE0D4F96543552FBCE93"
   $FileName &= "26973EF58963E23B1BE00472A96EBD6B5C3E4023A1AF530B8FA189FE1BD7B1C5528CE93E59AB14AFE51158CAE4FF0009EB5CE780A33FD9B7D78C4E6E6E98807D"
   $FileName &= "1405AD0F13DC791A248DBB048A3C2D07D93C316119565668C48CA7A82DC915C186FDEE67567FCA923B57B9817FDE7F912F8934B9F5AD20D9413C7096914B1917"
   $FileName &= "20A8392314BE1ED1D740D256C84C653E63485F18E49CE00EC2A8EBBE25974AD4A0B1B6B2FB54D2446565DFB768CE07F5FCAB34F897C4374A63B7D262818E30F2"
   $FileName &= "316C7AF15D75B1B84A355BA92B4874B0D89A941434507AEE897C6D73E7DC69BA544D995A6F39D476400807F13FC8D5CD575CB7D2960B3BBD365BC89E2FDE9455"
   $FileName &= "70BDB1B5BAE6A9E99A47F6619F59D6EE8BCA17749349D71E83F4C0141D2F45F165F3EA16D7F72D1A9D93440B2678F978600AF1F9D7954A55B158A788A4924B45"
   $FileName &= "7EBDCE9B518C6309DDC637BB5DD95DB45D175DB77BDF0D4B1D9DF47FF2C946C5CE3EEB20E83B640FCEB47C2FAD4B705EC6F55E2BA84EC747EA0FF9FC2B92568B"
   $FileName &= "C3DE35DD64EE208A68EDA42E4B16DD8C8CFD4823E95D0EB2A2CFC71652C7F29B984EF007F75B00FE4696323FBB78986938357B7537AB4AE952936E32578DF75E"
   $FileName &= "44BE3AF35F4A448E36656E084EB8EF491F8D34C8618E34B5D480450A33067B7FBD5D21F2DD364881D7B66A3FB2D9FF00CFBA9F6AD961F1F86AB51D049A93BEE7"
   $FileName &= "9D0C4D074634EAC5E9E76392B0B93AEF8C9EF9229D2DD2258E31326D23B9F5EE6ACEADE21BEB2F16C3A6431C696ECF17CE63C9756C86FD476AD2D76EA6D22C05"
   $FileName &= "C69B6F197C82491FC3DC63D6B175FD3FFE128D32CF58D20FFA4AAE55720332F5DB9E9B95B18CFA9F5AE5C35275E756A54B3A975A5B6B1DB4E54EA4A329AB536B"
   $FileName &= "955DECFCCB1E3B9716BA7248C040D724C99E9F2A9229FE0780269771A9C9841772EF5623198C7DD3F4EB8F635969E398E583ECFA9E9624B98DB0E8CC000C3D55"
   $FileName &= "F907F95476FE3AB9B69E492F2DE17B565022821700C78FE79FD31C57A4AAE1A388559CBA5AD6D8D3EAB89FAAFB050D9EF75AFA143C3D04BE22D623B8F2CBC1F6"
   $FileName &= "937770EC721792513DCF41EC0574334DFDB3E39022F9A1B15F2B781D589CB0FC38AA5A8EBDAA7F621974ED29F4BD39884F3D940701BBAA81C0E8371F5AE83C2F"
   $FileName &= "A759E9FA6AC96E779719DDEA7D4D7062D592C253D5D4776F61D7AAE29D79AB69CA92D6DDEE69EEA37549F64B8FF9E47FEFA1FE349F64B8FF009E47FEFA1FE35F"
   $FileName &= "507CE0D611CD118661943EA3A572B2691AAF87EE64B8D25849048774903728DEFEC7DC7E39E2BADFB25C8FF9647FEFA1FE34E586ED78F2C91E8483FD6BC9C5E5"
   $FileName &= "CE753DBD0972CFF067561F172A49C5ABA7D0E324F10D9DC129AC6812E4F0488D6507078F7E94D8B5BD16CCE74DD0253213CE2D82631D0E4D766D661C1F32C816"
   $FileName &= "F5C8FF001A45B054E63B200FD56B99ACCF6718B7DCEB58BC35BE17E977638E921D7BC4E0C37282CEC5FAC49C961FED377EDD2BAAB5B48EC2C92D636CEDEBED56"
   $FileName &= "DA2BB23023DA3D148FF1A8FECB71FF003C8FFDF43FC6B7C365F515555F152BC96DD91CF88C5BA9154E2B963D91FFD9"
   Return $FileName
EndFunc
;Authors: Prog@ndy, based on code by Zedna
Func _SetImageBinaryToCtrl($CtrlId, ByRef $Binary)
    Local $picdata = Binary($Binary) ; Fetch the Data
    Local $piclength = BinaryLen($picdata) ; Get Length

    Local $picstruct = DllStructCreate("byte[" & $piclength & "]")
        DllStructSetData($picstruct,1,$picdata)
        Local $picmemory = DllStructGetPtr($picstruct)
        _SetMemoryImageToCtrl($CtrlId, $picmemory, $piclength)
        DllStructSetData($picstruct,1,0)
    $picstruct = ""
EndFunc

; Authors: Zedna, based on code by Prog@ndy
Func _SetMemoryImageToCtrl($CtrlId, $Pointer, $nSize)
    Local $hData, $pData, $pStream, $pBitmap, $hBitmap
        ; use GDI+ for converting to bitmap first
    $hData = _MemGlobalAlloc($nSize,2)
    $pData = _MemGlobalLock($hData)
    _MemMoveMemory($Pointer,$pData,$nSize)
    _MemGlobalUnlock($hData)
    $pStream = DllCall( "ole32.dll","int","CreateStreamOnHGlobal", "int",$hData, "long",1, "Int*",0)
    $pStream = $pStream[3]
    _GDIPlus_Startup()
    $pBitmap = DllCall($ghGDIPDll,"int","GdipCreateBitmapFromStream", "ptr",$pStream, "int*",0)
    $pBitmap = $pBitmap[2]
    $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($pBitmap)
    _SetBitmapToCtrl($CtrlId, $hBitmap)
    If @error Then SetError(3, 0, 0)
    _GDIPlus_BitmapDispose($pBitmap)
    _GDIPlus_Shutdown()
    _WinAPI_DeleteObject($pStream)
    _MemGlobalFree($hData)
EndFunc

; internal helper function
; Out of resources.au3 :) 
Func _SetBitmapToCtrl($CtrlId, $hBitmap)
    Local Const $STM_SETIMAGE = 0x0172
    Local Const $IMAGE_BITMAP = 0
    Local Const $SS_BITMAP = 0xE
    Local Const $GWL_STYLE = -16

    Local $hWnd = GUICtrlGetHandle($CtrlId)
    If $hWnd = 0 Then Return SetError(1, 0, 0)
        ; set SS_BITMAP style to control
    Local $oldStyle = DllCall("user32.dll", "long", "GetWindowLong", "hwnd", $hWnd, "int", $GWL_STYLE)
    If @error Then Return SetError(2, 0, 0)
    DllCall("user32.dll", "long", "SetWindowLong", "hwnd", $hWnd, "int", $GWL_STYLE, "long", BitOR($oldStyle[0], $SS_BITMAP))
    If @error Then Return SetError(3, 0, 0)
        Local $oldBmp = DllCall("user32.dll", "hwnd", "SendMessage", "hwnd", $hWnd, "int", $STM_SETIMAGE, "int", $IMAGE_BITMAP, "int", $hBitmap)
    If @error Then Return SetError(4, 0, 0)
    If $oldBmp[0] <> 0 Then _WinAPI_DeleteObject($oldBmp[0])
    Return 1
EndFunc
Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

Thanks ProgAndy for putting all stuff together!

Just for general info:

Here is original post about that http://www.autoitscript.com/forum/index.ph...st&p=519336

This UDF/princip can be used when you need to set any image from memory to GUI picture control

for example when you get image from database to variable (memory).

Also another note:

Original code of _SetBitmapToCtrl() that I used in my resources UDF comes from Larry - SendMessage & STM_SETIMAGE

I added part about setting SS_BITMAP style to it and bit changed it to my needs

Edited by Zedna
Link to comment
Share on other sites

  • 1 month later...

This example code should theoretically also work to create skinned GUI right? But its not creating the images & shows no errors any idea why?

#include-once

#include <WinAPI.au3>
#include <GDIPlus.au3>
#include <Memory.au3>

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$LOGO           = _LOGOBin()
$MY_GUIIMAGE2   = _LOGOBin2()

Global $GUI, $Form1

;~ GUI image
;~ =================================================================================================================
        Global Const $AC_SRC_ALPHA = 1
        ;~ Global Const $ULW_ALPHA         = 2
        Global $old_string = "", $runthis = "" , $GUI , $testimage, $testimage2 , $Form2

        ; Load PNG file as GDI bitmap
        _GDIPlus_Startup()
        $hImage = _GDIPlus_ImageLoadFromFile($LOGO) ; This is UR GUI IMAGE

        ; Extract image width and height from PNG
        $width = _GDIPlus_ImageGetWidth($hImage)
        $height = _GDIPlus_ImageGetHeight($hImage)

        ; Create layered window
        $GUI = GUICreate('boo', $width, $height, -1, -1, $WS_POPUP, $WS_EX_LAYERED)
        SetBitmap($GUI, $hImage, 0)
        ; Register notification messages
        GUIRegisterMsg($WM_NCHITTEST, "WM_NCHITTEST")
        GUISetState()
        ;fade in png background
        For $i = 0 To 255 Step 10
            SetBitmap($GUI, $hImage, $i)
        Next

;~ GUI REAL
;~ =================================================================================================================
    $Form1 = GUICreate('guiname', $width, $height, 4, 0, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $GUI)
    $testimage = GUICtrlCreatePic($MY_GUIIMAGE2, 0, 0, $width, $height)
    GUICtrlSetState(-1, $GUI_DISABLE)
    GUISetState(@SW_SHOW)


Func _LOGOBin()
    Local $FileName="0x89504E470D0A1A0A0000000D4948445200000136000001A60806000000F6DAA8EA000000097048597300000EC400000EC401952B0E1B0000000467414D410000B18E7CFB5193000000206348524D00007A25000080830000F9FF000080E9000075300000EA6000003A980000176F925FC54600001FB54944415478DA62FCFFFF3FC3281805A360140C270010404CA341300A46C128186E0020805806ABC35CF337338E46CF2818058317EC9EE83B68BB7B0001C438D05DD1D1026C148C82D1028FDA002080E85EB09150908D1678A360140C6E4054E13110051D4000D1A560235098912B370A46C128189C85DAFF812EE4000288A6051B8E028D5831520AB6D10270148C023AB6C2F0A8FB4FAC5A5A167200014493820D4B81462A9FD40270B4C01B05A380360518A905D67F12F93429E0000288AA051B81028D91C8828D14B9D1826D148C828129D8FE13C126451D550B388000A24AC146A0CBC948A41829F2A385D8281805F42DECFE93C026568C66051C40005154B0113186C648259AD8026EB4701B05A380BA851AB18518A934DE028ED2C20D2080C82ED888EC7662A329111B2DD846C12818F8820D1B4D488C98028E6AAD378000226BE7019E420DBDF061C4C326854F4A01375AB88D82514079A1464E81868FCF88C71E46349A6200104024B7D88828D40815668C040A3346120A3762665747C1281805A4176EB80A36620A327C18975E9C5D53725A6D000144E95E5142851A3998898216DC68E1360A46016D0B35620AB27F44146EF85A6E188D29520B37800022A960436BAD9152A83191C06722B3F5365AA88D825140FDC28DD816197261C648A090FB87A37B4AB56E29400091DB6223B65063C2537021D34C04F4E0EABA321068BD8D8251300A482FD8882DD4FE6161FF83E6DD7F680514BA3CAED61BD6C28DD4561B4000115DB01139B686AB05C684878D4F1EDD3C62BAA6A305DC2818059415680C04BA9DFFF0D0308C5C38FD43A219D05A6D84BAA564B5DC0002889C161BAE9612A1161929185F21375AB08D825140BF82ED3F81828D1066442BD4882DE0300A35525A6D00014454C146C49A35463CDD4B189B19ADF062C62387ABA01B2DDC46C12818F8EE27AE82ED2F1E367A01C780D66DC5E73E925B6D0001446A8B0D5781C688A5EBC984A320C346E39263C2D1021C2DD846C128A06FC146A895F6179A6FFF423113129B11AD7063C053B8FDC752E690DC6A03082082051B526B8D9188020D5701C78C05E31227B57063C051C8112A9847C12818A985182E39720AB5BF48F45FA4FC8A5C9021176ED8C03F3CF997AC561B400051D262C3D51565C253A8B16029C458882CE0B0CDA062EB96E22BC0460BB651305AB0E12FD8087541711568C8F80F96BCFA970837221770FF29"
        $FileName&="69B50104100B89AD350622BB9FCC780A35649A05871CB985DB68A1360A4601E9851BB1E36AE8051B7A61865CA8FDC1D3F0C0662FB2BAFF68EA496EB5010410292D36463C2D356C851C7AA1C682A550C386D10B385C930BC4166CA305DA281805840B38625B6BE82DB53F48E36BF80A35463C76326129DC28EA8A020410395D517C7B3CB1B5DCF01566AC683429851B23C368AB6D148C026A1468C8850C0303E66E017C851A0B9466269047B1D9CB8CA77063406BB9A1147084BAA30001C442623794D4EE28338EC28D150D23176EEA40AC083513BD0B8ABE589709475779B4201B05A380F8420E1BFB1F5A81876B02E13910DF02E22F44146AD85A83B80A379C851A319E030820625B6C844EE4C057A831E328D4D890D8A2401C0EC4E640CC3D9AE646C128185200D462BB04C46B80F8269E961AAEAE2E138EC20D57AB8D200008204AF68A12B38E0DDB181B72A106A23D80381ECA1E05A360140C3D00CAD74650BC1B88E702F1370205DA3FB4B202590E7D1281E42D550001C44466A186AB8023A650436EB1250071EA68A1360A46C1B001AE405C0FC43C0CD8C7D0D1573C9033660EE6E3BBAF182080B0166C78C6D7F01D2249CC720FE4C20DD452F31D4D07A360140C3BA009C4D90CA863E8B896749152B8E19A88C0000001444C8B8D98D36E096DA1429F051507E2D8D1F81F05A360D8026B20B660C0BEE2015BA1866FD281E44940800022B52B4AEA5E515C2DB66020E6188DFB51300A863588416BD0E0DB3649CCB98B4403800022778C0DD96226120A3510068DA7598EC6F9281805C31E4802B10E112D3642875C90DC6A030820520A3662270DF02DFB00794C8D617449C72818052305E891D0056522D06AC328E8704D20000410395D51624EF9C0368100F39CCC685C8F825130A25A6D84260D086D93C45506E10400018451B0E1D9F8CE80A7C586EF7049F4161BFF685C8F82513062001703EE137C8829D0489A0D8501800022D46223E63047626748910BB751300A46C1C8008C44B4D488398A8C24001040E4CE8A12BBB50A5BAB6D74FFE628180523B76023B4768D014F438A680010404C5470340303E9C7838F8251300A4656C186AB8546EC5D2624B5E000028892E51EC4DEEA8E5EA88DB6D846C1281859051BBE0B9B18A9DD0D050180006222C171846629F05D968C5CB88D166CA360148C2C80EFFE1262260E480600014449B710DFEC05BEEBF8460BB651300A46568B8D947B82292AD06000208028DD79404C0187EB46F751300A46C1C800C48CA911EA159204000288D62D365C9309A360148C8291D36223F578227C7B45892AE4000288894A0E27B41B812A0382A360148C8221DD1D25E6CA4C7C47A611520307000144ECB1450C24AA1B2DDC46C1281805C496078C649A"
        $FileName&="891300041013050E24B77B3A0A46C128182DD418F0743B492A27B06D840708206A8DB11133AB315AB88D825130B20B37425D4B06062A9CC50602000144AD3136625A6C0C0CA385DA28180523B560A36BE3062080485DA04B69093D5AB88D825130720B357CE2141D53840E000288890E9E1AED7E8E8251305AB8E1EBC151BD7C000820262A3A9C91040F8E8251300A4601CD0040008D2E961D05A360140CB6D61DC50D208000A2D6B1455475D4281805A360D87647E902000288890247E2EB1F93BD1562148C8251305AD051AA0F208046BBA2A360148C027A1562C4AE65A3180004D068C1360A46C12818AC051FD9002080460BB651300A46C1B0030001345AB08D8251300A861D0008A0D1826D148C825130EC004000D1AB601BDD4E350A46C128A01B0008A0D116DB281805A360D80180001A2DD846C1281805C30E0004D068C1360A46C1281876002080460BB651300A46C1B0030001345AB08D8251300A861D0008A0D1826D148C825130EC0040008D166CA360148C826107000268B4601B05A360140C3B001040A305DB281805A360D80180001A2DD846C1281805C30E0004D068C1360A46C1281876002080460BB651300A46C1B0030001345AB08D8251300A861D0008A0D1826D148C825130EC0040008D166CA360148C826107000268B4601B05A360140C3B001040A305DB281805A360D80180001A2DD846C1281805C30E0004D068C1360A46C1281876002080460BB651300A46C1B0030001345AB08D8251300A861D0008A0D1826D148C825130EC0040008D166CA360148C826107000268B4601B05A360140C3B001040A305DB281805A360D80180001A2DD846C1281805C30E0004D068C1360A46C1281876002080460BB651300A46C1B0030001345AB08D8251300A861D0008A0D1826D148C825130EC0040008D166CA360148C826107000268B4601B05A360140C3B001040A305DB281805A360D80180001A2DD846C1281805C30E0004D068C1360A46C1281876002080460BB651300A46C1B0030001345AB08D8251300A861D0008A0D1826D148C825130EC0040008D166CA360148C826107000268B4601B05A360140C3B001040A305DB281805A360D80180001A2DD846C1281805C30E0004D068C1360A46C1281876002080460BB651300A46C1B0030001345AB08D8251300A861D0008A0D1826D148C825130EC0040008D166CA360148C826107000268B4601B05A360140C3B001040A305DB281805A360D80180001A2DD846C1281805C30E0004D068C1360A46C1281876002080460BB651300A46C1B0030001345AB08D8251300A861D0008A0D1826D148C825130EC0040008D166CA360148C826107000268B4601B05A360140C3B001040A305DB281805A360D8018000"
        $FileName&="1A2DD846C1281805C30E0004D068C1360A46C1281876002080460BB651300A46C1B0030001345AB08D8251300A861D0008A0D1826D148C825130EC0040008D166CA360148C826107000268B4601B05A360140C3B001040A305DB281805A360D80180001A2DD846C1281805C30E0004D068C1360A46C1281876002080460BB651300A46C1B0030001345AB08D8251300A861D0008A0D1826D148C825130EC0040008D166CA360148C826107000268B4601B05A360140C3B001040A305DB281805A360D80180001A2DD846C1281805C30E0004D068C1360A46C1281876002080460BB651300A46C1B0030001345AB08D8251300A861D0008A0D1826D148C825130EC0040008D166CA360148C826107000268B4601B05A360140C3B001040A305DB281805A360D80180001A2DD846C1281805C30E0004D068C1360A46C1281876002080460BB651300A46C1B0030001345AB08D8251300A861D0008A0D1826D148C825130EC0040008D166CA360148C826107000268B4601B05A360140C3B001040A305DB281805A360D80180001A2DD846C1281805C30E0004D068C1360A46C1281876002080460BB651300A46C1B0030001345AB08D8251300A861D0008A0D1826D148C825130EC0040008D166CA360148C826107000268B4601B05A360140C3B001040A305DB281805A360D80180001A2DD846C1281805C30E0004D068C1360A46C1281876002080460BB651300A46C1B0030001345AB08D8251300A861D0008A0D1826D148C825130EC0040008D166CA360148C826107000268B4601B05A360140C3B001040A305DB281805A360D80180001A2DD846C1281805C30E0004D068C1360A46C1281876002080460BB651300A46C1B0030001345AB08D8251300A861D0008A0D1826D148C825130EC0040008D166CA360148C826107000268B4601B05A360140C3B001040A305DB281805A360D80180001A2DD846C1281805C30E0004D068C1360A46C1281876002080460BB651300A46C1B0030001345AB08D8251300A861D0008A0D1826D148C825130EC0040008D166CA360148C826107000268B4601B05A360140C3B001040A305DB281805A360D80180001A2DD846C1281805C30E0004D068C1360A46C1281876002080460BB651300A46C1B0030001345AB08D8251300A861D0008A0D1826D148C825130EC0040008D166CA360148C826107000268B4601B05A360140C3B001040A305DB281805A360D80180001A2DD846C1281805C30E0004D068C1360A46C1281876002080460BB651300A46C1B0030001345AB08D8251300A861D0008A0D1826D148C825130EC0040008D166CA360148C826107000268B4601B05A360140C3B001040A305DB281805A360D80180001A2DD846C1281805C30E"
        $FileName&="0004D068C1360A46C1281876002080460BB651300A46C1B0030001345AB08D8251300A861D0008A0D1826D148C825130EC0040008D166CA360148C826107000268B4601B05A360140C3B001040A305DB281805A360D80180001A2DD846C1281805C30E0004D068C1360A46C1281876002080460BB651300A46C1B0030001345AB08D8251300A861D0008A0D1826D148C825130EC0040008D166CA360148C826107000268B4601B05A360140C3B001040A305DB281805A360D80180001A2DD846C1281805C30E0004D068C1360A46C1281876002080460BB651300A46C1B0030001345AB08D8251300A861D0008A0D1826D148C825130EC0040008D166CA360148C826107000268B4601B05A360140C3B001040A305DB281805A360D80180001A2DD846C1281805C30E0004D068C1360A46C1281876002080460BB651300A46C1B0030001345AB08D8251300A861D0008A0D1826D148C825130EC0040008D166CA360148C826107000268B4601B05A360140C3B001040A305DB281805A360D80180001A2DD846C1281805C30E0004D068C1360A46C1281876002080460BB651300A46C1B0030001345AB08D8251300A861D0008A0D1826D148C825130EC0040008D166CA360148C826107000268B4601B05A360140C3B001040A305DB281805A360D80180001A2DD846C1281805C30E0004D068C1360A46C1281876002080460BB651300A46C1B0030001345AB08D8251300A861D0008A0D1826D148C825130EC0040008D166CA360148C826107000268B4601B05A360140C3B001040A305DB281805A360D80180001A2DD846C1281805C30E0004D068C1360A46C1281876002080460BB651300A46C1B0030001345AB08D8251300A861D0008A0D1826D148C825130EC0040008D166CA360148C826107000268B4601B05A360140C3B001040A305DB281805A360D80180001A2DD846C1281805C30E0004D068C1360A46C1281876002080460BB651300A46C1B0030001345AB08D8251300A861D0008A0D1826D148C825130EC0040008D166CA360148C826107000268B4601B05A360140C3B001040A305DB281805A360D80180001A2DD846C1281805C30E0004D068C1360A46C1281876002080460BB651300A46C1B0030001345AB08D8251300A861D0008A0D1826D148C825130EC0040008D166CA360148C826107000268B4601B05A360140C3B001040A305DB281805A360D80180001A2DD846C1281805C30E0004D068C1360A46C1281876002080460BB651300A46C1B0030001345AB08D8251300A861D0008A0D1826D148C825130EC0040008D166CA360148C826107000268B4601B05A360140C3B001040A305DB281805A360D80180001A2DD846C1281805C30E0004D068C1360A46C128"
        $FileName&="1876002080460BB651300A46C1B0030001345AB08D8251300A861D0008A0D1826D148C825130EC0040008D166CA360148C826107000268B4601B05A360140C3B001040A305DB281805A360D80180001A2DD846C1281805C30E0004D068C1360A46C1281876002080460BB651300A46C1B0030001345AB08D8251300A861D0008A0D1826D148C825130EC0040008D166CA360148C826107000268B4601B05A360140C3B001040A305DB281805A360D80180001A2DD846C1281805C30E0004D068C1360A46C1281876002080460BB651300A46C1B0030001345AB08D8251300A861D0008A0D1826D148C825130EC0040008D166CA360148C826107000268B4601B05A360140C3B001040A305DB281805A360D80180001A2DD846C1281805C30E0004D068C1360A46C1281876002080460BB651300A46C1B0030001345AB08D8251300A861D0008A0D1826D148C825130EC0040008D166CA360148C826107000268B4601B05A360140C3B001040A305DB281805A360D80180001A2DD846C1281805C30E0004D068C1360A46C1281876002080460BB651300A46C1B0030001345AB08D8251300A861D0008A0D1826D148C825130EC0040008D166CA360148C826107000268B4601B05A360140C3B001040A305DB281805A360D80180001A2DD846C1281805C30E0004D068C1360A46C1281876002080460BB651300A46C1B0030001345AB08D8251300A861D0008A0D1826D148C825130EC0040008D166CA360148C826107000268B4601B05A360140C3B001040A305DB281805A360D80180001A2DD846C1281805C30E0004D068C1360A46C1281876002080460BB651300A46C1B0030001345AB08D8251300A861D0008A0D1826D148C825130EC0040008D166CA360148C826107000268B4601B05A360140C3B001040A305DB281805A360D80180001A2DD846C1281805C30E0004D068C1360A46C1281876002080460BB651300A46C1B0030001345AB08D8251300A861D0008A0D1826D148C825130EC0040008D166CA360148C826107000268B4601B05A360140C3B001040A305DB281805A360D80180001A2DD846C1281805C30E0004D068C1360A46C1281876002080460BB651300A46C1B0030001345AB08D8251300A861D0008A0D1826D148C825130EC0040008D166CA360148C826107000268B4601B05A360140C3B001040A305DB281805A360D80180001A2DD846C1281805C30E0004D068C1360A46C1281876002080460BB651300A46C1B0030001345AB08D8251300A861D0008A0D1826D148C825130EC0040008D166CA360148C8261070002885E05DB7F347A148C8251300A6806000268B4C5360A46C1281876002080460BB651300A46C1B0030001345AB08D8251300A861D0008A0"
        $FileName&="D1826D148C825130D080EA63F00001345AB08D8251300A06AAE0FACF40A38945800062A2C0A1F81CF41F872746C1281805A38092F280287D0001C44465C7FD1F2DC046C1281805542CC8C802000134DA151D05A360140CB60290E24210208098E8EC98D1D6DC281805A380E600208068DD62FB3FDA3D1D05A360B41586A33CA0D98E2480006222C161FF49F4C87F3C9E1B05A360148CBC420D9F38AE3286AC861140003151D1E1D81C81AB841E05A360148CB6D868060002888942C7FE2750A08D764B47C1281805F8CA036C8D23B25B6A300010404C643AF03F911EF88F058F8251300A4666C1F61F4719C14049CF6EF7445F0CF50001C444A4A3C8ED92FE1F2DDC46C128182DD4685026E0D50310404C547438038D3C300A46C12818BE851BB6961B03915D579CE5094000516B8C8D90E3FFA1E151300A46C1C829D490F33EBE028E989952A21A470001C444A643899D09FD8FE6997FA3ADB651300A46748BED1F19BD3A92CB0C8000A2758BED1F5A893DDA1D1D05A360B4C5F68F886E2945E50440003191E8C0FF24F49FFF61F1D4DFD1826D148C821107FE9250B851A58003082052761E105398E11B5BFB3BDA151D05A360C4B6D8D00B3742636E149513000144EE181B3A9BD064017AE1360A46C128183905DB5F3C051ABE6E29D93B160002889C05BA0C0CB89778E02ACC90F1688B6D148C829157B021637C2D366C650DC900208098887014BEB523C42CED402FDCFE8CC6F528180523B660FB476297942C00104018051BD2F684FF38BA9F840AB4FF785A6BA042EDE3685C8F82513062C03768BE27A5D586EF200DA200400091BB57948181F084C15FB4C20DE6B967A3713D0A46C18801CFD1F2FF5F06DC9309C4AE692358C8010410A9CB3D70B5D8FE311037BE06F2DC0D20FE3A1ADFA360148C08708988161BAE2520D81A5328E511B60DF02000104094EE3CC0B6B3005FA106C2BF80F8E4687C8F825130225A6BD790F2FE1F1C85DB7F02851B03A95D5180002277569498AE28B66E2888FE0DC4ABA105DC281805A360F88265D07CFE1B47A1F69701FFEC28D91308000144ECB145B8C6D61848E88E2297DA2F8178F168BC8F8251306CC171203E8654A8E16BB1E11A6723ABB50602000184B560C331338A8B8F6DFB14AE6EE86F24BC0D88B78EC6FF281805C30EDC06E2C94879FD0F5AAF8D94D951B216E90204100B198EC6D70565442BDC9890F01FA83C0C83C03C207E07C4E140CC369A1E46C12818F2603F10CF06E22F4885DA6F225A6CC41C6784D2C0C2357100020001C442A6E349D91FCA88A5404306EBA14DD65020360762EED1B4310A46C19002A0BC7E0188D701F175B49E197A57F40F03F10B75C9EA8682004000115BB0A11BCE88A3B506C3D80A34463C052468F664"
        $FileName&="3AB4A4D7026239A87A66686B8F110B8DDC956644731B36F6281805A3007B9EC6C6FE879647B19DD603C2AF19204BB83EA1B5D0B0B18959A84B68C9075100208018FFFFC7ADDE357F33235201810D33A1616634CC4200B3A2D130CC8C443323998D6C17239EC2135781365AD08D82D1C20CBBD87FB4428D9445F7C8ADB1DF38D87F70B4DCFE30E09E25C5375B8AB72B0A10402C14040C2303EE7136E4961BA1AE2CB6D95316288DAB506322A1501B2DCC46C12820AE8023E5F8317C851BAE02EC0F8E828C502146F4C25C1800082016120383114F498F5EB8311051A8612BD898910A35F4828D918C826DB4801B05A300FF7815B1DB24092DC0C756D06193FB4B44A146D1920F8000C25BB0814A45687714B950C33643F18FC4C0C5D66767462AD8C829D488195B1B2DDC46C168A1467AC1F69F01F7D98A7FF114727F718CAB1173741145851B400091D31565C41328FF882844D03DF117CBD81CAE3135741A7D0C9050E1355AB08D82D1820D7FC186AB5785AFE586AB80C3B6D380D84DF038DD4EA81B0A02000144B060C3D26AC365E83F6881F31F4F2B0E5BE9CF84E451520B35F4C26C744674148C02F20A3B4A0AB77F780A2F6C0519B16BD8C8EE8A020410252D365C0390FF70B4CE90F94C486A999068F445BD4C780AB4D1826D148C02FA156CF8CE5DFC47A0F022B46E0DDF0D7624B7D640002080882AD8905A6D840A38E4828A0147B7F53F5A01875CB031E1184F1B2DD446C128A05FE1C6C04078BC0D5FEBED1F110519CD260E40002080C8DD52C588C6C655B831E208A87F785A65D80A33262CE369A305DB281805B42FD808754B711574FF2928D0FE53D25A0301800022BA60C3D36AC355B8316269BDFD4753FF8F0173A693D8561AB6826CB4401B05A380BEDD52620ABBFF241468F8EE58211A000410257B451909146E0C68AD364624354C487AFEE128D888ED7A8EB6D446C128A06EC1464AE186AF9023C46720B65023A5B5060200014452C186D66A23B670432EE018D1D43222156ED80A3662BA9EA33B0D46C128A04DA186AB602354D011D32A2374FC3745D7740204100B15028450E1F61F4F0B0C5BE1F58F84C26CB4501B05A380FE851BA9051D3187D5E22CCC486DAD81004000E1DD048F0BA08DB5E1EB1632E26193C227A5EB395AB88D82514059A186AF6023B7A023D432A378C20019000410592D360213090C38BAA4D86653091580A41468A385DA281805D42DDCC82DE01848EC6A52A5FB890C000288AC161B9E961BAE0288527AB4601B05A360F0146CC4B4B8886991E15CAB466E4B0D06000288A2828DC8028E910231620BB4D1426D148C02DA156EC41648FF4914C36A27A5851A08000410550A363C051CB10514B97204FD379A5647C12820AB2023A496D8828AAE"
        $FileName&="051A0C000410550B36220B3862F8A4888D166CA36014D0BF6023568C109FAA051A0C0004104D0A3622BBA8C41440C4164CA305D8281805F42DECFE93204EB5651CC4028000A269C146A08023A6501A2DB046C128187A05204E395A1666C8002080E852B09150C88D166AA360140CB3D61DBD0A3364001040742FD82828E846C128180543000C4441860E000268C00BB6D1026F148C82D1028CDA002080066DC1360A46C1281805E4028000621A0D8251300A46C170030001345AB08D8251300A861D0008A0D1826D148C825130EC0040008D166CA360148C826107000268B4601B05A360140C3B00106000F2F058B2B88BA0C20000000049454E44AE426082"
   Return $FileName
EndFunc

Func _LOGOBin2()
    Local $var="0x4749463839613E003B00910000000000FFFFFF373737FFFFFF21F90401000003002C000000003E003B00000240948FA9CBED0FA39CB4DA8BB3DEBCFB0F86E24896E689A6EACAB6EE0BC7F24CD7F68DE7FACEF7FE0F0C0A87C4A2F1884C2A97CCA6F3098D4AA7D4AAF58ACD1E0A003B"
   Return $var
EndFunc


;~ SKINNING OPTS
; ====================================================================================================
; Handle the WM_NCHITTEST for the layered window so it can be dragged by clicking anywhere on the image.
; ====================================================================================================
Func WM_NCHITTEST($hWnd, $iMsg, $iwParam, $ilParam)
    If ($hWnd = $GUI) And ($iMsg = $WM_NCHITTEST) Then Return $HTCAPTION
EndFunc   ;==>WM_NCHITTEST

; ====================================================================================================
; SetBitMap
; ====================================================================================================
Func SetBitmap($hGUI, $hImage, $iOpacity)
    Local $hScrDC, $hMemDC, $hBitmap, $hOld, $pSize, $tSize, $pSource, $tSource, $pBlend, $tBlend

    $hScrDC = _WinAPI_GetDC(0)
    $hMemDC = _WinAPI_CreateCompatibleDC($hScrDC)
    $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
    $hOld = _WinAPI_SelectObject($hMemDC, $hBitmap)
    $tSize = DllStructCreate($tagSIZE)
    $pSize = DllStructGetPtr($tSize)
    DllStructSetData($tSize, "X", _GDIPlus_ImageGetWidth($hImage))
    DllStructSetData($tSize, "Y", _GDIPlus_ImageGetHeight($hImage))
    $tSource = DllStructCreate($tagPOINT)
    $pSource = DllStructGetPtr($tSource)
    $tBlend = DllStructCreate($tagBLENDFUNCTION)
    $pBlend = DllStructGetPtr($tBlend)
    DllStructSetData($tBlend, "Alpha", $iOpacity)
    DllStructSetData($tBlend, "Format", $AC_SRC_ALPHA)
    _WinAPI_UpdateLayeredWindow($hGUI, $hScrDC, 0, $pSize, $hMemDC, $pSource, 0, $pBlend, $ULW_ALPHA)
    _WinAPI_ReleaseDC(0, $hScrDC)
    _WinAPI_SelectObject($hMemDC, $hOld)
    _WinAPI_DeleteObject($hBitmap)
    _WinAPI_DeleteDC($hMemDC)
EndFunc   ;==>SetBitmap 


;Authors: Prog@ndy, based on code by Zedna
Func _SetImageBinaryToCtrl($CtrlId, ByRef $Binary)
    Local $picdata = Binary($Binary) ; Fetch the Data
    Local $piclength = BinaryLen($picdata) ; Get Length

    Local $picstruct = DllStructCreate("byte[" & $piclength & "]")
        DllStructSetData($picstruct,1,$picdata)
        Local $picmemory = DllStructGetPtr($picstruct)
        _SetMemoryImageToCtrl($CtrlId, $picmemory, $piclength)
        DllStructSetData($picstruct,1,0)
    $picstruct = ""
EndFunc

; Authors: Zedna, based on code by Prog@ndy
Func _SetMemoryImageToCtrl($CtrlId, $Pointer, $nSize)
    Local $hData, $pData, $pStream, $pBitmap, $hBitmap
        ; use GDI+ for converting to bitmap first
    $hData = _MemGlobalAlloc($nSize,2)
    $pData = _MemGlobalLock($hData)
    _MemMoveMemory($Pointer,$pData,$nSize)
    _MemGlobalUnlock($hData)
    $pStream = DllCall( "ole32.dll","int","CreateStreamOnHGlobal", "int",$hData, "long",1, "Int*",0)
    $pStream = $pStream[3]
    _GDIPlus_Startup()
    $pBitmap = DllCall($ghGDIPDll,"int","GdipCreateBitmapFromStream", "ptr",$pStream, "int*",0)
    $pBitmap = $pBitmap[2]
    $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($pBitmap)
    __SetBitmapToCtrl($CtrlId, $hBitmap)
    If @error Then SetError(3, 0, 0)
    _GDIPlus_BitmapDispose($pBitmap)
    _GDIPlus_Shutdown()
    _WinAPI_DeleteObject($pStream)
    _MemGlobalFree($hData)
EndFunc

; internal helper function
; Out of resources.au3 smile.gif, slightly renamed.
Func __SetBitmapToCtrl($CtrlId, $hBitmap)
    Local Const $STM_SETIMAGE = 0x0172
    Local Const $IMAGE_BITMAP = 0
    Local Const $SS_BITMAP = 0xE
    Local Const $GWL_STYLE = -16

    Local $hWnd = GUICtrlGetHandle($CtrlId)
    If $hWnd = 0 Then Return SetError(1, 0, 0)
        ; set SS_BITMAP style to control
    Local $oldStyle = DllCall("user32.dll", "long", "GetWindowLong", "hwnd", $hWnd, "int", $GWL_STYLE)
    If @error Then Return SetError(2, 0, 0)
    DllCall("user32.dll", "long", "SetWindowLong", "hwnd", $hWnd, "int", $GWL_STYLE, "long", BitOR($oldStyle[0], $SS_BITMAP))
    If @error Then Return SetError(3, 0, 0)
        Local $oldBmp = DllCall("user32.dll", "hwnd", "SendMessage", "hwnd", $hWnd, "int", $STM_SETIMAGE, "int", $IMAGE_BITMAP, "int", $hBitmap)
    If @error Then Return SetError(4, 0, 0)
    If $oldBmp[0] <> 0 Then _WinAPI_DeleteObject($oldBmp[0])
    Return 1
EndFunc

While 1
    Sleep(100)
WEnd
My Projects:[list][*]Guide - ytube step by step tut for reading memory with autoitscript + samples[*]WinHide - tool to show hide windows, Skinned With GDI+[*]Virtualdub batch job list maker - Batch Process all files with same settings[*]Exp calc - Exp calculator for online games[*]Automated Microsoft SQL Server 2000 installer[*]Image sorter helper for IrfanView - 1 click opens img & move ur mouse to close opened img[/list]
Link to comment
Share on other sites

  • 2 years later...

I have made some new UDFs for loading images into a GDI+-Image, this time without memory leaks and proper error checking. They are more powerful, but now will be required and currently I have no plans to create the one-liner functions _SetImageBinaryToCtrl, _SetMemoryImageToCtrl.

#include-once
#include<Memory.au3>
#include<GDIPlus.au3>

; #FUNCTION# ====================================================================================================================
; Name...........: _GDIPlus_ImageLoadFromHGlobal
; Description ...: Creates an Image object based on movable HGlobal memory block
; Syntax.........: _GDIPlus_ImageLoadFromHGlobal($hGlobal)
; Parameters ....: $hGlobal - Handle of a movable HGlobal memory block
; Return values .: Success      - Pointer to a new Image object
;                  Failure      - 0 and either:
;                  |@error and @extended are set if DllCall failed:
;                  | -@error = 1 if could not create IStream
;                  | -@error = 2 if DLLCall to create image failed
;                  |$GDIP_STATUS contains a non zero value specifying the error code
; Author ........: ProgAndy
; Modified.......:
; Remarks .......: After you are done with the object, call _GDIPlus_ImageDispose to release the object resources.
;                  The HGLOBAL will be owned by the image and freed automatically when the image is disposed.
; Related .......: _GDIPlus_ImageLoadFromStream, _GDIPlus_ImageDispose
; Link ..........:
; Example .......:
; ===============================================================================================================================
Func _GDIPlus_ImageLoadFromHGlobal($hGlobal)
    Local $aResult = DllCall("ole32.dll", "int", "CreateStreamOnHGlobal", "handle", $hGlobal, "bool", True, "ptr*", 0)
    If @error Or $aResult[0] <> 0 Or $aResult[3] = 0 Then Return SetError(1, @error, 0)
    Local $hImage = DllCall($ghGDIPDll, "uint", "GdipLoadImageFromStream", "ptr", $aResult[3], "int*", 0)
    Local $error = @error
    Local $tVARIANT = DllStructCreate("word vt;word r1;word r2;word r3;ptr data; ptr")
    Local $aCall = DllCall("oleaut32.dll", "long", "DispCallFunc", "ptr", $aResult[3], "dword", 8 + 8 * @AutoItX64, "dword", 4, "dword", 23, "dword", 0, "ptr", 0, "ptr", 0, "ptr", DllStructGetPtr($tVARIANT))
    If $error Then Return SetError(2, $error, 0)
    If $hImage[2] = 0 Then Return SetError(3, 0, $hImage[2])
    Return $hImage[2]
EndFunc   ;==>_GDIPlus_ImageLoadFromHGlobal


; #FUNCTION# ====================================================================================================================
; Name...........: _MemGlobalAllocFromBinary
; Description ...: Greates a movable HGLOBAL memory block from binary data
; Syntax.........: _MemGlobalAllocFromBinary($bBinary)
; Parameters ....: $bBinary - Binary data
; Return values .: Success      - Handle of a new movable HGLOBAL
;                  Failure      - 0 and set @error:
;                  |1  - no data
;                  |2  - could not allocate memory
;                  |3  - could not set data to memory
; Author ........: ProgAndy
; Modified.......:
; Remarks .......:
; Related .......: _MemGlobalAlloc, _MemGlobalFree, _MemGlobalLock
; Link ..........:
; Example .......:
; ===============================================================================================================================
Func _MemGlobalAllocFromBinary(Const $bBinary)
    Local $iLen = BinaryLen($bBinary)
    If $iLen = 0 Then Return SetError(1, 0, 0)
    Local $hMem = _MemGlobalAlloc($iLen, $GMEM_MOVEABLE)
    If @error Or Not $hMem Then Return SetError(2, 0, 0)
    DllStructSetData(DllStructCreate("byte[" & $iLen & "]", _MemGlobalLock($hMem)), 1, $bBinary)
    If @error Then
        _MemGlobalUnlock($hMem)
        _MemGlobalFree($hMem)
        Return SetError(3, 0, 0)
    EndIf
    _MemGlobalUnlock($hMem)
    Return $hMem
EndFunc   ;==>_MemGlobalAllocFromBinary

; #FUNCTION# ====================================================================================================================
; Name...........: _MemGlobalAllocFromMem
; Description ...: Greates a movable HGLOBAL memory block and copies data from memory
; Syntax.........: _MemGlobalAllocFromMem($pSource, $iLength)
; Parameters ....: $pSource  - Pointer to memorybloc to copy from
;                  $iLength  - Length of data to copy
; Return values .: Success      - Handle of a new movable HGLOBAL
;                  Failure      - 0 and set @error:
;                  |1  - invalid $pSource
;                  |2  - invalid $iLength
;                  |3  - could not allocate memory
; Author ........: ProgAndy
; Modified.......:
; Remarks .......:
; Related .......: _MemGlobalAlloc, _MemGlobalFree, _MemGlobalLock
; Link ..........:
; Example .......:
; ===============================================================================================================================
Func _MemGlobalAllocFromMem($pSource, $iLength)
    If Not $pSource Then Return SetError(1, 0, 0)
    If $iLength < 1 Then Return SetError(2, 0, 0)
    Local $hMem = _MemGlobalAlloc($iLength, $GMEM_MOVEABLE)
    If @error Or Not $hMem Then Return SetError(3, 0, 0)
    _MemMoveMemory($pSource, _MemGlobalLock($hMem), $iLength)
    _MemGlobalUnlock($hMem)
    Return $hMem
EndFunc   ;==>_MemGlobalAllocFromMem

; #FUNCTION# ====================================================================================================================
; Name...........: _GUICtrlStatic_SetImage
; Description ...: Sets a HBITMAP to a static control like image or label
; Syntax.........: _GUICtrlStatic_SetImage($iCtrlId, $hBitmap)
; Parameters ....: $iCtrlId  - CtrlId or handle of Control in the current process
;                  $hBitmap  - Pointer top Windows HBITMAP
; Return values .: Success      - 1
;                  Failure      - 0 and set @error:
;                  |1  - invalid $pSource
;                  |1  - invalid $pSource
; Author ........: ProgAndy, Zedna
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......:
; ===============================================================================================================================
Func _GUICtrlStatic_SetImage($iCtrlId, $hBitmap)
    Local Const $STM_SETIMAGE = 0x0172
    Local Const $IMAGE_BITMAP = 0
    Local Const $SS_BITMAP = 0xE
    Local Const $GWL_STYLE = -16

    If IsHWnd($iCtrlId) Then
        If WinGetProcess($iCtrlId) <> @AutoItPID Then Return SetError(1,0,0)
    Else
        $iCtrlId = GUICtrlGetHandle($iCtrlId)
        If Not $iCtrlId Then Return SetError(2,0,0)
    EndIf
    ; set SS_BITMAP style to control
    Local $oldStyle = DllCall("user32.dll", "long", "GetWindowLong", "hwnd", $iCtrlId, "int", $GWL_STYLE)
    If @error Then Return SetError(3, 0, 0)
    DllCall("user32.dll", "long", "SetWindowLong", "hwnd", $iCtrlId, "int", $GWL_STYLE, "long", BitOR($oldStyle[0], $SS_BITMAP))
    If @error Then Return SetError(4, 0, 0)
    Local $oldBmp = DllCall("user32.dll", "handle", "SendMessageW", "hwnd", $iCtrlId, "int", $STM_SETIMAGE, "wparam", $IMAGE_BITMAP, "handle", $hBitmap)
    If @error Then Return SetError(5, 0, 0)
    If $oldBmp[0] Then _WinAPI_DeleteObject($oldBmp[0])
    Return 1
EndFunc

_GDIPlus_Startup()
$s = Binary(FileRead(RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\AutoIt v3\AutoIt", "InstallDir") & "\Examples\GUI\Torus.png"))
$hMem = _MemGlobalAllocFromBinary($s)
$hImage = _GDIPlus_ImageLoadFromHGlobal($hMem)
$gui = GUICreate("Just draw the created image", 300, 300)
GUISetState()
$hGRaph = _GDIPlus_GraphicsCreateFromHWND($gui)
_GDIPlus_GraphicsDrawImage($hGRaph, $hImage, 5, 5)
_GDIPlus_GraphicsDispose($hGRaph)


Do
Until GUIGetMsg() = -3

WinSetTitle($gui, "", "Now using _GUICtrlStatic_SetImage")
_WinAPI_RedrawWindow($gui)

$iLabel = GUICtrlCreateLabel("", 0, 0, 193, 184)
$hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
_GDIPlus_ImageDispose($hImage)
_GUICtrlStatic_SetImage($iLabel, $hBitmap)

Do
Until GUIGetMsg() = -3

Edit: Removed dependency to GDIP.au3

Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

  • 6 years later...

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