Jump to content

Recommended Posts

Posted

Hello guys!
I'm new to this forum,
I have a problem where I tried to find a solution for 1 day, but I didn't find a solution.
I have a script with many images, much more complicated than the attached example, the problem is that when I use the "GUICtrlSetImage" function, several times, it starts to flickers.
If anyone knows how to solve this, I appreciate it!

 

Thanks!

 

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

$Form1 = GUICreate("Form1", 1051, 613, 192, 124)
$Pic1 = GUICtrlCreatePic("1.bmp", 0, 0, 1030, 547)
$Button1 = GUICtrlCreateButton("SWAP", 56, 576, 75, 25)
GUISetState(@SW_SHOW)


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            GUICtrlSetImage($Pic1, Random(1, 3, 1) & ".bmp")
    EndSwitch
WEnd

 

 

test flipping.zipFetching info...

Posted

Haha yes we just sit here to answer you :P 

by the way it works for me without flicker ... seems like it's your equipment

why do i get garbage when i buy garbage bags? <_<

Posted

I have 16 Gb RAM, not my equipment is the problem.
The problem is the "GUICtrlSetImage" function
When you use it, it's actually flickering and doesn't look professional.
I tried all , I tried to use "GUICtrlSetState (-1, $ GUI_HIDE)" before  GUICtrlSetImage, but it has no effect.

Posted (edited)

Are you kidding me? (!)

I mean i can see in your video it's not the code you have posted...

You added a While loop ..  And obviously it flickers then.

The code you have posted above works pretty well

Maybe you can tell me what you are trying to do and i can help you then .

 

EDIT: By the way the rects aren't on the same position so you would never have the same rect....

 

I would say you take a look on GDI+ image buffering  maybe that does what you want

Edited by Aelc

why do i get garbage when i buy garbage bags? <_<

Posted

I have already found a forum with this discussion, but it is an old thread and many links there no longer work

 

It seems that this problem is major and there are not many solutions for it.

 

 

 

Posted (edited)

Actually guictrlset(..) aren't the best ways to update something without flicker when it goes that fast.

#include <GdiPlus.au3>
OnAutoItExitRegister("_exit")
$hGUI = GUICreate("test", 300, 200)
GUISetState()
_GDIPlus_Startup()
$hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI)
$hBitmap = _GDIPlus_BitmapCreateFromGraphics(280, 180, $hGraphics)
$buffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
_GDIPlus_GraphicsSetSmoothingMode($buffer, 2)

Local $Bitmaps[3]

$Bitmaps[0] = _GDIPlus_ImageLoadFromFile("1.bmp")
$Bitmaps[1] = _GDIPlus_ImageLoadFromFile("2.bmp")
$Bitmaps[2] = _GDIPlus_ImageLoadFromFile("3.bmp")

While 1
    For $i = 0 To 2
        _GDIPlus_GraphicsDrawImageRect($buffer, $Bitmaps[$i], 0, 0, 280, 180)
        _GDIPlus_GraphicsDrawImageRect($hGraphics, $hBitmap, 0, 0, 280, 180)
        $nMsg = GUIGetMsg()
        Sleep(50)
        If $nMsg = -3 Then Exit
    Next
WEnd

Func _exit()
    _GDIPlus_GraphicsDispose($hGraphics)
    For $i = 0 To 2
    _GDIPlus_ImageDispose($Bitmaps[$i])
    Next
    _GDIPlus_GraphicsDispose($buffer)
    _GDIPlus_Shutdown()
EndFunc   ;==>_exit

this is an example with GDI+

The only flicker is now your rects :P But still, it would look better when your rects would be on same position...

alternative you could also draw your rects with GDI+ and without bitmaps and fade some colors for a smooth fade

 

Edited by Aelc

why do i get garbage when i buy garbage bags? <_<

Posted

Waw. it really works. Honestly, I didn't expect it to work.
I appreciate your help. Thank you!

I will attach my original code and the code solved with your functions, for who will need it in the future.

(Download zip images)

GUICtrlSetImage / flickers problem code

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

AutoItSetOption("GuiOnEventMode", 1)

$Img1_1 = @TempDir & "\Dashboard left.bmp"
FileInstall("Dashboard left.bmp", $Img1_1, 1)
$Img1_2 = @TempDir & "\Dashboard up.bmp"
FileInstall("Dashboard up.bmp", $Img1_2, 1)

