Sign in to follow this  
Followers 0
jennico

need help with memory leak _MemGlobalAlloc please

7 posts in this topic

;#Include <_Ani.au3>
#include <WinAPI.au3>
#include <Memory.au3>
#include <GDIPlus.au3>
#Include <Timers.au3>

_GDIPlus_Startup ()

Global Const $_ani_Separator = Chr(0x21) & Chr(0xF9) & Chr(0x04)
Dim $adata[36], $atime[36], $hspeed = 1, $hcount = 0, $paused = 0

$pic = "Isaac_Newton.gif" 
$gui = GUICreate("Example #1 : GIF Animation", 500, 460)
$label = GUICtrlCreateLabel("An animated license free gif will now be downloaded from Wikipedia.", 20, 20, 360, 360)
GUISetState()

If FileExists($pic) = 0 Then InetGet("http://upload.wikimedia.org/wikipedia/commons/d/d3/Newtons_cradle_animation_book_2.gif", $pic)
GUICtrlDelete($label)

$gif = GUICtrlCreatePic($pic, 10, 10, 480, 360)
$a = StringSplit(FileRead($pic), $_ani_Separator, 1)
For $i = 2 To $a[0]
    $adata[$i - 2] = BinaryToString(StringTrimRight($a[1] & $_ani_Separator & $a[$i] & Chr(0x3B), $i = $a[0]))
    $atime[$i - 2] = (Dec(Hex(BinaryMid($a[$i], 2, 1))) + Dec(Hex(BinaryMid($a[$i], 3, 1))) * 256) * 3 / 5
Next
$timer = _Timer_SetTimer ($gui, $atime[0] / 6 * 100 / $hspeed, "__Ani_SetAni", -1)
GUICtrlSetCursor(-1, 0)

$button = GUICtrlCreateButton("| |", 30, 420, 25, 25)
GUICtrlSetTip(-1, "Pause")

$slider = GUICtrlCreateSlider(90, 418, 380, 30)
GUICtrlSetTip(-1, "Speed")
GUICtrlSetLimit(-1, 200, -200)
GUICtrlSetData(-1, 25)

Do
    $msg = GUIGetMsg()
    If $msg = $slider Then
        $hspeed = GUICtrlRead($msg) / 25
        ToolTip("Speed " & Round($hspeed, 2) & "x", MouseGetPos(0) + 5, MouseGetPos(1) - 20)
    ElseIf $msg = $button Then
        If $paused Then
            GUICtrlSetTip($msg, "Pause")
            GUICtrlSetData($msg, "| |")
            $paused = 0
        Else
            GUICtrlSetTip($msg, "Resume")
            GUICtrlSetData($msg, ">")
            $paused = 1
        EndIf
    EndIf
Until $msg = -3

_GDIPlus_Shutdown ()
Exit

Func __Ani_SetAni($hWnd, $msg, $iIDTimer, $dwTime)
    If $paused Then Return 1
    $hcount += $hspeed / Abs($hspeed)
    If $hcount = 36 Then $hcount = 0
    If $hcount < 0 Then $hcount = 36
    _SetImageBinaryToCtrl($gif, $adata[$hcount])
    Return _Timer_SetTimer ($gui, $atime[$hcount] / 6 * 100 / $hspeed, "__Ani_SetAni", $timer)
EndFunc   ;==>__Ani_SetAni

;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   ;==>_SetImageBinaryToCtrl

; Authors: Zedna, based on code by Prog@ndy
Func _SetMemoryImageToCtrl($CtrlId, $Pointer, $nSize)
    Local $hData, $pData, $pStream, $pBitmap, $hBitmap
    $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   ;==>_SetMemoryImageToCtrl

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   ;==>__SetBitmapToCtrl

the above is excerpted from my _Ani.au3 UDF, which makes animated gifs work with pic controls. in that script i use temporary files for the extracted gif frames. now i want to go a step ahead and directly use the binary image data instead, which should be faster (and better).

i implemented progandy's _SetImageBinaryToCtrl() but this causes a severe memory leak (use example with caution !). i guess that _MemGlobalFree does not work, like it is pointed out in help file.

can anyone help me to fix this problem, maybe show me the way how to use _MemVirtualAlloc instead ? i would really get this working !

