找回密码
 加入
搜索
查看: 4011|回复: 3

[AU3基础] 关于禁用并灰色显示指定列表视图项[Pusofalse]的应用问题!

[复制链接]
发表于 2015-9-7 22:42:33 | 显示全部楼层 |阅读模式
本帖最后由 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[0]
EndFunc ;==>_DrawFocusRect
 楼主| 发表于 2015-9-13 16:09:58 | 显示全部楼层
就没有高人指点一下啊?
发表于 2015-9-13 17:08:55 | 显示全部楼层
你的代码有误
#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[0]
EndFunc ;==>_DrawFocusRect
 楼主| 发表于 2016-10-23 17:25:30 | 显示全部楼层
子项目不显示。
#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-12-25 14:32 , Processed in 0.076735 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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