[Function] GuiButtonIcon

Post a reply

Confirmation code
Enter the code exactly as it appears. All letters are case insensitive.
Smilies
:D :) ;) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :!: :?: :idea: :| :mrgreen: :geek: :ugeek: :arrow: :angel: :clap: :crazy: :eh: :lolno: :problem: :shh: :shifty: :sick: :silent: :think: :thumbup: :thumbdown: :salute: :wave: :wtf: :yawn: :facepalm: :bravo: :dance: :beard: :morebeard: :xmas: :HeHe: :trollface: :cookie: :rainbow: :monkeysee: :monkeysay: :happybday: :headwall: :offtopic: :superhappy: :terms: :beer:
View more smilies

BBCode is ON
[img] is OFF
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: [Function] GuiButtonIcon

Re: [Function] GuiButtonIcon

Post by DigiDon » 12 Feb 2018, 05:44

Long time I was looking for a solution to use an image as a real button with the standard look and effect!
Just found this topic now !
Simple and great, still working fine, so thanks many years later :D

To add my 2cts I want to remind that you can use also handle to images or other image types (jpg, png etc.)

From Help File on ListView IL_Add
A bitmap or icon handle can be used instead of a filename. For example, HBITMAP:%handle%.

And for other images it seems this should be something like
IL_Add(ImageListID, Filename.jpg (png,...), Transp=0xFFFFFF , ResizeNonIcon=1])

Re: [Function] GuiButtonIcon

Post by animagus46 » 23 Jul 2017, 14:57

it is possibel to hide a icon?
like;
GuiControl, Hide%Button2Shown%, Button2

example;
if "A" exist show button2
if "A" not exist hide Button2

Terribel: GuiControl, Hide%Button2Shown%, Button2 was the solution....

Re: [Function] GuiButtonIcon

Post by Helgef » 23 Nov 2016, 12:24

Very nice! Thanks

Re: [Function] GuiButtonIcon

Post by SirRFI » 22 Nov 2016, 17:42

Nice one. Is it possible to set transparency on the icons? Let's say make the "save" icon half-transparent.

Re: [Function] GuiButtonIcon

Post by huyaowen » 29 Dec 2014, 10:55

Very nice. Easy and small.

Re: [Function] GuiButtonIcon

Post by enthused » 25 Dec 2014, 14:14

This is great and makes for better user experience and enhances GUI look.
I'm almost certain this can be done, but I'm not sure how:
Can Icon be selected at run time from an exe file? Say the button acts as OpenDialog and opens for file selection with only exe files can be selected. What the file the user selects, then that Icon from that file is what is on the button.

I think it can be done with other function help to extract Icon from exe file and so on.
Thank you for this nice addition.

Re: [Function] GuiButtonIcon

Post by TedStriker » 05 Jun 2014, 14:16

After reading your post I didn't think you'd change the function, but now it can do even more and is easier to use. :shock: Thank you! I hope your function gets included in AHK or at least mentioned in the help file.

I am serious... and don't call me Shirley.

I love these old ZAZ movies/series... "Cigarettes?" - "Yes, I know." :-D

Re: [Function] GuiButtonIcon

Post by FanaticGuru » 31 May 2014, 22:05

TedStriker wrote:Thank you for the explanation. I thought the margin would be from the left, as I configured the alignment to be left. Guess it's not that easy. ;-) No need to enhance your function. It's good as it is. Being an amateur script writer I truly enjoy putting icons on buttons so easily.

Also welcome to the boards TedStriker.

I noticed this was your first post here.

I am serious... and don't call me Shirley.

FG

Re: [Function] GuiButtonIcon

Post by FanaticGuru » 31 May 2014, 21:41

Updated Script in First Post

Change Log: Version 2.0, 2014-05-31
Changed the way options are passed to the script to allow more flexibility.
Now an icon can have individual left, top, right and bottom margins that allow for more control over positioning of the icon on the button. The margin is on the icon image not the button.
This margin is like transparent padding that is being added to the image. By using a center alignment and then adding this margin to the image you can effectively push the image where ever you want on the button.
It is possible to use button, icon and margin sizes that create clipping of the image if sizes are used that will not all fit within the size of the button.

FG

Re: [Function] GuiButtonIcon

Post by TedStriker » 31 May 2014, 17:18

Thank you for the explanation. I thought the margin would be from the left, as I configured the alignment to be left. Guess it's not that easy. ;-) No need to enhance your function. It's good as it is. Being an amateur script writer I truly enjoy putting icons on buttons so easily.

Re: [Function] GuiButtonIcon

Post by FanaticGuru » 31 May 2014, 01:55

TedStriker wrote:Maybe I just miss-understood this parameter. Is there any way to get the icon a bit more to the right? (Using AHK 1.1.15 unicode 32b)

Margin does just shrink the icon.

If a button is created that is w38 h38 then you can create a GuiButtonIcon with a size of 38 and margin of 6. This actually creates an icon that is 32 which leaves a margin of 3 spaces on all sides if the icon is centered on the button.