thx j.


Spoiler

I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.OixB7.jpgDon't forget this IP: 213.251.145.96

 

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

jennico you have copy of ResourcesViewerAndCompiler.au3 on you? My impression was that you do.

If so take a look there, it's all been taking care of.

This is almost a cut from it:

Opt("MustDeclareVars", 1)

DllOpen("gdiplus.dll")

Global $hTimer, $aHGIFBitmaps, $iGIFFrameSwitch, $iFrame

Global $hGui = GUICreate("Example #1 : GIF Animation", 500, 460)
Global $hLabel = GUICtrlCreateLabel("An animated license free gif will now be downloaded from Wikipedia.", 20, 20, 360, 360)

GUISetState()

Global $sFile = @ScriptDir & "\Isaac_Newton.gif"
If Not FileExists($sFile) Then InetGet("http://upload.wikimedia.org/wikipedia/commons/d/d3/Newtons_cradle_animation_book_2.gif", $sFile)


Global $hFile = FileOpen($sFile, 16)
Global $bData = FileRead($hFile)
FileClose($hFile)


Global $iWidthGDI
Global $iHeightGDI
Global $iTransparency
Global $aHGIFBitmaps = _CreateArrayHBitmapsFromGIFBinaryImage($bData, $iWidthGDI, $iHeightGDI, $iTransparency)

Global $hPic = GUICtrlCreatePic("", 10, 10, $iWidthGDI, $iHeightGDI)

Global $hTimer = TimerInit()

While 1

    Switch GUIGetMsg()
        Case - 3
            Exit
    EndSwitch

    If Mod(Floor(TimerDiff($hTimer) / ($aHGIFBitmaps[$iFrame][1] / 2)), 2) Then
        If $iGIFFrameSwitch Then
            $iFrame += 1
            If $iFrame = UBound($aHGIFBitmaps) Then
                $iFrame = 0
            EndIf
            Local $iHMsg = GUICtrlSendMsg($hPic, 370, 0, $aHGIFBitmaps[$iFrame][0])
            If $iTransparency Then
                GUICtrlSetStyle($hPic, 270) ; SS_BITMAP|SS_NOTIFY (default) - 'refreshing'. Or maybe GUICtrlSetState($hPic, 64)  ; $hGui_ENABLE, or 16.
            EndIf
            If $iHMsg Then
                DllCall("gdi32.dll", "int", "DeleteObject", "hwnd", $iHMsg)
            EndIf
            $iGIFFrameSwitch = 0
        EndIf
    Else
        If Not $iGIFFrameSwitch Then
            $iGIFFrameSwitch = 1
        EndIf
    EndIf

WEnd



; Function

