PDA

View Full Version : Visual designer generated code - TreeView



DirectuX
02-11-2018, 11:37
Hi,

This is VD generated code for a simple window with a treeview,
line 94 , UDT are not defined, thus not working, and this code way of doing differs from the treeview sample bundled with thinbasic.

What was intended with TV_INSERTSTRUCT and TV_ITEM ?
What method would you counsel between VD generated code and bundled sample ?

file : 9903


'------------------------------------------------------------------------------
'thinAir Visual Designer
'------------------------------------------------------------------------------
' Project: Visual Designer generated code
' File: Your file name
' Created: On 11-02-2018 at 10:05:30
'------------------------------------------------------------------------------

'---Needed thinBasic modules
USES "UI"

'---Controls IDs---
Begin ControlID
%IDC_TREEVIEW_1
End ControlID



'------------------------------------------------------------------------------
' Main thinBasic function
'------------------------------------------------------------------------------
Function TBMain() As Long

MainWindow_Create(%HWND_DESKTOP)

End Function

'------------------------------------------------------------------------------
' Create main Window
'------------------------------------------------------------------------------
Function MainWindow_Create(ByVal hParent As Long) As Long

Local hDlg As Long
Local hFont As Long
Local lStyle As Long
Local lStyleEx As Long
lStyle = _
%WS_DLGFRAME | _
%WS_CAPTION | _
%WS_SYSMENU | _
%WS_OVERLAPPEDWINDOW | _
%WS_CLIPCHILDREN | _
%WS_CLIPSIBLINGS | _
%DS_CENTER
lStyleEx = 0

Dialog New Pixels, hParent, "Form1", -1, -1, 468, 225, lStyle, lStyleEx, TO hDlg

hFont = Font_Create("MS Sans Serif", 8)
Dialog Send hDlg, %WM_SETFONT, hFont, 0



CONTROL ADD "SysTreeView32", hDlg, %IDC_TREEVIEW_1, "TreeView1", 40, 16, 192, 184, %WS_CHILD OR %WS_CLIPSIBLINGS OR %WS_TABSTOP OR %WS_VISIBLE OR %TVS_HASBUTTONS OR %TVS_HASLINES OR %TVS_LINESATROOT, %WS_EX_CLIENTEDGE

SampleTreeView(hDlg, %IDC_TREEVIEW_1, 3)

Dialog Show Modal hDlg, CALL MainWindow_Proc

Win_DeleteObject hFont

End Function

'------------------------------------------------------------------------------
' Main WIndow CallBack handler
'------------------------------------------------------------------------------
CallBack Function MainWindow_Proc() As Long

LOCAL pNMHDR AS NMHDR PTR

LOCAL PageNo AS LONG

LOCAL hFontTab AS LONG

SELECT CASE (CBMSG)

CASE %WM_INITDIALOG
CASE %WM_COMMAND
SELECT CASE LOWRD(CBWPARAM)
CASE %IDOK
CASE %IDCANCEL
END SELECT

CASE %WM_NOTIFY
CASE %WM_DESTROY
End Select
End Function

'--------------------------------------------------------------------------------
' ** Sample code **
'--------------------------------------------------------------------------------
FUNCTION SampleTreeViewInsertItem(BYVAL hTree AS LONG,BYVAL hParent AS LONG, sItem AS STRING) AS LONG

LOCAL tTVInsert AS TV_INSERTSTRUCT, tTVItem AS TV_ITEM

IF hParent THEN
tTVItem.mask = %TVIF_CHILDREN OR %TVIF_HANDLE
tTVItem.hItem = hParent
tTVItem.cchildren = 1
TreeView_SetItem hTree, tTVItem
END IF

tTVInsert.hParent = hParent
tTVInsert.Item.Item.mask = %TVIF_TEXT
tTVInsert.Item.Item.pszText = STRPTR(sItem)
tTVInsert.Item.Item.cchTextMax = LEN(sItem)

FUNCTION = TreeView_InsertItem(hTree, tTVInsert)

END FUNCTION

'------------------------------------------------------------------------------
'
'------------------------------------------------------------------------------
FUNCTION SampleTreeView(BYVAL hDlg AS LONG,BYVAL lID AS LONG,BYVAL lCount AS LONG) AS LONG

LOCAL hRoot AS LONG,hParent AS LONG,i AS LONG
LOCAL j AS LONG,k AS LONG, hCtl AS LONG

CONTROL HANDLE hDlg, lID TO hCtl

FOR i = 1 TO lCount
hRoot = SampleTreeViewInsertItem(hCtl, %NULL, "Root" + FORMAT$(i))
FOR j = 1 TO lCount
hParent = SampleTreeViewInsertItem(hCtl, hRoot, "Item" + FORMAT$(j))
FOR k = 1 TO lCount
CALL SampleTreeViewInsertItem(hCtl, hParent, "SubItem" + _
FORMAT$(j) + "." + FORMAT$(k))
NEXT k
NEXT j
NEXT i

END FUNCTION

ErosOlmi
02-11-2018, 15:30
Thanks, great catch.
This oblige me to rewrite some code in Visual designer and UI module.

Fixed, I will release soon a new version.