[Class] ImageButton - 1.5.00.00 - 20201230

Post your working scripts, libraries and tools for AHK v1.1 and older
tmplinshi
Posts: 1604
Joined: 01 Oct 2013, 14:57

Re: [Class] ImageButton

20 Jul 2015, 08:25

ok, thanks for reply.
User avatar
kczx3
Posts: 1640
Joined: 06 Oct 2015, 21:39

Re: [Class] ImageButton

28 Dec 2015, 08:23

Is it possible to use Windows system icons with this class? For instance, Icon239 from Global iconPath := A_WinDir "\system32\shell32.dll"
User avatar
kczx3
Posts: 1640
Joined: 06 Oct 2015, 21:39

Re: [Class] ImageButton

28 Dec 2015, 08:25

NVM, I see that you simply add the picture first and then call the Create method so that should work fine.
just me
Posts: 9442
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: [Class] ImageButton

28 Dec 2015, 10:54

Hi kczx3, did you solve your problem?
User avatar
kczx3
Posts: 1640
Joined: 06 Oct 2015, 21:39

Re: [Class] ImageButton

28 Dec 2015, 12:48

Not really. I decided it wasn't really worth it though. I think I was just trying to force a use case for this to see it work.
Thorondor

Re: [Class] ImageButton

12 Jan 2016, 08:29

Trying to run the sample code, I am getting the error at line 72 in #include file