Func _CreateArrayHBitmapsFromGIFBinaryImage($bBinary, ByRef $iWidth, ByRef $iHeight, ByRef $iTransparency) ; ProgAndy's originally

    Local $tBinary = DllStructCreate("byte[" & BinaryLen($bBinary) & "]")
    DllStructSetData($tBinary, 1, $bBinary)

    Local $a_hCall = DllCall("kernel32.dll", "hwnd", "GlobalAlloc", _  ;  local version will work too (no difference in local and global heap)
            "dword", 2, _  ; LMEM_MOVEABLE
            "dword", DllStructGetSize($tBinary))

    If @error Or Not $a_hCall[0] Then
        Return SetError(1, 0, "")
    EndIf

    Local $hMemory = $a_hCall[0]

    Local $a_pCall = DllCall("kernel32.dll", "ptr", "GlobalLock", "hwnd", $hMemory)

    If @error Or Not $a_pCall[0] Then
        DllCall("kernel32.dll", "int", "GlobalFree", "hwnd", $hMemory)
        Return SetError(2, 0, "")
    EndIf

    Local $pMemory = $a_pCall[0]

    DllCall("kernel32.dll", "none", "RtlMoveMemory", _
            "ptr", $pMemory, _
            "ptr", DllStructGetPtr($tBinary), _
            "dword", DllStructGetSize($tBinary))

    DllCall("kernel32.dll", "int", "GlobalUnlock", "hwnd", $hMemory)

    Local $a_iCall = DllCall("ole32.dll", "int", "CreateStreamOnHGlobal", _
            "ptr", $pMemory, _
            "int", 1, _
            "ptr*", 0)

    If @error Or $a_iCall[0] Then
        DllCall("kernel32.dll", "int", "GlobalFree", "hwnd", $hMemory)
        Return SetError(3, 0, "")
    EndIf

    Local $pStream = $a_iCall[3]

    Local $tGdiplusStartupInput = DllStructCreate("dword GdiplusVersion;" & _
            "ptr DebugEventCallback;" & _
            "int SuppressBackgroundThread;" & _
            "int SuppressExternalCodecs")

    DllStructSetData($tGdiplusStartupInput, "GdiplusVersion", 1)

    $a_iCall = DllCall("gdiplus.dll", "dword", "GdiplusStartup", _
            "dword*", 0, _
            "ptr", DllStructGetPtr($tGdiplusStartupInput), _
            "ptr", 0)

    If @error Or $a_iCall[0] Then
        DllCall("kernel32.dll", "int", "GlobalFree", "hwnd", $hMemory)
        Return SetError(4, 0, "")
    EndIf

    Local $hGDIplus = $a_iCall[1]

    $a_iCall = DllCall("gdiplus.dll", "dword", "GdipCreateBitmapFromStream", _ ; GdipLoadImageFromStream
            "ptr", $pStream, _
            "ptr*", 0)

    If @error Or $a_iCall[0] Then
        DllCall("gdiplus.dll", "none", "GdiplusShutdown", "dword*", $hGDIplus)
        DllCall("kernel32.dll", "int", "GlobalFree", "hwnd", $hMemory)
        Return SetError(5, 0, "")
    EndIf

    Local $pBitmap = $a_iCall[2]

    $a_iCall = DllCall("gdiplus.dll", "dword", "GdipGetImageDimension", _
            "ptr", $pBitmap, _
            "float*", 0, _
            "float*", 0)

    If @error Or $a_iCall[0] Then
        DllCall("gdiplus.dll", "dword", "GdipDisposeImage", "ptr", $pBitmap)
        DllCall("gdiplus.dll", "none", "GdiplusShutdown", "dword*", $hGDIplus)
        DllCall("kernel32.dll", "int", "GlobalFree", "hwnd", $hMemory)
        Return SetError(5, 0, "")
    EndIf

    $iWidth = $a_iCall[2]
    $iHeight = $a_iCall[3]

    Local $a_iCall = DllCall("gdiplus.dll", "dword", "GdipImageGetFrameDimensionsCount", _
            "ptr", $pBitmap, _
            "dword*", 0)

    If @error Or $a_iCall[0] Then
        DllCall("gdiplus.dll", "dword", "GdipDisposeImage", "ptr", $pBitmap)
        DllCall("gdiplus.dll", "none", "GdiplusShutdown", "dword*", $hGDIplus)
        DllCall("kernel32.dll", "int", "GlobalFree", "hwnd", $hMemory)
        Return SetError(8, 0, "")
    EndIf

    Local $iFrameDimensionsCount = $a_iCall[2]

    Local $tGUID = DllStructCreate("int;short;short;byte[8]")

    $a_iCall = DllCall("gdiplus.dll", "dword", "GdipImageGetFrameDimensionsList", _
            "ptr", $pBitmap, _
            "ptr", DllStructGetPtr($tGUID), _
            "dword", $iFrameDimensionsCount)

    If @error Or $a_iCall[0] Then
        DllCall("gdiplus.dll", "dword", "GdipDisposeImage", "ptr", $pBitmap)
        DllCall("gdiplus.dll", "none", "GdiplusShutdown", "dword*", $hGDIplus)
        DllCall("kernel32.dll", "int", "GlobalFree", "hwnd", $hMemory)
        Return SetError(9, 0, "")
    EndIf

    $a_iCall = DllCall("gdiplus.dll", "dword", "GdipImageGetFrameCount", _
            "ptr", $pBitmap, _
            "ptr", DllStructGetPtr($tGUID), _
            "dword*", 0)

    If @error Or $a_iCall[0] Then
        DllCall("gdiplus.dll", "dword", "GdipDisposeImage", "ptr", $pBitmap)
        DllCall("gdiplus.dll", "none", "GdiplusShutdown", "dword*", $hGDIplus)
        DllCall("kernel32.dll", "int", "GlobalFree", "hwnd", $hMemory)
        Return SetError(10, 0, "")
    EndIf

    Local $iFrameCount = $a_iCall[3]

    Local $aHBitmaps[$iFrameCount][3]

    For $j = 0 To $iFrameCount - 1

        $a_iCall = DllCall("gdiplus.dll", "dword", "GdipImageSelectActiveFrame", _
                "ptr", $pBitmap, _
                "ptr", DllStructGetPtr($tGUID), _
                "dword", $j)

        If @error Or $a_iCall[0] Then
            ContinueLoop
        EndIf

        $a_iCall = DllCall("gdiplus.dll", "dword", "GdipCreateHBITMAPFromBitmap", _
                "ptr", $pBitmap, _
                "hwnd*", 0, _
                "dword", 0xFF000000)

        If @error Or $a_iCall[0] Then
            ContinueLoop
        EndIf

        $aHBitmaps[$j][0] = $a_iCall[2]

    Next

    $a_iCall = DllCall("gdiplus.dll", "dword", "GdipGetPropertyItemSize", _
            "ptr", $pBitmap, _
            "dword", 20736, _ ; PropertyTagFrameDelay
            "dword*", 0)

    If @error Or $a_iCall[0] Then
        DllCall("gdiplus.dll", "dword", "GdipDisposeImage", "ptr", $pBitmap)
        DllCall("gdiplus.dll", "none", "GdiplusShutdown", "dword*", $hGDIplus)
        DllCall("kernel32.dll", "int", "GlobalFree", "hwnd", $hMemory)
        Return SetError(11, 0, "")
    EndIf

    Local $iPropertyItemSize = $a_iCall[3]

    Local $tRawPropItem = DllStructCreate("byte[" & $iPropertyItemSize & "]")

    $a_iCall = DllCall("gdiplus.dll", "dword", "GdipGetPropertyItem", _
            "ptr", $pBitmap, _
            "dword", 20736, _ ; PropertyTagFrameDelay
            "dword", DllStructGetSize($tRawPropItem), _
            "ptr", DllStructGetPtr($tRawPropItem))

    If @error Or $a_iCall[0] Then
        DllCall("gdiplus.dll", "dword", "GdipDisposeImage", "ptr", $pBitmap)
        DllCall("gdiplus.dll", "none", "GdiplusShutdown", "dword*", $hGDIplus)
        DllCall("kernel32.dll", "int", "GlobalFree", "hwnd", $hMemory)
        Return SetError(12, 0, "")
    EndIf

    Local $tPropItem = DllStructCreate("int Id;" & _
            "dword Length;" & _
            "ushort Type;" & _
            "ptr Value", _
            DllStructGetPtr($tRawPropItem))

    Local $iSize = DllStructGetData($tPropItem, "Length") / 4 ; 'Delay Time' is dword type

    Local $tPropertyData = DllStructCreate("dword[" & $iSize & "]", DllStructGetData($tPropItem, "Value"))

    For $j = 0 To $iFrameCount - 1
        $aHBitmaps[$j][1] = DllStructGetData($tPropertyData, 1, $j + 1) * 10 ; 1 = 10 msec
        $aHBitmaps[$j][2] = $aHBitmaps[$j][1] ; read values
        If Not $aHBitmaps[$j][1] Then
            $aHBitmaps[$j][1] = 130 ; 0 is interpreted as 130 ms
        EndIf
        If $aHBitmaps[$j][1] < 50 Then ; will slow it down to prevent more extensive cpu usage
            $aHBitmaps[$j][1] = 50
        EndIf
    Next

    $iTransparency = 1 ; predefining

    $a_iCall = DllCall("gdiplus.dll", "dword", "GdipBitmapGetPixel", _
            "ptr", $pBitmap, _
            "int", 0, _  ; left
            "int", 0, _  ; upper
            "dword*", 0)

    If @error Or $a_iCall[0] Then
        DllCall("gdiplus.dll", "dword", "GdipDisposeImage", "ptr", $pBitmap)
        DllCall("gdiplus.dll", "none", "GdiplusShutdown", "dword*", $hGDIplus)
        DllCall("kernel32.dll", "int", "GlobalFree", "hwnd", $hMemory)
        Return SetError(13, 0, "")
    EndIf

    If $a_iCall[4] > 16777215 Then
        $iTransparency = 0
    EndIf

    DllCall("gdiplus.dll", "dword", "GdipDisposeImage", "ptr", $pBitmap)
    DllCall("gdiplus.dll", "none", "GdiplusShutdown", "dword*", $hGDIplus)
    DllCall("kernel32.dll", "int", "GlobalFree", "hwnd", $hMemory)

    Return SetError(0, 0, $aHBitmaps)

