关于禁用并灰色显示指定列表视图项[Pusofalse]的应用问题!
本帖最后由 sunkiss 于 2015-9-8 17:00 编辑这个列表视图只能显示第一列,使用_GUICtrlListView_AddSubItem添加的子项目根本不显示啊!还请高手指点啊~!
我想禁用列表视图里所有带2014的项目,在查看Pusofalse写的这个的时候想加以利用一下,结果不成功啊~!
列表如下:
1张三2015无
2李四2014无
3王五2013无
4黄七2014无
5陈九2013无
6刘十2015无
还请高手给予指导啊~!帮个忙啊~!给点建设性的提示也行啊~!
贴上Pusofalse写的代码。#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) ; 禁用
_GUICtrlListView_AddItem($hListView, "Item 2", -1, 1) ; 警用
_GUICtrlListView_AddItem($hListView, "Item 3", -1, 0) ; 启用
_GUICtrlListView_AddItem($hListView, "Item 4", -1, 0) ; 启用
$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 就没有高人指点一下啊? 你的代码有误#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) ; 禁用
_GUICtrlListView_AddItem($hListView, "Item 2", -1, 1) ; 警用
_GUICtrlListView_AddItem($hListView, "Item 3", -1, 0) ; 启用
_GUICtrlListView_AddItem($hListView, "Item 4", -1, 0) ; 启用
$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 子项目不显示。#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]