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

[AU3基础] 如何使用左键单点击达成LISTVIEW连续选中状态??

 火..   [复制链接]
 楼主| 发表于 2017-8-27 17:53:57 | 显示全部楼层
回复 12# yamakawa


    官方網站 舊版下載
https://www.autoitscript.com/autoit3/files/archive/autoit/

上面有
autoit-v3.3.8.1-setup.exe 2016-06-12 19:42  7.0M
发表于 2017-8-27 18:10:55 | 显示全部楼层
回复 15# yamakawa
6楼的代码我要改为事件模式,结果不行,要怎样改呢?
不知LZ这个要用在哪方面?
我想要用在点击条目,显示在另外一个列表或显示在编辑框。
因我大部份用事件模式,所以改为事件模式要套进去比较顺手。
先谢谢了!
发表于 2017-8-27 18:55:16 | 显示全部楼层
回复 16# kk_lee69


    不要安装版的,有绿色版的么,直接点开就能用的。因为我已经装了新版的,再装旧的。。以后还得删除。装新的。。麻烦
发表于 2017-8-27 19:00:29 | 显示全部楼层
回复 17# chzj589


    6楼的代码?这个,,,,,基本上是高级模式,不是事件也不是消息循环,,怎么说呢。。windows消息队列?
   楼主主要是想实现 点击鼠标的效果 等同于 按住ctrl的时候点击鼠标。好别扭,,,就是说触发鼠标事件的同时,设置ctrl为按下状态。。
  你想要的那个效果。。点击条目,捕捉信息好像在源码区有。。

SQLite - 增、删、改、查,操作示例。 - 『 源码作品 』 - AUTOIT CN AutoIt中文论坛|acn|au3|软件汉化 - 分享您的技术!
http://www.autoitx.com/forum.php ... mp;highlight=sqlite

这个是你要的么
发表于 2017-8-27 19:06:40 | 显示全部楼层
回复 19# yamakawa
不是。我要的只是:
左键单点击达成LISTVIEW连续选中状态
发表于 2017-8-27 19:17:36 | 显示全部楼层
回复 19# yamakawa
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPIShellEx.au3>
#include <GuiListView.au3>
Opt("GUIOnEventMode", 1);事件模式
Opt( "MustDeclareVars", 1 )
Global $idListView, $idAddSingleSel, $idDelSingleSel
Example()
Func Example()
  GUICreate( "ctrl+single-click --> single-click", 420, 200 )
  $idListView = GUICtrlCreateListView( "", 10, 10, 400, 180, $GUI_SS_DEFAULT_LISTVIEW-$LVS_SINGLESEL, $WS_EX_CLIENTEDGE )
  _GUICtrlListView_SetExtendedListViewStyle( $idListView, $LVS_EX_DOUBLEBUFFER+$LVS_EX_FULLROWSELECT )
  Local $hListView = GUICtrlGetHandle( $idListView )
  _GUICtrlListView_InsertColumn( $idListView, 0, "Column 1", 94 )
  _GUICtrlListView_InsertColumn( $idListView, 1, "Column 2", 94 )
  _GUICtrlListView_InsertColumn( $idListView, 2, "Column 3", 94 )
  _GUICtrlListView_InsertColumn( $idListView, 3, "Column 4", 94 )
  Local $iItems = 100
  For $i = 0 To $iItems - 1
    GUICtrlCreateListViewItem( $i & "/Column 1|" & $i & "/Column 2|" & $i & "/Column 3|" & $i & "/Column 4", $idListView )
  Next
  Local $pListViewFunc = DllCallbackGetPtr( DllCallbackRegister( "ListViewFunc", "lresult", "hwnd;uint;wparam;lparam;uint_ptr;dword_ptr" ) )
  _WinAPI_SetWindowSubclass( $hListView, $pListViewFunc, 0, 0 ) ; $iSubclassId = 0, $pData = 0
  $idAddSingleSel = GUICtrlCreateDummy()
  $idDelSingleSel = GUICtrlCreateDummy()
  Local $iItem
  GUISetState( @SW_SHOW )
