Sign in to follow this  
Followers 0
Celtic88

Problem Gdi ++ uses much RAM

11 posts in this topic

#1 ·  Posted (edited)

LOOK

 

http://www.youtube.com/watch?v=khUZIy22idg

#include <GDIPlus.au3>
#include <WindowsConstants.au3>
#include <GuiConstantsEx.au3>
#include <StaticConstants.au3>

Global $_Gui[30], $fontsiz = 32, $txtsiz = 222, $nexttmp, $b, $Search, _
        $shadow, $next, $i, $Opas = 40, $String = Getext(), $picp = Getjpg()
For $i = 1 To 15
    _GDIPlus_Startup()
    spic(randpic(), randtxt())
    Sleep(999)
    DelGui()
    _GDIPlus_Shutdown()
Next
exitt()

Func Getext()
    Local $OPENEtx, $Read, $CHARS, $Zz, $txtphat
    $txtphat = @ScriptDir & "\data\data.txt"
    If FileExists($txtphat) = 0 Then Exit
    $OPENEtx = FileOpen($txtphat, 0)
    If @error Then Exit
    $Read = FileRead($OPENEtx)
    FileClose($OPENEtx)
    Local $CHARS = StringReplace(StringRegExpReplace($Read, "\r\n|\r|\n", Chr(32)), '"', "'")
    For $i = 1 To StringLen($CHARS) Step 1
        If StringMid($CHARS, $i, 1) = Chr(32) And StringMid($CHARS, $i - 1, 1) = Chr(32) Then ContinueLoop
        $Zz &= StringMid($CHARS, $i, 1)
    Next
    Return StringReplace($Zz, "*", @CRLF)
EndFunc   ;==>Getext
Func Getjpg()
    Local $jpg[30], $file, $Search
    $Search = FileFindFirstFile(@ScriptDir & "\data\*.jpg")
    If $Search = -1 Then Exit
    For $i = 1 To 29
        $file = FileFindNextFile($Search)
        If @error Then ExitLoop
        $jpg[$i] = $file
    Next
    $jpg[0] = $i - 1
    FileClose($Search)
    Return $jpg
EndFunc   ;==>Getjpg
Func randpic()
    Local $random
    If $picp[0] = 1 Then
        $random = 1
    Else
        $random = Random(1, $picp[0], 1)
    EndIf
    Return @ScriptDir & "\data\" & $picp[$random]
EndFunc   ;==>randpic
Func randtxt()
    Local $random, $arr
    $arr = StringSplit($String, "|", 1)
    If @error Then Return $String
    $random = Random(1, $arr[0], 1)
    Return $arr[$random]
EndFunc   ;==>randtxt
Func spic($_PngPath, $text)
    $i = 0
    Local $_Image, $_Width, $_Height, $_Ratio, $trans, $DesktopWidth = @DesktopWidth, _
            $pWidth = Round($DesktopWidth / 3, 0)
    $_Image = _GDIPlus_ImageLoadFromFile($_PngPath)
    $_Width = _GDIPlus_ImageGetWidth($_Image)
    $_Height = _GDIPlus_ImageGetHeight($_Image)
    $_Ratio = $_Width / $_Height
    Switch $_Ratio
        Case 0 To 0.8
            $txtsiz = 550
        Case 0.8 To 1
            $txtsiz = 450
        Case 1 To 1.6
            $txtsiz = 250
        Case 1.6 To 2
            $txtsiz = 180
    EndSwitch
    For $_Width = $DesktopWidth / 6 To $pWidth Step 25
        $i += 1
        $_Gui[$i] = GUICreate("", $_Width, $_Width / $_Ratio, -1, -1, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST, $WS_EX_TOOLWINDOW))
        $_Image = _ImageResize($_PngPath, $_Width, $_Width / $_Ratio)
        $trans = Round(Round($_Width, 0) * $Opas / $pWidth, 0)
        _SetBitmap($_Gui[$i], $_Image, $trans, $_Width, $_Width / $_Ratio)
        GUISetState(@SW_SHOW)
        Sleep(22)
    Next
    Opt("GUIONEVENTMODE", 1)
    $chil = GUICreate("", $DesktopWidth / 3, $_Width / $_Ratio, 0, 0, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $_Gui[$i])
    GUISetBkColor(0x222222)
    GUICtrlCreatePic(@ScriptDir & "\data\grey.gif", 0, 0, $DesktopWidth / 3, $_Width / $_Ratio)
    GUICtrlSetState(-1, $GUI_DISABLE)
    $b = addlab("...تكملة", 25, $_Width / $_Ratio - 110, $DesktopWidth / 3 - 25, 300, "", "DecoType Naskh Variants", 44, 800)
    GUICtrlSetOnEvent($b, "nex")
    GUICtrlSetState($b, $GUI_hide)
    $exit = addbot("X", $_Width - 20, 5, 15, 15, "0xFFFFFF", "0x448CAF")
    GUICtrlSetOnEvent($exit, "DelGui")
    $shadow = addlab("", 2, 15, $DesktopWidth / 3 - 18, $_Width / $_Ratio - 85, $SS_CENTER, "DecoType Naskh Variants", $fontsiz, 400, "")
    $Search = addlab("", 0, 13, $DesktopWidth / 3 - 16, $_Width / $_Ratio - 85, $SS_CENTER, "DecoType Naskh Variants", $fontsiz, 400)
    strinsiz($text)
    GUISetState()
    _GDIPlus_GraphicsDispose($_Image)