Line Text: Class ImageButton {
Error: This line does not contain a recognized action.

I have never worked with classes in ahk before. Any idea what causes this error?
just me
Posts: 9442
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: [Class] ImageButton

12 Jan 2016, 08:32

I guess you have to update your AHK.
Thorondor

Re: [Class] ImageButton

12 Jan 2016, 08:38

Wow, okay, that worked. Haha, thanks for the fast response and easy solution. :thumbup:
lblb
Posts: 190
Joined: 30 Sep 2013, 11:31

Re: [Class] ImageButton

05 Feb 2016, 13:54

Hi just me,

Thanks again for this fantastic script! It works great and I use it in most of my projects.

Since creating buttons takes surprisingly (at least to me) quite a bit of memory (something like 50-80 Kb per button, as seen through Task Manager, which can add up very fast), I use the function you shared in the following post to release memory when a button is not needed anymore:
https://autohotkey.com/boards/viewtopic ... 287#p44287

That works great. However, in a script with multiple gui's, is there a faster way to destroy all the buttons on a given gui apart from looping that function through all its buttons? If I simply destroy the gui, the memory from the ImageButtons is not released.

Thanks again!
just me
Posts: 9442
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: [Class] ImageButton

06 Feb 2016, 04:28

Hi lblb,

the class doesn't store any information about the buttons or the parent GUIs. So the answer is: No!
lblb
Posts: 190
Joined: 30 Sep 2013, 11:31

Re: [Class] ImageButton

06 Feb 2016, 05:08

Hi just me,

Excellent! A clear answer, even if it doesn't make my life easier, is always appreciated!

Thanks again for all your contributions here and everywhere else, I've certainly learned a lot from and been inspired by your work.
roflcoopter

Re: [Class] ImageButton

12 Feb 2016, 03:02

Hello!

I have been using ImageButton with great success, but i bumped into a problem when trying to use a custom font. Im using the method described here: https://autohotkey.com/board/topic/31031-portable-font/

I have DllCall( "GDI32.DLL\AddFontResourceEx", Str,"VCR_OSD_MONO_1.001.ttf",UInt,(FR_PRIVATE:=0x10), Int,0) at the top of my script and when i add my button the script finds the font and uses it correctly. However when i call ImageButton with:

Opt1 := [1, "BLACK", , 0x7890F0, , , 0x7890F0, 1]
ImageButton.Create(HBT%A_Index%, Opt1)

It returns nothing, as if it was never called. If i use a standard Windows font ImageButton works great.

Is there anyway to get ImageButton to work with a font used in this way? Installing it in Windows directly is not an option sadly.

Thanks in advance
just me
Posts: 9442
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: [Class] ImageButton

12 Feb 2016, 03:40

Just add MsgBox, % ImageButton.LastError after ImageButton.Create(...). What does it show?
Roflcoopter

Re: [Class] ImageButton

12 Feb 2016, 04:02

It returns Couldn't get buttons font!

Can i maybe hardcode the font somehow?
just me
Posts: 9442
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: [Class] ImageButton

12 Feb 2016, 04:42

I have no experience with temporarily added private fonts. Would you please change the ImageButton.Create() method as follows

Code: Select all

      ; Get the button's font
      GDIPFont := 0
      HFONT := DllCall("User32.dll\SendMessage", "Ptr", HWND, "UInt", WM_GETFONT, "Ptr", 0, "Ptr", 0, "Ptr")
      MsgBox, 0, %A_ThisFunc%, HFONT: %HFONT% - A_LastError: %A_LastError% ; <<<<< added
      DC := DllCall("User32.dll\GetDC", "Ptr", HWND, "Ptr")
      DllCall("Gdi32.dll\SelectObject", "Ptr", DC, "Ptr", HFONT)
      DllCall("Gdiplus.dll\GdipCreateFontFromDC", "Ptr", DC, "PtrP", PFONT)
      MsgBox, 0, %A_ThisFunc%, PFONT: %PFONT% - A_LastError: %A_LastError% ; <<<<< added
      DllCall("User32.dll\ReleaseDC", "Ptr", HWND, "Ptr", DC)
      If !(PFONT)
         Return This.SetError("Couldn't get button's font!")
and tell me what the MsgBoxes are showing?
Roflcoopter

Re: [Class] ImageButton

12 Feb 2016, 05:06

They show

HFONT: 520754222 - A_LastError: 0

PFONT: 0 - A_LastError: 0

HFONT changes with every reload but PFONT remains 0
just me
Posts: 9442
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: [Class] ImageButton

12 Feb 2016, 05:43

So it seems to be a GDI+ problem with private fonts. All I could find is that GDI+ distinguishes between InstalledFontCollection and PrivateFontCollection classes. Would you please run the following changed version

Code: Select all

      ; Get the button's font
      GDIPFont := 0
      HFONT := DllCall("User32.dll\SendMessage", "Ptr", HWND, "UInt", WM_GETFONT, "Ptr", 0, "Ptr", 0, "Ptr")
      MsgBox, 0, %A_ThisFunc%, HFONT: %HFONT% - A_LastError: %A_LastError% ; <<<<< added
      DC := DllCall("User32.dll\GetDC", "Ptr", HWND, "Ptr")
      DllCall("Gdi32.dll\SelectObject", "Ptr", DC, "Ptr", HFONT)
      Status := DllCall("Gdiplus.dll\GdipCreateFontFromDC", "Ptr", DC, "PtrP", PFONT)
      MsgBox, 0, %A_ThisFunc%, PFONT: %PFONT% - A_LastError: %A_LastError% - Status: %Status% ; <<<<< added, changed
      DllCall("User32.dll\ReleaseDC", "Ptr", HWND, "Ptr", DC)
      If !(PFONT)
         Return This.SetError("Couldn't get button's font!")
Roflcoopter

Re: [Class] ImageButton

12 Feb 2016, 05:55

PFONT: 0 - A_LastError: 0 - Status: 16
just me
Posts: 9442
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: [Class] ImageButton

12 Feb 2016, 05:59

Interesting! From the GDI+ Status enumeration:
NotTrueTypeFont = 16
I don't know how to fix this. :(
Roflcoopter

Re: [Class] ImageButton

12 Feb 2016, 06:08

Hmm, I was under the impression that if the file extension is .ttf, it is a TrueTypeFont. Ill keep searching and see if i can figure something out :crazy:

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: gongnl and 65 guests