Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

[Function] _CreateImageButton_ (Colored buttons with GDI)


  • Please log in to reply
19 replies to this topic
nick
  • Members
  • 549 posts
  • Last active: Jul 03 2010 09:31 PM
  • Joined: 24 Aug 2005
*deleted*
nick :wink:

HotKeyIt
  • Moderators
  • 7439 posts
  • Last active: Jun 22 2016 09:14 PM
  • Joined: 18 Jun 2008
Many thanks for this great function.

SoggyDog
  • Members
  • 803 posts
  • Last active: Mar 04 2013 06:27 AM
  • Joined: 02 May 2006
Nice!

Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005
Wunderschön!

Frankie
  • Members
  • 2930 posts
  • Last active: Feb 05 2015 02:49 PM
  • Joined: 02 Nov 2008
This could be really helpful for creating more interesting guis easily. Thanks :D
aboutscriptappsscripts
Request Video Tutorials Here or View Current Tutorials on YouTube
Any code ⇈ above ⇈ requires AutoHotkey_L to run

sslbebd
  • Members
  • 12 posts
  • Last active:
  • Joined: 06 Apr 2008
Can the 1-line text restriction be removed? because the original display in buttons is useful, esp, the vertically centered, which exists only in Button but not other controls?

bhenkz
  • Guests
  • Last active:
  • Joined: --
Thankyou for the script.

Drugwash
  • Members
  • 1078 posts
  • Last active: May 24 2016 04:20 PM
  • Joined: 07 Sep 2008
Just letting you know that it also works in Win98SE. Danke sehr! ;)
Only thing is that the radio buttons become checkboxes but retain the radio group behavior.

(AHK 1.0.48.05 and Win98SE) forever | My scripts are here


Erittaf
  • Members
  • 192 posts
  • Last active: Feb 28 2013 11:49 PM
  • Joined: 02 Nov 2007
Hi, I was trying this function and it works alright, however when I disable a button it nukes the image. I'm not very good at deciphering code that is not mine >< Can anyone help me out? I'd like the button and/or the text to change colors when disabled, I don't mind calling the function extra times to redraw the button as long it draws properly on a disabled button.

nick
  • Members
  • 549 posts
  • Last active: Jul 03 2010 09:31 PM
  • Joined: 24 Aug 2005
... two workarounds:

#NoEnv
#Include _CreateImageButton_.ahk
FS := 14
BMIX := 0
Disabled := False
Gui, Margin, 20, 20
Gui, Color, 608080
Gui, Font, s%FS%
Gui, Add, Button, vButton1 gButton1 hwndBT1ID, Not really regular!
BMIX++, hBM%BMIX% := _CreateImageButton_(BT1ID, "000000", "00FF00", 2, "E0E0E0")
Gui, Add, Button, xp yp  vButton2 hwndBT2ID, Not really regular!
BMIX++, hBM%BMIX% := _CreateImageButton_(BT2ID, "000000", "008000", 2, "808080")
GuiControl, Hide, Button2
Gui, Add, Button, vButton3 gButton3 hwndBT3ID, Not really regular!
BMIX++, hBM%BMIX% := _CreateImageButton_(BT3ID, "000000", "00FF00", 2, "E0E0E0")
Gui, Add, Text, xp yp wp hp vText1 cGreen BackGroundTrans Center 0x200 Hidden
   , Not really regular!
Gui, Add, Button, xm wp hp vButton gButton, Disable
Gui, Show, , Colored Buttons
Return

GuiClose:
GuiEscape:
Loop, %BMIX% {
   DllCall("DeleteObject", "UInt", hBM%A_Index%)
}
ExitApp

Button1:
Button3:
Gui, +OwnDialogs
MsgBox, Button is enabled!
Return

Button:
Disabled ^= True
GuiControl, Disabled%Disabled%, Button1
GuiControl, Disabled%Disabled%, Button3
GuiControl, % (Disabled ? "Show" : "Hide"), Button2
GuiControl, % (Disabled ? "Show" : "Hide"), Text1
GuiControl, , Button, % (Disabled ? "Enable" : "Disable")
Return

nick :wink:

nick
  • Members
  • 549 posts
  • Last active: Jul 03 2010 09:31 PM
  • Joined: 24 Aug 2005
Version 2 released!
Look at first post!
nick :wink:

Drugwash
  • Members
  • 1078 posts
  • Last active: May 24 2016 04:20 PM
  • Joined: 07 Sep 2008
You're right, v2.0 doesn't work in Win98SE. :(
I have my system skinned and some of the buttons in the example inherit the skin while the others won't even show up. For comparison, I attached the result of the first example script with v1.0 of the function.
v2.0 Posted Image v1.0 Posted Image

(AHK 1.0.48.05 and Win98SE) forever | My scripts are here


mrgerbik
  • Members
  • 3 posts
  • Last active: May 07 2009 12:34 AM
  • Joined: 27 Feb 2009
awesome function - its exactly what i was as looking for ..

one issue (or something im overlooking) when calling the function to redraw an already function created button, it clears the text ...

my script makes lots of button color updates (i was previously just enabling/disabling a blank colored picture behind the button as to simulate a colored border)
is it just me (or maybe vista) ?
or should i be clearing anything prior to calling the func?

ive tried using DllCall("DeleteObject", "UInt", BTID) with no results


again great func - many thanks


---
UPDATE: I found the problem --

DllCall("GetWindowText", "UInt", HWND, "Str", TX, "Int", 255) can't retrieve the text of the control after its been created with the func

my hacky workaround was to just add a TX="" parameter to supply a text label when needed

hope this helps :D

nick
  • Members
  • 549 posts
  • Last active: Jul 03 2010 09:31 PM
  • Joined: 24 Aug 2005
Bugfix on 2009-08-25 (http://de.autohotkey...p?p=43871#43871)
nick :wink:

majkinetor
  • Moderators
  • 4512 posts
  • Last active: May 20 2019 07:41 AM
  • Joined: 24 May 2006
Awesome function. Ty.

One wish - Add option to specify bitmap file directly or pass bitmap handle.
Posted Image