EndFunc   ;==>spic
Func addlab($txxt, $w, $h, $wp, $hp, $sty, $font, $fsiz, $fg, $col = 0xF1F1F1)
    Local $clab
    $clab = GUICtrlCreateLabel($txxt, $w, $h, $wp, $hp, $sty)
    GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
    GUICtrlSetFont(-1, $fsiz, $fg, 0, $font)
    GUICtrlSetColor(-1, $col)
    Return $clab
EndFunc   ;==>addlab
Func addbot($txxt, $w, $h, $wp, $hp, $bcol, $col)
    Local $cbou
    $cbou = GUICtrlCreateButton($txxt, $w, $h, $wp, $hp)
    GUICtrlSetBkColor(-1, $bcol)
    GUICtrlSetColor(-1, $col)
    Return $cbou
EndFunc   ;==>addbot
Func DelGui()
    For $s = $i To 1 Step -1
        Sleep(29)
        GUIDelete($_Gui[$s])
    Next
EndFunc   ;==>DelGui
Func exitt()
    Exit
EndFunc   ;==>exitt
Func nex()
    strinsiz($nexttmp)
EndFunc   ;==>nex
Func strinsiz($txto)
    Local $STEXT1, $TXT
    $STEXT1 = StringSplit($txto, Chr(32), 1)
    For $O = 1 To $STEXT1[0]
        $TXT &= $STEXT1[$O] & Chr(32)
        If StringLen($TXT) > $txtsiz Then
            GUICtrlSetState($b, $GUI_show)
            GUICtrlSetData($Search, $TXT)
            GUICtrlSetData($shadow, $TXT)
            $next = 1
            $nexttmp = StringTrimLeft($txto, StringLen($TXT))
            ExitLoop
        ElseIf $O = $STEXT1[0] Then
            If $next = 1 Then
                GUICtrlSetState($b, $GUI_hide)
                $next = 0
            EndIf
            GUICtrlSetData($Search, $TXT)
            GUICtrlSetData($shadow, $TXT)
        EndIf
    Next
EndFunc   ;==>strinsiz
Func _SetBitmap($hGUI, $hImage, $iOpacity, $n_width, $n_height)
    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", $n_width)
    DllStructSetData($tSize, "Y", $n_height)
    $tSource = DllStructCreate($tagPOINT)
    $pSource = DllStructGetPtr($tSource)
    $tBlend = DllStructCreate($tagBLENDFUNCTION)
    $pBlend = DllStructGetPtr($tBlend)
    DllStructSetData($tBlend, "Alpha", $iOpacity)
    DllStructSetData($tBlend, "Format", 1)
    _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
Func _ImageResize($sInImage, $newW, $newH, $sOutImage = "")
    Local $oldImage, $GC, $newBmp, $newGC
    If $sOutImage = "" Then _GDIPlus_Startup()
    $oldImage = _GDIPlus_ImageLoadFromFile($sInImage)
    $GC = _GDIPlus_ImageGetGraphicsContext($oldImage)
    $newBmp = _GDIPlus_BitmapCreateFromGraphics($newW, $newH, $GC)
    $newGC = _GDIPlus_ImageGetGraphicsContext($newBmp)
    _GDIPlus_GraphicsDrawImageRect($newGC, $oldImage, 0, 0, $newW, $newH)
    _GDIPlus_GraphicsDispose($GC)
    _GDIPlus_GraphicsDispose($newGC)
    _GDIPlus_ImageDispose($oldImage)
    Return $newBmp