The margin parameter was added so that you could use the same size number for both the button and the icon size and the icon would be shrunk by default to be a little smaller than the button.

These two GuiButtonIcon commands do functionally exactly the same thing.
Gui, Add, Button, w38 h38 hwndIcon
GuiButtonIcon(Icon, "shell32.dll", 23, 38) ; size 38 with default of 6 margin
GuiButtonIcon(Icon, "shell32.dll", 23, 32, 0) ; size 32 with 0 margin

But the first is suppose to be easier because you can use the same size for the button and icon and let the margin provide the shrinkage amount to have the icon be a little smaller to fit on the button.

This all works fine when the icon is centered on the button but when you use the align to an edge this can be confusing because information in the Image List determines how far the icon will be from the edge.

This information in the Image List can most likely be altered with NumPut the same way the alignment is altered in the image structure.

When I get time I will fool around with it. I just hate having to pass up to 4 more parameters to the function. It is more about how to get all the information to the function in an elegant way.

I might just rewrite it to have options like Gui where all the options are sent in one parameter with stuff like w38 h48 a4 mt5 mb5 ml10 mr8 for width 38, height 48, alignment 4, margin top 5, margin bottom 5, margin left 10, margin right 8.

The point of the whole function is to keep it simple and easy but I still might be able to do that and provide more control to those that need it. The function will end up being more code to sort out the options than actually creating the button icon.

FG

Re: [Function] GuiButtonIcon

Post by TedStriker » 30 May 2014, 13:59

Hi,

thank you for this very nice function. Adding icons to buttons without making clickable pictures is pretty useful. :)

I've a question about the margin parameter. As far as I understood, it should move the icon, but it only makes them smaller.

This is what I get with GuiButtonIcon(Icon1, Icons.icl, 11, 16, 0, 0)
Image

And this is what I get with GuiButtonIcon(Icon1, Icons.icl, 11, 16, 6, 0)
Image

Maybe I just miss-understood this parameter. Is there any way to get the icon a bit more to the right? (Using AHK 1.1.15 unicode 32b)

Re: [Function] GuiButtonIcon

Post by FanaticGuru » 26 Mar 2014, 17:21

Relayer wrote:It looks like the image list facility is designed around icons. Can your script be adapted to place any picture file on a button?

I know PNGs can be done. Just make sure the PNG is where it will be found or include the full path. Also choose an index of 0.

GuiButtonIcon(Icon, "C:\Users\Guru\Desktop\fire.png", 0)

I don't know about other picture formats, I have not tried them.

FG

Re: [Function] GuiButtonIcon

Post by Relayer » 26 Mar 2014, 15:59

Thank you... I see the benefits now.

It looks like the image list facility is designed around icons. Can your script be adapted to place any picture file on a button?

Relayer

Re: [Function] GuiButtonIcon

Post by FanaticGuru » 25 Mar 2014, 16:57

Relayer wrote:Doesn't the following essentially do the same thing using the native Gui commands?

Gui, Add, Picture, x%x_location% y%y_location% w-1 h10 hwndPicHandle gGuiCall, %A_ScriptDir%\263.ico

The width and height parameters can adjust the rendered size. The only thing missing is flagging a missing icon file.

Relayer

It really depends on whether you want a button or a picture. Both can do something when you click on them but they are not exactly the same. For one a button provides a graphical cue that it is a button and meant to be click on also a button provides graphical feedback when you click on it.

Below is code that shows both. They look different and behave different when you click on them.

Code: [Select all] [Expand]GeSHi © Codebox Plus

In general buttons normally make better buttons.

FG

Re: [Function] GuiButtonIcon

Post by Relayer » 25 Mar 2014, 14:42

Doesn't the following essentially do the same thing using the native Gui commands?

Gui, Add, Picture, x%x_location% y%y_location% w-1 h10 hwndPicHandle gGuiCall, %A_ScriptDir%\263.ico

The width and height parameters can adjust the rendered size. The only thing missing is flagging a missing icon file.

Relayer

Re: [Function] GuiButtonIcon

Post by FanaticGuru » 24 Mar 2014, 13:48

UPDATED SCRIPT ON FIRST PAGE

Change Log: Version 1.1
Function now returns true or false depending on whether icon image was found
Added in example a use of this returned information to retry with a different icon if the first failed

FG

Re: [Function] GuiButtonIcon

Post by Dragonslayr » 24 Mar 2014, 11:42

Is there a way this function can return a default icon if no icon is found for a file?

I do not understand good enough how the function achieves it's goal to add this feature. :(

Re: [Function] GuiButtonIcon

Post by Dragonslayr » 22 Mar 2014, 22:32

Thank You!
I really appreciate the Documentation in the Function Code!!

Seems to work nicely!

Re: [Function] GuiButtonIcon

Post by jballi » 14 Feb 2014, 21:06

Looks useful. Thanks.

Top