$interface_1 = @TempDir & "\1.bmp"
FileInstall("1.bmp", $interface_1, 1)
$interface_2 = @TempDir & "\2.bmp"
FileInstall("2.bmp", $interface_2, 1)
$interface_3 = @TempDir & "\3.bmp"
FileInstall("3.bmp", $interface_3, 1)

$Form1 = GUICreate("Form1", 1325, 999, -1, -1, BitOR($WS_SYSMENU, $WS_POPUP, $WS_EX_LAYERED))
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

$Pic1 = GUICtrlCreatePic($Img1_1, 0, 0, 297, 899)
GUICtrlSetState(-1, $GUI_DISABLE)
$Pic2 = GUICtrlCreatePic($Img1_2, 295, 0, 1030, 353)
GUICtrlSetState(-1, $GUI_DISABLE)
$Pic3 = GUICtrlCreatePic($interface_1, 295, 352, 1030, 547)
GUICtrlSetState(-1, $GUI_DISABLE)

$Button1 = GUICtrlCreateButton("IMG1", 100, 920, 83, 25)
GUICtrlSetOnEvent($Button1, "IMG1")
$Button2 = GUICtrlCreateButton("IMG2", 200, 920, 83, 25)
GUICtrlSetOnEvent($Button2, "IMG2")
$Button3 = GUICtrlCreateButton("IMG3", 300, 920, 83, 25)
GUICtrlSetOnEvent($Button3, "IMG3")

GUISetState(@SW_SHOW)


While 1
    Sleep(10)
WEnd

Func IMG1()
    GUICtrlSetImage($Pic3, $interface_1)
EndFunc   ;==>IMG1
Func IMG2()
    GUICtrlSetImage($Pic3, $interface_2)
EndFunc   ;==>IMG2
Func IMG3()
    GUICtrlSetImage($Pic3, $interface_3)
EndFunc   ;==>IMG3

Func _Exit()
    Exit
EndFunc   ;==>_Exit

 

GDI+  / flickers problem fixed by Aelc

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GdiPlus.au3>
AutoItSetOption("GuiOnEventMode", 1)

$Img1_1 = @TempDir & "\Dashboard left.bmp"
FileInstall("Dashboard left.bmp", $Img1_1, 1)
$Img1_2 = @TempDir & "\Dashboard up.bmp"
FileInstall("Dashboard up.bmp", $Img1_2, 1)

$interface_1 = @TempDir & "\1.bmp"
FileInstall("1.bmp", $interface_1, 1)
$interface_2 = @TempDir & "\2.bmp"
FileInstall("2.bmp", $interface_2, 1)
$interface_3 = @TempDir & "\3.bmp"
FileInstall("3.bmp", $interface_3, 1)


OnAutoItExitRegister("_exit")

$Form1 = GUICreate("Form1", 1325, 999, -1, -1, BitOR($WS_SYSMENU, $WS_POPUP, $WS_EX_LAYERED))
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

$Pic1 = GUICtrlCreatePic($Img1_1, 0, 0, 297, 899)
GUICtrlSetState(-1, $GUI_DISABLE)
$Pic2 = GUICtrlCreatePic($Img1_2, 295, 0, 1030, 353)
GUICtrlSetState(-1, $GUI_DISABLE)

$Button1 = GUICtrlCreateButton("IMG1", 100, 920, 83, 25)
GUICtrlSetOnEvent($Button1, "IMG1")
$Button2 = GUICtrlCreateButton("IMG2", 200, 920, 83, 25)
GUICtrlSetOnEvent($Button2, "IMG2")
$Button3 = GUICtrlCreateButton("IMG3", 300, 920, 83, 25)
GUICtrlSetOnEvent($Button3, "IMG3")

GUISetState(@SW_SHOW)
_GDIPlus_Startup()
$hGraphics = _GDIPlus_GraphicsCreateFromHWND($Form1)
$hBitmap = _GDIPlus_BitmapCreateFromGraphics(1030, 547, $hGraphics)
$buffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
_GDIPlus_GraphicsSetSmoothingMode($buffer, 2)

While 1
    Sleep(10)
WEnd

Func IMG1()
    _GDIPlus_GraphicsDrawImageRect($buffer, _GDIPlus_ImageLoadFromFile($interface_1), 0, 0, 1030, 547)
    _GDIPlus_GraphicsDrawImageRect($hGraphics, $hBitmap, 295, 352, 1030, 547)