EndFunc   ;==>_ImageResize

Download ful pack : http://www.mediafire.com/?9vzknf0ep281177

Edited by Mrbenkali

Share this post


Link to post
Share on other sites



It would have been much better if you had just listed the RAM usage, because your video is hard to read even at full screen. Plus your script isn't runnable due to not having all the files it needs to run, it just exits immediately when it can't find them.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

It would have been much better if you had just listed the RAM usage, because your video is hard to read even at full screen. Plus your script isn't runnable due to not having all the files it needs to run, it just exits immediately when it can't find them.

Thank you for your response Download ful file : http://www.mediafire.com/?9vzknf0ep281177

Share this post


Link to post
Share on other sites

A few things I noticed right away is that you're running _GDIPlus_Startup() every time through the first loop. Probably not the problem due to you shutting it down every time too, although I'd consider it bad coding practice to do it this way. It would probably be better to start it once before the loop, and then shut it down after the loop. It works exactly the same way doing it this way.

Second thing I saw was that you declare the $i variable as a global and then use it everywhere in your script, including the loop at the start of the script. This caused the loop to never end because $i is being given new values everywhere in your script. Changing the $i in the For loop to any other name fixes that problem.

Third, you're calling _ImageResize 8 times for every loop iteration, plus because you called it with the $sOutImage parameter blank, it calls _GDIPlus_Startup every time it runs the imageresize function. You might be better off to do the image resize once, and fix the $sOutImage parameter issue in your script.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

ok all the bugs fixi May The unresolved problem 

#include <GDIPlus.au3>
#include <WindowsConstants.au3>
#include <GuiConstantsEx.au3>
#include <StaticConstants.au3>

;_WinAPI_AddFontResourceEx(@ScriptDir & "\data\DTNASKH2.TTF")

Global $_Gui[30], $fontsiz = 32, $txtsiz, $nexttmp, $b, $Search, _
        $shadow, $next, $i, $Opas = 40, $String = Getext(), $picp = Getjpg()

_GDIPlus_Startup()
For $ir = 1 To 15
    spic(randpic(), randtxt())
    Sleep(999)
    DelGui()
Next
_GDIPlus_Shutdown()

exitt()

Func Getext()
    Local $OPENEtx, $Read, $CHARS, $Zz, $txtphat
    $txtphat = @ScriptDir & "\data\data.txt"
    If FileExists($txtphat) = 0 Then Exit
    $OPENEtx = FileOpen($txtphat, 0)
    If @error Then Exit
    $Read = FileRead($OPENEtx)
    FileClose($OPENEtx)
    Local $CHARS = StringReplace(StringRegExpReplace($Read, "\r\n|\r|\n", Chr(32)), '"', "'")
    For $ii = 1 To StringLen($CHARS) Step 1
        If StringMid($CHARS, $ii, 1) = Chr(32) And StringMid($CHARS, $ii - 1, 1) = Chr(32) Then ContinueLoop
        $Zz &= StringMid($CHARS, $ii, 1)
    Next
    Return StringReplace($Zz, "*", @CRLF)
EndFunc   ;==>Getext
Func Getjpg()
    Local $jpg[30], $file, $Search
    $Search = FileFindFirstFile(@ScriptDir & "\data\*.jpg")
    If $Search = -1 Then Exit
    For $iz = 1 To 29
        $file = FileFindNextFile($Search)
        If @error Then ExitLoop
        $jpg[$iz] = $file
    Next
    $jpg[0] = $iz - 1
    FileClose($Search)
    Return $jpg
EndFunc   ;==>Getjpg
Func randpic()
    Local $random
    If $picp[0] = 1 Then
        $random = 1
    Else
        $random = Random(1, $picp[0], 1)
    EndIf
    Return @ScriptDir & "\data\" & $picp[$random]
EndFunc   ;==>randpic
Func randtxt()
    Local $random, $arr
    $arr = StringSplit($String, "|", 1)
    If @error Then Return $String
    $random = Random(1, $arr[0], 1)
    Return $arr[$random]
