Jump to content

GUI double buffering with $WS_EX_COMPOSITED


KaFu
 Share

Recommended Posts

Hiho,

I saw this GUI style in recent discussions and did some reading. After I implemented it in SMF's main GUI I thought it would be worth to write a little example around it :)...

http://msdn.microsoft.com/en-us/library/ms632680%28VS.85%29.aspx

Windows XP: With WS_EX_COMPOSITED set, all descendants of a window get 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.

Note that the "bottom-to-top painting order" requires you to draw overlapping controls in the opposite order as usually done, means with the $WS_EX_COMPOSITED style set you need to create the background control AFTER the foreground control. It makes GUI updates a little more sluggish, but I think that's fully acceptable.

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.0.0
 Author:         KaFu, Authenticity, Zedna

 Script Function:
    Double buffered GUI with $WS_EX_COMPOSITED
    See also http://msdn.microsoft.com/en-us/library/ms632680%28VS.85%29.aspx

#ce ----------------------------------------------------------------------------

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

HotKeySet("{ESC}", "_Exit")

; ===============
; Test #1 with double buffer
; ===============

Global Const $WS_EX_COMPOSITED = 0x2000000

$hGUI = GUICreate("Test #1 with double buffer", 300, 200, -1, -1, -1, $WS_EX_COMPOSITED)

$button = GUICtrlCreateButton("Double Buffer Test", 50, 45, 200, 20)

$label = GUICtrlCreateLabel("Double Buffer Test", 0, 115, 300, 20, $SS_CENTER)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)

; Background control, create AFTER foreground control
GUICtrlCreateLabel("", 0, 0, 300, 200)
GUICtrlSetBkColor(-1, 0x21AB9A)

GUISetState()
Sleep(1000)

For $i = 0 To 3000
    GUICtrlSetData($label, "Double Buffer Test " & $i)
    GUICtrlSetData($button, "Double Buffer Test " & $i)
Next

GUIDelete($hGUI)

; ===============
; Test #2 without double buffer
; ===============
$hGUI = GUICreate("Test #2 without double buffer", 300, 200)

; Background control, create BEFORE foreground control
GUICtrlCreateLabel("", 0, 0, 300, 200)
GUICtrlSetBkColor(-1, 0x21AB9A)

$button = GUICtrlCreateButton("Double Buffer Test", 50, 45, 200, 20)

$label = GUICtrlCreateLabel("Double Buffer Test", 0, 115, 300, 20, $SS_CENTER)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)

GUISetState()
Sleep(1000)

For $i = 0 To 10000
    GUICtrlSetData($label, "Double Buffer Test " & $i)
    GUICtrlSetData($button, "Double Buffer Test " & $i)
Next

GUIDelete($hGUI)

_Exit()

Func _Exit()
    Exit
EndFunc   ;==>_Exit

Cheers ;)...

Edited by KaFu
Link to comment
Share on other sites

Good trick.

P.S

I wonder why is this not documented, and/or why $WS_EX_COMPOSITED is not in the «WindowsConstants.au3» include?

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

Hm, i've noticed that with this style the data updated slower than usualy...

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

Hm, i've noticed that with this style the data updated slower than usualy...

Yeah, I think double buffering just takes some time for background processing. But it's still fast enough for my needs :)...
Link to comment
Share on other sites

Nice stuff, but what if I want to use, for example, buttons?

Still works like a charm ;), updated example in first post. Btw, I'm using it in SMF now, and that one I think contains all available standard controls :)... Edited by KaFu
Link to comment
Share on other sites

Strange things happening with tree view controls (tooltips mostly) here.

Thinking about it... you're right :), after adding that style to the GUI I also added $TVS_NOTOOLTIPS to my TreeView controls.
Link to comment
Share on other sites

I'm using it in SMF now

It's not a good idea to use that abbreviature, well known Simple Machines Forum abbreviated as SMF :) Edited by MrCreatoR

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

Global Const $WS_EX_COMPOSITED = 0x2000000

GUICreate('MyGUI', 400, 400, -1, -1, -1, $WS_EX_COMPOSITED)
GUICtrlCreateListView('Test', 10, 10, 380, 353)
GUICtrlCreateButton('OK', 170, 370, 70, 23)
GUISetState()

Do
Until GUIGetMsg() = -3

???

Edited by Yashied
Link to comment
Share on other sites

sandin already used $WS_EX_COMPOSITED in his game Bounce The Sun. It is unfortunatelly not working with Vista and probably not with Win7 - it is flickering! :)

The days with WinXP are numbered...

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

The days with WinXP are numbered.

Can not agree on that one. Win XP still used on school's and offices's computers. Win Vista / Seven is very demanding on computer resources.

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

Can not agree on that one. Win XP still used on school's and offices's computers. Win Vista / Seven is very demanding on computer resources.

Computers are also updating though. When XP was first released as a beta thats probably what everyone said ;), and in 20 years time, windows XP will be like what windows 2000 is today.

As to the topic, as shown in bounce the sun, this makes games very easy to make, :)

Mat

Link to comment
Share on other sites

Link to comment
Share on other sites

As I mentioned in sandin's thread it flickers with my Vista x32. I don't know whether $WS_EX_COMPOSITED works for Vista and above.

I will try the game in my VM with Win7 x64 but VMs have sometimes not same behaviour as on real hardware.

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Can not agree on that one. Win XP still used on school's and offices's computers. Win Vista / Seven is very demanding on computer resources.

Yes, but old hardware will be replaced someday. WinXP is not sold anymore and like Win98SE it will became someday a rememberance. All new hardware will be installed with Win7+...

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

It's not a good idea to use that abbreviature, well known Simple Machines Forum abbreviated as SMF ;)

Yeah, learned that earlier and decided to ignore it...theirs is a forum software, mines a window application, theirs is for sale, mine for free, they're sitting in the US, I'm in Germany... and the official name of my tool is "SMF - Search my Files". If they'll ever complain (which I doubt), we'll see :)...
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...