;--------------------------以下如何改----------------------------------
  While 1
    Switch GUIGetMsg()
      Case $idAddSingleSel
        $iItem = GUICtrlRead( $idAddSingleSel )
        _GUICtrlListView_SetItemSelected( $idListView, $iItem, True )
        _GUICtrlListView_SetItemFocused( $idListView, $iItem )
      Case $idDelSingleSel
        $iItem = GUICtrlRead( $idDelSingleSel )
        _GUICtrlListView_SetItemSelected( $idListView, $iItem, False )
        _GUICtrlListView_SetItemFocused( $idListView, $iItem )
      Case $GUI_EVENT_CLOSE
        ExitLoop
    EndSwitch
  WEnd
  _WinAPI_RemoveWindowSubclass( $hListView, $pListViewFunc, 0 )
  GUIDelete()
;----------------------------------修改结束-------------------------------------

EndFunc

Func ListViewFunc( $hWnd, $iMsg, $wParam, $lParam, $iSubclassId, $pData )
  If $iMsg <> $WM_LBUTTONDOWN Then Return DllCall( "comctl32.dll", "lresult", "DefSubclassProc", "hwnd", $hWnd, "uint", $iMsg, "wparam", $wParam, "lparam", $lParam )[0]

  Switch $wParam
    Case 0x0001  ; 0x0001 = MK_LBUTTON (LButton down)
      If _GUICtrlListView_GetSelectedCount( $idListView ) Then
        Local $aHit = _GUICtrlListView_HitTest( GUICtrlGetHandle( $idListView ), BitAND( $lParam, 0xFFFF ), BitShift( $lParam, 16 ) )
        If Not ( @error Or $aHit[0] = -1 ) Then
          If _GUICtrlListView_GetItemSelected( $idListView, $aHit[0] ) Then
            GUICtrlSendToDummy( $idDelSingleSel, $aHit[0] )
          Else
            GUICtrlSendToDummy( $idAddSingleSel, $aHit[0] )
          EndIf
        EndIf
        Return 0 ; Disable single-click in ListView to prevent resetting selections
      EndIf
    Case 0x0009  ; 0x0009 = MK_LBUTTON (LButton down) + MK_CONTROL (Ctrl down)
      Return 0   ; Disable single selections in ListView with ctrl+single-click
  EndSwitch
  Return DllCall( "comctl32.dll", "lresult", "DefSubclassProc", "hwnd", $hWnd, "uint", $iMsg, "wparam", $wParam, "lparam", $lParam )[0]
; Call next function in subclass chain (this forwards messages to main GUI)
  #forceref $iSubclassId, $pData
EndFunc
发表于 2017-8-27 19:45:00 | 显示全部楼层
回复 21# chzj589



#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <GuiListView.au3>

Opt('GUIOnEventMode', 1)

Global $idListView, $hListView, $pListViewFunc, $idAddSingleSel, $idDelSingleSel

Example()
While 1
        Sleep(1000)
WEnd

Func Example()
        ; Create GUI
        GUICreate("ctrl+single-click --> single-click", 420, 200)
        GUISetOnEvent(-3, '_Exit')
        ; Create ListView
        $idListView = GUICtrlCreateListView("", 10, 10, 400, 180, $GUI_SS_DEFAULT_LISTVIEW - $LVS_SINGLESEL, $WS_EX_CLIENTEDGE)
        _GUICtrlListView_SetExtendedListViewStyle($idListView, $LVS_EX_DOUBLEBUFFER + $LVS_EX_FULLROWSELECT)
        $hListView = GUICtrlGetHandle($idListView)

        ; Add columns to ListView
        _GUICtrlListView_InsertColumn($idListView, 0, "Column 1", 94)
        _GUICtrlListView_InsertColumn($idListView, 1, "Column 2", 94)
        _GUICtrlListView_InsertColumn($idListView, 2, "Column 3", 94)
        _GUICtrlListView_InsertColumn($idListView, 3, "Column 4", 94)

        ; Fill ListView
        Local $iItems = 100
        For $i = 0 To $iItems - 1
                GUICtrlCreateListViewItem($i & "/Column 1|" & $i & "/Column 2|" & $i & "/Column 3|" & $i & "/Column 4", $idListView)
        Next

        ; Subclass ListView to receive keyboard/mouse messages
        $pListViewFunc = DllCallbackGetPtr(DllCallbackRegister("ListViewFunc", "lresult", "hwnd;uint;wparam;lparam;uint_ptr;dword_ptr"))
        _WinAPI_SetWindowSubclass($hListView, $pListViewFunc, 0, 0) ; $iSubclassId = 0, $pData = 0

        ; Add/del single selection
        $idAddSingleSel = GUICtrlCreateDummy()
        GUICtrlSetOnEvent(-1, '_AddSingleSel')
        $idDelSingleSel = GUICtrlCreateDummy()
        GUICtrlSetOnEvent(-1, '_DelSingleSel')

        ; Show GUI
        GUISetState(@SW_SHOW)
