双击 工具或密码修改 项,读取出错,设置红色
读取过的正常颜色 绿色
当前读取项 蓝色,加粗,这个不知怎么搞
#include <GUIConstantsEx.au3>
#include <GuiTreeView.au3>
#include <WindowsConstants.au3>
#AutoIt3Wrapper_UseX64 = n
Global $hTreeView0, $hTreeView
Global Const $Crimson = 0x990000
Global Const $ColorRoot = 0x990000
Global Const $COLOR_Turquoise = 0xfbfcfd ;0x40e0d0
Global Const $COLOR_Crimson = 0xDC143C
Global Enum $hParamTvItem0 = 990000, $hParamTvItem1, $hParamTvItem2, $hParamTvItem3, $hParamTvItem02
Global Const $UDFTextColor = 0x0000FF
Global Const $ContrlTextColor = 0x009900
Global Const $CommentsTextColor = 0xFF00FF
Example()
Func Example()
Local $hGUI, $hItem
$hGUI = GUICreate("(UDF 创建) TreeView", 900, 500)
$hTreeView0 = GUICtrlCreateTreeView(5, 5, 230, 490, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE) ;);,$WS_BORDER); BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE)
GUICtrlSetFont(-1, 9, 400, 0, '微软雅黑')
$hTvItem0 = GUICtrlCreateTreeViewItem("三年段成绩统计", $hTreeView0)
$hTvItem01 = GUICtrlCreateTreeViewItem("三年五班统计", $hTvItem0)
$hTvItem011 = GUICtrlCreateTreeViewItem("语文-数学-英语", $hTvItem01)
;_GUICtrlTreeView_SetItemParam($hTreeView0, _GUICtrlTreeView_GetItemHandle($hTreeView0, $hTvItem011), $hParamTvItem0)
$hTvItem012 = GUICtrlCreateTreeViewItem("美术-体育-音乐", $hTvItem01)
;_GUICtrlTreeView_SetItemParam($hTreeView0, _GUICtrlTreeView_GetItemHandle($hTreeView0, $hTvItem012), $hParamTvItem1)
$hTvItem02 = GUICtrlCreateTreeViewItem("三年六班统计", $hTvItem0)
;_GUICtrlTreeView_SetItemParam($hTreeView0, _GUICtrlTreeView_GetItemHandle($hTreeView0, $hTvItem02), $hParamTvItem2)
$hTvItem03 = GUICtrlCreateTreeViewItem("三年七班统计", $hTvItem0)
;_GUICtrlTreeView_SetItemParam($hTreeView0, _GUICtrlTreeView_GetItemHandle($hTreeView0, $hTvItem03), $hParamTvItem3)
$hTvItem1 = GUICtrlCreateTreeViewItem("四年段成绩统计", $hTreeView0)
GUICtrlCreateTreeViewItem("四年一班统计", $hTvItem1)
GUICtrlCreateTreeViewItem("四年二班统计", $hTvItem1)
$hTvItem02 = GUICtrlCreateTreeViewItem("工具", $hTreeView0)
$MenuItemd4 = GUICtrlCreateTreeViewItem("密码修改", $hTvItem02)
$MenuItemd5 = GUICtrlCreateTreeViewItem("备份数据库", $hTvItem02)
$MenuItemd6 = GUICtrlCreateTreeViewItem("桌面快捷方式", $hTvItem02)
$MenuItemd7 = GUICtrlCreateTreeViewItem("计算器", $hTvItem02)
$hTvItem3 = GUICtrlCreateTreeViewItem("系统设置目录", $hTreeView0)
GUICtrlCreateTreeViewItem("系统设置", $hTvItem3)
GUICtrlCreateTreeViewItem("系统优化", $hTvItem3)
GUICtrlCreateTreeViewItem("系统显示", $hTvItem3)
$MenuItem20 = GUICtrlCreateTreeViewItem("注册", $hTvItem3)
$MenuItem21 = GUICtrlCreateTreeViewItem("关于注册", $hTvItem3)
$MenuItem22 = GUICtrlCreateTreeViewItem("关于程序", $hTvItem3)
$MenuItem23 = GUICtrlCreateTreeViewItem("查看属性", $hTvItem3)
$MenuItem24 = GUICtrlCreateTreeViewItem("关闭", $hTvItem3)
Local $hImage = _GUIImageList_Create(16, 16, 5, 3)
_GUIImageList_AddIcon($hImage, 'shell32.dll', 137)
_GUICtrlTreeView_SetNormalImageList($hTreeView0, $hImage)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUISetState(@SW_SHOW)
;_GUICtrlTreeView_BeginUpdate($hTreeView0)
;_GUICtrlTreeView_EndUpdate($hTreeView0)
_GUICtrlTreeView_Expand($hTreeView0)
Local $idListview = GUICtrlCreateListView("col1 |col2|col3 ", 240, 5, 200, 150) ;,$LVS_SORTDESCENDING)
Local $idItem1 = GUICtrlCreateListViewItem("item2|col22|col23", $idListview)
Local $idItem2 = GUICtrlCreateListViewItem("item1|col12|col13", $idListview)
Local $idItem3 = GUICtrlCreateListViewItem("item3|col32|col33", $idListview)
$Edit1 = GUICtrlCreateEdit("", 240, 160, 300, 209)
GUICtrlSetData(-1, StringFormat("双击 工具或密码修改 项,读取出错,设置红色\r\n读取过的正常颜色 绿色\r\n当前读取项 蓝色,加粗,这个不知怎么搞"))
Global $CurrentTreeID = 0 ;当前打开的命名空间ID
; 循环到用户退出.
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
GUIDelete()
EndFunc ;==>Example
Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
#forceref $hWnd, $iMsg, $wParam
Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndTreeview
$hWndTreeview = $hTreeView0
If Not IsHWnd($hTreeView0) Then $hWndTreeview = GUICtrlGetHandle($hTreeView0)
$tNMHDR = DllStructCreate($tagNMHDR, $lParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
$iCode = DllStructGetData($tNMHDR, "Code")
Switch $hWndFrom
Case $hWndTreeview
Switch $iCode
Case $NM_DBLCLK ; 用户在控件中双击了鼠标左键,读取类
ConsoleWrite("上次ID:" & $CurrentTreeID)
GUICtrlSetState($CurrentTreeID, 0) ;取消上次命名空间加粗
;GUICtrlSetColor($CurrentTreeID, 0x000000) ;取消上次命名空间颜色
$CurrentTreeID = GUICtrlRead($hTreeView0) ;设定当前选择项ID
ConsoleWrite(",本次ID:" & $CurrentTreeID & @CRLF)
;$CurrentNamespacesHWnd = _GUICtrlTreeView_GetSelection($hTreeView0) ;设定当前选择项句柄
GUICtrlSetState($CurrentTreeID, 512) ;当前使用的命名空间加粗,成功读取后设置颜色
GUICtrlSetColor($CurrentTreeID, 0x0000C0)
DBLCLK(GUICtrlRead($hTreeView0, 1), $CurrentTreeID)
If @error Then
GUICtrlSetColor($CurrentTreeID, 0xFF0000)
Else
GUICtrlSetColor($CurrentTreeID, 0x008000)
EndIf
#CS Case $NM_CUSTOMDRAW
; Local $tCustDraw = DllStructCreate($tagNMTVCUSTOMDRAW, $lParam)
; Local $iDrawStage = DllStructGetData($tCustDraw, 'DrawStage')
; Local $ItemParam = DllStructGetData($tCustDraw, 'ItemParam')
; If $iDrawStage = $CDDS_PREPAINT Then Return $CDRF_NOTIFYITEMDRAW ;request custom drawing of items
; Switch $ItemParam
; Case $hParamTvItem0
; DllStructSetData($tCustDraw, 'clrText', _RGB2BGR($ColorRoot)) ;根颜色
; Case $hParamTvItem1
; DllStructSetData($tCustDraw, 'clrText', _RGB2BGR($UDFTextColor)) ;udf颜色
; Case $hParamTvItem2 ;$hTvItem2
; DllStructSetData($tCustDraw, 'clrText', _RGB2BGR($ContrlTextColor)) ;控制颜色
; Case $hParamTvItem3
; DllStructSetData($tCustDraw, 'clrText', _RGB2BGR($CommentsTextColor)) ;注释颜色
; EndSwitch
; Return $CDRF_NEWFONT
#CE
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY
Func _RGB2BGR($iColor)
Return BitAND(BitShift(String(Binary($iColor)), 8), 0xFFFFFF)
EndFunc ;==>_RGB2BGR
;双击目录树项
Func DBLCLK($TreeItemTexe, $TreeItemID)
ConsoleWrite("目录树项文本:" & $TreeItemTexe & ",ID:" & $TreeItemID & @CRLF)
If $TreeItemTexe = "工具" Or $TreeItemTexe = "密码修改" Then
SetError(1)
EndIf
EndFunc ;==>DBLCLK
|