是的。当ITEM是灰色的时候。是不能选中的。 #include <WinAPI.au3>
#include <GUIListView.au3>
#include <WindowsConstants.au3>
Const $tagDRAW_ITEM = "uint CtlType;uint CtlId;uint ItemId;uint ItemAction;uint ItemState;hWnd HWndItem;hWnd hDC;long Left;long Top;long Right;long Bottom;ulong_ptr ItemData"
$hGUI = GUICreate("Test", 400, 300)
$iStyle = BitOR($LVS_REPORT, $LVS_SINGLESEL, $LVS_SHOWSELALWAYS, $LVS_OWNERDRAWFIXED)
$iExStyle = BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_DOUBLEBUFFER)
$hListView = _GUICtrlListView_Create($hGUI, "Test", 5, 5, 390, 290, $iStyle, $WS_EX_CLIENTEDGE)
_GUICtrlListView_SetExtendedListViewStyle($hListView, $iExStyle)
_GUICtrlListView_AddItem($hListView, "Item 1", -1, 1) ; Disabled
_GUICtrlListView_AddItem($hListView, "Item 2", -1, 1) ; Disabled
_GUICtrlListView_AddItem($hListView, "Item 3", -1, 0) ; Enable
_GUICtrlListView_AddItem($hListView, "Item 4", -1, 0) ; Enable
$hSelected = _WinAPI_GetSysColorBrush(13)
$hDeselected = _WinAPI_CreateSolidBrush(0xFFFFFF)
GUIRegisterMsg($WM_DRAWITEM, "WM_DRAWITEM")
GUISetState()
While GUIGetMsg() <> -3
WEnd
GUIDelete($hGUI)
_WinAPI_DeleteObject($hSelected)
_WinAPI_DeleteObject($hDeselected)
Func WM_DRAWITEM($hWnd, $iMsg, $iwParam, $ilParam)
Local $tDrawItem = DllStructCreate($tagDRAW_ITEM, $ilParam)
Local $hDC = DllStructGetData($tDrawItem, "hDC")
Local $hListView = DllStructGetData($tDrawItem, "HWndItem")
Local $iIndex = DllStructGetData($tDrawItem, "ItemId")
Local $iState = DllStructGetData($tDrawItem, "ItemState")
Local $tRect = DllStructCreate($tagRECT)
DllStructSetData($tRect, "Left", DllStructGetData($tDrawItem, "Left") + 5)
DllStructSetData($tRect, "Top", DllStructGetData($tDrawItem, "Top"))
DllStructSetData($tRect, "Right", DllStructGetData($tDrawItem, "Right"))
DllStructSetData($tRect, "Bottom", DllStructGetData($tDrawItem, "Bottom"))
If DllStructGetData($tDrawItem, "ItemData") Then
_WinAPI_SetTextColor($hDC, 0xC0C0C0)
Else
If BitAnd($iState, 1) Then
_WinAPI_FillRect($hDC, DllStructGetPtr($tDrawItem, "Left"), $hSelected)
_DrawFocusRect($hDC, DllStructGetPtr($tDrawItem, "Left"))
Else
_WinAPI_FillRect($hDC, DllStructGetPtr($tDrawItem, "Left"), $hDeselected)
EndIf
_WinAPI_SetTextColor($hDC, 0)
EndIf
_WinAPI_DrawText($hDC, _GUICtrlListView_GetItemText($hListView, $iIndex), $tRect, 0)
EndFunc ;==>WM_DRAWITEM
Func _DrawFocusRect($hDC, $pRect)
Local $iResult = DllCall("User32.dll", "bool", "DrawFocusRect", "hwnd", $hDC, "ptr", $pRect)
Return $iResult
EndFunc ;==>_DrawFocusRect
pusofalse 发表于 2011-2-26 11:26 http://www.autoitx.com/images/common/back.gif
就是这样子效果。多谢pusofalse版主!非常感谢! 是不是disable的效果了?即是关闭了 子项目不显示~!#include <WinAPI.au3>
#include <GUIListView.au3>
#include <WindowsConstants.au3>
Const $tagDRAW_ITEM = "uint CtlType;uint CtlId;uint ItemId;uint ItemAction;uint ItemState;hWnd HWndItem;hWnd hDC;long Left;long Top;long Right;long Bottom;ulong_ptr ItemData"
$hGUI = GUICreate("Test", 400, 300)
$iStyle = BitOR($LVS_REPORT, $LVS_SINGLESEL, $LVS_SHOWSELALWAYS, $LVS_OWNERDRAWFIXED)
$iExStyle = BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_DOUBLEBUFFER)
$hListView = _GUICtrlListView_Create($hGUI, "Test", 5, 5, 390, 290, $iStyle, $WS_EX_CLIENTEDGE)
_GUICtrlListView_SetExtendedListViewStyle($hListView, $iExStyle)
_GUICtrlListView_AddItem($hListView, "Item 1", -1, 1) ; Disabled
_GUICtrlListView_AddSubItem($hListView, 0, "Row 1: Col 2", 1, 1)
_GUICtrlListView_AddSubItem($hListView, 0, "Row 1: Col 3", 2, 2)
_GUICtrlListView_AddItem($hListView, "Item 2", -1, 1) ; Disabled
_GUICtrlListView_AddItem($hListView, "Item 3", -1, 0) ; Enable
_GUICtrlListView_AddItem($hListView, "Item 4", -1, 0) ; Enable
$hSelected = _WinAPI_GetSysColorBrush(13)
$hDeselected = _WinAPI_CreateSolidBrush(0xFFFFFF)
GUIRegisterMsg($WM_DRAWITEM, "WM_DRAWITEM")
GUISetState()
While GUIGetMsg() <> -3
WEnd
GUIDelete($hGUI)
_WinAPI_DeleteObject($hSelected)
_WinAPI_DeleteObject($hDeselected)
Func WM_DRAWITEM($hWnd, $iMsg, $iwParam, $ilParam)
Local $tDrawItem = DllStructCreate($tagDRAW_ITEM, $ilParam)
Local $hDC = DllStructGetData($tDrawItem, "hDC")
Local $hListView = DllStructGetData($tDrawItem, "HWndItem")
Local $iIndex = DllStructGetData($tDrawItem, "ItemId")
Local $iState = DllStructGetData($tDrawItem, "ItemState")
Local $tRect = DllStructCreate($tagRECT)
DllStructSetData($tRect, "Left", DllStructGetData($tDrawItem, "Left") + 5)
DllStructSetData($tRect, "Top", DllStructGetData($tDrawItem, "Top"))
DllStructSetData($tRect, "Right", DllStructGetData($tDrawItem, "Right"))
DllStructSetData($tRect, "Bottom", DllStructGetData($tDrawItem, "Bottom"))
If DllStructGetData($tDrawItem, "ItemData") Then
_WinAPI_SetTextColor($hDC, 0xC0C0C0)
Else
If BitAnd($iState, 1) Then
_WinAPI_FillRect($hDC, DllStructGetPtr($tDrawItem, "Left"), $hSelected)
_DrawFocusRect($hDC, DllStructGetPtr($tDrawItem, "Left"))
Else
_WinAPI_FillRect($hDC, DllStructGetPtr($tDrawItem, "Left"), $hDeselected)
EndIf
_WinAPI_SetTextColor($hDC, 0)
EndIf
_WinAPI_DrawText($hDC, _GUICtrlListView_GetItemText($hListView, $iIndex), $tRect, 0)
EndFunc ;==>WM_DRAWITEM
Func _DrawFocusRect($hDC, $pRect)
Local $iResult = DllCall("User32.dll", "bool", "DrawFocusRect", "hwnd", $hDC, "ptr", $pRect)
Return $iResult
EndFunc ;==>_DrawFocusRect
页:
1
[2]