[已解决]设置 _GuiCtrlTreeView_Create 里的 Item 颜色 会闪烁,求解决办法
本帖最后由 Ycxw2008 于 2013-6-5 23:11 编辑知道GUICtrlSetColor可以设置GUICtrlCreateTreeViewItem的颜色哈.
只是想解决这个问题{:face (229):} 难道要用GDI吗?{:face (52):}
图 和 代码 在下面
#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")
Switch $DrawStage
Case $CDDS_PREPAINT
Return $CDRF_NOTIFYITEMDRAW;$CDRF_NOTIFYITEMDRAW
Case $CDDS_ITEMPREPAINT
If DllStructGetData($pCustomDraw, "Level") Then
If _GUICtrlTreeView_GetSelected($hTreeView, $ItemSpec) Then
DllStructSetData($pCustomDraw, "ClrText", 0x00FFFFFF)
Else
DllStructSetData($pCustomDraw, "ClrText", 0x000000FF)
EndIf
EndIf
Return $CDRF_DODEFAULT;
Case BitOR($CDDS_ITEMPREPAINT, $CDDS_SUBITEM)
Return $CDRF_DODEFAULT;
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY
即便不设置颜色,好像也是闪烁的 回复 2# seniors
注释了Register WM_NOTIFY
加了句_GuiCtrlTreeView_SetTextColor的效果就不像我那样
我感觉我消息处理的不对,但是不知道怎么改了
回复 2# seniors
大神{:face (361):}
要不你帮我试试GDI怎么处理呗。
对GDI表示有压力 一直没研究 新选择一项时,当鼠标按下,原选择的一项字串全变白了,鼠标弹起时原选择的一项字串才恢复变红,选中的项变蓝,造成闪烁。如第49-53行5行代码中,只用第52行代码,会改变此现象,同没有设置颜色时一样。 回复 5# shqf
我知道。我再研究研究结构吧 本帖最后由 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 回复 7# seniors
算了 不弄了,搞的头都昏了 ,谢谢了哦
页:
[1]