EndFunc   ;==>Example

Func ListViewFunc($hWnd, $iMsg, $wParam, $lParam, $iSubclassId, $pData)
        If $iMsg <> $WM_LBUTTONDOWN Then
                Local $result = DllCall("comctl32.dll", "lresult", "DefSubclassProc", "hwnd", $hWnd, "uint", $iMsg, "wparam", $wParam, "lparam", $lParam)
                If Not @error Then
                        Return $result[0]
                Else
                        Return
                EndIf
        EndIf
        Switch $wParam
                Case 0x0001
                        If _GUICtrlListView_GetSelectedCount($idListView) Then
                                Local $aHit = _GUICtrlListView_HitTest(GUICtrlGetHandle($idListView), BitAND($lParam, 0xFFFF), BitShift($lParam, 16))
                                If Not (@error Or $aHit[0] = -1) Then
                                        If _GUICtrlListView_GetItemSelected($idListView, $aHit[0]) Then
                                                GUICtrlSendToDummy($idDelSingleSel, $aHit[0])
                                        Else
                                                GUICtrlSendToDummy($idAddSingleSel, $aHit[0])
                                        EndIf
                                EndIf
                                Return 0
                        EndIf
                Case 0x0009
                        Return 0
        EndSwitch
        Local $result = DllCall("comctl32.dll", "lresult", "DefSubclassProc", "hwnd", $hWnd, "uint", $iMsg, "wparam", $wParam, "lparam", $lParam)
        If Not @error Then
                Return $result[0]
        Else
                Return
        EndIf
        #forceref $iSubclassId, $pData
EndFunc   ;==>ListViewFunc

Func _AddSingleSel()
        Local $iItem = GUICtrlRead($idAddSingleSel)
        _GUICtrlListView_SetItemSelected($idListView, $iItem, True)
        _GUICtrlListView_SetItemFocused($idListView, $iItem)
EndFunc   ;==>_AddSingleSel
Func _DelSingleSel()
        Local $iItem = GUICtrlRead($idDelSingleSel)
        _GUICtrlListView_SetItemSelected($idListView, $iItem, False)
        _GUICtrlListView_SetItemFocused($idListView, $iItem)
EndFunc   ;==>_DelSingleSel
Func _Exit()
        _WinAPI_RemoveWindowSubclass($hListView, $pListViewFunc, 0)
        GUIDelete()
        Exit
EndFunc   ;==>_Exit

Func _WinAPI_SetWindowSubclass($hWnd, $pSubclassProc, $idSubClass, $pData = 0)
        Local $aRet = DllCall('comctl32.dll', 'bool', 'SetWindowSubclass', 'hwnd', $hWnd, 'ptr', $pSubclassProc, 'uint_ptr', $idSubClass, _
                        'dword_ptr', $pData)
        If @error Then Return SetError(@error, @extended, 0)
        ; If Not $aRet[0] Then Return SetError(1000, 0, 0)

        Return $aRet[0]
EndFunc   ;==>_WinAPI_SetWindowSubclass
Func _WinAPI_RemoveWindowSubclass($hWnd, $pSubclassProc, $idSubClass)
        Local $aRet = DllCall('comctl32.dll', 'bool', 'RemoveWindowSubclass', 'hwnd', $hWnd, 'ptr', $pSubclassProc, 'uint_ptr', $idSubClass)
        If @error Then Return SetError(@error, @extended, False)
        Return $aRet[0]
EndFunc   ;==>_WinAPI_RemoveWindowSubclass


