本帖最后由 seniors 于 2013-6-5 19:47 编辑
测试感觉可能是你的_GUICtrlTreeView_GetSelected($hTreeView, $ItemSpec) 获取状态花的时间长,通知消息中,本来就有状态的,不需要另外判断
改成下面的好像正常了
另外说明一下,API中用的颜色多是BGR格式的,不需要用32位的,24位就够了
发现问题了,原来是你的文字颜色是白色后,和背景相同,当没有选中的蓝背景后,感觉没有字,所以感觉闪烁了#include <GUIConstantsEx.au3>
#include <GuiTreeView.au3>
#include <WindowsConstants.au3>
Global $hTreeView
$Debug_TV = False
$GUI = GUICreate("TreeView Create", 400, 300)
$Edit = GUICtrlCreateEdit("", 250, 0, 150, 300);
$iStyle = BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT)
$hTreeView = _GUICtrlTreeView_Create($GUI, 2, 2, 250, 300, $iStyle, $WS_EX_CLIENTEDGE)
GUISetState()
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
_GUICtrlTreeView_BeginUpdate($hTreeView)
For $x = 1 To 10
$hItem = _GUICtrlTreeView_InsertItem($hTreeView, "Parent" & $x)
For $y = 1 To 10
$Item = _GUICtrlTreeView_InsertItem($hTreeView, "Child" & $y, $hItem)
Next
Next
_GUICtrlTreeView_EndUpdate($hTreeView)
_GUICtrlTreeView_Expand($hTreeView, _GUICtrlTreeView_GetFirstVisible($hTreeView), True)
; 循环直到用户退出
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
GUIDelete()
Func WM_NOTIFY($hWndGUI, $MsgID, $wParam, $lParam)
Local $tNMHDR, $hwndFrom, $code
$tNMHDR = DllStructCreate($tagNMHDR, $lParam)
$code = DllStructGetData($tNMHDR, "Code")
Switch $code
Case $NM_CUSTOMDRAW
Local $pCustomDraw, $DrawStage, $ItemSpec, $ItemState
$pCustomDraw = DllStructCreate($tagNMTVCUSTOMDRAW, $lParam)
$DrawStage = DllStructGetData($pCustomDraw, "DrawStage")
$ItemSpec = DllStructGetData($pCustomDraw, "ItemSpec")
$ItemState = DllStructGetData($pCustomDraw, "ItemState")
$bSelect = BitAND($CDIS_SELECTED,$ItemState)
Switch $DrawStage
Case $CDDS_PREPAINT
Return $CDRF_NOTIFYITEMDRAW;$CDRF_NOTIFYITEMDRAW
Case $CDDS_ITEMPREPAINT
If DllStructGetData($pCustomDraw, "Level") Then
If $bSelect Then
DllStructSetData($pCustomDraw, "ClrText", 0xFFFFFF)
Else
DllStructSetData($pCustomDraw, "ClrText", 0x0000FF)
EndIf
EndIf
Return $CDRF_DODEFAULT;
Case BitOR($CDDS_ITEMPREPAINT, $CDDS_SUBITEM)
Return $CDRF_DODEFAULT;
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY
|