Code:
Debug.ShowWindow(true) User32 = Library.Load("user32.dll"); Comctl32 = Library.Load("Comctl32.dll"); MHDL = Application.GetWndHandle() function QueryAllowProjectClose() Subclass.Remove(MHDL) end; OS_Name = System.GetOSName() if OS_Name == "Windows XP" or OS_Name == "Windows Server 2003" then REDUCEDGUI = true else REDUCEDGUI = false end INITCOMMONCONTROLSEX = MemoryEx.DefineStruct{ DWORD "dwSize"; DWORD "dwICC"; }; NMHDR = MemoryEx.DefineStruct{ UINT "hWndFrom"; UINT "idFrom"; UINT "code"; }; RECT = MemoryEx.DefineStruct{ INT "left"; INT "top"; INT "right"; INT "bottom"; }; NMCUSTOMDRAW = MemoryEx.DefineStruct{ NMHDR "hdr"; DWORD "dwDrawStage"; INT "hdc"; RECT "rc"; DWORD "dwItemSpec"; UINT "uItemState"; INT "lItemlParam"; }; NMTVCUSTOMDRAW = MemoryEx.DefineStruct{ NMCUSTOMDRAW "nmcd"; INT "clrText"; INT "clrTextBk"; INT "iLevel"; }; TVINSERTSTRUCT = MemoryEx.DefineStruct{ INT "hParent"; INT "hInsertAfter"; INT "itemex"; INT "item"; } TVITEM = MemoryEx.DefineStruct{ UINT "mask"; INT "hItem"; UINT "state"; UINT "stateMask"; INT "pszText"; INT "cchTextMax"; INT "iImage"; INT "iSelectedImage"; INT "cChildren"; INT "lParam"; } InitCommonControls = function() local S = INITCOMMONCONTROLSEX:New() S.dwSize = S:Size() S.dwICC = 0x822F Comctl32.InitCommonControlsEx(S:GetPointer()) S:Free() end; InitCommonControls() AddParent = function(Hdl) Struct.B.mask = TVIF_CHILDREN + TVIF_PARAM; Struct.B.hItem = 0; Struct.B.state = 0; Struct.B.stateMask = 0; Struct.B.pszText = 0; Struct.B.cchTextMax = 0; Struct.B.iImage = 0; Struct.B.iSelectedImage = 0; Struct.B.cChildren = -2; Struct.B.lParam = 0; Struct.A.hParent = 0; Struct.A.hInsertAfter = TVI_LAST; Struct.A.itemex = 0; Struct.A.item = Struct.B:GetPointer(); local R = User32.SendMessageA(Hdl,TVM_INSERTITEMA,0,Struct.A:GetPointer()) if R == 0 then return false, "Can't add item" else return true, R end end; AddChild = function(Hdl,Parent) Struct.B.mask = TVIF_IMAGE + TVIF_SELECTEDIMAGE + TVIF_CHILDREN; Struct.B.hItem = 0; Struct.B.state = 0; Struct.B.stateMask = 0; Struct.B.pszText = 0; Struct.B.cchTextMax = 0; Struct.B.iImage = 0; Struct.B.iSelectedImage = 0; Struct.B.cChildren = -2; Struct.B.lParam = 0; Struct.A.hParent = Parent; Struct.A.hInsertAfter = TVI_LAST; Struct.A.itemex = 0; Struct.A.item = Struct.B:GetPointer(); local R = User32.SendMessageA(Hdl,TVM_INSERTITEMA,0,Struct.A:GetPointer()) if R == 0 then return false, "Can't add item" else return true, R end end; SetItem = function(Hdl,Txt,Ihdl,Ico) if Ico then --IcX = Comctl32.ImageList_ReplaceIcon(ImageList,-1,Ico) end local m = MemoryEx.Allocate(String.Length(Txt) + 1) MemoryEx.String(m,-1,MEMEX_ASCII,Txt) if Ico then Struct.B.mask = TVIF_TEXT + TVIF_IMAGE + TVIF_SELECTEDIMAGE + TVIF_CHILDREN; else Struct.B.mask = TVIF_TEXT + TVIF_CHILDREN; end Struct.B.hItem = Ihdl; Struct.B.state = 0; Struct.B.stateMask = 0; Struct.B.pszText = m; Struct.B.cchTextMax = n; if Ico then Struct.B.iImage = IcX; Struct.B.iSelectedImage = IcX; else Struct.B.iImage = 0; Struct.B.iSelectedImage = 0; end Struct.B.cChildren = -2; Struct.B.lParam = 0; User32.SendMessageA(Hdl,TVM_SETITEMA,0,Struct.B:GetPointer()) MemoryEx.Free(m) end; WM_NOTIFY = 0x004E; CDDS_ITEM = 0x10000; CDDS_PREPAINT = 0x1; CDDS_ITEMPREPAINT = CDDS_ITEM + CDDS_PREPAINT; CDRF_DODEFAULT = 0x0; CDRF_NEWFONT = 0x2; CDRF_NOTIFYITEMDRAW = 0x20; CDIS_SELECTED = 0x0001; CDIS_GRAYED = 0x0002; CDIS_DISABLED = 0x0004; CDIS_CHECKED = 0x0008; CDIS_FOCUS = 0x0010; CDIS_DEFAULT = 0x0020; CDIS_HOT = 0x0040; CDIS_MARKED = 0x0080; CDIS_INDETERMINATE = 0x0100; TVS_SHOWSELALWAYS = 0x0020; TVS_DISABLEDRAGDROP = 0x0010; TVM_SETEXTENDEDSTYLE = 0x112C; TVS_EX_DOUBLEBUFFER = 0x0004; WS_VISIBLE = 0x10000000; WS_CHILD = 0x40000000; WS_EX_CLIENTEDGE = 0x00000200; TVIF_SELECTEDIMAGE = 0x0020; TVIF_TEXT = 0x0001; TVIF_IMAGE = 0x0002; TVM_SETITEMA = 0x110D; TVIF_CHILDREN = 0x0040; TVI_LAST = 0xFFFF0002; TVM_INSERTITEMA = 0x1100; TVIF_PARAM = 0x0004; TVI_LAST = 0xFFFF0002; TVM_INSERTITEMA = 0x1100; TVIF_CHILDREN = 0x0040; Struct = {} Struct.A = TVINSERTSTRUCT:New() Struct.B = TVITEM:New() Subclass.Create(MHDL, function(hWnd, uMsg, wParam, lParam) if (uMsg == WM_NOTIFY) then local s = MemoryEx.AssignStruct(lParam,NMTVCUSTOMDRAW); if(s)then if (s.nmcd.hdr.hwndFrom == TREEHDL) then if s.nmcd.dwDrawStage == CDDS_PREPAINT then Debug.Print("CDDS_PREPAINT".."\r\n") return CDRF_NOTIFYITEMDRAW end if (s.nmcd.dwDrawStage == CDDS_ITEMPREPAINT) then Debug.Print("ITEMPREPAINT".."\r\n") return CDRF_DODEFAULT end end end end return Subclass.OldWinProc(hWnd, uMsg, wParam, lParam); end) TREEHDL = User32.CreateWindowExA(WS_EX_CLIENTEDGE,"SysTreeView32","",WS_VISIBLE + WS_CHILD + TVS_SHOWSELALWAYS + TVS_DISABLEDRAGDROP,10,10,200,200,MHDL,0,0,0) if not REDUCEDGUI then User32.SendMessageA(TREEHDL,TVM_SETEXTENDEDSTYLE,TVS_EX_DOUBLEBUFFER,TVS_EX_DOUBLEBUFFER) end User32.BringWindowToTop(TREEHDL) _, _TP1 = AddParent(TREEHDL) SetItem(TREEHDL,"One",_TP1) _, _TP11 = AddChild(TREEHDL,_TP1) SetItem(TREEHDL,"One One",_TP11) _, _TP111 = AddChild(TREEHDL,_TP11) SetItem(TREEHDL,"One One One",_TP111) _, _TP2 = AddParent(TREEHDL) SetItem(TREEHDL,"Two",_TP2) _, _TP22 = AddChild(TREEHDL,_TP2) SetItem(TREEHDL,"Two Two",_TP22) _, _TP222 = AddChild(TREEHDL,_TP22) SetItem(TREEHDL,"Two Two Two",_TP222)
I know MemoryEx can deal with Custom Draw because I used it on a ListView before figuring Owner Draw was better but I dont have the code anymore to reference.
Comment