EndFunc   ;==>randtxt
Func spic($_PngPath, $text)
    $i = 0
    Local $_Image, $_Width, $_Height, $_Ratio, $trans, $DesktopWidth = @DesktopWidth, _
            $pWidth = Round($DesktopWidth / 3, 0)
    $_Image = _GDIPlus_ImageLoadFromFile($_PngPath)
    $_Width = _GDIPlus_ImageGetWidth($_Image)
    $_Height = _GDIPlus_ImageGetHeight($_Image)
    $_Ratio = $_Width / $_Height
    Switch $_Ratio
        Case 0 To 0.8
            $txtsiz = 550
        Case 0.8 To 1
            $txtsiz = 450
        Case 1 To 1.6
            $txtsiz = 250
        Case 1.6 To 2
            $txtsiz = 180
    EndSwitch
    For $_Width = $DesktopWidth / 6 To $pWidth Step 25
        $i += 1
        $_Gui[$i] = GUICreate("", $_Width, $_Width / $_Ratio, -1, -1, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST, $WS_EX_TOOLWINDOW))
        $_Image = _ImageResize($_PngPath, $_Width, $_Width / $_Ratio)
        $trans = Round(Round($_Width, 0) * $Opas / $pWidth, 0)
        _SetBitmap($_Gui[$i], $_Image, $trans, $_Width, $_Width / $_Ratio)
        GUISetState(@SW_SHOW)
        Sleep(22)
    Next
    Opt("GUIONEVENTMODE", 1)
    $chil = GUICreate("", $DesktopWidth / 3, $_Width / $_Ratio, 0, 0, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $_Gui[$i])
    GUISetBkColor(0x222222)
    GUICtrlCreatePic(@ScriptDir & "\data\grey.gif", 0, 0, $DesktopWidth / 3, $_Width / $_Ratio)
    GUICtrlSetState(-1, $GUI_DISABLE)
    $b = addlab("...تكملة", 25, $_Width / $_Ratio - 110, $DesktopWidth / 3 - 25, 300, "", "DecoType Naskh Variants", 44, 800)
    GUICtrlSetOnEvent($b, "nex")
    GUICtrlSetState($b, $GUI_hide)
    $exit = addbot("X", $_Width - 20, 5, 15, 15, "0xFFFFFF", "0x448CAF")
    GUICtrlSetOnEvent($exit, "DelGui")
    $shadow = addlab("", 2, 15, $DesktopWidth / 3 - 18, $_Width / $_Ratio - 85, $SS_CENTER, "DecoType Naskh Variants", $fontsiz, 400, "")
    $Search = addlab("", 0, 13, $DesktopWidth / 3 - 16, $_Width / $_Ratio - 85, $SS_CENTER, "DecoType Naskh Variants", $fontsiz, 400)
    strinsiz($text)
    GUISetState()
    _GDIPlus_GraphicsDispose($_Image)
EndFunc   ;==>spic
Func addlab($txxt, $w, $h, $wp, $hp, $sty, $font, $fsiz, $fg, $col = 0xF1F1F1)
    Local $clab
    $clab = GUICtrlCreateLabel($txxt, $w, $h, $wp, $hp, $sty)
    GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
    GUICtrlSetFont(-1, $fsiz, $fg, 0, $font)
    GUICtrlSetColor(-1, $col)
    Return $clab
EndFunc   ;==>addlab
Func addbot($txxt, $w, $h, $wp, $hp, $bcol, $col)
    Local $cbou
    $cbou = GUICtrlCreateButton($txxt, $w, $h, $wp, $hp)
    GUICtrlSetBkColor(-1, $bcol)
    GUICtrlSetColor(-1, $col)
    Return $cbou
EndFunc   ;==>addbot
Func DelGui()
    For $s = $i To 1 Step -1
        Sleep(29)
        GUIDelete($_Gui[$s])
    Next
EndFunc   ;==>DelGui
Func exitt()
    Exit
EndFunc   ;==>exitt
Func nex()
    strinsiz($nexttmp)