EndFunc   ;==>IMG1
Func IMG2()
    _GDIPlus_GraphicsDrawImageRect($buffer, _GDIPlus_ImageLoadFromFile($interface_2), 0, 0, 1030, 547)
    _GDIPlus_GraphicsDrawImageRect($hGraphics, $hBitmap, 295, 352, 1030, 547)
EndFunc   ;==>IMG2
Func IMG3()
    _GDIPlus_GraphicsDrawImageRect($buffer, _GDIPlus_ImageLoadFromFile($interface_3), 0, 0, 1030, 547)
    _GDIPlus_GraphicsDrawImageRect($hGraphics, $hBitmap, 295, 352, 1030, 547)
EndFunc   ;==>IMG3

Func _Exit()
    Exit
EndFunc   ;==>_Exit

 

imagesdld.zip 38.15 kB · 165 downloads

Posted (edited)

Indeed the above code works very well, I tried to make a function easier to use than this, it is not the best function, but it works.

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GdiPlus.au3>

_GDIPlus_Startup()

AutoItSetOption("GuiOnEventMode", 1)

$Img1_1 = @TempDir & "\Dashboard left.bmp"
FileInstall("Dashboard left.bmp", $Img1_1, 1)
$Img1_2 = @TempDir & "\Dashboard up.bmp"
FileInstall("Dashboard up.bmp", $Img1_2, 1)

$interface_1 = @TempDir & "\1.bmp"
FileInstall("1.bmp", $interface_1, 1)
$interface_2 = @TempDir & "\2.bmp"
FileInstall("2.bmp", $interface_2, 1)
$interface_3 = @TempDir & "\3.bmp"
FileInstall("3.bmp", $interface_3, 1)


OnAutoItExitRegister("_exit")

$Form1 = GUICreate("Form1", 1325, 999, -1, -1)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

$Pic1 = GUICtrlCreatePic($Img1_1, 0, 0, 297, 899)
GUICtrlSetState(-1, $GUI_DISABLE)
$Pic2 = GUICtrlCreatePic($Img1_2, 295, 0, 1030, 353)
GUICtrlSetState(-1, $GUI_DISABLE)

$Button1 = GUICtrlCreateButton("IMG1", 100, 920, 83, 25)
GUICtrlSetOnEvent($Button1, "IMG1")
$Button2 = GUICtrlCreateButton("IMG2", 200, 920, 83, 25)
GUICtrlSetOnEvent($Button2, "IMG2")
$Button3 = GUICtrlCreateButton("IMG3", 300, 920, 83, 25)
GUICtrlSetOnEvent($Button3, "IMG3")


GUICtrlCreatePic_GDI($Form1, 1030, 547)

GUISetState(@SW_SHOW)
GUICtrlSetImage_GDI($interface_1, 295, 352, 1030, 547)

While 1
    Sleep(10)
WEnd


Func IMG1()
    GUICtrlSetImage_GDI($interface_1, 295, 352, 1030, 547)
EndFunc   ;==>IMG1
Func IMG2()
    GUICtrlSetImage_GDI($interface_2, 295, 352, 1030, 547)
EndFunc   ;==>IMG2
Func IMG3()
    GUICtrlSetImage_GDI($interface_3, 295, 352, 1030, 547)
EndFunc   ;==>IMG3

Func _Exit()
    Exit
EndFunc   ;==>_Exit

Func GUICtrlCreatePic_GDI($form_use, $widh_pos, $height_pos)
    Global $hGraphics = _GDIPlus_GraphicsCreateFromHWND($form_use)
    Global $hBitmap = _GDIPlus_BitmapCreateFromGraphics($widh_pos, $height_pos, $hGraphics)
    Global $buffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    _GDIPlus_GraphicsSetSmoothingMode(_GDIPlus_ImageGetGraphicsContext($hBitmap), 2)
EndFunc   ;==>GUICtrlCreatePic_GDI

Func GUICtrlSetImage_GDI($img_location_pos, $left_pos, $top_pos, $widh_pos, $height_pos)
    _GDIPlus_GraphicsDrawImageRect($buffer, _GDIPlus_ImageLoadFromFile($img_location_pos), 0, 0, $widh_pos, $height_pos)
    _GDIPlus_GraphicsDrawImageRect($hGraphics, $hBitmap, $left_pos, $top_pos, $widh_pos, $height_pos)
EndFunc   ;==>GUICtrlSetImage_GDI

But there is a problem for which I did not find a solution, when I press the minimize button, the interface goes to the bar, and when I restore the form, the picture disappeared. Why is this happening?

