Page 4 of 10

Re: [Class] ImageButton

Posted: 20 Jul 2015, 08:25
by tmplinshi
ok, thanks for reply.

Re: [Class] ImageButton

Posted: 28 Dec 2015, 08:23
by kczx3
Is it possible to use Windows system icons with this class? For instance, Icon239 from Global iconPath := A_WinDir "\system32\shell32.dll"

Re: [Class] ImageButton

Posted: 28 Dec 2015, 08:25
by kczx3
NVM, I see that you simply add the picture first and then call the Create method so that should work fine.

Re: [Class] ImageButton

Posted: 28 Dec 2015, 10:54
by just me
Hi kczx3, did you solve your problem?

Re: [Class] ImageButton

Posted: 28 Dec 2015, 12:48
by kczx3
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.

Re: [Class] ImageButton

Posted: 12 Jan 2016, 08:29
by Thorondor
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?

Re: [Class] ImageButton

Posted: 12 Jan 2016, 08:32
by just me
I guess you have to update your AHK.

Re: [Class] ImageButton

Posted: 12 Jan 2016, 08:38
by Thorondor
Wow, okay, that worked. Haha, thanks for the fast response and easy solution. :thumbup:

Re: [Class] ImageButton

Posted: 05 Feb 2016, 13:54
by lblb
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!

Re: [Class] ImageButton

Posted: 06 Feb 2016, 04:28
by just me
Hi lblb,

the class doesn't store any information about the buttons or the parent GUIs. So the answer is: No!

Re: [Class] ImageButton

Posted: 06 Feb 2016, 05:08
by lblb
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.

Re: [Class] ImageButton

Posted: 12 Feb 2016, 03:02
by roflcoopter
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

Re: [Class] ImageButton

Posted: 12 Feb 2016, 03:40
by just me
Just add MsgBox, % ImageButton.LastError after ImageButton.Create(...). What does it show?

Re: [Class] ImageButton

Posted: 12 Feb 2016, 04:02
by Roflcoopter
It returns Couldn't get buttons font!

Can i maybe hardcode the font somehow?

Re: [Class] ImageButton

Posted: 12 Feb 2016, 04:42
by just me
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?

Re: [Class] ImageButton

Posted: 12 Feb 2016, 05:06
by Roflcoopter
They show

HFONT: 520754222 - A_LastError: 0

PFONT: 0 - A_LastError: 0

HFONT changes with every reload but PFONT remains 0

Re: [Class] ImageButton

Posted: 12 Feb 2016, 05:43
by just me
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!")

Re: [Class] ImageButton

Posted: 12 Feb 2016, 05:55
by Roflcoopter
PFONT: 0 - A_LastError: 0 - Status: 16

Re: [Class] ImageButton

Posted: 12 Feb 2016, 05:59
by just me
Interesting! From the GDI+ Status enumeration:
NotTrueTypeFont = 16
I don't know how to fix this. :(

Re: [Class] ImageButton

Posted: 12 Feb 2016, 06:08
by Roflcoopter
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: