Page 3 of 10

Re: [Class] ImageButton

Posted: 06 Mar 2014, 02:30
by just me
The current version fills the button's background with the AHK default window color:

Code: Select all

   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.

Re: [Class] ImageButton

Posted: 26 May 2014, 01:21
by jNizM
Example: Ghost Buttons
Image

Code: Select all

#NoEnv
SetBatchLines, -1
#Include Class_ImageButton.ahk

Gui, Margin, 50, 20
Gui, Font, s14 bold, Segoe UI

Gui, Add, Button, vBT1 w200 h65 hwndhBT1, ECOMMERCE
Opt1 := [0, 0x80f0f0f0, , 0xD308d860, 2, , 0x8008d860, 3]
Opt2 := [, 0x8008d860, , 0x00FFFFFF]
Opt5 := [ , ,  ,0x00FFFFFF]
if !(ImageButton.Create(hBT1, Opt1, Opt2, , , Opt5))
    MsgBox, 0, ImageButton Error btn1, % ImageButton.LastError


Gui, Add, Button, vBT2 w200 h65 hwndhBT2, MOBILE APPS
Opt1 := [0, 0x80f0f0f0, , 0xD30bb1d0, 2, , 0x800bb1d0, 3]
Opt2 := [0, 0x800bb1d0, , 0x00FFFFFF]
Opt3 := [0, 0x800bb1d0, , 0x00FFFFFF]
Opt4 := [0, 0x80aceffb, , 0x00FFFFFF, 2, , 0x807ce5f8, 3]
Opt5 := [0, 0x800bb1d0, , 0x00FFFFFF]
if !(ImageButton.Create(hBT2, Opt1, Opt2, Opt3, Opt4, Opt5))
    MsgBox, 0, ImageButton Error btn3, % ImageButton.LastError

Gui, Add, Button, vBT3 w200 h65 hwndhBT3 disabled, MOBILE APPS
Opt1 := [0, 0x80f0f0f0, , 0xD30bb1d0, 2, , 0x800bb1d0, 3]
Opt2 := [0, 0x800bb1d0, , 0x00FFFFFF]
Opt3 := [0, 0x807ce5f8, , 0x00FFFFFF]
Opt4 := [0, 0x80aceffb, , 0x00FFFFFF, 2, , 0x804bdbf5, 3]
Opt5 := [0, 0x800bb1d0, , 0x00FFFFFF]
if !(ImageButton.Create(hBT3, Opt1, Opt2, Opt3, Opt4, Opt5))
    MsgBox, 0, ImageButton Error btn3, % ImageButton.LastError

Gui, Add, Button, vBT4 w200 h65 hwndhBT4, MARKETING
Opt1 := [0, 0x80f0f0f0, , 0xD3d84896, 2, , 0x80d84896, 3]
Opt2 := [ , 0xD3d84896, , 0x00FFFFFF]
Opt5 := [ , , ,0x00FFFFFF]
if !(ImageButton.Create(hBT4, Opt1, Opt2, , , Opt5))
	MsgBox, 0, ImageButton Error btn4, % ImageButton.LastError

Gui, Show, , Image Buttons
return

GuiClose:
GuiEscape:
ExitApp

Re: [Class] ImageButton

Posted: 26 May 2014, 08:20
by jNizM
@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

#NoEnv
SetBatchLines, -1
#Include Class_ImageButton.ahk

Gui, Margin, 3, 3
Gui, Font, s10 bold, Segoe UI

Gui, Add, Button, vBT1 w151 h27 hwndhBT1, BUTTON 1
Opt1 := [0, 0x80f0f0f0, , 0xD3000000, 2, , 0x800099CC, 1]
Opt2 := [0, 0x8033B5E5, , 0x00FFFFFF, 2, , 0x800099CC, 1]
Opt3 := [0, 0x8033B5E5, , 0x00FFFFFF, 2, , 0x800099CC, 3]
Opt4 := [0, 0x80aceffb, , 0x00FFFFFF, 2, , 0x800099CC, 3]
Opt5 := [0, 0x8033B5E5, , 0x00FFFFFF, 2, , 0x800099CC, 3]
if !(ImageButton.Create(hBT1, Opt1, Opt2, Opt3, Opt4, Opt5))
    MsgBox, 0, ImageButton Error btn1, % ImageButton.LastError

