TreeList Control (Experimental)

Post your working scripts, libraries and tools for AHK v1.1 and older
User avatar
Alguimist
Posts: 428
Joined: 05 Oct 2015, 16:41
Contact:

Re: TreeList Control (Experimental)

30 Dec 2017, 17:54

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)
*/
lexikos
Posts: 9780
Joined: 30 Sep 2013, 04:07
Contact:

Re: TreeList Control (Experimental)

23 Mar 2024, 05:47

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.

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: No registered users and 32 guests