To LZ: au338 缺少的两个api函数给加上了,引用数组的语法也改了,应该可以各版通用
发表于 2017-8-27 21:00:44 | 显示全部楼层
哦哦。原来338没有那俩函数啊。。。。原谅我没有用过旧版的。不了解
发表于 2017-8-27 21:03:53 | 显示全部楼层
回复 22# afan


    也不对啊。。如果是没有那函数,不是应该有提示 未定义函数么?
   为嘛楼主会直接没掉?scite旧版的没有这功能?
 楼主| 发表于 2017-8-27 21:32:56 | 显示全部楼层
回复 22# afan

果然 3.3.8版 可以用了 感謝 修改

我研究看看怎麼合併到我的程式裡
发表于 2017-8-27 21:54:41 | 显示全部楼层
回复 22# afan
太棒了,学习学习


Func ListViewFunc( $hWnd, $iMsg, $wParam, $lParam, $iSubclassId, $pData )
  If $iMsg <> $WM_LBUTTONDOWN Then Return DllCall( "comctl32.dll", "lresult", "DefSubclassProc", "hwnd", $hWnd, "uint", $iMsg, "wparam", $wParam, "lparam", $lParam )[0]

  Switch $wParam
    Case 0x0001  ; 0x0001 = MK_LBUTTON (LButton down)
      If _GUICtrlListView_GetSelectedCount( $idListView ) Then
        Local $aHit = _GUICtrlListView_HitTest( GUICtrlGetHandle( $idListView ), BitAND( $lParam, 0xFFFF ), BitShift( $lParam, 16 ) )
        If Not ( @error Or $aHit[0] = -1 ) Then
          If _GUICtrlListView_GetItemSelected( $idListView, $aHit[0] ) Then
            GUICtrlSendToDummy( $idDelSingleSel, $aHit[0] )
          Else
            GUICtrlSendToDummy( $idAddSingleSel, $aHit[0] )
          EndIf
        EndIf
        Return 0 ; Disable single-click in ListView to prevent resetting selections
      EndIf
    Case 0x0009  ; 0x0009 = MK_LBUTTON (LButton down) + MK_CONTROL (Ctrl down)
      Return 0   ; Disable single selections in ListView with ctrl+single-click
  EndSwitch
  Return DllCall( "comctl32.dll", "lresult", "DefSubclassProc", "hwnd", $hWnd, "uint", $iMsg, "wparam", $wParam, "lparam", $lParam )[0]
; Call next function in subclass chain (this forwards messages to main GUI)
  #forceref $iSubclassId, $pData
EndFunc
 楼主| 发表于 2017-8-27 23:02:34 | 显示全部楼层
回复 22# afan


afan  可問個很笨的問題嗎??

我能了解
        $pListViewFunc = DllCallbackGetPtr(DllCallbackRegister("ListViewFunc", "lresult", "hwnd;uint;wparam;lparam;uint_ptr;dword_ptr"))

這句話是建立 取得我們所建立的 函數指標
      
  _WinAPI_SetWindowSubclass($hListView, $pListViewFunc, 0, 0) ; $iSubclassId = 0, $pData = 0   

但是 這句話看到的意思是  把 $pListViewFunc 跟 $hListView 關聯

但是 想詢問的是 為何 這樣就可以接收 鍵盤與MOUSE 消息呢???

我沒看到任何跟 鍵盤或者滑鼠的字眼阿

我之前嘗試過 GUIRegisterMsg(0x0201, "WM_LBUTTONDOWN")

但是這樣 反而只在 非 LISTVIEW區 才有反應  在 LISTVIEW 不會有反應

但是我就是無法理解  怎麼知道 滑鼠的消息  可以用上面的兩個語法  就可以建立關連呢??
发表于 2017-8-27 23:41:53 | 显示全部楼层
回复 27# kk_lee69


    大致上 这就是使用回调函数先行处理windows窗口的控件消息。在$wParam中应该就包含你所说的键鼠消息
 楼主| 发表于 2017-8-28 01:06:13 | 显示全部楼层
回复 28# afan

對我的主要意思是 他怎麼會知道要這樣處理  那這些知識我要去哪邊學習 或者 找資料??
 楼主| 发表于 2017-8-28 01:46:02 | 显示全部楼层
回复 22# afan

不過好像 使用這個方法後  就不能 同時 註冊 WM_NOTIFY

我嘗試 不出來
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-4-19 17:06 , Processed in 0.072532 second(s), 14 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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