Gui, Add, Button, vBT2 w151 h27 hwndhBT2, BUTTON 2
Opt1 := [0, 0x80f0f0f0, , 0xD3000000, 2, , 0x800099CC, 1]
Opt2 := [0, 0x8033B5E5, , 0x00FFFFFF, 2, , 0x800099CC, 1]
Opt3 := [0, 0x8033B5E5, , 0x00FFFFFF, 2, , 0x800099CC, 3]
Opt4 := [0, 0x80aceffb, , 0x00FFFFFF, 2, , 0x800099CC, 3]
Opt5 := [0, 0x8033B5E5, , 0x00FFFFFF, 2, , 0x800099CC, 3]
if !(ImageButton.Create(hBT2, Opt1, Opt2, Opt3, Opt4, Opt5))
    MsgBox, 0, ImageButton Error btn3, % ImageButton.LastError

Gui, Add, Button, vBT3 w151 h27 hwndhBT3, BUTTON 3
Opt1 := [0, 0x80f0f0f0, , 0xD3000000, 2, , 0x800099CC, 1]
Opt2 := [0, 0x8033B5E5, , 0x00FFFFFF, 2, , 0x800099CC, 1]
Opt3 := [0, 0x8033B5E5, , 0x00FFFFFF, 2, , 0x800099CC, 3]
Opt4 := [0, 0x80aceffb, , 0x00FFFFFF, 2, , 0x800099CC, 3]
Opt5 := [0, 0x8033B5E5, , 0x00FFFFFF, 2, , 0x800099CC, 3]
if !(ImageButton.Create(hBT3, Opt1, Opt2, Opt3, Opt4, Opt5))
    MsgBox, 0, ImageButton Error btn3, % ImageButton.LastError

Gui, Add, Button, vBT4 w151 h27 hwndhBT4, BUTTON 4
Opt1 := [0, 0x80f0f0f0, , 0xD3000000, 2, , 0x800099CC, 1]
Opt2 := [0, 0x8033B5E5, , 0x00FFFFFF, 2, , 0x800099CC, 1]
Opt3 := [0, 0x8033B5E5, , 0x00FFFFFF, 2, , 0x800099CC, 3]
Opt4 := [0, 0x80aceffb, , 0x00FFFFFF, 2, , 0x800099CC, 3]
Opt5 := [0, 0x8033B5E5, , 0x00FFFFFF, 2, , 0x800099CC, 3]
if !(ImageButton.Create(hBT4, Opt1, Opt2, Opt3, Opt4, Opt5))
	MsgBox, 0, ImageButton Error btn4, % ImageButton.LastError

Gui, Show, , Image Buttons
return

GuiClose:
GuiEscape:
ExitApp

Re: [Class] ImageButton

Posted: 02 Jun 2014, 14:44
by tmplinshi
Image

Code: Select all

#NoEnv
SetBatchLines -1
#Include <Class_ImageButton>

Gui, Color, White
Gui, Font, s10
Gui, Margin, 0, 0
Gui, -Caption +HwndHGUI
ImageButton.SetGuiColor("0xFFFFFF")