EndFunc   ;==>nex
Func strinsiz($txto)
    Local $STEXT1, $TXT
    $STEXT1 = StringSplit($txto, Chr(32), 1)
    For $O = 1 To $STEXT1[0]
        $TXT &= $STEXT1[$O] & Chr(32)
        If StringLen($TXT) > $txtsiz Then
            GUICtrlSetState($b, $GUI_show)
            GUICtrlSetData($Search, $TXT)
            GUICtrlSetData($shadow, $TXT)
            $next = 1
            $nexttmp = StringTrimLeft($txto, StringLen($TXT))
            ExitLoop
        ElseIf $O = $STEXT1[0] Then
            If $next = 1 Then
                GUICtrlSetState($b, $GUI_hide)
                $next = 0
            EndIf
            GUICtrlSetData($Search, $TXT)
            GUICtrlSetData($shadow, $TXT)
        EndIf
    Next
EndFunc   ;==>strinsiz
Func _SetBitmap($hGUI, $hImage, $iOpacity, $n_width, $n_height)
    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", $n_width)
    DllStructSetData($tSize, "Y", $n_height)
    $tSource = DllStructCreate($tagPOINT)
    $pSource = DllStructGetPtr($tSource)
    $tBlend = DllStructCreate($tagBLENDFUNCTION)
    $pBlend = DllStructGetPtr($tBlend)
    DllStructSetData($tBlend, "Alpha", $iOpacity)
    DllStructSetData($tBlend, "Format", 1)
    _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
Func _WinAPI_AddFontResourceEx($sFont, $iFlag = 0, $fNotify = 0)
    Local $Ret = DllCall('gdi32.dll', 'int', 'AddFontResourceExW', 'wstr', $sFont, 'dword', $iFlag, 'ptr', 0)
    If (@error) Or (Not $Ret[0]) Then
        Return SetError(1, 0, 0)
    EndIf
    If $fNotify Then
        DllCall('user32.dll', 'none', 'SendMessage', 'hwnd', 0xFFFF, 'uint', 0x001D, 'wparam', 0, 'lparam', 0)
    EndIf
    Return $Ret[0]
EndFunc   ;==>_WinAPI_AddFontResourceEx
Func _ImageResize($sInImage, $newW, $newH)
    Local $oldImage, $GC, $newBmp, $newGC
    $oldImage = _GDIPlus_ImageLoadFromFile($sInImage)
    $GC = _GDIPlus_ImageGetGraphicsContext($oldImage)
    $newBmp = _GDIPlus_BitmapCreateFromGraphics($newW, $newH, $GC)
    $newGC = _GDIPlus_ImageGetGraphicsContext($newBmp)
    _GDIPlus_GraphicsDrawImageRect($newGC, $oldImage, 0, 0, $newW, $newH)
    _GDIPlus_GraphicsDispose($GC)
    _GDIPlus_GraphicsDispose($newGC)
    _GDIPlus_ImageDispose($oldImage)
    Return $newBmp
EndFunc   ;==>_ImageResize

Share this post


Link to post
Share on other sites

According to your video on YT it seems that you have a memory leak. That means you create a bitmap/image/context handle without disposing it.

Br,

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!
¯\_(ツ)_/¯

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

According to your video on YT it seems that you have a memory leak. That means you create a bitmap/image/context handle without disposing it.

Br,

UEZ

i am noooob  :graduated:  you can correct this problem in my script thank you UEZ

Edited by Mrbenkali

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Try this:

#include <GDIPlus.au3>
#include <WindowsConstants.au3>
#include <GuiConstantsEx.au3>
#include <StaticConstants.au3>

_WinAPI_AddFontResourceEx(@ScriptDir & "\data\DTNASKH2.TTF")

Global $_Gui[30], $fontsiz = 32, $txtsiz, $nexttmp, $b, $Search, _
        $shadow, $next, $i, $Opas = 40, $String = Getext(), $picp = Getjpg()

_GDIPlus_Startup()
For $ir = 1 To 10
    spic(randpic(), randtxt())
    Sleep(9999)
    DelGui()
Next
_GDIPlus_Shutdown()

exitt()

Func Getext()
    Local $OPENEtx, $Read, $CHARS, $Zz, $txtphat
    $txtphat = @ScriptDir & "\data\data.txt"
    If FileExists($txtphat) = 0 Then Exit
    $OPENEtx = FileOpen($txtphat, 0)
    If @error Then Exit
    $Read = FileRead($OPENEtx)
    FileClose($OPENEtx)
    Local $CHARS = StringReplace(StringRegExpReplace($Read, "\r\n|\r|\n", Chr(32)), '"', "'")
    For $ii = 1 To StringLen($CHARS) Step 1
        If StringMid($CHARS, $ii, 1) = Chr(32) And StringMid($CHARS, $ii - 1, 1) = Chr(32) Then ContinueLoop
        $Zz &= StringMid($CHARS, $ii, 1)
    Next
    Return StringReplace($Zz, "*", @CRLF)
