#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiImageList.au3>
;#include <WinAPITheme.au3>
#include <GuiListView.au3>
#include <WinAPISys.au3>
#include <WinAPI.au3>
#include <GuiEdit.au3>
#include <array.au3>
#include <Misc.au3>
Global $B_DESCENDING
Global $hActLst
Global $bCtrlDown = False
Global $hEdit, $Item = -1, $SubItem = 0
Global $hEnter, $aAccelKeys = [["{ENTER}", $hEnter]]
$iSelItem = -1
Local $hUser32 = DllOpen("user32.dll")
Local $ichked = 0
Local $tText = DllStructCreate("wchar Text")
Local $GUI, $hImage
Local $iITEM_COUNT = 1000, $aShowdata[$iITEM_COUNT], $aShowdata2[$iITEM_COUNT], $aShowdata3[$iITEM_COUNT]
Local $sSomeString = ""
Local $hGUI, $hListView, $hListView2, $hListView3
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
$hGUI = GUICreate("ListView[" & UBound($aShowdata) & "]", 600, 605)
$hListView2 = GUICtrlCreateListView("$hListView2| | ", 300, 2, 295, 296, BitOR($LVS_REPORT, $LVS_SINGLESEL, $LVS_SHOWSELALWAYS, $LVS_OWNERDATA), $LVS_EX_GRIDLINES + $LVS_EX_FULLROWSELECT + $LVS_EX_CHECKBOXES + $LVS_EX_DOUBLEBUFFER) ;+ $LVS_EX_DOUBLEBUFFER
;~ _WinAPI_SetWindowTheme(GUICtrlGetHandle($hListView), "Explorer");
GUICtrlSendMsg($hListView2, $LVM_SETCOLUMNWIDTH, 0, 110)
GUICtrlSendMsg($hListView2, $LVM_SETCOLUMNWIDTH, 1, 80)
GUICtrlSendMsg($hListView2, $LVM_SETCOLUMNWIDTH, 2, 80)
GUICtrlSendMsg($hListView2, $LVM_SETITEMCOUNT, $iITEM_COUNT, 0) ;
;===========創建並關聯圖像清單
$hImage = _GUIImageList_Create()
_GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 110)
_GUICtrlListView_SetImageList($hListView, $hImage, 1) ;
_GUICtrlListView_SetImageList($hListView2, $hImage, 1) ;
GUISetState()
For $i = 0 To $iITEM_COUNT - 1
If $i = 18 Then
GUICtrlSendMsg($hListView, $LVM_REDRAWITEMS, 0, $i)
GUICtrlSendMsg($hListView2, $LVM_REDRAWITEMS, 0, $i)
GUICtrlSendMsg($hListView3, $LVM_REDRAWITEMS, 0, $i)
EndIf
$aShowdata2[$i] = "2AA" & $i
$aShowdata2[$i] = "2BB" & $i
$aShowdata2[$i] = "2CC" & $i
$aShowdata2[$i] = 4096 ;
Next
While 1
$bCtrlDown = _IsPressed("11", $hUser32) ;
Switch GUIGetMsg()
Case -3
ExitLoop
EndSwitch
WEnd
GUIDelete()
DllClose($hUser32)
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
#forceref $hWnd, $iMsg, $iwParam
Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $tInfo
$tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
$iCode = DllStructGetData($tNMHDR, "Code")
Switch $iIDFrom
Case $hListView2
Switch $iCode
Case $NM_CLICK ; Sent by a list-view control when the user clicks an item with the left mouse button
;~ ConsoleWrite("$NM_CLICK" & @CRLF)
Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
Local $Index = DllStructGetData($tInfo, "Index"), _
$SubItem = DllStructGetData($tInfo, "SubItem"), _
$X = DllStructGetData($tInfo, "X")
If $X < 18 And (BitAND(_GUICtrlListView_GetExtendedListViewStyle($hWndFrom), $LVS_EX_CHECKBOXES) = $LVS_EX_CHECKBOXES) Then ;使用x坐标来判断是否在复选框上点击
If $aShowdata2[$Index] = 4096 Then
$aShowdata2[$Index] = 8192 ;4096未选中 8192选中
Else
$aShowdata2[$Index] = 4096 ;4096未选中 8192选中
EndIf
EndIf
Local $Info = DllStructCreate($tagNMLVDISPINFO, $ilParam)
DllStructSetData($Info, "State", $aShowdata2[$Index]) ;设置复选框状态
_GUICtrlListView_RedrawItems($hWndFrom, $Index, $Index) ;<====好像可以了。。。。复选框正常
Case -150, -177
_LVN_GETDISPINFO($iIDFrom, $ilParam, $aShowdata2)
Case $NM_CUSTOMDRAW
;~ ConsoleWrite("$NM_CUSTOMDRAW" & @CRLF)
Local $tNMLVCUSTOMDRAW = DllStructCreate($tagNMLVCUSTOMDRAW, $ilParam)
Local $dwDrawStage = DllStructGetData($tNMLVCUSTOMDRAW, "dwDrawStage")
Switch $dwDrawStage ; Holds a value that specifies the drawing stage
Case $CDDS_PREPAINT
; Before the paint cycle begins
Return $CDRF_NOTIFYITEMDRAW ; Notify the parent window of any item-related drawing operations
Case $CDDS_ITEMPREPAINT
; Before painting an item
Local $iItem = DllStructGetData($tNMLVCUSTOMDRAW, "dwItemSpec") ; Item index
Switch $iItem
Case 5, 8, 11, 33, 56, 4
DllStructSetData($tNMLVCUSTOMDRAW, "ClrTextBk", 0x00CC00)
EndSwitch
If $iItem = $iSelItem Then
DllStructSetData($tNMLVCUSTOMDRAW, "ClrTextBk", 0xADFF2F)
DllStructSetData($tNMLVCUSTOMDRAW, "clrText", 0xFFFFFF)
EndIf
EndSwitch
Return $CDRF_NEWFONT ; $CDRF_NEWFONT must be returned after changing font or colors
;~ Return $CDRF_NOTIFYSUBITEMDRAW
Case $LVN_ITEMCHANGED ; An item has changed
;~ ConsoleWrite("$LVN_ITEMCHANGED" & @CRLF)
Local $tNMLISTVIEW = DllStructCreate($tagNMLISTVIEW, $ilParam)
;~ _GUICtrlListView_RedrawItems($hWndFrom, $iSelItem, $iSelItem)
$iSelItem = DllStructGetData($tNMLISTVIEW, "Item")
_GUICtrlListView_SetItemSelected($hWndFrom, $iSelItem, False) ; Remove selected state
;~ _GUICtrlListView_SetItemState($hListView2, $iSelItem, 0, $LVIS_FOCUSED) ; Remove focused state
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY
Func _LVN_GETDISPINFO($hlst, $ilParam, ByRef $aDataArray)
If Not IsArray($aDataArray) Then Return
$tInfo = DllStructCreate($tagNMLVDISPINFO, $ilParam)
$iIndex = Int(DllStructGetData($tInfo, "Item"))
$iSub = Int(DllStructGetData($tInfo, "SubItem"))
If BitAND(DllStructGetData($tInfo, "Mask"), $LVIF_IMAGE) And $iSub = 0 Then DllStructSetData($tInfo, "Image", 0)
If (BitAND(_GUICtrlListView_GetExtendedListViewStyle($hlst), $LVS_EX_CHECKBOXES) = $LVS_EX_CHECKBOXES) Then
DllStructSetData($tInfo, "Mask", BitOR($LVIF_STATE, DllStructGetData($tInfo, "Mask")))
DllStructSetData($tInfo, "StateMask", $LVIS_STATEIMAGEMASK)
DllStructSetData($tInfo, "State", $aDataArray[$iIndex])
EndIf
DllStructSetData($tText, "Text", $aDataArray[$iIndex][$iSub])
DllStructSetData($tInfo, "Text", DllStructGetPtr($tText))
DllStructSetData($tInfo, "TextMax", StringLen($aDataArray[$iIndex][$iSub]))
EndFunc ;==>_LVN_GETDISPINFO
Func _DebugPrint($s_Text, $sLine = @ScriptLineNumber)
ConsoleWrite( _
"!===========================================================" & @CRLF & _
"+======================================================" & @CRLF & _
"-->Line(" & StringFormat("%04d", $sLine) & "):" & @TAB & $s_Text & @CRLF & _
"+======================================================" & @CRLF)
EndFunc ;==>_DebugPrint
Func RGB2BGR($iColor)
Return BitAND(BitShift(String(Binary($iColor)), 8), 0xFFFFFF)
EndFunc ;==>RGB2BGR
本帖最后由 yamakawa 于 2017-8-17 21:43 编辑
{:face (356):}可以安心睡觉了
#PRE_UseX64=n
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiImageList.au3>
;#include <WinAPITheme.au3>
#include <GuiListView.au3>
#include <WinAPISys.au3>
#include <WinAPI.au3>
#include <GuiEdit.au3>
#include <array.au3>
#include <Misc.au3>
Global $B_DESCENDING
Global $hActLst
Global $bCtrlDown = False
Global $hEdit, $Item = -1, $SubItem = 0
Global $hEnter, $aAccelKeys = [["{ENTER}", $hEnter]]
$iSelItem = -1
Local $hUser32 = DllOpen("user32.dll")
Local $ichked = 0
Local $tText = DllStructCreate("wchar Text")
Local $GUI, $hImage
Local $iITEM_COUNT = 1000, $aShowdata[$iITEM_COUNT], $aShowdata2[$iITEM_COUNT], $aShowdata3[$iITEM_COUNT]
Local $sSomeString = ""
Local $hGUI, $hListView, $hListView2, $hListView3
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
$hGUI = GUICreate("ListView[" & UBound($aShowdata) & "]", 600, 605)
$hListView2 = GUICtrlCreateListView("$hListView2| | ", 300, 2, 295, 296, BitOR($LVS_REPORT, $LVS_SINGLESEL, $LVS_SHOWSELALWAYS, $LVS_OWNERDATA), $LVS_EX_GRIDLINES + $LVS_EX_FULLROWSELECT + $LVS_EX_CHECKBOXES + $LVS_EX_DOUBLEBUFFER) ;+ $LVS_EX_DOUBLEBUFFER
;~ _WinAPI_SetWindowTheme(GUICtrlGetHandle($hListView), "Explorer");
GUICtrlSendMsg($hListView2, $LVM_SETCOLUMNWIDTH, 0, 110)
GUICtrlSendMsg($hListView2, $LVM_SETCOLUMNWIDTH, 1, 80)
GUICtrlSendMsg($hListView2, $LVM_SETCOLUMNWIDTH, 2, 80)
GUICtrlSendMsg($hListView2, $LVM_SETITEMCOUNT, $iITEM_COUNT, 0) ;
;===========創建並關聯圖像清單
$hImage = _GUIImageList_Create()
_GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 15)
_GUICtrlListView_SetImageList($hListView, $hImage, 1) ;
_GUICtrlListView_SetImageList($hListView2, $hImage, 1) ;
GUISetState()
For $i = 0 To $iITEM_COUNT - 1
If $i = 18 Then
GUICtrlSendMsg($hListView, $LVM_REDRAWITEMS, 0, $i)
GUICtrlSendMsg($hListView2, $LVM_REDRAWITEMS, 0, $i)
GUICtrlSendMsg($hListView3, $LVM_REDRAWITEMS, 0, $i)
EndIf
$aShowdata2[$i] = "2AA" & $i
$aShowdata2[$i] = "2BB" & $i
$aShowdata2[$i] = "2CC" & $i
$aShowdata2[$i] = 4096 ;
Next
While 1
$bCtrlDown = _IsPressed("11", $hUser32) ;
Switch GUIGetMsg()
Case -3
ExitLoop
EndSwitch
WEnd
GUIDelete()
DllClose($hUser32)
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
#forceref $hWnd, $iMsg, $iwParam
Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $tInfo
$tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
$iCode = DllStructGetData($tNMHDR, "Code")
Switch $iIDFrom
Case $hListView2
Switch $iCode
Case $NM_CLICK ; Sent by a list-view control when the user clicks an item with the left mouse button
;~ ConsoleWrite("$NM_CLICK" & @CRLF)
Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
Local $Index = DllStructGetData($tInfo, "Index"), _
$SubItem = DllStructGetData($tInfo, "SubItem"), _
$X = DllStructGetData($tInfo, "X")
If $X < 18 And (BitAND(_GUICtrlListView_GetExtendedListViewStyle($hWndFrom), $LVS_EX_CHECKBOXES) = $LVS_EX_CHECKBOXES) Then ;使用x坐标来判断是否在复选框上点击
If $aShowdata2[$Index] = 4096 Then
$aShowdata2[$Index] = 8192 ;4096未选中 8192选中
Else
$aShowdata2[$Index] = 4096 ;4096未选中 8192选中
EndIf
EndIf
Local $Info = DllStructCreate($tagNMLVDISPINFO, $ilParam)
DllStructSetData($Info, "State", $aShowdata2[$Index]) ;设置复选框状态
_GUICtrlListView_RedrawItems($hWndFrom, $Index, $Index) ;<====好像可以了。。。。复选框正常
Case -150, -177
_LVN_GETDISPINFO($iIDFrom, $ilParam, $aShowdata2)
Case $NM_CUSTOMDRAW
;~ ConsoleWrite("$NM_CUSTOMDRAW" & @CRLF)
Local $tNMLVCUSTOMDRAW = DllStructCreate($tagNMLVCUSTOMDRAW, $ilParam)
Local $dwDrawStage = DllStructGetData($tNMLVCUSTOMDRAW, "dwDrawStage")
Switch $dwDrawStage ; Holds a value that specifies the drawing stage
Case $CDDS_PREPAINT
; Before the paint cycle begins
Return $CDRF_NOTIFYITEMDRAW ; Notify the parent window of any item-related drawing operations
Case $CDDS_ITEMPREPAINT
Return $CDRF_NOTIFYSUBITEMDRAW
Case BitOR($CDDS_ITEMPREPAINT, $CDDS_SUBITEM) ;$CDDS_ITEMPREPAINT
; Before painting an item
Local $iItem = DllStructGetData($tNMLVCUSTOMDRAW, "dwItemSpec") ; Item index
Switch $iItem
Case 5, 8, 11, 4
Switch DllStructGetData($tNMLVCUSTOMDRAW, "iSubItem")
Case 0
DllStructSetData($tNMLVCUSTOMDRAW, "ClrTextBk", 0x00CC00)
Case 1
DllStructSetData($tNMLVCUSTOMDRAW, "ClrTextBk", 0x008b00)
Case 2
DllStructSetData($tNMLVCUSTOMDRAW, "ClrTextBk", 0xe4CC00)
EndSwitch
Case 0 To 3
DllStructSetData($tNMLVCUSTOMDRAW, "ClrTextBk", 0xffCC00)
DllStructSetData($tNMLVCUSTOMDRAW, "clrText", 0xff00cc)
EndSwitch
If $iItem = $iSelItem Then
DllStructSetData($tNMLVCUSTOMDRAW, "ClrTextBk", 0xADFF2F)
DllStructSetData($tNMLVCUSTOMDRAW, "clrText", 0xFFFFFF)
EndIf
EndSwitch
Return $CDRF_NEWFONT ; $CDRF_NEWFONT must be returned after changing font or colors
;~ Return $CDRF_NOTIFYSUBITEMDRAW
Case $LVN_ITEMCHANGED ; An item has changed
;~ ConsoleWrite("$LVN_ITEMCHANGED" & @CRLF)
Local $tNMLISTVIEW = DllStructCreate($tagNMLISTVIEW, $ilParam)
;~ _GUICtrlListView_RedrawItems($hWndFrom, $iSelItem, $iSelItem)
$iSelItem = DllStructGetData($tNMLISTVIEW, "Item")
_GUICtrlListView_SetItemSelected($hWndFrom, $iSelItem, False) ; Remove selected state
_GUICtrlListView_SetItemState($hListView2, $iSelItem, 0, $LVIS_FOCUSED) ; Remove focused state
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY
Func _LVN_GETDISPINFO($hlst, $ilParam, ByRef $aDataArray)
If Not IsArray($aDataArray) Then Return
$tInfo = DllStructCreate($tagNMLVDISPINFO, $ilParam)
$iIndex = Int(DllStructGetData($tInfo, "Item"))
$iSub = Int(DllStructGetData($tInfo, "SubItem"))
If BitAND(DllStructGetData($tInfo, "Mask"), $LVIF_IMAGE) And $iSub = 0 Then DllStructSetData($tInfo, "Image", 0)
If (BitAND(_GUICtrlListView_GetExtendedListViewStyle($hlst), $LVS_EX_CHECKBOXES) = $LVS_EX_CHECKBOXES) Then
DllStructSetData($tInfo, "Mask", BitOR($LVIF_STATE, DllStructGetData($tInfo, "Mask")))
DllStructSetData($tInfo, "StateMask", $LVIS_STATEIMAGEMASK)
DllStructSetData($tInfo, "State", $aDataArray[$iIndex])
EndIf
DllStructSetData($tText, "Text", $aDataArray[$iIndex][$iSub])
DllStructSetData($tInfo, "Text", DllStructGetPtr($tText))
DllStructSetData($tInfo, "TextMax", StringLen($aDataArray[$iIndex][$iSub]))
EndFunc ;==>_LVN_GETDISPINFO
Func _DebugPrint($s_Text, $sLine = @ScriptLineNumber)
ConsoleWrite( _
"!===========================================================" & @CRLF & _
"+======================================================" & @CRLF & _
"-->Line(" & StringFormat("%04d", $sLine) & "):" & @TAB & $s_Text & @CRLF & _
"+======================================================" & @CRLF)
EndFunc ;==>_DebugPrint
Func RGB2BGR($iColor)
Return BitAND(BitShift(String(Binary($iColor)), 8), 0xFFFFFF)
EndFunc ;==>RGB2BGR
本帖最后由 kk_lee69 于 2017-8-17 23:38 编辑
回复 17# yamakawa
這樣好像可以了ㄟ感謝!! 回复 18# kk_lee69
{:face (356):}你在官网问的替换鼠标左键为 同时按下ctrl的问题。。有可能可以。。。
$tagNMITEMACTIVATE结构中
KeyFlags 修改激活时按下的键.
该成员保持为 0 或下列值的组合:
$LVKF_ALT - 按下 ALT 键.
$LVKF_CONTROL - 按下 CONTROL 键.
$LVKF_SHIFT - 按下 SHIFT 键
就保存了功能键状态。。但是不知道,好像不接受修改。。我修改了状态。然后setdata。但是没起作用。不知道为什么。。你可以直接问问大神。。。
另外,我给你另一个帖子里面回的,那个可以的吧?我测试可以啊? 回复 19# yamakawa
還沒有測試ㄟ 我再找個時間測試
明天要員工旅遊....
其實我都知道 想要達成CTRL+滑鼠點擊簡單的作法 其實就是找時機點 按下CTRL 鍵
只是我寫的軟體是 ERP 用途 難保 時機點錯誤的時候 會造成 使用者輸入的困擾
因此 一直想 看看能不能直接 在 WM_NOTIFY 裡面把這個問題解決掉
我倒覺得當你按下 單擊的時候
WM_NOTIFY 一定先把所有的狀態清掉然後才選擇你選的因此 會造成我說的問題
可是 當你按著 CTRL的時候 WM_NOTIFY 會進入到另外一種狀態不會去清以前的狀態
所以才想著 是否 可以攔截調 這個 訊息就可以不用 按下 CTRL 按鈕 回复 20# kk_lee69
这个简单啊。。。
1.可以弄个checkbox。选中的情况下,才启用ctrl
2.判断鼠标位置。在listview范围内,才启用ctrl 回复 21# yamakawa
试了你17楼的例子,如果把列表控件设置为:
$hListView2 = GUICtrlCreateListView("$hListView2| | ", 10, 12, 580, 578,
点击列表空白处,出现错误:
--> 点击 Ctrl+Alt+Break 重新启动, 或 Ctrl+Break 停止脚本执行
"F:\????\ListView????\???? LISTVIEW?????? ???????????.au3" (110) : ==> ????????.:
DllStructSetData($Info, "State", $aShowdata2[$Index])
DllStructSetData($Info, "State", $aShowdata2[^ ERROR
->16:37:44 AutoIt3.exe 结束.rc: 1
修改:
把105行的<EndIf>移动到111行。
问题就解决了。 回复 22# chzj589
你列表控件设置成什么?你发的代码没有后面。看不出
那个也好解决。空白就是Index = -1 设置一个判断,-1就返回就是了 回复 22# chzj589
{:face (303):}看见了,知道你意思了。。。那啥,,旁边的空白我认了,是我没检查好,下面暂时没显示不是我的事啊{:face (356):}他原来代码只设置初始显示到18.。。 回复 22# chzj589 For $i = 0 To $iITEM_COUNT - 1
If $i = 18 Then
GUICtrlSendMsg($hListView, $LVM_REDRAWITEMS, 0, $i)
GUICtrlSendMsg($hListView2, $LVM_REDRAWITEMS, 0, $i)
GUICtrlSendMsg($hListView3, $LVM_REDRAWITEMS, 0, $i)
EndIf
$aShowdata2[$i] = "2AA" & $i
$aShowdata2[$i] = "2BB" & $i
$aShowdata2[$i] = "2CC" & $i
$aShowdata2[$i] = 4096 ;
Next这段代码不知道是谁写的。。我都没注意过。。。太搞笑了。。。那个sendmessage干嘛放到循环里面啊。。。。。。GUICtrlSendMsg($hListView2, $LVM_REDRAWITEMS, 0, $i)放到next下面,然后直接0,30就搞定了。。。 回复 19# yamakawa
KeyFlags 修改激活时按下的键.
该成员保持为 0 或下列值的组合:
$LVKF_ALT - 按下 ALT 键.
$LVKF_CONTROL - 按下 CONTROL 键.
$LVKF_SHIFT - 按下 SHIFT 键
這段 你說道你測試過是否有你的源碼可以參考看看 回复 26# kk_lee69
不好意思。只是随手写的一段代码,测试无效就删除掉了。。。现在手上没有
页:
1
[2]