SmartErase!

Share your advanced PureBasic knowledge/code with the community.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

SmartErase!

Post by srod »

Update. 18th March 2009.

If you apply SmartErase to a particular window/control, but wish to exlude some child control or other from being removed from the erasing process (such as a toolbar), then simply set a Window property for the child control as follows :

Code: Select all

SetProp_(childHwnd, #SmartErase_IGNORECHILD, 1)
This child will then not be excluded from the erasing of it's parent.

Useful for keeping PB toolbars transparent etc. (See post below regarding toolbars).

You will of course need to remove this property yourself before you destroy the control in question. I did not automate this because SmartErase would then have to subclass the control in order to remove the property and that seemed like overkill in this case.

Download is through the nxSoftware site.

=============================================


Hi,

on a drive to reduce flicker in an application I am working upon when the user resizes the main window prompted me to create this little utility (Windows only).

It is similar to SmartWindowRefresh() in the way it is used, but (and I have never had any success with SmartWindowRefresh()) in tests, SmartErase has resulted in some drastic reductions in flicker.

Like SmartWindowRefresh(), SmartErase() is not guaranteed to work with any particular project. Unlike SmartWindowRefresh(), however, you apply SmartErase() not necessarily to an entire window, but to individual windows or parent controls as appropriate. Like SmartWindowRefresh(), SmartErase() would ideally be used in combination with other techniques (such as using #WS_CLIPCHILDREN and so on) for reducing flicker.

The idea is that you would generally apply ‘SmartErase’ to a parent window/control (e.g. a container gadget) whose child gadgets flicker inordinately when dynamically resized etc. SmartErase() will then assume responsibility for erasing that window/control's background whilst following certain rules (e.g. ignore all child windows) etc. SmartErase() can even be instructed to bypass all erasing for a particular window/control which is useful if the window is completely covered by child controls etc.

Very simple, quite crude, but with the 6 demo programs tested on XP and Vista, it can be damn effective! :)

The download includes the full source, six demos and a very short user manual. Please read the manual before attempting to use this utility as it contains some important info.

All of the the demo programs have SmartErase() disabled. Run them with xp themes enabled and resize the main window to see some appalling flicker. Then uncomment the appropriate line(s) to see the effect SmartErase() may or may not be having.

My thanks to Kinglestat for helping to test the code and the demos.

Please proceed to the nxSoftware site for the download (Freeware section).

Regards.
Last edited by srod on Wed Mar 18, 2009 1:03 pm, edited 1 time in total.
I may look like a mule, but I'm not a complete ass.
kinglestat
Enthusiast
Enthusiast
Posts: 746
Joined: Fri Jul 14, 2006 8:53 pm
Location: Malta
Contact:

Post by kinglestat »

Thanks for sharing
I may not help with your coding
Just ask about mental issues!

http://www.lulu.com/spotlight/kingwolf
http://www.sen3.net
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

Not bad. :) It certainly helps a lot here on XP!
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

Works fine on vista :D
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Post by Mistrel »

New solutions for reducing flickering are always welcome! Sometimes all it takes is the right creative combination. :)
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Post by Kwai chang caine »

Thanks MASTER for sharing and furthermore the source 8)

It's just for inform and help you. :oops:
I believe that "Flickering" it's like when the gadget jerk :roll:
If it's that, on W2000 when i resize that's always flickering
It's surely normal, because you talk of XP and vista.
Surrely W2000 is too old like OS

So Again thanks 8)
ImageThe happiness is a road...
Not a destination
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Kwai, I see no reason why it should not work on Win2000. Let me fire up the VM and take a look.
I may look like a mule, but I'm not a complete ass.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Kwai, it works fine on Win2000 here.

First thing is that Win2000 does not allow you to enable XP themes and so there is not as much flicker anyhow. More importantly, each of the SmartErase demo programs has SmartErase disabled! You must enable it by uncommenting the marked lines! Now did you do this?

The thing is that SmartErase should work on all versions of Windows because it is in principal a very simple affair!
I may look like a mule, but I'm not a complete ass.
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

srod wrote:Kwai, it works fine on Win2000 here.
Quickly tested on NT4 : works very well !
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Excellent. :)

I just applied SmartErase to my current app which has a rather complex GUI (including the flickery panel gadgets!) and it has removed absolutely all flicker! (Tested on Vista and XP!) Even the panels no longer flicker, but I think that has something to do with the fact that they are within Nexus splitter gadgets with a fixed section (although without SmartErase these same panels flicker appallingly!)

Huh, just goes to show; sometimes the dumbest ideas are the most effective! :wink:
I may look like a mule, but I'm not a complete ass.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Tip.

If you apply SmartErase to a window containing a toolbar, then depending on the toolbar's styles, the toolbar may not get erased at all. To combat this simply remove the #TBSTYLE_TRANSPARENT and #TBSTYLE_FLAT styles from the toolbar.

For a PB toolbar, simply remove the #TBSTYLE_TRANSPARENT style :

Code: Select all

SetWindowLong_(ToolBarID(#MyToolbar), #GWL_STYLE, GetWindowLong_(ToolBarID(#MyToolbar), #GWL_STYLE)&~#TBSTYLE_TRANSPARENT)
(My thanks to Kiffi for reporting this problem.)
I may look like a mule, but I'm not a complete ass.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Update. 18th March 2009.
If you apply SmartErase to a particular window/control, but wish to exlude some child control or other from being removed from the erasing process (such as a toolbar), then simply set a Window property for the child control as follows :

Code: Select all

SetProp_(childHwnd, #SmartErase_IGNORECHILD, 1)
This child will then not be excluded from the erasing of it's parent.

Useful for keeping PB toolbars transparent etc. (See post above regarding toolbars).

You will of course need to remove this property yourself before you destroy the control in question. I did not automate this because SmartErase would then have to subclass the control in order to remove the property and that seemed like overkill in this case.

Download is through the nxSoftware site.
I may look like a mule, but I'm not a complete ass.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Post by Kwai chang caine »

Master SROD wrote:You must enable it by uncommenting the marked lines!
:oops:

Have i need to say something other :oops:
My shame is without limit :oops:

I'm tired to be a trumpet :oops: :?
I promise to you, that i don't do that purposely, it's incredible no ??
Because i can to be again more IDIOT :D

One thousand of thanks for your great code, sharing and tolerance

Good news
Your code works also on W2000 :lol:
ImageThe happiness is a road...
Not a destination
Post Reply