Hi! :) Issue with retreiving font from button.
BanditTech opened this issue · 6 comments
I am creating a GUI class, based on the idea by lemasato but using the HWND of the elements to catalogue everything.
I am at the point where I am attempting to integrate your newer version of the library with this one. I am having some issues though, and was wondering if you could give some feedback.
First, in the method to add a new element: If I used the value inserted into the hwndHWND from the GUI control, it says that it fails to find the font
---------------------------
Icarus.ahk
---------------------------
GUI: "MainMenu"
Error: "Couldn't get button's font!
0
0
-905312327"
Control: "0x34289e" - Control Handle: "2042052"
Options: "w200 h50"
ImageButton Style: "[{"1":0,"2":"0x274554","3":"","4":"0xebebeb","7":"0xd6d6d6"},[0,"0x355e73"],[0,"0xffffff"]]"
---------------------------
OK
---------------------------
But if I instead use the HWND returned from DllCall("GetParent", "UInt", HWND)
It no longer says that it fails to find the font, and instead the creation fails altogether:
---------------------------
Icarus.ahk
---------------------------
Failed to create control.
Message: 1
Extra:
GUI Label: TestButton2
GUI HWND: 0x312898
Control type: ImageButton
Options: w200 h50
Content: Text
CtlColor:
Font: Segoe UI 10 Green
---------------------------
OK
---------------------------
This is the testbench I am using to try this class with:
; Create Menu
Gui.New("MainMenu","Icarus Main Menu","+AlwaysOnTop")
Gui.FontInit("Segoe UI","10","Green")
ButtonHWND := Gui.Add("Button","TestButton","Text","w200 h50","This Button is Not Active")
Gui.SetControl(Gui.GetHWND("TestButton"),"This is new text")
Gui.BindMethodToControl(Gui,ButtonHWND,"TooltipToggle")
Gui.TooltipUpdate(ButtonHWND,"This button toggles tooltips")
Gui.SetHover(ButtonHWND,"Segoe UI","16","FF8000","Replaced With This")
specialBtnStyle := [ [0, "0x274554", "", "0xebebeb", , , "0xd6d6d6"] ; normal
, [0, "0x355e73"] ; hover
, [0, "0xffffff"] ] ; press
; Gui.FontSet("Segoe UI","24","808010")
ButtonHWND := Gui.Add("ImageButton","TestButton2","Text","w200 h50","This Button is Also Not Active",,,specialBtnStyle)
Gui.SetControl(Gui.GetHWND("TestButton2"),ButtonHWND)
Gui.Add("Edit","My Edit Field","This is the text that will occupy the field"
,"w200 r6 -Theme",App.Lang.English["My Edit Field"])
Gui.Show("MainMenu","w1000 h500 x800 y250")
The button just becomes blank instead of completing the process
I am trying to simplify the process, and still having the same issue on a much simpler configuration.
Gui, New
Gui, Add, Button, hwndHWND, My Button
specialBtnStyle := [ [0, "0x274554", "", "0xebebeb", , , "0xd6d6d6"] ; normal
, [0, "0x355e73"] ; hover
, [0, "0xffffff"] ] ; press
JustOneStyle := [[0, "0x355e73"]]
; If !ImageButton.Create(HWND,specialBtnStyle){
; Msg := "Failed ImageButton`n" ImageButton.LastError
; If !ImageButton.Create(DllCall("GetParent", "UInt", HWND),specialBtnStyle){
; Msg .= "`nFailed ImageButton`n" ImageButton.LastError
; }
; }
If !ImageButton.Create(HWND,JustOneStyle){
Msg := "Failed ImageButton`n" ImageButton.LastError
If !ImageButton.Create(DllCall("GetParent", "UInt", HWND),JustOneStyle){
Msg .= "`nFailed ImageButton`n" ImageButton.LastError
}
}
Gui, Show
if msg
MsgBox, % msg
If msg
ExitApp
#Include, %A_ScriptDir%\lib\CLASS_ImageButton.ahk
Now using this code, it states that either the button font cannot be access, or if I change to DllCall("GetParent", "UInt", HWND) as the provided HWND handle, it instead tells me that the control must be a pushbutton.
What am I doing wrong, or what step is required for me to get this working?
AHK version 1.1.33.02
---------------------------
TestBench.ahk
---------------------------
Failed ImageButton
Couldn't get button's font!
Failed ImageButton
The control must be a pushbutton!
---------------------------
OK
---------------------------
the thing that is puzzling me, where does it assign a value to This.Font? I cannot find where its referenced for assignment at all XD
Edit: lol I must have been tired, its assigned right in front of my eyes lol I did not see the : symbol
I already have the values for the font saved in my GUI object, so I could pass this into the class like older versions, but I wanted to use your new improvements :)
At the risk of sounding desperate for an answer, I am back. I want to move on with my project so I can begin work on the actual content and not with the interface :D This step and getting Ctl_Colors to work properly within my class are the last two steps I need to finish, and you designed both! :D
If I can ask a more simple question, what content is the Font that is returned, so that I might provide it instead?
Do I need to do something like This and load the font hIcon itself?
Edit: I have also verified that I am using the GDIP_All library, but am using the 1.47 subversion which does not differ in the functions your using. (file comparison shows minimal differences where they fixed some datatype bugs in the dll calls)
I was looking for possible differences, and was wondering if its possible that I am not initializing GDIP the same method that you are?
I was initializing it with the Gdip_Startup() helper function in Gdip.ahk
Gdip_Startup()
{
if !DllCall("GetModuleHandle", "str", "gdiplus")
DllCall("LoadLibrary", "str", "gdiplus")
VarSetCapacity(si, 16, 0), si := Chr(1)
DllCall("gdiplus\GdiplusStartup", "uint*", pToken, "uint", &si, "uint", 0)
return pToken
}
While in your example you have:
UseGDIP(Params*) { ; Loads and initializes the Gdiplus.dll at load-time
; GET_MODULE_HANDLE_EX_FLAG_PIN = 0x00000001
Static GdipObject := ""
, GdipModule := ""
, GdipToken := ""
Static OnLoad := UseGDIP()
If (GdipModule = "") {
If !DllCall("LoadLibrary", "Str", "Gdiplus.dll", "UPtr")
UseGDIP_Error("The Gdiplus.dll could not be loaded!`n`nThe program will exit!")
If !DllCall("GetModuleHandleEx", "UInt", 0x00000001, "Str", "Gdiplus.dll", "PtrP", GdipModule, "UInt")
UseGDIP_Error("The Gdiplus.dll could not be loaded!`n`nThe program will exit!")
VarSetCapacity(SI, 24, 0), NumPut(1, SI, 0, "UInt") ; size of 64-bit structure
If DllCall("Gdiplus.dll\GdiplusStartup", "PtrP", GdipToken, "Ptr", &SI, "Ptr", 0)
UseGDIP_Error("GDI+ could not be startet!`n`nThe program will exit!")
GdipObject := {Base: {__Delete: Func("UseGDIP").Bind(GdipModule, GdipToken)}}
}
Else If (Params[1] = GdipModule) && (Params[2] = GdipToken)
DllCall("Gdiplus.dll\GdiplusShutdown", "Ptr", GdipToken)
}
Is it possible this is related to why I am receiving the error?
Edit:
It seems that you need specifically the dll loaded for this to work. Using the GDIP library startup by tic will not work.
ok, so my conclusions after getting this working. It is not compatible with the standard GDIP library and must load the dll like you have shown in your sample. The error that it cannot find the font only happens when this dll is not loaded properly.
edit: I speak too soon, seems the font I was using was also causing issues saying that it cannot be found, but the default button had no issue... idk, really was hoping you would give some feedback on how to fix this
Another thing to note, the parameters of this version of the library are not able to be set with an array of options, and must instead be set individually in each option slot. Say an optionarray is [ [option_one], , [third_options], [fourth_options] ]
, it must be (HWND, option_one, , third_options, fourth_options)
in the function call instead of just (HWND,optionarray)
I added this portion to line 250 to fix that:
For _, Opt In Options {
If !IsObject(Opt)
Continue
For Idx, Obj in Opt {
If IsObject(Obj)
ArrayOfOptions := True
}
}
If (_ = 1 && ArrayOfOptions)
Options := Opt
Thanks a ton for talking to yourself here, don't know if you'll ever see this message but you really helped me out.