找回密码
 加入
搜索
楼主: binshiwo

[AU3基础] 如何使listview里面的项变成灰色,也就是不可用状态【已解决】

 火.. [复制链接]
 楼主| 发表于 2011-2-26 09:36:54 | 显示全部楼层
回复 15# pusofalse


是的。当ITEM是灰色的时候。是不能选中的。
发表于 2011-2-26 11:26:17 | 显示全部楼层
#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[0]
EndFunc        ;==>_DrawFocusRect
 楼主| 发表于 2011-2-26 11:51:45 | 显示全部楼层
pusofalse 发表于 2011-2-26 11:26



就是这样子效果。多谢pusofalse版主!非常感谢!
发表于 2011-2-28 21:01:39 | 显示全部楼层
是不是disable的效果了?即是关闭了
发表于 2016-10-23 17:25:12 | 显示全部楼层
子项目不显示~!
#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[0]
EndFunc ;==>_DrawFocusRect
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-6-12 13:49 , Processed in 0.077875 second(s), 15 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表