EndFunc   ;==>Getext
Func Getjpg()
    Local $jpg[30], $file, $Search
    $Search = FileFindFirstFile(@ScriptDir & "\data\*.jpg")
    If $Search = -1 Then Exit
    For $iz = 1 To 29
        $file = FileFindNextFile($Search)
        If @error Then ExitLoop
        $jpg[$iz] = $file
    Next
    $jpg[0] = $iz - 1
    FileClose($Search)
    Return $jpg
EndFunc   ;==>Getjpg
Func randpic()
    Local $random
    If $picp[0] = 1 Then
        $random = 1
    Else
        $random = Random(1, $picp[0], 1)
    EndIf
    Return @ScriptDir & "\data\" & $picp[$random]
EndFunc   ;==>randpic
Func randtxt()
    Local $random, $arr
    $arr = StringSplit($String, "|", 1)
    If @error Then Return $String
    $random = Random(1, $arr[0], 1)
    Return $arr[$random]
EndFunc   ;==>randtxt
Func spic($_PngPath, $text)
    $i = 0
    Local $_Image, $_Image2, $_Width, $_Height, $_Ratio, $trans, $DesktopWidth = @DesktopWidth, _
            $pWidth = Round($DesktopWidth / 3, 0)
    $_Image = _GDIPlus_ImageLoadFromFile($_PngPath)
    $_Width = _GDIPlus_ImageGetWidth($_Image)
    $_Height = _GDIPlus_ImageGetHeight($_Image)
    $_Ratio = $_Width / $_Height
    Switch $_Ratio
        Case 0 To 0.8
            $txtsiz = 550
        Case 0.8 To 1
            $txtsiz = 420
        Case 1 To 1.6
            $txtsiz = 230
        Case 1.6 To 2
            $txtsiz = 180
    EndSwitch
    For $_Width = $DesktopWidth / 6 To $pWidth Step 25
        $i += 1
        $_Gui[$i] = GUICreate("", $_Width, $_Width / $_Ratio, -1, -1, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST, $WS_EX_TOOLWINDOW))
        $_Image2 = _ImageResize($_PngPath, $_Width, $_Width / $_Ratio) ;<<<<<<<<<<<<<<<< change here
        $trans = Round(Round($_Width, 0) * $Opas / $pWidth, 0)
        _SetBitmap($_Gui[$i], $_Image2, $trans, $_Width, $_Width / $_Ratio)
        _GDIPlus_BitmapDispose($_Image2) ;<<<<<<<<<<<<<<<< change here
        GUISetState(@SW_SHOW)
        Sleep(22)
    Next
    Opt("GUIONEVENTMODE", 1)
    $chil = GUICreate("", $DesktopWidth / 3, $_Width / $_Ratio, 0, 0, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $_Gui[$i])
    GUISetBkColor(0x222222)
    GUICtrlCreatePic(@ScriptDir & "\data\grey.gif", 0, 0, $DesktopWidth / 3, $_Width / $_Ratio)
    GUICtrlSetState(-1, $GUI_DISABLE)
    $b = addlab("..تكملة", 22, $_Width / $_Ratio - 110, $DesktopWidth / 3 - 22, 300, "", "DecoType Naskh Variants", 33, 800)
    GUICtrlSetOnEvent($b, "nex")
    GUICtrlSetState($b, $GUI_hide)
    $exit = addbot("X", $_Width - 20, 5, 15, 15, "0xFFFFFF", "0x448CAF")
    GUICtrlSetOnEvent($exit, "DelGui")
    $shadow = addlab("", 2, 15, $DesktopWidth / 3 - 18, $_Width / $_Ratio - 70, $SS_CENTER, "DecoType Naskh Variants", $fontsiz, 400, "")
    $Search = addlab("", 0, 13, $DesktopWidth / 3 - 16, $_Width / $_Ratio - 70, $SS_CENTER, "DecoType Naskh Variants", $fontsiz, 400)
    strinsiz($text)
    GUISetState()
    _GDIPlus_ImageDispose($_Image) ;<<<<<<<<<<<<<<<< change here
