Jump to content

GUICtrlSetImage & WM_ERASEBKGND --> avoid flicke


Zedna
 Share

Recommended Posts

I posted this in "v3 Idea Lab" forum

but I don't know if it's better place for that here.

So if can somebody help with this problem

I will be very gratefull  :)

Thanks

Here is my Topic:

http://www.autoitscript.com/forum/index.php?showtopic=13953

<{POST_SNAPBACK}>

I see your posts but I can not find any solution. Perhaps it is due to overlap control or out of the GUI windows.

Can you correct your script so that the status bar appear completly when you zoon or not?

:">

Link to comment
Share on other sites

here is a fade in/out effort for you

(you need to fix the Displays at the bottom of your GUI)

#include <GUIConstants.au3>

Global $Pause
Global $sirka, $vyska; obrazku vcetne zvetseni
Global $velikost; zvetseni

Opt("GUICloseOnESC",1)
Opt("GUIOnEventMode",1)

$velikost = 1
$sirka = 400 * $velikost
$vyska = 300 * $velikost

$gui = GUICreate("Radar",400,310+41+4,-1,-1,BitOr($WS_MINIMIZEBOX,$WS_SYSMENU)); $WS_SIZEBOX
GUISetOnEvent ($GUI_EVENT_CLOSE, "Konec" )
$status1 = GUICtrlCreateLabel ("Príprava dat ...",0,$vyska+3,$sirka -150,17,$GUI_SS_DEFAULT_LABEL, $WS_EX_CLIENTEDGE ) 
$status2 = GUICtrlCreateLabel ("Velikost = " & StringFormat("%.1f", $velikost) & "x",$sirka-150,$vyska+3,100,17,BitOr($GUI_SS_DEFAULT_LABEL, $SS_CENTER ), $WS_EX_CLIENTEDGE )
GUICtrlSetOnEvent (-1, "OnStatus2" )
$status3 = GUICtrlCreateLabel ("+2 hod.",$sirka-50,$vyska+3,50,17,BitOr($GUI_SS_DEFAULT_LABEL, $SS_CENTER ), $WS_EX_CLIENTEDGE )
$zoommenu = GUICtrlCreateContextMenu ($status2)
$zoom10x = GUICtrlCreateMenuitem("Velikost 1.0x",$zoommenu,1,1)
GUICtrlSetOnEvent (-1, "OnZoomMenu" )
GUICtrlSetState($zoom10x,$GUI_CHECKED)
$zoom15x = GUICtrlCreateMenuitem("Velikost 1.5x",$zoommenu,2,1)
GUICtrlSetOnEvent (-1, "OnZoomMenu" )
$zoom20x = GUICtrlCreateMenuitem("Velikost 2.0x",$zoommenu,3,1)
GUICtrlSetOnEvent (-1, "OnZoomMenu" )
$pic=GUICtrlCreatePic("01.jpg",0,0,$sirka,$vyska)
WinSetTrans("Radar","", 1)
GUISetState (@SW_SHOW)
HotKeySet("{PAUSE}", "ZmenaPause")

Dim $TIn = 0
Dim $pocet = 5
Dim $nazvy[$pocet]

For $i = 0 To $pocet-1
    $nazvy[$i] = StringFormat("%02i", $i+1) & ".jpg"
Next

; test to avoid flickering...
;~ $WM_SETREDRAW = 0x000B
;~ $hwnd = ControlGetHandle("Radar", "Velikost =", $pic)

; main loop
While 1
    
    For $i = 0 To $pocet-1
;~         GUICtrlSendMsg ($pic, $WM_SETREDRAW,0,0)
        If $TIn = 1 Then
            $Out = 254
            For $XOut = 1 to 254
                $Out = $Out -1
                WinSetTrans("Radar","", $Out)
            ;Sleep(2) 
                If $XOut = 0 Then ExitLoop
            Next
        EndIf
        GUICtrlSetImage ($pic, $nazvy[$i])
;~         GUICtrlSendMsg ($pic, $WM_SETREDRAW,1,0)
;~         DLLCall("user32.dll","int","InvalidateRect","hwnd",$hwnd,"int",0,"int",0); bErase=False
        GUICtrlSetData ($status1, "  " & $i+1 & "/" & $pocet)
        Sleep(50)
        $In = 1
        For $In = $In to 254
            WinSetTrans("Radar","", $In)
        ;Sleep(2)
        Next
        Sleep(3000)
        $TIn = 1
    Next
  ;Sleep(3000)