Thank you

Download images bellow

imagesdld.zip 38.15 kB · 165 downloads

Edited by beginner10
Posted (edited)

 

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GdiPlus.au3>

Global $pic_state = 1
_GDIPlus_Startup()

AutoItSetOption("GuiOnEventMode", 1)

$Img1_1 = @TempDir & "\Dashboard left.bmp"
FileInstall("Dashboard left.bmp", $Img1_1, 1)
$Img1_2 = @TempDir & "\Dashboard up.bmp"
FileInstall("Dashboard up.bmp", $Img1_2, 1)

$interface_1 = @TempDir & "\1.bmp"
FileInstall("1.bmp", $interface_1, 1)
$interface_2 = @TempDir & "\2.bmp"
FileInstall("2.bmp", $interface_2, 1)
$interface_3 = @TempDir & "\3.bmp"
FileInstall("3.bmp", $interface_3, 1)


OnAutoItExitRegister("_exit")

$Form1 = GUICreate("Form1", 1325, 999, -1, -1)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

$Pic1 = GUICtrlCreatePic($Img1_1, 0, 0, 297, 899)
GUICtrlSetState(-1, $GUI_DISABLE)
$Pic2 = GUICtrlCreatePic($Img1_2, 295, 0, 1030, 353)
GUICtrlSetState(-1, $GUI_DISABLE)

$Button1 = GUICtrlCreateButton("IMG1", 100, 920, 83, 25)
GUICtrlSetOnEvent($Button1, "IMG1")
$Button2 = GUICtrlCreateButton("IMG2", 200, 920, 83, 25)
GUICtrlSetOnEvent($Button2, "IMG2")
$Button3 = GUICtrlCreateButton("IMG3", 300, 920, 83, 25)
GUICtrlSetOnEvent($Button3, "IMG3")

GUIRegisterMsg($WM_PAINT, "WM_PAINT")
GUICtrlCreatePic_GDI($Form1, 1030, 547)
GUISetState(@SW_SHOW)
GUICtrlSetImage_GDI($interface_1, 295, 352, 1030, 547)

While 1
    Sleep(10)
WEnd


Func IMG1()
    GUICtrlSetImage_GDI($interface_1, 295, 352, 1030, 547)
    $pic_state = 1
EndFunc   ;==>IMG1
Func IMG2()
    GUICtrlSetImage_GDI($interface_2, 295, 352, 1030, 547)
    $pic_state = 2
EndFunc   ;==>IMG2
Func IMG3()
    GUICtrlSetImage_GDI($interface_3, 295, 352, 1030, 547)
    $pic_state = 3
EndFunc   ;==>IMG3

Func _Exit()
    Exit
EndFunc   ;==>_Exit

Func WM_PAINT($hGUI, $iMsg, $wParam, $lParam)

    _WinAPI_RedrawWindow($hGUI, 0, 0, $RDW_UPDATENOW)
    Switch $pic_state
        Case 1
            GUICtrlSetImage_GDI($interface_1, 295, 352, 1030, 547)
        Case 2
            GUICtrlSetImage_GDI($interface_2, 295, 352, 1030, 547)
        Case 3
            GUICtrlSetImage_GDI($interface_3, 295, 352, 1030, 547)
    EndSwitch
    Return 0 ;'GUI_RUNDEFMSG'
EndFunc   ;==>WM_PAINT


Func GUICtrlCreatePic_GDI($form_use, $widh_pos, $height_pos)
    Global $hGraphics = _GDIPlus_GraphicsCreateFromHWND($form_use)
    Global $hBitmap = _GDIPlus_BitmapCreateFromGraphics($widh_pos, $height_pos, $hGraphics)
    Global $buffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    _GDIPlus_GraphicsSetSmoothingMode(_GDIPlus_ImageGetGraphicsContext($hBitmap), 2)
EndFunc   ;==>GUICtrlCreatePic_GDI

Func GUICtrlSetImage_GDI($img_location_pos, $left_pos, $top_pos, $widh_pos, $height_pos)
    _GDIPlus_GraphicsDrawImageRect($buffer, _GDIPlus_ImageLoadFromFile($img_location_pos), 0, 0, $widh_pos, $height_pos)
    _GDIPlus_GraphicsDrawImageRect($hGraphics, $hBitmap, $left_pos, $top_pos, $widh_pos, $height_pos)
EndFunc   ;==>GUICtrlSetImage_GDI

 

