GDI usage

The place for threads about TimoSoft EditControls.
Post Reply
baron
Lt. Commander
Posts: 31
Joined: 21 Sep 2013, 18:55

GDI usage

Post by baron »

Hello,

First of all thank you very much for these great controls. I played with a few similar controls and these seem to be the best so far.

I found a problem with GDI handle usage that took me hours to track down... Whenever the BackColor or DisabledBackgroundColor properties are set on your TextBox, it takes at least 1 more GDI for each function. I.e. if i set both background colors the TextBox control takes 2 GDIs instead of 0.

I have a very heavy form with hundreds of controls so the GDI count is important: With 500 controls, this means 1000 GDI handles just for setting background colors!

Please tell me this is a quick fix since i am stuck and have a deadline ;-)

P.S. Do you know of a trick to make VB6 UserControls take 0 GDI handles? Best I managed was 1.

Much appreciated.
User avatar
TiKu
Administrator
Administrator
Posts: 832
Joined: 28 Sep 2004, 21:10
Location: Unterföhring
Contact:

Re: GDI usage

Post by TiKu »

Hi,

I've changed a few implementation details. Please have a look at this pre-release and tell me whether it uses less resources:
www.timosoft-software.de/stuff/editctls185171-rel.zip
http://www.timosoft-software.de/stuff/E ... elease.exe

Regards
TiKu
Crunching for Fab36_Folding-Division at Folding@Home. Join Fab36/Fab30! - Folding@Home and BOINC
Boycott DRM! Boycott HDCP!
baron
Lt. Commander
Posts: 31
Joined: 21 Sep 2013, 18:55

Re: GDI usage

Post by baron »

Wow, thank you. That was fast.

There is a definite improvement by about half. It seems inconsistent, but from my tests now it looks like:
1. DisabledBackColor does not add GDIs at all.
2. This seems weird but: BackColor adds GDI handles only after a few components. I.e. you have to add at least 10-15 components to the form, then every component adds one more GDI. It also seems to behave slightly differently if the component is embedded inside a VB6 UserControl or not, but I'm not sure about this.

So now, for 500 TextBox components I get roughly 500 GDI. Is there any chance that BackColor could work the same way as DisabledBackColor?
User avatar
TiKu
Administrator
Administrator
Posts: 832
Joined: 28 Sep 2004, 21:10
Location: Unterföhring
Contact:

Re: GDI usage

Post by TiKu »

Well, my change was to take advantage of the fact that BackColor and DisabledBackColor never are used at the same time (within the same instance of the control). So while I need a GDI object for one of them, I don't need a GDI object for the other property at the same time. That's why the GDI usage dropped down to the half.
How many GDI resources the BackColor and DisabledBackColor properties require, depends on the values that you set them to. System colors should not need any additional GDI resource because the control will use system-wide GDI objects. Only if you use RGB colors, the control will create its own GDI objects. Maybe I can tweak this a bit, but I cannot promise anything.

By the way, on which version of Windows do you test? The controls contain extra code for Windows XP and resource usage on Windows XP probably will be higher than on Windows Vista/7/8, if the control sits on a TabStrip. So you should test my changes especially on Windows XP - I only did rough tests on Windows 7.

Regards
TiKu
Crunching for Fab36_Folding-Division at Folding@Home. Join Fab36/Fab30! - Folding@Home and BOINC
Boycott DRM! Boycott HDCP!
baron
Lt. Commander
Posts: 31
Joined: 21 Sep 2013, 18:55

Re: GDI usage

Post by baron »

Actually I am testing on XP. I am glad to hear that it uses less on Win7. I do put the controls inside Containers such as user controls and PictureBoxes but not inside a VB TabStrip.

When I tested, it seemed that setting DisabledBackColor WITHOUT touching BackColor never added any GDI objects whereas BackColor did add GDI with or without DisabledBackColor. I may have misunderstood what I did, but I triple-checked everything and that's what it looked like. I guess this makes sense because the controls were never disabled during the test.

I use both settings because the user needs the form to use its own color scheme against custom graphics, so obviously I need to set RGB values separate from the Windows system colors.

Thanks for your efforts. If you can find a way, that would be great. Otherwise they will have to be limited to opening about 10 forms at once which is livable but not ideal.
User avatar
TiKu
Administrator
Administrator
Posts: 832
Joined: 28 Sep 2004, 21:10
Location: Unterföhring
Contact:

Re: GDI usage

Post by TiKu »

This pre-release should reduce the GDI usage even more:

www.timosoft-software.de/stuff/editctls185172-rel.zip
http://www.timosoft-software.de/stuff/E ... elease.exe

However, before you use this in production, you should really test this thoroughly on all versions of Windows.

Regards
TiKu
Crunching for Fab36_Folding-Division at Folding@Home. Join Fab36/Fab30! - Folding@Home and BOINC
Boycott DRM! Boycott HDCP!
baron
Lt. Commander
Posts: 31
Joined: 21 Sep 2013, 18:55

Re: GDI usage

Post by baron »

Superb. Thank you very much! I'll be testing the next few days so if I find something I'll update, but so far all the tests look great.
User avatar
TiKu
Administrator
Administrator
Posts: 832
Joined: 28 Sep 2004, 21:10
Location: Unterföhring
Contact:

Re: GDI usage

Post by TiKu »

Did you notice any problems? Which versions of Windows have you already tested on?
Crunching for Fab36_Folding-Division at Folding@Home. Join Fab36/Fab30! - Folding@Home and BOINC
Boycott DRM! Boycott HDCP!
baron
Lt. Commander
Posts: 31
Joined: 21 Sep 2013, 18:55

Re: GDI usage

Post by baron »

Tested quite a lot on WinXP and Win7 so far without problems.
Post Reply