EndFunc   ;==>spic
Func addlab($txxt, $w, $h, $wp, $hp, $sty, $font, $fsiz, $fg, $col = 0xF1F1F1)
    Local $clab
    $clab = GUICtrlCreateLabel($txxt, $w, $h, $wp, $hp, $sty)
    GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
    GUICtrlSetFont(-1, $fsiz, $fg, 0, $font)
    GUICtrlSetColor(-1, $col)
    Return $clab
EndFunc   ;==>addlab
Func addbot($txxt, $w, $h, $wp, $hp, $bcol, $col)
    Local $cbou
    $cbou = GUICtrlCreateButton($txxt, $w, $h, $wp, $hp)
    GUICtrlSetBkColor(-1, $bcol)
    GUICtrlSetColor(-1, $col)
    Return $cbou
EndFunc   ;==>addbot
Func DelGui()
    For $s = $i To 1 Step -1
        Sleep(29)
        GUIDelete($_Gui[$s])
    Next
EndFunc   ;==>DelGui
Func exitt()
    Exit
EndFunc   ;==>exitt
Func nex()
    strinsiz($nexttmp)
EndFunc   ;==>nex
Func strinsiz($txto)
    Local $STEXT1, $TXT
    $STEXT1 = StringSplit($txto, Chr(32), 1)
    For $O = 1 To $STEXT1[0]
        $TXT &= $STEXT1[$O] & Chr(32)
        If StringLen($TXT) > $txtsiz Then
            GUICtrlSetState($b, $GUI_show)
            GUICtrlSetData($Search, $TXT)
            GUICtrlSetData($shadow, $TXT)
            $next = 1
            $nexttmp = StringTrimLeft($txto, StringLen($TXT))
            ExitLoop
        ElseIf $O = $STEXT1[0] Then
            If $next = 1 Then
                GUICtrlSetState($b, $GUI_hide)
                $next = 0
            EndIf
            GUICtrlSetData($Search, $TXT)
            GUICtrlSetData($shadow, $TXT)
        EndIf
    Next
EndFunc   ;==>strinsiz
Func _SetBitmap($hGUI, $hImage, $iOpacity, $n_width, $n_height)
    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", $n_width)
    DllStructSetData($tSize, "Y", $n_height)
    $tSource = DllStructCreate($tagPOINT)
    $pSource = DllStructGetPtr($tSource)
    $tBlend = DllStructCreate($tagBLENDFUNCTION)
    $pBlend = DllStructGetPtr($tBlend)
    DllStructSetData($tBlend, "Alpha", $iOpacity)
    DllStructSetData($tBlend, "Format", 1)
    _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
Func _WinAPI_AddFontResourceEx($sFileName, $iFlag = 0x10)
    Local $aResult
    $aResult = DllCall("Gdi32.dll", "int", "AddFontResourceEx", "str", $sFileName, "dword", $iFlag, "ptr", 0)
    If @error Then Return SetError(@error, @extended, 0)
    Return $aResult[0]
EndFunc   ;==>_WinAPI_AddFontResourceEx
Func _ImageResize($sInImage, $newW, $newH)
    Local $oldImage, $GC, $newBmp, $newGC
    $oldImage = _GDIPlus_ImageLoadFromFile($sInImage)
    $GC = _GDIPlus_ImageGetGraphicsContext($oldImage)
    $newBmp = _GDIPlus_BitmapCreateFromGraphics($newW, $newH, $GC)
    $newGC = _GDIPlus_ImageGetGraphicsContext($newBmp)
    _GDIPlus_GraphicsDrawImageRect($newGC, $oldImage, 0, 0, $newW, $newH)
    _GDIPlus_GraphicsDispose($GC)
    _GDIPlus_GraphicsDispose($newGC)
    _GDIPlus_ImageDispose($oldImage)
    Return $newBmp
EndFunc   ;==>_ImageResize

What is the topic of the slide show?
 
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!
¯\_(ツ)_/¯

Share this post


Link to post
Share on other sites

No, you didn't see what I did!

The faulty function is spic()

I update the code from >post#8 again.

Have a closer look to it.

Br,

UEZ

1 person likes this

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!
¯\_(ツ)_/¯

Share this post


Link to post
Share on other sites

OHHHHHH THANK YOU 100000000000000   :thumbsup:  WORK CASE CLOSED

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