Reduce Flicker dramatically (Double Buffer)

Post your working scripts, libraries and tools for AHK v1.1 and older
User avatar
elModo7
Posts: 217
Joined: 01 Sep 2017, 02:38
Location: Spain
Contact:

Reduce Flicker dramatically (Double Buffer)

22 Jun 2020, 16:44

I think this has been said already in a russian and autoit forums but there is not a widely known method to prevent flicker when you use ahk for constant gui updates.

According to MSDN:
Paints all descendants of a window in bottom-to-top painting order using double-buffering. Bottom-to-top painting order allows a descendent window to have translucency (alpha) and transparency (color-key) effects, but only if the descendent window also has the WS_EX_TRANSPARENT bit set. Double-buffering allows the window and its descendents to be painted without flicker. This cannot be used if the window has a class style of either CS_OWNDC or CS_CLASSDC.

Code: Select all

Gui, +E0x02000000 +E0x00080000 ; WS_EX_COMPOSITED & WS_EX_LAYERED => Double Buffer
It works quite well:


Sample downloads attached.
Attachments
Double Buffer Reduce Flickering.zip
(12.85 KiB) Downloaded 494 times
Last edited by elModo7 on 23 Jun 2020, 10:23, edited 3 times in total.
geek
Posts: 1052
Joined: 02 Oct 2013, 22:13
Location: GeekDude
Contact:

Re: Reduce Flicker dramatically (Double Buffer)

22 Jun 2020, 16:47

10/10 would WS_EX_COMPOSITED again
User avatar
SKAN
Posts: 1551
Joined: 29 Sep 2013, 16:58

Re: Reduce Flicker dramatically (Double Buffer)

22 Jun 2020, 17:09

elModo7 wrote:
22 Jun 2020, 16:44
It works quite well:
Yes! :bravo:
Thanks for sharing. :thumbup:
User avatar
Hellbent
Posts: 2102
Joined: 23 Sep 2017, 13:34

Re: Reduce Flicker dramatically (Double Buffer)

22 Jun 2020, 19:09

Nice. I had actually come across that

Code: Select all

Gui, +E0x02000000 +E0x00080000 ; WS_EX_COMPOSITED & WS_EX_LAYERED => Double Buffer
a few months ago when looking for a way to add default controls to a layered window without knowing that it could be used to do what you have it doing. :thumbup:
User avatar
SirSocks
Posts: 360
Joined: 26 Oct 2018, 08:14

Re: Reduce Flicker dramatically (Double Buffer)

22 Jun 2020, 19:36

I'll be using this for sure! Thank you very much!
User avatar
Xtra
Posts: 2744
Joined: 02 Oct 2015, 12:15

Re: Reduce Flicker dramatically (Double Buffer)

22 Jun 2020, 20:28

+Thanks for sharing.
robodesign
Posts: 934
Joined: 30 Sep 2017, 03:59
Location: Romania
Contact:

Re: Reduce Flicker dramatically (Double Buffer)

23 Jun 2020, 02:59

For UIs with Tab3, the content comes out white.... that is, the interior / content of the tab is empty....

Best regards, Marius.
-------------------------
KeyPress OSD v4: GitHub or forum. (presentation video)
Quick Picto Viewer: GitHub or forum.
AHK GDI+ expanded / compilation library (on GitHub)
My home page.
User avatar
elModo7
Posts: 217
Joined: 01 Sep 2017, 02:38
Location: Spain
Contact:

Re: Reduce Flicker dramatically (Double Buffer)

23 Jun 2020, 04:06

Thank you for the feedback!
Indeed on some controls it's a hit or miss, it works great with text, images and a few others.
Also @robodesign that might be supposed to happen, you have to change the order of the gui elements (reverse them).
This two styles draw the gui elements in reverse order, so where in a script sprites are on the foreground and background stays behind, if you use the styles you have to repossition the background/sprites or else the sprites will be drawn to the first layer and the background will be on top of everything else.
That could be it, can you confirm?
robodesign
Posts: 934
Joined: 30 Sep 2017, 03:59
Location: Romania
Contact:

Re: Reduce Flicker dramatically (Double Buffer)

23 Jun 2020, 07:42

I don't know how to reverse the drawing order.... I have GUI tab3, and then each control inside tab 1 and so on...

Best regards, Marius.
-------------------------
KeyPress OSD v4: GitHub or forum. (presentation video)
Quick Picto Viewer: GitHub or forum.
AHK GDI+ expanded / compilation library (on GitHub)
My home page.
User avatar
SpeedMaster
Posts: 494
Joined: 12 Nov 2016, 16:09

Re: Reduce Flicker dramatically (Double Buffer)

23 Jun 2020, 08:03

Thank you for that tip. :bravo:
I tested it with my vintage "Basic Hello" clone game.
That game was full of screen flickering and now the problem is solved. :thumbup:
Basic Hello v1.2:
https://www.autohotkey.com/boards/viewtopic.php?f=6&t=56717
Thanks.
User avatar
Delta Pythagorean
Posts: 627
Joined: 13 Feb 2017, 13:44
Location: Somewhere in the US
Contact:

Re: Reduce Flicker dramatically (Double Buffer)

23 Jun 2020, 09:53

Hot damn! I'm gonna use this nearly everywhere now :D

[AHK]......: v2.0.12 | 64-bit
[OS].......: Windows 11 | 23H2 (OS Build: 22621.3296)
[GITHUB]...: github.com/DelPyth
[PAYPAL]...: paypal.me/DelPyth
[DISCORD]..: tophatcat

User avatar
elModo7
Posts: 217
Joined: 01 Sep 2017, 02:38
Location: Spain
Contact:

Re: Reduce Flicker dramatically (Double Buffer)

23 Jun 2020, 10:09

robodesign wrote:
23 Jun 2020, 07:42
I don't know how to reverse the drawing order.... I have GUI tab3, and then each control inside tab 1 and so on...

Best regards, Marius.
This is what I mean, in case of tab3:

Code: Select all

; No double buffer
Gui Add, Tab3, x8 y8 w225 h160, Tab 1|Tab 2 ; This goes First
Gui Tab, 1
Gui Add, Progress, x56 y88 w120 h20 -Smooth, 33
Gui Tab, 2
Gui Add, ListBox, x40 y40 w134 h108, ListBox
Gui Tab
Gui Show, w247 h182 x0 y0, Sample NoBuffer

; Double Buffer
Gui, 2: +E0x02000000 +E0x00080000
Gui 2:Tab, 1
Gui 2:Add, Progress, x56 y88 w120 h20 -Smooth, 33
Gui 2:Tab, 2
Gui 2:Add, ListBox, x40 y40 w134 h108, ListBox
Gui 2:Tab
Gui 2:Add, Tab3, x8 y8 w225 h160, Tab 1|Tab 2 ; Here it goes Last
Gui 2:Show, w247 h182 x250 y0, Sample Buffered
return
Cheers! :thumbup:
robodesign
Posts: 934
Joined: 30 Sep 2017, 03:59
Location: Romania
Contact:

Re: Reduce Flicker dramatically (Double Buffer)

23 Jun 2020, 15:59

elModo7 wrote:
23 Jun 2020, 10:09
robodesign wrote:
23 Jun 2020, 07:42
I don't know how to reverse the drawing order.... I have GUI tab3, and then each control inside tab 1 and so on...

Best regards, Marius.
This is what I mean, in case of tab3:

Code: Select all

; No double buffer
Gui Add, Tab3, x8 y8 w225 h160, Tab 1|Tab 2 ; This goes First
Gui Tab, 1
Gui Add, Progress, x56 y88 w120 h20 -Smooth, 33
Gui Tab, 2
Gui Add, ListBox, x40 y40 w134 h108, ListBox
Gui Tab
Gui Show, w247 h182 x0 y0, Sample NoBuffer