EndFunc   ;==>_CreateArrayHBitmapsFromGIFBinaryImage

edit:

Removed unused variables

Edited by trancexx

♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

yes, that works fine, thx.

but why does my script loose memory, and yours does not ? it's about the same code, just the other way round. before i start rewriting it i would like to allocate my error.

j.


Spoiler

I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.OixB7.jpgDon't forget this IP: 213.251.145.96

 

Share this post


Link to post
Share on other sites

yes, that works fine, thx.

but why does my script loose memory, and yours does not ? it's about the same code, just the other way round. before i start rewriting it i would like to allocate my error.

j.

Your script is leaking both in memory and gdi objects (task manager -> View -> Select Columns... -> GDI Objects).

This is because you are not getting rid of bitmap handles. If you look at this link then you will see that by:

If $oldBmp[0] <> 0 Then _WinAPI_DeleteObject ($oldBmp[0])

you delete only copy of the bitmap (old one). That is necessary, but you need to delete the original too.

Gdip handles are specific so you can delete as soon as you draw. Just add this

_WinAPI_DeleteObject ($hBitmap)
below mentioned line and you are ok. But there could be a side efect (I forgot what it is).

My script is having that handles in an array and in ResourcesViewerAndCompiler.au3 I took care of them when gif is out.


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Just add this CODE_WinAPI_DeleteObject ($hBitmap)below mentioned line and you are ok. But there could be a side efect (I forgot what it is).

