[Class] ImageButton - 1.5.00.00 - 20201230

Post your working scripts, libraries and tools for AHK v1.1 and older
lblb
Posts: 190
Joined: 30 Sep 2013, 11:31

Re: [Class] ImageButton

14 Apr 2016, 02:04

@just me and @Roflcoopter:

Since you last discusses, have you found a way to use custom fonts in combination with ImageButton? It would really make my life easier if it were possible. Thanks in advance for any info and help you may be able to provide.
just me
Posts: 9424
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: [Class] ImageButton

14 Apr 2016, 06:24

No progress here!
lblb
Posts: 190
Joined: 30 Sep 2013, 11:31

Re: [Class] ImageButton

14 Apr 2016, 12:06

Hi just me,

Thanks for the quick reply. Ok then, I'll just have to install the font on the system when the user runs the installer for my program.

On a different topic:

Do you know if it's possible to affect the antialiasing of the button's border and font. Specifically, after creating an ImageButton, if I set the Gui background color to be transparent I get terribly jagged edges for the button outline. If I also set the button's background color (set in ImageButton options) to be transparent using TransColor, then both the button outline and the text on the button are very jagged.
For a normal Gui text control, it seems like the only option to eliminate the jagginess is to use GDI+ (see a recent post: https://autohotkey.com/board/topic/1502 ... -osd-text/). Is it possible to do something similar by modifying something in the ImageButton code? Or by somehow applying the GDI+ strategy outlined in that post in combination with ImageButton?

Thanks again for all your help and your dedicated work on this! Your insight is always much appreciated.
just me
Posts: 9424
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: [Class] ImageButton

16 Apr 2016, 03:01

Hi lblb,

the class doesn't know anything about transparency settings for the GUI.

For the captions you might play around with:

Code: Select all

            ; Set render quality to system default
            DllCall("Gdiplus.dll\GdipSetTextRenderingHint", "Ptr", PGRAPHICS, "Int", 0)
/*
typedef enum  {
  TextRenderingHintSystemDefault              = 0,
  TextRenderingHintSingleBitPerPixelGridFit   = 1,
  TextRenderingHintSingleBitPerPixel          = 2,
  TextRenderingHintAntiAliasGridFit           = 3,
  TextRenderingHintAntiAlias                  = 4,
  TextRenderingHintClearTypeGridFit           = 5 
} TextRenderingHint;
*/
For the borders I have no clue. I assume that you talk about 'rounded' buttons.
lblb
Posts: 190
Joined: 30 Sep 2013, 11:31

Re: [Class] ImageButton

25 Apr 2016, 01:42

Hi just me,

Sorry for the late reply as I just found time to get back into this. Unfortunately, what you suggested doesn't improve the rendering of the text (and indeed I was talking about rounded buttons). I guess the real problem is that the transparency relies on "Winset, Transcolor" and that this messes the antialiasing as as been discussed many times before such as in the link I provided. I guess I'll have to look somewhere else... Anyway, thanks again for your help and for your work on this, all very appreciated.
User avatar
kczx3
Posts: 1640
Joined: 06 Oct 2015, 21:39

Re: [Class] ImageButton

25 Apr 2016, 14:04

kczx3 wrote:Is it possible to use Windows system icons with this class? For instance, Icon239 from Global iconPath := A_WinDir "\system32\shell32.dll"
I wonder if we can revisit this? I'm trying to wrap my brain around creating a bitmap from a resource in a Dll file to use in your class but am simply getting a headache. :(
just me
Posts: 9424
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: [Class] ImageButton

26 Apr 2016, 02:07

You can pass a HBITMAP handle to be used as the background image. Now we have LoadPicture() so it should be a bit easier. Icons would need to draw both the icon and the background.
User avatar
kczx3
Posts: 1640
Joined: 06 Oct 2015, 21:39

Re: [Class] ImageButton

26 Apr 2016, 13:05

Cool, I recall seeing the addition of that function but had forgotten about it. That's a good starting point. Thank you :)
lblb
Posts: 190
Joined: 30 Sep 2013, 11:31

Re: [Class] ImageButton

26 Jun 2016, 18:02

Hi just me,

I'm still very much enjoying this class. Fantastic work!

Is there any way to create on the same Gui different series of independent buttons? To illustrate what I mean, here is a simple example:
- I set the "pressed" option to a blue button background
- If I press button 1, it becomes active and its background becomes blue.
- If I now press button 2, it now becomes the active button and becomes blue AND button 1 goes back to normal.
- Would it be possible to have a button 3 on the same gui that when pressed doesn't make buttons 1 and 2 go back to normal (i.e., if I press button 3 while button 2 is blue and active, button 2 stays blue and active)?

My guess would be that, if it's possible, I would have to put button 3 in a different array of buttons than buttons 1 and 2. Is that possible? If yes, would I need to use a different Create function with its own array for button 3?

I tried doing that (by adding a Create2 function and modifying the "Create a HBITMAP handle from the bitmap and add it to the array" and the "Create the ImageList" sections of the code) but couldn't get it to work. I tried doing what's below, but I don't know if that's even supposed to work or if I did something wrong (I can't seem to add text formatting to the code below to show what I changed so I marked with *** the lines on which I made changes and added "2" in an attempt to create a new array of buttons):

Code: Select all

Create2(HWND, Options*) {
...
...

; Create a HBITMAP handle from the bitmap and add it to the array
DllCall("Gdiplus.dll\GdipCreateHBITMAPFromBitmap", "Ptr", PBITMAP, "PtrP", HBITMAP, "UInt", 0X00FFFFFF)
***This.BitMaps2 := HBITMAP
; Free resources
DllCall("Gdiplus.dll\GdipDisposeImage", "Ptr", PBITMAP)
DllCall("Gdiplus.dll\GdipDeleteBrush", "Ptr", PBRUSH)
DllCall("Gdiplus.dll\GdipDeleteStringFormat", "Ptr", HFORMAT)
DllCall("Gdiplus.dll\GdipDeleteGraphics", "Ptr", PGRAPHICS)
; Add the bitmap to the array
}
; Now free the font object
DllCall("Gdiplus.dll\GdipDeleteFont", "Ptr", PFONT)
; ----------------------------------------------------------------------------------------------------------------
; Create the ImageList
***HIL2 := DllCall("Comctl32.dll\ImageList_Create"
             , "UInt", BtnW, "UInt", BtnH, "UInt", ILC_COLOR32, "Int", 6, "Int", 0, "Ptr")
***Loop, % (This.BitMaps2.MaxIndex() > 1 ? 6 : 1) {
***HBITMAP := This.BitMaps2.HasKey(A_Index) ? This.BitMaps2[A_Index] : This.BitMaps2.1
***DllCall("Comctl32.dll\ImageList_Add", "Ptr", HIL2, "Ptr", HBITMAP, "Ptr", 0)
}
; Create a BUTTON_IMAGELIST structure
***VarSetCapacity(BIL2, 20 + A_PtrSize, 0)
***NumPut(HIL2, BIL2, 0, "Ptr")
***Numput(BUTTON_IMAGELIST_ALIGN_CENTER, BIL2, A_PtrSize + 16, "UInt")
; Hide buttons's caption
ControlSetText, , , ahk_id %HWND%
Control, Style, +%BS_BITMAP%, , ahk_id %HWND%
; Assign the ImageList to the button
SendMessage, %BCM_SETIMAGELIST%, 0, 0, , ahk_id %HWND%
***SendMessage, %BCM_SETIMAGELIST%, 0, % &BIL2, , ahk_id %HWND%
; Free the bitmaps
This.FreeBitmaps()
just me
Posts: 9424
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: [Class] ImageButton

27 Jun 2016, 01:47

Hi lblb,

I think that's not the way push buttons are intended to work. All visual effects are performed automatically by the controls according to the current state and the associated image of its image list. And each button can have only one associated image list at a time. To change the appearance of a button for a given state, you either would have to replace its image list (BCM_SETIMAGELIST (0x1602)), set its state (BM_SETSTATE (0x00F3)), or make it the current default button. I don't know other options.
lblb
Posts: 190
Joined: 30 Sep 2013, 11:31

Re: [Class] ImageButton

05 Jul 2016, 23:46

Hi just me,

Thanks for your thoughtful answer, much appreciated. I'll look into more closely. Cheers!
Nutcracker

Re: [Class] ImageButton

06 Dec 2016, 09:05

Hi just me,

I use your script and don't understant how to add an icon (from dll or exe, or just an ico) to yourButtonClass. When I tried to do that I see "Invalid value for startcolor in optons[1]!" Standart methods adding pics on UI now working.
just me
Posts: 9424
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: [Class] ImageButton

06 Dec 2016, 09:27

Hi,

the ImageButton class is not designed to set button icons. It will always fill the whole rectangle of the button is you pass an image handle or file name.
User avatar
Flipeador
Posts: 1204
Joined: 15 Nov 2014, 21:31
Location: Argentina
Contact:

Re: [Class] ImageButton

06 Dec 2016, 11:40

I love this class. I share a file to facilitate the creation of the colors for the buttons, I made it a long time ago. I no longer have the script, I converted it to .exe and I do not know what I did with the script.
https://www.dropbox.com/s/ozrtdt38ph2cc ... r.exe?dl=0
User avatar
Klark92
Posts: 161
Joined: 18 Jan 2015, 19:33

Re: [Class] ImageButton

31 Dec 2016, 22:38

Disabling "Animate controls and elements inside" at Performance Options/Visual Effects is giving best result about bad/slow fading... Is there any method to disable that option only for application ?
Smart Kombo 1.0 | One of the best Knight Online's key combo program...
just me
Posts: 9424
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: [Class] ImageButton

01 Jan 2017, 05:26

I don't know. It might be better to ask in "Ask For Help".
User avatar
Klark92
Posts: 161
Joined: 18 Jan 2015, 19:33

Re: [Class] ImageButton

01 Jan 2017, 07:11

I can't even get answer from there for easy questions...
Smart Kombo 1.0 | One of the best Knight Online's key combo program...
tmplinshi
Posts: 1604
Joined: 01 Oct 2013, 14:57

Re: [Class] ImageButton

20 Jan 2017, 11:42

Hi, I added support for icon and checkbox/radio buttons.

Image

When used for checkbox/radio controls, the BS_PUSHLIKE style is added to the control, so that the default checkbox/radio icon will not display.
It's not perfect: 1) When you are pressing the button you will see the checked image. 2) There's only one disabled image (check/uncheck) can be used.

Details: https://github.com/tmplinshi/Class_Imag ... d-features
User avatar
Klark92
Posts: 161
Joined: 18 Jan 2015, 19:33

Re: [Class] ImageButton

20 Jan 2017, 12:35

That is awesome tmplinshi! I already downloaded it =^_^=

We should remove/reduce this long fading effect :)
Smart Kombo 1.0 | One of the best Knight Online's key combo program...
tmplinshi
Posts: 1604
Joined: 01 Oct 2013, 14:57

Re: [Class] ImageButton

20 Jan 2017, 12:48

Klark92 wrote:We should remove/reduce this long fading effect :)
I want that too, but searched many times, with no luck.

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: No registered users and 122 guests