本帖最后由 kjgmj 于 2011-1-20 09:22 编辑
'--------------------------------------------------------------
'--------------------------------------------------------------
#引用 仅一次 "windows.bi"
#引用 仅一次 "win/commctrl.bi"
#引用 仅一次 "win/shellapi.bi"
变量 共享 hInstance 为 HINSTANCE
变量 共享 rc 为 RECT
变量 共享 htv 为 hwnd
变量 共享 ilist 为 HIMAGELIST
变量 共享 iccx 为 INITCOMMONCONTROLSEX
hInstance = GetModuleHandle( null )
ilist = ImageList_Create( GetSystemMetrics(SM_CXSMICON), _
GetSystemMetrics(SM_CYSMICON), _
ILC_COLOR8 或 ILC_MASK, _
1, _
1 )
iccx.dwSize = 取长度( INITCOMMONCONTROLSEX )
iccx.dwICC = ICC_TREEVIEW_CLASSES 或 ICC_WIN95_CLASSES
InitCommonControlsEx( @iccx )
''
'' Window Procedure Handler
''
函数 WndProc ( 传值 hwnd 为 hwnd, _
传值 uMsg 为 UINT, _
传值 wParam 为 WPARAM, _
传值 lParam 为 LPARAM ) 为 整数型
函数 = 0
判断 分支 ( uMsg )
分支 WM_CREATE
变量 tvis 为 TVINSERTSTRUCT
变量 i 为 long, _
hico 为 HICON, _
hPrev 为 HTREEITEM, _
tlib 为 long
变量 为 文本 ico, Text
GetClientRect( hwnd, @rc )
htv = CreateWindowEx( WS_EX_CLIENTEDGE, WC_TREEVIEW, "",_
WS_CHILD 或 WS_VISIBLE 或 TVS_HASLINES _
或 TVS_LINESATROOT 或 TVS_HASBUTTONS,_
0, 18, 160, rc.bottom-20,_
hwnd, 0, hInstance, 0 )
TreeView_SetBkColor( htv, &hfff0e1 )
计次循环 i = 3 至 5
ico = 到文本( i )
hico = ExtractIcon( 0, "Shell32.DLL", i )
ImageList_ReplaceIcon( ilist, -1, hico )
DestroyIcon( hico )
计次循环尾 i
TreeView_SetImageList( htv, ilist, TVSIL_NORMAL )
设置内存 tvis, 0, 取长度(tvis)
tvis.Item.Mask = TVIF_TEXT 或 TVIF_IMAGE 或 TVIF_SELECTEDIMAGE
'-- Root: tv.additem -> tv.item(0)
Text = "freebasic"
tvis.item.pszText = 取文本指针(Text)
tvis.item.cchTextMax = 取长度(Text)
tvis.item.iImage = 0
tvis.item.iSelectedImage = 1
tvis.hInsertAfter = 0
tvis.hParent = TVI_ROOT
hPrev = TreeView_InsertItem( htv, @tvis )
'-- tv.additem -> tv.item(1) | tv.children=0
Text = "Inc"
tvis.item.pszText = 取文本指针(Text)
tvis.item.cchTextMax = 取长度(Text)
tvis.hParent = hPrev
hPrev = TreeView_InsertItem( htv, @tvis )
'-- tv.additem -> tv.item(2) | tv.children=1
Text = "Win"
tvis.item.pszText = 取文本指针(Text)
tvis.item.cchTextMax = 取长度(Text)
tvis.hParent = hPrev
hPrev = TreeView_InsertItem( htv, @tvis )
'-- tv.additem -> tv.item(3) | tv.children=2
Text = "Gui"
tvis.item.pszText = 取文本指针(Text)
tvis.item.cchTextMax = 取长度(Text)
tvis.hParent = hPrev
hPrev = TreeView_InsertItem( htv, @tvis )
'-- tv.additem -> tv.item(4) | tv.children=0
Text = "Assembler"
tvis.item.pszText = 取文本指针(Text)
tvis.item.cchTextMax = 取长度(Text)
tvis.hParent = TVI_ROOT
hPrev = TreeView_InsertItem( htv, @tvis )
'-- tv.additem -> tv.item(5) | tv.children=0
Text = "Tutorials"
tvis.item.pszText = 取文本指针(Text)
tvis.item.cchTextMax = 取长度(Text)
hPrev = TreeView_InsertItem( htv, @tvis )
'-- tv.additem -> tv.item(6) | tv.children=0
Text = "Object Oriented"
tvis.item.pszText = 取文本指针(Text)
tvis.item.cchTextMax = 取长度(Text)
hPrev = TreeView_InsertItem( htv, @tvis )
分支 WM_SIZE
GetClientRect( hwnd, @rc )
如果 ( htv <> 0 ) 则
MoveWindow( htv, 0, 18, 160, rc.bottom - rc.top - 20, 1 )
结束 如果
分支 WM_KEYDOWN
如果( 取低八位( wParam ) = 27 ) 则
PostMessage( hwnd, WM_CLOSE, 0, 0 )
结束 如果
分支 WM_DESTROY
ImageList_Destroy( ilist )
PostQuitMessage( 0 )
退出 函数
结束 判断
函数 = DefWindowProc( hwnd, uMsg, wParam, lParam )
结束 函数
''
'' Main Program Exclusive Entry
''
变量 wMsg 为 MSG
变量 wcls 为 WNDCLASS
变量 hwnd 为 hwnd
变量 appName 为 文本
appName = "WinTreeView"
成员赋值 wcls
.style = CS_HREDRAW 或 CS_VREDRAW
.lpfnWndProc = @WndProc
.cbClsExtra = 0
.cbWndExtra = 0
.hInstance = hInstance
.hIcon = LoadIcon( null, IDI_APPLICATION )
.hCursor = LoadCursor( null, IDC_ARROW )
.hbrBackground = 转换类型( HGDIOBJ, 16 ) ' btnface 颜色
.lpszMenuName = null
.lpszClassName = 取文本指针( appName )
结束 成员赋值
如果 ( RegisterClass( @wcls ) = false ) 则
MessageBox( null, "Failed 至 register wcls!", appName, MB_ICONERROR )
结束 1
结束 如果
hwnd = CreateWindowEx( 0, appName, "Treeview Demo", _
WS_OVERLAPPEDWINDOW 或 WS_VISIBLE, _
100, 100, 420, 240, _
null, null, hInstance, null )
''
'' messages loop
''
循环 直到( GetMessage( @wMsg, null, 0, 0 ) = FALSE )
TranslateMessage( @wMsg )
DispatchMessage( @wMsg )
循环尾
结束
|