Reduce Flicker dramatically (Double Buffer)

Post your working scripts, libraries and tools
User avatar
elModo7
Posts: 167
Joined: 01 Sep 2017, 02:38
GitHub: elModo7
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 78 times
Last edited by elModo7 on 23 Jun 2020, 10:23, edited 3 times in total.
:beer:
User avatar
SKAN
Posts: 668
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: 1058
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: 184
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: 1792
Joined: 02 Oct 2015, 12:15

Re: Reduce Flicker dramatically (Double Buffer)

22 Jun 2020, 20:28

+Thanks for sharing.
robodesign
Posts: 661
Joined: 30 Sep 2017, 03:59
Facebook: marius.sucan
GitHub: mariussucan
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: 167
Joined: 01 Sep 2017, 02:38
GitHub: elModo7
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?
:beer:
robodesign
Posts: 661
Joined: 30 Sep 2017, 03:59
Facebook: marius.sucan
GitHub: mariussucan
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: 389
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: 566
Joined: 13 Feb 2017, 13:44
GitHub: DelPyth
Location: Somewhere in the US

Re: Reduce Flicker dramatically (Double Buffer)

23 Jun 2020, 09:53

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

- [AHK].......: 1.1.33.02 Unicode 64-bit
- [OS].........: Windows 10.0.18362
- [GITHUB]...: github.com/DeltaPyth
- [PAYPAL]....: paypal.me/DelPyth
- [DISCORD]..: Delta#3324

Remember to use [code]CODE[/code] for your multi-line scripts.
Stay safe, stay inside, and remember to wash your hands for 20 seconds!
User avatar
elModo7
Posts: 167
Joined: 01 Sep 2017, 02:38
GitHub: elModo7
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:
:beer:
robodesign
Posts: 661
Joined: 30 Sep 2017, 03:59
Facebook: marius.sucan
GitHub: mariussucan
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.
User avatar
hasantr
Posts: 501
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?
gwarble
Posts: 431
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 2141 times
EitherMouse - Multiple mice, individual settings . . . . www.EitherMouse.com . . . . forum . . . .
User avatar
elModo7
Posts: 167
Joined: 01 Sep 2017, 02:38
GitHub: elModo7
Location: Spain
Contact:

Re: Reduce Flicker dramatically (Double Buffer)

03 Jul 2020, 03:50

I think adding transcolor also had some weird effects.
:beer:
AHKStudent
Posts: 882
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: 167
Joined: 01 Sep 2017, 02:38
GitHub: elModo7
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.
:beer:

Return to “Scripts and Functions”

Who is online

Users browsing this forum: Google [Bot] and 23 guests