EDIT: By the way to save some lines you can use arrays like me above :P 

Edited by Aelc

why do i get garbage when i buy garbage bags? <_<

Posted (edited)

Add your BMP files as resources (#AutoIt3Wrapper_Res_File_Add=image1.bmp, rt_bitmap, TEST_BMP_1)

and use RecourcesEx UDF (link in my signature) --> _Resource_SetToCtrlID()

This will fix flicker problem and minimize (WM_PAINT) problem too and your code in your script will be very simple and

you will not need FileInstall() BMPs to TEMP directory.

Edited by Zedna
Posted (edited)

@zedna so it's normal it disappears when minimized? i mean i my opinion this shouldn't happen. Also it doesn't on other GDI+ things  (never seen) ... and then you wouldn't need anything else :P 

 

EDIT: Just realized i tested it where it got updated in  a loop :> my bad 

Edited by Aelc

why do i get garbage when i buy garbage bags? <_<

Posted (edited)

Thanks Aelc and Zedna for help,
The both versions is works, but I chose to use RecourcesEx UDF because it is faster.

_Resource_SetToCtrlID() is not working fine for me, maybe because i have .bmp file. but working fine with this function:

$hHBITMAP = _Resource_GetAsBitmap('TEST_BMP_2', $RT_BITMAP)
_Resource_SetBitmapToCtrlID($Pic3, $hHBITMAP)

 

My code.

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Res_File_Add=bmp_1.bmp, RT_BITMAP, TEST_BMP_1
#AutoIt3Wrapper_Res_File_Add=bmp_2.bmp, RT_BITMAP, TEST_BMP_2
#AutoIt3Wrapper_Res_File_Add=bmp_3.bmp, RT_BITMAP, TEST_BMP_3
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <ResourcesEx.au3>

AutoItSetOption("GuiOnEventMode", 1)

$Img1_1 = @TempDir & "\Dashboard left.bmp"
FileInstall("Dashboard left.bmp", $Img1_1, 1)
$Img1_2 = @TempDir & "\Dashboard up.bmp"
FileInstall("Dashboard up.bmp", $Img1_2, 1)

$Form1 = GUICreate("Form1", 1325, 999, -1, -1)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

$Pic1 = GUICtrlCreatePic($Img1_1, 0, 0, 297, 899)
;GUICtrlSetState(-1, $GUI_DISABLE)
$Pic2 = GUICtrlCreatePic($Img1_2, 295, 0, 1030, 353)
;GUICtrlSetState(-1, $GUI_DISABLE)
$Pic3 = GUICtrlCreatePic("", 295, 352, 1030, 547)
;GUICtrlSetState(-1, $GUI_DISABLE)

$Button1 = GUICtrlCreateButton("IMG1", 100, 920, 83, 25)
GUICtrlSetOnEvent($Button1, "IMG1")
$Button2 = GUICtrlCreateButton("IMG2", 200, 920, 83, 25)
GUICtrlSetOnEvent($Button2, "IMG2")
$Button3 = GUICtrlCreateButton("IMG3", 300, 920, 83, 25)
GUICtrlSetOnEvent($Button3, "IMG3")

GUISetState(@SW_SHOW)


While 1
    Sleep(10)
WEnd

Func IMG1()
    $hHBITMAP = _Resource_GetAsBitmap('TEST_BMP_1', $RT_BITMAP)
    _Resource_SetBitmapToCtrlID($Pic3, $hHBITMAP)
EndFunc   ;==>IMG1
Func IMG2()
    $hHBITMAP = _Resource_GetAsBitmap('TEST_BMP_2', $RT_BITMAP)
    _Resource_SetBitmapToCtrlID($Pic3, $hHBITMAP)
EndFunc   ;==>IMG2
Func IMG3()
    $hHBITMAP = _Resource_GetAsBitmap('TEST_BMP_3', $RT_BITMAP)
    _Resource_SetBitmapToCtrlID($Pic3, $hHBITMAP)
EndFunc   ;==>IMG3

Func _Exit()
    Exit
EndFunc   ;==>_Exit

 

hi, 

How can I use this without compiling?
If I press F5 and start the program from the code, then the image does not appear, but if I compile codulin .exe and start it, it works fine.

Edited by beginner10
not working without compile
  • 2 months later...
Posted

hi, 

How can I use this without compiling?
If I press F5 and start the program from the code, then the image does not appear, but if I compile codulin .exe and start it, it works fine.

Thanks

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...