; GUI Border
Gui, Add, Button, w564 h325 hwndHBT Disabled
	Opt := [0, 0xffffff,,,,, 0x1CA7EF, 2]
	ImageButton.Create(HBT, Opt, "", "", Opt)

	; Title Bar
	Gui, Add, Button, xp+2 yp+2 w560 h27 hwndHBT Disabled, ImageButton Sample
		Opt := [0, 0x1CA7EF,, 0xffffff]
		ImageButton.Create(HBT, Opt, "", "", Opt)

		Gui, Font,, Marlett

		; Minimize Button
		Gui, Add, Button, x500 yp w30 h25 hwndHBT gGuiMinimize, 0
			Opt1 := [0, 0x1CA7EF,, 0xCCCCCC]
			Opt2 := [0, 0xC0C0C0,, 0xffffff]
			Opt3 := [0, 0x808080,, 0xffffff]
			ImageButton.Create(HBT, Opt1, Opt2, Opt3)

		; Close Button
		Gui, Add, Button, x+0 w30 h25 hwndHBT gGuiClose, r
			Opt1 := [0, 0x1CA7EF,, 0xCCCCCC]
			Opt2 := [0, 0xFF7171,, 0xffffff]
			Opt3 := [0, 0xFF0000,, 0xffffff]
			ImageButton.Create(HBT, Opt1, Opt2, Opt3)

	Gui, Font
	Gui, Font, s15 bold
	Gui, Add, Button, x80 y+135 w150 h40 HwndHBT vBtnStart gBtnStart, Start
		Opt1 := [3, 0x46cc9b, 0x228731, "White", 4]
		Opt2 := [3, 0x5bf0b9, 0x35bd47, "White", 4]
		Opt3 := [3, 0x228731, 0x46cc9b, "White", 4]
		Opt4 := [0, 0xF0F0EE,, 0xCACBC2, 4,, 0xCACBC2, 1]
		ImageButton.Create(HBT, Opt1, Opt2, Opt3, Opt4)
	Gui, Add, Button, x+100 wp hp HwndHBT Disabled vBtnStop gBtnStop, Stop
		Opt1 := [3, 0xFF4A4A, 0xCC0000, "White", 4]
		Opt2 := [3, 0xFF6A6A, 0xFF2424, "White", 4]
		Opt3 := [3, 0xEA0000, 0x9B0000, "White", 4]
		Opt4 := [0, 0xF0F0EE,, 0xCACBC2, 4,, 0xCACBC2, 1]
		ImageButton.Create(HBT, Opt1, Opt2, Opt3, Opt4)

Gui, Show
Return

BtnStart:
	GuiControl, Disable, BtnStart
	GuiControl, Enable, BtnStop
Return

BtnStop:
	GuiControl, Disable, BtnStop
	GuiControl, Enable, BtnStart
Return

GuiMinimize:
	Gui, Minimize
Return

GuiClose:
ExitApp

WM_LBUTTONDOWN(wParam, lParam, msg, hwnd) {
	global HGUI
	static init := OnMessage(0x0201, "WM_LBUTTONDOWN")

	If (hwnd = HGUI) {
		PostMessage, 0xA1, 2,,, A
	}
}
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

Re: [Class] ImageButton

Posted: 06 Jun 2014, 04:04
by just me
@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.

Re: [Class] ImageButton

Posted: 06 Jun 2014, 04:07
by jNizM
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

Re: [Class] ImageButton

Posted: 06 Jun 2014, 05:50
by just me
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.

Re: [Class] ImageButton

Posted: 06 Jun 2014, 05:54
by jNizM
Add Opt6 = Problem Solved
thx just me

Re: [Class] ImageButton

Posted: 07 Jun 2014, 02:06
by just me
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!

Re: [Class] ImageButton

Posted: 13 Oct 2014, 04:02
by jNizM
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

Re: [Class] ImageButton

Posted: 13 Oct 2014, 05:20
by just me
The caption is removed from the button:

Code: Select all

    ; 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).

Re: [Class] ImageButton

Posted: 23 Apr 2015, 22:44
by lblb
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

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

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

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.

Re: [Class] ImageButton

Posted: 26 Apr 2015, 00:15
by just me
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.

Re: [Class] ImageButton

Posted: 27 Apr 2015, 13:26
by lblb
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* ?

Re: [Class] ImageButton

Posted: 02 May 2015, 03:58
by just me
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:

Code: Select all

[c]...[/c]
Edit:
In the meantime you could use a function like

Code: Select all

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.

Re: [Class] ImageButton

Posted: 08 May 2015, 12:56
by oneoneoneone
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)

Re: [Class] ImageButton

Posted: 08 May 2015, 14:42
by just me
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.

Re: [Class] ImageButton

Posted: 15 May 2015, 01:40
by lblb
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.

Re: [Class] ImageButton

Posted: 20 Jul 2015, 07:37
by tmplinshi
Is there a way to disable the fade-out of the hot state? See this gif image:

Image
Code

Re: [Class] ImageButton

Posted: 20 Jul 2015, 08:06
by just me
I don't know. All effects are defined in the theme settings.