Wend

Func ZmenaPause()
    $Pause = Not $Pause
    If Not $Pause Then Return
        
    $text = GUICtrlRead($status1)
    GUICtrlSetData ($status1, $text & " PAUSE")
    While $Pause
        Sleep(100)
    WEnd
    GUICtrlSetData ($status1, $text)
EndFunc

; zajistit otevreni popupmenu i na leve tlacitko
Func OnStatus2()
    ControlClick($gui, "", @GUI_CTRLID, "right")
EndFunc

Func OnZoomMenu()
    GUICtrlSetState ($gui,$GUI_HIDE)
    Sleep(500)
    $menutext = GUICtrlRead(@GUI_CTRLID,1); Velikost 1.0x
    Zoom(@GUI_CTRLID, StringMid($menutext[0], 10, 3)); 1.0
EndFunc

Func Zoom($menu_id, $zoom)
    $velikost = $zoom
    $sirka = 400 * $zoom
    $vyska = 300 * $zoom
    GUICtrlSetData ($status2, "Velikost = " & StringFormat("%.1f", $zoom) & "x")
    WinMove("Radar", "Velikost = ", (@DesktopWidth - $sirka)/2, (@DesktopHeight - $vyska - 45)/2, $sirka, $vyska + 45)
    GUICtrlSetPos($pic, 0, 0, $sirka, $vyska)
    GUICtrlSetPos($status1, 0, $vyska + 3,$sirka - 150, 17)
    GUICtrlSetPos($status2, $sirka - 150, $vyska + 3,100, 17)
    GUICtrlSetPos($status3, $sirka - 50, $vyska + 3, 50, 17)
EndFunc

Func Konec()
    Exit
EndFunc

Func OnAutoItExit()
    GUIDelete($gui)
    HotKeySet("{PAUSE}")
EndFunc

Just and idea...

and as a second idea

you could create all 5 pics

$pic_1=GUICtrlCreatePic("01.jpg",0,0,$sirka,$vyska)

$pic_2=GUICtrlCreatePic("01.jpg",0,0,$sirka,$vyska)

GUICtrlSetState(-1, $GUI_HIDE)

$pic_3=GUICtrlCreatePic("01.jpg",0,0,$sirka,$vyska)

GUICtrlSetState(-1, $GUI_HIDE)

etc, etc

Then hide and show the pics

hope it helps

8)

Edited by Valuater

NEWHeader1.png

Link to comment
Share on other sites

Thanks for every ideas very much.

@jpm:

Here is my simpified code completely without statusbar and with zoom=2x

but there is still flicker :)

so your pressumtion about overlaying with statusbar probably was not right

#include <GUIConstants.au3>

Global $Pause
Global $sirka, $vyska; obrazku vcetne zvetseni
Global $velikost; zvetseni

Opt("GUICloseOnESC",1)
Opt("GUIOnEventMode",1)

$velikost = 2
$sirka = 400 * $velikost
$vyska = 300 * $velikost

$gui = GUICreate("Radar",$sirka,$vyska+25,-1,-1,BitOr($WS_MINIMIZEBOX,$WS_SYSMENU)); $WS_SIZEBOX
GUISetOnEvent ($GUI_EVENT_CLOSE, "Konec" )
$pic=GUICtrlCreatePic("01.gif",0,0,$sirka,$vyska)
GUISetState (@SW_SHOW)
HotKeySet("{PAUSE}", "ZmenaPause")

Dim $pocet = 5
Dim $nazvy[$pocet]

For $i = 0 To $pocet-1
    $nazvy[$i] = StringFormat("%02i", $i+1) & ".gif"
Next

; test to avoid flickering...
;~ $WM_SETREDRAW = 0x000B
;~ $hwnd = ControlGetHandle("Radar", "Velikost =", $pic)

; main loop
While 1
    For $i = 0 To $pocet-1
;~       GUICtrlSendMsg ($pic, $WM_SETREDRAW,0,0)
        GUICtrlSetImage ($pic, $nazvy[$i])
;~       GUICtrlSendMsg ($pic, $WM_SETREDRAW,1,0)
;~       DLLCall("user32.dll","int","InvalidateRect","hwnd",$hwnd,"int",0,"int",0); bErase=False
        Sleep(750)
    Next
    Sleep(3000)
Wend

Func ZmenaPause()
    $Pause = Not $Pause
    If Not $Pause Then Return
        
    While $Pause
        Sleep(100)
    WEnd
EndFunc

Func Konec()
    Exit
EndFunc

Func OnAutoItExit()
    GUIDelete($gui)
    HotKeySet("{PAUSE}")
EndFunc

@Valuater:

I tested fade in/out but unfortunately this dont't solve my problem

because I need change images as quickly as possible to imitate animation.

And WinSetTran also doesn't work on WIN98.

And your second idea with more images and showing/hiding them also doesn't work.

I tested this solution as my very first attempt long ago with no luck.

I think this is not working because when image is showing (SW_SHOW)

then is invoked message WM_PAINT also with WM_ERASEBKGND at beginpaint.

***

As I said I thought there could be change in code of AutoIt

that handle message WM_ERASEBKGND at Picture control and

according to new parameter eraseBKGND

of function GUICtrlSetImage (or maybe GUICtrlCreatePic)

will or will not erase background of image when image is painted.

In C++ this is one line of code:

in message WM_ERASEBKGND return 1

to avoid erasing background when image is painted.

Or another change in AutoIt code could help with this:

Possibility to handle any windows message at user level (in AU3 code)

Then I could handle WM_ERASEBKGND (return 1 here) myself to solve this problem.

So another ideas or inventions or opinions are welcome...

EDIT: only spelling corrections

Edited by Zedna
Link to comment
Share on other sites

In my script Radar I have one display error with positioning statusbar

but it's not related to problem with flickering.

I tested my script only on WIN98SE and WINXP without XP themes.

On WINXP with themes there is different heght of window title bar.

In my script I have a constant for that and this is why it's not exact

in this situation. I will correct this later.

Here are attached screenshots - one correct and one not correct

(see how titlebars looks like):

Edited by Zedna
Link to comment
Share on other sites

I found AutoIt's BUG in rendering pictures!

Images of picture controls are rendering twice (after GUICtrlSetImage)

- first in original size (in which picture control was created or internal size of picture)

- second in actual size of control (after zoom by GUICtrlSetPos)

It's very nice visible in my script from

http://www.autoitscript.com/forum/index.php?showtopic=13953

when it's seen over MSRDP client

then it's very slow rendering.

It's best to see it there in Zoom=2x

here are sample pics captured from that slow rendering

(both pictures shlould be big over whole app client area):

- first rendering

- second rendering

May I post this BUG in Bug reports forum too?

EDIT: corrected typing error: "dirst rendering" instead of "first rendering"

Edited by Zedna
Link to comment
Share on other sites

I found AutoIt's BUG in rendering pictures!

Images of picture controls are rendering twice (after GUICtrlSetImage)

- first in original size (in which picture control was created or internal size of picture)

- second in actual size of control (after zoom by GUICtrlSetPos)

It's very nice visible in my script from

http://www.autoitscript.com/forum/index.php?showtopic=13953

when it's seen over MSRDP client

then it's very slow rendering.

It's best to see it there in Zoom=2x

here are sample pics captured from that slow rendering

(both pictures shlould be big over whole app client area):

- dirst rendering

- second rendering

May I post this BUG in Bug reports forum too?

<{POST_SNAPBACK}>

I am not sure the script you use to have this behavior can you point to it. I use the other post I experience the flickering your speaking about but not the dirst rendering.

Can you repost it?

Link to comment
Share on other sites

I am not sure the script you use to have this behavior can you point to it. I use the other post I experience the flickering your speaking about but not the dirst rendering.

Can you repost it?

<{POST_SNAPBACK}>

Here is whole source of my program Radar version 1.2:

radar_src.zip

Note this is version, which downloads images direct from internet

and not only sample images from HDD.

In this version is also corrected overlapping statusbar

and handled various sizes of titlebar and thickness of window borders.

Link to comment
Share on other sites

I am not sure the script you use to have this behavior can you point to it. I use the other post I experience the flickering your speaking about but not the dirst rendering.

Can you repost it?

<{POST_SNAPBACK}>

On fast machine it's very quick, so it's only like flickering

but on very slow machine or over very slow internet conncetion to other PC

it's visible as I described...

First rendering stadium I quickly grabbed at such slow conncetion.

Link to comment
Share on other sites

On fast machine it's very quick, so it's only like flickering

