[Class] ImageButton

Post your working scripts, libraries and tools
just me
Posts: 5459
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: [Class] ImageButton

06 Mar 2014, 02:30

The current version fills the button's background with the AHK default window color:

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

   InitClass() {
; ----------------------------------------------------------------------------------------------------------------
; Get AHK's default GUI background color
GuiColor := DllCall("User32.dll\GetSysColor", "Int", 15, "UInt") ; COLOR_3DFACE is used by AHK as default
This.DefGuiColor := ((GuiColor >> 16) & 0xFF) | (GuiColor & 0x00FF00) | ((GuiColor & 0xFF) << 16)
Return True
}
This has visibly effects only for rounded buttons or transparent colors. If you assign a different background color with Gui, Color, %MyGuiColor%, you should set this color as default by calling MyImageButton.SetGuiColor(MyGuiColor) or specify it in the 6th entry of the option parameters in these cases.

Drawing only a border around a common push button is not a task Class_ImageButton has been designed for.
User avatar
jNizM
Posts: 2320
Joined: 30 Sep 2013, 01:33
GitHub: jNizM
Contact:

Re: [Class] ImageButton

26 May 2014, 01:21

Example: Ghost Buttons
Image

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

[AHK] 1.1.29.01 x64 Unicode | [WIN] 10 Pro (Version 1803) x64 | [GitHub] Profile
Donations are appreciated if I could help you
User avatar
jNizM
Posts: 2320
Joined: 30 Sep 2013, 01:33
GitHub: jNizM
Contact:

Re: [Class] ImageButton

26 May 2014, 08:20

@just me
[GER]
Gibt es die Möglichkeit den aktivierten (gepressten) Button farbig zu lassen?
Aktuell ist es so, dass der Button dann flackert, nach dem ich ihn gedrückt habe.

bsp

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

[AHK] 1.1.29.01 x64 Unicode | [WIN] 10 Pro (Version 1803) x64 | [GitHub] Profile
Donations are appreciated if I could help you
tmplinshi
Posts: 1242
Joined: 01 Oct 2013, 14:57

Re: [Class] ImageButton

02 Jun 2014, 14:44

Image

Code: [Select all] [Expand] [Download] (Script.ahk)GeSHi © Codebox Plus



Found a small bug, the single 0 (or 000) as button text will be ignored. Change If (BtnCaption) to If (BtnCaption != "") will fix it. :P
Last edited by tmplinshi on 31 Dec 2016, 23:49, edited 1 time in total.
just me
Posts: 5459
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: [Class] ImageButton

06 Jun 2014, 04:04

@jNizM:

What Du you mean with 'flicker'? I cannot reproduce it here.
Was meinst Du mit Flackern? Ich kann das hier mit Deinem Beispiel nicht sehen.

@tmplinshi:

Thanks for reporting. I'll will fix it soon.
User avatar
jNizM
Posts: 2320
Joined: 30 Sep 2013, 01:33
GitHub: jNizM
Contact:

Re: [Class] ImageButton

06 Jun 2014, 04:07

Wenn ich in meinem Beispiel auf ein Butten klicke (Pressed) wechseld die Farbe zwischen Opt1 & Opt5 hin und her.
Ich möchte aber das die Farbe eines gepressten Buttons bleibt (nicht die Ausgangsfarben)

normal = transparent + dünner ramen
hover = ausgefüllt
gedrückt = ausgefüllt (ohne animation)


edit
habs mal recorded...
https://dl.dropboxusercontent.com/u/186 ... /Video.avi
[AHK] 1.1.29.01 x64 Unicode | [WIN] 10 Pro (Version 1803) x64 | [GitHub] Profile
Donations are appreciated if I could help you
just me
Posts: 5459
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: [Class] ImageButton

06 Jun 2014, 05:50

That's a Windows (at least Vista and 7) feature. After you've clicked a button it will become the default button and the image will change among states 5 and 6. Because you didn't provide an option for state 6 the values of state 1 are used for 6.

Das ist eine von Microsoft so gewollte Animation (zumindest in Windows Vista und 7). Nachdem Du auf einen Button geklickt hast, wird der zum Defaultbutton und das angezeigte Bild wechselt zwischen den Stati 5 und 6. Weil Du keine Werte für den Status 6 übergeben hast, werden dafür die Werte für den Status 1 genommen.

Für eine weitere Kommunikation auf Deutsch mach doch bitte einen Thread im deutschen Forum auf.
User avatar
jNizM
Posts: 2320
Joined: 30 Sep 2013, 01:33
GitHub: jNizM
Contact:

Re: [Class] ImageButton

06 Jun 2014, 05:54

Add Opt6 = Problem Solved
thx just me
[AHK] 1.1.29.01 x64 Unicode | [WIN] 10 Pro (Version 1803) x64 | [GitHub] Profile
Donations are appreciated if I could help you
just me
Posts: 5459
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: [Class] ImageButton

07 Jun 2014, 02:06

tmplinshi wrote:Found a small bug, the single 0 (or 000) as button text will be ignored. Change If (BtnCaption) to If (BtnCaption != "") will fix it. :P

Fixed! Thanks for reporting!
User avatar
jNizM
Posts: 2320
Joined: 30 Sep 2013, 01:33
GitHub: jNizM
Contact:

Re: [Class] ImageButton

13 Oct 2014, 04:02

Cant get ControlGetText on Class_ImageButtons

Normal Button:
Gui, Add, Button, x+4 yp w70 h22 +0x8000000 gAdd vButtonNeu, % "New"
ControlGetText, GetButton, Button3, A ==> "New"

