#include <GUIConstantsEx.au3>
#include <GuiTreeView.au3>
#include <WindowsConstants.au3>
#include <GUIEdit.au3>
#include <ListViewConstants.au3>
#AutoIt3Wrapper_UseX64 = n
Global $TreeView1, $Edit1, $Button1, $Label1, $Label2, $CurrentTreeID;, $TreeItemTexe
#Region ### START Koda GUI section ### Form=
$Form2 = GUICreate("窗体1", 785, 401, 514, 375)
$TreeView1 = GUICtrlCreateTreeView(5, 5, 330, 305)
$TreeView1_0 = GUICtrlCreateTreeViewItem("设置", $TreeView1)
$TreeView1_1 = GUICtrlCreateTreeViewItem("双击这项1(出错,立即红色)", $TreeView1_0)
$TreeView1_2 = GUICtrlCreateTreeViewItem("双击这项2(出错,立即红色)", $TreeView1_1)
$TreeView1_3 = GUICtrlCreateTreeViewItem("双击这项3(正常,双击其它项后绿色)", $TreeView1_1)
$TreeView1_4 = GUICtrlCreateTreeViewItem("双击这项4(正常,双击其它项后绿色)", $TreeView1_1)
$TreeView1_5 = GUICtrlCreateTreeViewItem("双击这项5(正常,蓝色,加粗,最后双击项)", $TreeView1_1)
$TreeView1_6 = GUICtrlCreateTreeViewItem("其它项6(点击其它项后蓝色正常)", $TreeView1_1)
$TreeView1_7 = GUICtrlCreateTreeViewItem("其它项7(双击后点击文本框等蓝色不正常)", $TreeView1_1)
$ListView1 = GUICtrlCreateListView("列1|列2", 340, 5, 440, 150, -1, BitOR($WS_EX_CLIENTEDGE, $LVS_EX_GRIDLINES))
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 50)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 50)
$ListView1_0 = GUICtrlCreateListViewItem("11|12", $ListView1)
$Edit1 = GUICtrlCreateEdit("", 340, 160, 440, 150, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL));, $ES_MULTILINE)
GUICtrlSetFont(-1, 11, 600, 0, '微软雅黑')
$Button1 = GUICtrlCreateButton("按钮1", 355, 320, 75, 25)
GUICtrlSetColor(-1, $COLOR_RED)
GUICtrlSetTip(-1, "点击按钮取按钮文字颜色")
$Label1 = GUICtrlCreateLabel("按钮文字颜色,取值错误,不知如何获取DC。", 435, 320, 340, 25)
GUICtrlSetFont($Label1, 9, 400, 0, '微软雅黑')
$Label2 = GUICtrlCreateLabel("蓝色不正常应该是需要设置选择项的前景色,这不管它了。" & @CRLF & "如何能做到不要$ComError全局变量。", 5, 320, 340, 47)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
_GUICtrlTreeView_Expand($TreeView1)
Global $ComError = False ;设置一个执行错误时的全局变量
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
GUICtrlSetData($Label1, GUICtrlRead($Button1)& "--"&"红色")
GUICtrlSetColor($Label1, $COLOR_RED)
GUICtrlSetFont($Label1, 11, 600, 0, '微软雅黑')
GUICtrlSetFont($Label2, 10, 400, 0, '微软雅黑')
GUICtrlSetColor($Label2, 0x008000) ;$COLOR_RED)
DBLCLK(GUICtrlRead($TreeView1, 1), $CurrentTreeID)
EndSwitch
WEnd
Func WM_NOTIFY($hWnd, $iMsg, $wParam, $ilParam);$lParam)
#forceref $hWnd, $iMsg, $wParam
Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndTreeview
$hWndTreeview = $TreeView1
If Not IsHWnd($TreeView1) Then $hWndTreeview = GUICtrlGetHandle($TreeView1)
$tNMHDR = DllStructCreate($tagNMHDR, $ilParam);$lParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
$iCode = DllStructGetData($tNMHDR, "Code")
Switch $hWndFrom
Case $hWndTreeview
Switch $iCode
Case $NM_DBLCLK ; 用户在控件中双击了鼠标左键
;Local Static $CurrentTreeID
GUICtrlSetData($Edit1, GUICtrlRead($Edit1) & @CRLF & "上次ID:" & $CurrentTreeID)
$CurrentTreeID = GUICtrlRead($TreeView1) ;设定当前选择项ID
GUICtrlSetColor($CurrentTreeID, 0x0000C0)
_GUICtrlTreeView_SetBold($TreeView1, $CurrentTreeID);加粗
DBLCLK(GUICtrlRead($TreeView1, 1), $CurrentTreeID)
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY
;双击目录树项
Func DBLCLK($TreeItemTexe, $TreeItemID)
GUICtrlSetData($Edit1, GUICtrlRead($Edit1) & @CRLF & "本次文本:" & $TreeItemTexe & ",ID:" & $CurrentTreeID)
;这里实际为执行其它代码,最终可能会出错。
If $TreeItemTexe = "双击这项1(出错,立即红色)" Or $TreeItemTexe = "双击这项2(出错,立即红色)" Or $TreeItemTexe = "双击这项3(正常,双击其它项后绿色)" Then
GUICtrlSetColor($CurrentTreeID, 0xFF0000)
$Ed1 = 0xFF0000;文本颜色
GUICtrlSetColor($Edit1, $Ed1);文本颜色
;SetError(1)
Else
GUICtrlSetColor($Edit1, 0x008000)
GUICtrlSetColor($CurrentTreeID, 0x008000)
EndIf
EndFunc ;==>DBLCLK
|