Page 2 of 2

Re: TreeList Control (Experimental)

Posted: 30 Dec 2017, 17:54
by Alguimist
tidbit wrote:though, any reason you didn't use gui,add,custom?
I made some attempts with Gui, Add, Custom. It fails with the message "Unregistered window class".

The reason, apparently, is that TreeList is not registered with CS_GLOBALCLASS. AutoHotkey checks the return value of GetClassInfoEx without passing a handle to rasdlg.dll.

Code: Select all

VarSetCapacity(WNDCLASSEX, A_PtrSize == 8 ? 80 : 48, 0)

hModule := DllCall("LoadLibrary", "Str", "rasdlg.dll", "Ptr")
MsgBox % DllCall("GetClassInfoEx", "Ptr", hModule, "Str", "TreeList", "Ptr", &WNDCLASSEX)

/*
; Scintilla has CS_GLOBALCLASS and can be created with "Gui, Add, Custom".
DllCall("LoadLibrary", "Str", "SciLexer.dll", "Ptr")
MsgBox % DllCall("GetClassInfoEx", "Ptr", 0, "Str", "Scintilla", "Ptr", &WNDCLASSEX)
*/

Re: TreeList Control (Experimental)

Posted: 23 Mar 2024, 05:47
by lexikos
Alguimist wrote:The reason, apparently, is that TreeList is not registered with CS_GLOBALCLASS.
I happened to come across this at some point, and made a note to look into this limitation.

At first glance, it would seem that the Custom control needs a way to specify the module. However, it is quite trivial to work around the limitation: all you need to do is reregister the class with hInstance = NULL. CS_GLOBALCLASS isn't needed in that case.

Code: Select all

#Requires AutoHotkey v1.1.37

VarSetCapacity(WNDCLASSEX, WNDCLASSEX_size := A_PtrSize == 8 ? 80 : 48, 0)
NumPut(WNDCLASSEX_size, WNDCLASSEX, "uint")
hModule := DllCall("LoadLibrary", "Str", "rasdlg.dll", "Ptr")
DllCall("GetClassInfoEx", "Ptr", hModule, "Str", "TreeList", "Ptr", &WNDCLASSEX)
NumPut(0, WNDCLASSEX, 16+A_PtrSize, "ptr")
DllCall("RegisterClassEx", "ptr", &WNDCLASSEX)

Gui Add, Custom, ClassTreeList hwndhwnd
Gui Show
It works for me (but of course, there is no column or data).

I guess you can also get the old WndProc from WNDCLASSEX and put the new one in, instead of replacing the WndProc after creating each control.

Microsoft's documentation says "Be sure to set [cbSize] before calling the GetClassInfoEx function." Apparently you can get away with not doing that for GetClassInfoEx, but not RegisterClassEx.