; Double Buffer
Gui, 2: +E0x02000000 +E0x00080000
Gui 2:Tab, 1
Gui 2:Add, Progress, x56 y88 w120 h20 -Smooth, 33
Gui 2:Tab, 2
Gui 2:Add, ListBox, x40 y40 w134 h108, ListBox
Gui 2:Tab
Gui 2:Add, Tab3, x8 y8 w225 h160, Tab 1|Tab 2 ; Here it goes Last
Gui 2:Show, w247 h182 x250 y0, Sample Buffered
return
Cheers! :thumbup:
Thank you. I wasn't aware I can reverse the order like that.... I expected ahk would go bonkers if I end with add tab 3.

Best regards, Marius.
-------------------------
KeyPress OSD v4: GitHub or forum. (presentation video)
Quick Picto Viewer: GitHub or forum.
AHK GDI+ expanded / compilation library (on GitHub)
My home page.
hasantr
Posts: 933
Joined: 05 Apr 2016, 14:18
Location: İstanbul

Re: Reduce Flicker dramatically (Double Buffer)

24 Jun 2020, 15:43

Thanks this is very nice.
Does ListView completely hide its contents?
User avatar
gwarble
Posts: 524
Joined: 30 Sep 2013, 15:01

Re: Reduce Flicker dramatically (Double Buffer)

02 Jul 2020, 23:29

this works pretty well in my test in windows 7 and windows 10 without WinSet Transparent, many thanks for sharing... I'm looking forward to going back to some old scripts and trying this


the same code unfortunately intermittently suffers from major clipping on Windows 10 when using WinSet, Transparent, can anyone else duplicate this? About half the time it works as desired, half the time the background picture (which is drawn last in reverse-z order) never gets fully drawn, only the area around the text. The problem has not been apparent on win7

I'm using WinSet, Transparent, 0 before Gui, Show, I can't recreate the problem without WinSet, Transparent
Attachments
DoubleBuffer-20200702211751.png
DoubleBuffer-20200702211751.png (412.09 KiB) Viewed 8194 times
EitherMouse - Multiple mice, individual settings . . . . www.EitherMouse.com . . . . forum . . . .
AHKStudent
Posts: 1472
Joined: 05 May 2018, 12:23

Re: Reduce Flicker dramatically (Double Buffer)

03 Jul 2020, 11:58

I tried it with dragging an image and for the first time no flicker this is a real breakthrough especially for small games :thumbup: :thumbup: :thumbup: :thumbup:
User avatar
elModo7
Posts: 217
Joined: 01 Sep 2017, 02:38
Location: Spain
Contact:

Re: Reduce Flicker dramatically (Double Buffer)

04 Jul 2020, 04:36

@AHKStudent yeah, I do a lot of interactive guis for twitch streaming and this is a joy.
Felt like it was needed to be known.
User avatar
manehscripts
Posts: 126
Joined: 03 May 2019, 16:10

Re: Reduce Flicker dramatically (Double Buffer)

15 Mar 2021, 16:26

I expected it to work very well for my code, but I have 3 listviews in the same GUI, and they are all capturing information from external files. When I use the Gui, +E0x02000000 +E0x00080000 it does not load any listview :(
-----------------------------------------------------------
Stop to think, shut up to resist, and act to win!
hasantr
Posts: 933
Joined: 05 Apr 2016, 14:18
Location: İstanbul

Re: Reduce Flicker dramatically (Double Buffer)

16 Mar 2021, 02:49

manehscripts wrote:
15 Mar 2021, 16:26
I expected it to work very well for my code, but I have 3 listviews in the same GUI, and they are all capturing information from external files. When I use the Gui, +E0x02000000 +E0x00080000 it does not load any listview :(
Yes I am having the Listview problem too.

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: gwarble and 109 guests