but on very slow machine or over very slow internet conncetion to other PC

it's visible as I described...

First rendering stadium I quickly grabbed at such slow conncetion.

<{POST_SNAPBACK}>

you can I think avoid it with a GUISetState($gui,@SW_LOCK)/GUISetState($gui,@SW_UNLOCK) around your Winmove/GUICtrlSetPOs.

I cannot find a solution for the time being I try but ... :whistle:

Link to comment
Share on other sites

you can I think avoid it with a GUISetState($gui,@SW_LOCK)/GUISetState($gui,@SW_UNLOCK) around your Winmove/GUICtrlSetPOs.

I cannot find a solution for the time being I try but ... :whistle:

<{POST_SNAPBACK}>

I don't think LOCK/UNLOCK will help because I tried

(it's commented in my sources):

GUICtrlSendMsg ($pic, $WM_SETREDRAW,0,0)

GUICtrlSetImage ($pic, @Scriptdir & "\data\" & $nazvy[$i])

GUICtrlSendMsg ($pic, $WM_SETREDRAW,1,0)

with no effect and I think LOCK/UNLOCK is based on this message ($WM_SETREDRAW), isn't it?

I think it's somehow related to "stretched" function of picture control:

It probably renders image in its original size and then

do some StrechBitBlt API calls to resize it to actual size of picture control

as I suppose - but I'm not exactly sure with this.

You have sources, so you could see where problem is ...

Thanks for interest in my problem.

Edited by Zedna
Link to comment
Share on other sites

Here is my post I think most close to solution of problem

#98708

By me maybe solution is:

change in WM_PAINT code of picture control in AutoIt...

<{POST_SNAPBACK}>

I understand the code when when every painting is manage in WM_PAINT but that's not the case the GUI functions work except the graphics ones. So I don't think I can incorporate such strategy while reusing all standard Windows API which implement the basic controls. If you think I can fill free to upload somewhere the delphi code so I can look at it. :whistle:
Link to comment
Share on other sites

I understand the code when when every painting is manage in WM_PAINT but that's not the case the GUI functions work except the graphics ones. So I don't think I can incorporate such strategy while reusing all standard Windows API which implement the basic controls. If you think I can fill free to upload somewhere the delphi code so I can look at it. :dance:

<{POST_SNAPBACK}>

#98708

I added there also full sources in Delphi and comment from me...

Thanks a lot for your support :whistle:

Edited by Zedna
Link to comment
Share on other sites

  • 2 weeks later...

For easy invoking this situation (double rendering of picture control)

I tested small FREE utility Sleeper from

http://www.slunecnice.cz/product/Sleeper/

http://www.slunecnice.cz/product/Sleeper/download.html

It slow down CPU, so rendering of picture control is nice visible.

Note Sleeper trackbar must be at less than 10% (may be also 0%).

Here are screenshots:

I think this is BUG in rendering picture control

and should be corrected...

Edited by Zedna
Link to comment
Share on other sites

Here is source of my program Radar - new version 1.31:

http://www.autoitscript.com/fileman/users/Zedna/radar_src.zip

It's in Czech language --> names of variables and functions and comments

I added painting red cross over main image

but it's not perfect solution, because of lacking AutoIt's possibility of handling

windows messages - here WM_PAINT.

My function MalujKriz should be mapped into WM_PAINT but it's impossible with current version of AutoIt, so maybe sometime in the future ....

Edited by Zedna
Link to comment
Share on other sites

  • 2 years later...

I found AutoIt's BUG in rendering pictures!

Images of picture controls are rendering twice (after GUICtrlSetImage)

- first in original size (in which picture control was created or internal size of picture)

- second in actual size of control (after zoom by GUICtrlSetPos)

It's very nice visible in my script from

http://www.autoitscript.com/forum/index.php?showtopic=13953

when it's seen over MSRDP client

then it's very slow rendering.

It's best to see it there in Zoom=2x

here are sample pics captured from that slow rendering

(both pictures shlould be big over whole app client area):

- first rendering

- second rendering

May I post this BUG in Bug reports forum too?

EDIT: corrected typing error: "dirst rendering" instead of "first rendering"

In AutoIt 3.2.6.0 this bug was corrected.

I recompiled my old Radar project and no flicker!!

:):):P

Thanks AutoIt developer team.

Link to comment
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
 Share

  • Recently Browsing   0 members

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