Class_ImageButton:
Gui, Add, Button, x+4 yp w70 h22 +0x8000000 hwndhBT1_1 gAdd vButtonNeu, % "New"
ControlGetText, GetButton, Button3, A ==> empty
[AHK] 1.1.29.01 x64 Unicode | [WIN] 10 Pro (Version 1803) x64 | [GitHub] Profile
Donations are appreciated if I could help you
just me
Posts: 5459
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: [Class] ImageButton

13 Oct 2014, 05:20

The caption is removed from the button:

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

    ; Hide buttons's caption
ControlSetText, , , ahk_id %HWND%
Control, Style, +%BS_BITMAP%, , ahk_id %HWND%
Otherwise, the caption will de drawn by the control's window procedure (AFAIR at least on Win XP).
lblb
Posts: 124
Joined: 30 Sep 2013, 11:31

Re: [Class] ImageButton

23 Apr 2015, 22:44

Hi just me,

Thanks for all your work on this, it's exactly what I needed and it works beautifully.

Once a button's colors have been set via, for example,

Code: [Select all] [Download] (Script.ahk)GeSHi © Codebox Plus

ImageButton.Create(HButton, Opt1)
is there a way to later on change the background color by applying a different set of options, say through something like

Code: [Select all] [Download] (Script.ahk)GeSHi © Codebox Plus

ImageButton.Create(HButton, Opt2)
where the background color is different in Opt2? If I do that, then the caption disappears. Or would that necessitate the nonexistent

Code: [Select all] [Download] (Script.ahk)GeSHi © Codebox Plus

Change() 
method that you mentioned four posts up? Or maybe is there a way to remove the color settings and reapply a new set of colors?

Thanks again for developing this.
just me
Posts: 5459
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: [Class] ImageButton

26 Apr 2015, 00:15

Hi lblb,

as is, you have to call ImageButton.Create() once again passing a complete Options* array. Before you do it, you have to restore the button's caption. The only issue might be that it will leave an orphaned image list.
lblb
Posts: 124
Joined: 30 Sep 2013, 11:31

Re: [Class] ImageButton

27 Apr 2015, 13:26

Hi just me,

Thanks for the quick reply. Excellent, it seems to work well if I reset the button text using the GuiControl command before calling ImageButton.Create() again. Is that what you had in mind when you said "restore a button's caption"?

Also, are there any bad consequences to having this orphaned image list? For the usage that I have here, the color of multiple Gui buttons could be changed multiple times depending on the user's interactions with the GUI. So I'm guessing that that would leave an orphaned image list every time a color is changed, right? Would that creep up memory-wise, or in any other way?

Thanks again for your help, much appreciated.

By the way, on this forum how do you include text in boxes like you did in your previous post for ImageButton.Create() and Options* ?
just me
Posts: 5459
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: [Class] ImageButton

02 May 2015, 03:58

Hi lblb,

sorry for the late reply. I've been working on a conceptual change, but I'm still not clear how I want it to work.

lblb wrote:Is that what you had in mind when you said "restore a button's caption"?
Yes.
lblb wrote:Would that creep up memory-wise, ...
Yes.
lblb wrote:By the way, on this forum how do you include text in boxes like you did in your previous post for ImageButton.Create() and Options* ?
It's the c button on the left side of the second button row:

Edit:
In the meantime you could use a function like

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

DestroyBtnImgList(HBTN) {
; BCM_GETIMAGELIST = 0x1603
VarSetCapacity(BtnImgList, A_PtrSize + 24, 0)
SendMessage, 0x1603, 0, % &BtnImgList, , ahk_id %HBTN%
Return IL_Destroy(NumGet(BtnImgList, "UPtr"))
}
to destroy the image list before you recreate the button.
oneoneoneone
Posts: 1
Joined: 08 May 2015, 08:57

Re: [Class] ImageButton

08 May 2015, 12:56

Hello just me,

Could you please help me with this problem?

I have an image button with different pictures for each condition - normal/pressed. Pic1.png for normal state, Pic2.png for pressed state. Whenever I press a button, first image starts to disappear with some fadeout effect. What I need is to either decrease fadeout time or get rid of it at all(first pic instantly gets replaced with the second one). If I use -Theme option, fadeout disappears, however it brings dark grey frame around the button.

Example of my problem:

gif


code


AutoHotkey: AutoHotkey_L
AHK Version: 1.1.15.00
Operating System: WIN 7 (64-bit)
Last edited by oneoneoneone on 09 May 2015, 06:25, edited 5 times in total.
just me
Posts: 5459
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: [Class] ImageButton

08 May 2015, 14:42

Hello oneoneoneone,

I cannot view the picture. Your issue is caused by one of these animations introduced with the Win Vista themes. If you want to get rid of it at all you have to
  • create an ownerdrwan button or
  • subclass the button
and do all the drawing by yourself.
lblb
Posts: 124
Joined: 30 Sep 2013, 11:31

Re: [Class] ImageButton

15 May 2015, 01:40

Hi just me,

I somehow missed your reply to my previous post. Thanks a lot for all the info, much appreciated. And thanks again for all your work on this and everything else around here.
tmplinshi
Posts: 1242
Joined: 01 Oct 2013, 14:57

Re: [Class] ImageButton

20 Jul 2015, 07:37

Is there a way to disable the fade-out of the hot state? See this gif image:

Image
Code
just me
Posts: 5459
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: [Class] ImageButton

20 Jul 2015, 08:06

I don't know. All effects are defined in the theme settings.

Return to “Scripts and Functions”

Who is online

Users browsing this forum: feiyue and 23 guests