Important

In version 6 of the Microsoft Win32 controls, a bitmap passed to a static control using the STM_SETIMAGE message was the same bitmap returned by a subsequent STM_SETIMAGE message. The client is responsible to delete any bitmap sent to a static control.

With Microsoft Windows XP, if the bitmap passed in the STM_SETIMAGE message contains pixels with non-zero alpha, the static control takes a copy of the bitmap. This copied bitmap is returned by the next STM_SETIMAGE message. The client code may independently track the bitmaps passed to the static control, but if it does not check and release the bitmaps returned from STM_SETIMAGE messages, the bitmaps are leaked.

thx very much. i hope progandy reads this and corrects his "prototype":

;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   ;==>_SetImageBinaryToCtrl

; Authors: Zedna, based on code by Prog@ndy
Func _SetMemoryImageToCtrl($CtrlId, $Pointer, $nSize)
    Local $hData, $pData, $pStream, $pBitmap, $hBitmap
    $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)
;#################
    _WinAPI_DeleteObject ($hBitmap)
;#################
    _GDIPlus_BitmapDispose ($pBitmap)
    _GDIPlus_Shutdown ()
    _WinAPI_DeleteObject ($pStream)
    _MemGlobalFree ($hData)
EndFunc   ;==>_SetMemoryImageToCtrl

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   ;==>__SetBitmapToCtrl

task manager -> View -> Select Columns... -> GDI Objects

thx for this as well. this is very useful !

j.

Edited by jennico

Spoiler

I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.OixB7.jpgDon't forget this IP: 213.251.145.96

 

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

one last question: what secret line makes your gif always being refreshed ? i cannot find it.

j.

(edit: i mean the refreshing when the gui gets active.)

Edited by jennico

Spoiler

I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.OixB7.jpgDon't forget this IP: 213.251.145.96

 

Share this post


Link to post
Share on other sites

one last question: what secret line makes your gif always being refreshed ? i cannot find it.

j.

(edit: i mean the refreshing when the gui gets active.)

There isn't any.

Btw, switching to icon handles drastically reduces cpu and memory usage. That's interesting.


♡♡♡

.

eMyvnE

Share this post


Link to post
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
Sign in to follow this  
Followers 0