Page 1 of 2

ButtonGadgetEx.pbi (buttons with image and text), v0.4

Posted: Mon Feb 08, 2010 11:13 am
by Inf0Byt3
Description:
I have just finished a small include file that can help create buttons with both icons and text. The buttons are theme aware, so they will look and behave exactly like the ones that are drawn by the system. The code should work on all major OS's (tested on NT4, 98, 2K, XP, Vista, 7, 32 bit only). Unicode is also supported. Please note that this is the first time I use GDI all by myself so there could be leaks inside the code (although there were no obvious ones I could spot). If you see anything that doesn't fit please let me know.

Screenshot:
Image

License:
The include is licensed under the Zlib license.

Download:
Here's where you can download the package from :
Size: 7.16 KB
MD5: 8A8B251AB7D8B776C315607BD2F6BB6E
URL: http://www.bytessence.com/download/temp ... dgetEx.zip

Changelog:
* Version 0.4, 02 Jun 2010
- Made some minor changes, made possible to use this include with more than 1 window callback

* Version 0.3, 09 Feb 2010
- Added a 'disabled' state for the icon when the buttons are disabled (uses the DrawState API call - ugly but works)
- Made some optimizations, removed the #ODS_DEFAULT state (it is never used for the buttons it seems). Now the buttons also show the focus state correctly

* Version 0.2, 08 Feb 2010
- Implemented SetProp/GetProp calls instead of the linked list (thanks to Srod for the suggestion)

* Version 0.1, 07 Feb 2010
- First release
I hope this will be useful to someone :D.

Re: ButtonGadgetEx.pbi (buttons with image and text), v0.1

Posted: Mon Feb 08, 2010 11:50 am
by srod
Very nice Info, great work. 8)

One tiny suggestion perhaps.... because of your use of a linked list, this library is not strictly threadsafe. Imagine one thread to be adding a button whilst another thread is owner-drawing a different button on a different window... crash! I know that most 'sensible' applications will not attempt such things, but, well, there's always idiots like me around creating non-sensible apps! :mrgreen:

Rather than employ mutex protection (which is not a good idea for a streamlined painting process) I would abandon the list and instead place a pointer to each button's structure within a 'window property'. Use SetProp_() to do this. Just remember to use RemoveProp_() when the button is destroyed because Windows will not do this automatically.

Just a suggestion! :)

Thanks again.

Re: ButtonGadgetEx.pbi (buttons with image and text), v0.1

Posted: Mon Feb 08, 2010 11:58 am
by Inf0Byt3
Oops, I knew I forgot something. I'll have a look at SetProp/RemoveProp and update the code accordingly. Thank you for the suggestion.

Re: ButtonGadgetEx.pbi (buttons with image and text), v0.2

Posted: Mon Feb 08, 2010 1:18 pm
by Inf0Byt3
Version 0.2 released, SetProp_() implemented :D.

Re: ButtonGadgetEx.pbi (buttons with image and text), v0.2

Posted: Mon Feb 08, 2010 1:47 pm
by srod
:)

That's the ticket! :wink:

Nice code there Info. Anyone wondering how to use XP's theming engine would do well to take a look at this code.

One observation Info... the disabled buttons still show the full icon. It would of course look better if you could 'grey' the icon in these cases. :wink:

Re: ButtonGadgetEx.pbi (buttons with image and text), v0.2

Posted: Mon Feb 08, 2010 2:03 pm
by Inf0Byt3
srod wrote: :)

That's the ticket! :wink:
Thank you for the tip :D.
One observation Info... the disabled buttons still show the full icon. It would of course look better if you could 'grey' the icon in these cases. :wink:
Yes you're right. I wanted to draw them as grayed-out but didn't manage to find anything good for that. While searching on the net for a solution I found the DrawState_() API function but the results are really bad, the 'disabled' icon looked awful. Will search more and see what's to be done about this :).

Re: ButtonGadgetEx.pbi (buttons with image and text), v0.2

Posted: Mon Feb 08, 2010 2:11 pm
by srod
Yes I never managed to get any decent results from the DrawState_() api either.

Re: ButtonGadgetEx.pbi (buttons with image and text), v0.2

Posted: Mon Feb 08, 2010 2:19 pm
by srod

Re: ButtonGadgetEx.pbi (buttons with image and text), v0.2

Posted: Mon Feb 08, 2010 11:35 pm
by Rook Zimbabwe
Inf0byt3 is the MAN!!! :mrgreen: Thanks buddy this is going to be fun!

and SRod ain't not half bad at this codizing thing either! 8)

Re: ButtonGadgetEx.pbi (buttons with image and text), v0.2

Posted: Tue Feb 09, 2010 12:50 am
by SFSxOI
Very nice Inf0Byt3, Thank You :)

Re: ButtonGadgetEx.pbi (buttons with image and text), v0.3

Posted: Tue Feb 09, 2010 12:59 am
by Inf0Byt3
Thank you for the kind words lads :D.

I've uploaded version 0.3 which fixes some of the button states and makes the icon look disabled when the buttons are disabled. Note that I used DrawState_() for the moment as it was quicker to implement. I will be working to add Srod's excellent procedure for disabling icons as soon as I have more time.

Another feature to think about is to have total control over the state icons e.g. to define an icon for each button state (normal, hot, pressed, disabled).

Re: ButtonGadgetEx.pbi (buttons with image and text), v0.3

Posted: Sat Feb 13, 2010 3:32 am
by Rook Zimbabwe
My only want for this brilliant piece of code is:

If I could put the text on TOP of the icon! :D

Re: ButtonGadgetEx.pbi (buttons with image and text), v0.3

Posted: Sat Feb 13, 2010 1:13 pm
by Inf0Byt3
You can already do that :). To select where the icon will be placed (thus the text), use the following 'flags' when creating the buttons:
#BIGE_Top ;For putting the image on top of the text
#BIGE_Right ;For putting the text on the left and the image on the right
#BIGE_Bottom ;For putting the text on top of the image
#BIGE_Left ;For putting the image on the left and the text on the right
For example for your need you can use:

Code: Select all

ButtonGadgetEx(0, 10, 10, 100, 30, "Button", MyImage, #BIGE_Bottom)

Re: ButtonGadgetEx.pbi (buttons with image and text), v0.3

Posted: Sun Feb 14, 2010 2:31 am
by Rook Zimbabwe
Ay no... I too that as text ABOVE the image or BELOW the image... I want teh text in FRONT of the image...

Hmmm... Subclassing?

http://www.codeproject.com/KB/miscctrl/ ... sdemo.aspx

Re: ButtonGadgetEx.pbi (buttons with image and text), v0.3

Posted: Sun Feb 14, 2010 2:55 am
by Rook Zimbabwe
Just found this example of imagegadget and what I think is subclassing:

http://www.purebasic.fr/english/viewtop ... adget+text