找回密码
 加入
搜索
查看: 1658|回复: 6

请问一下关于ListView的问题!!

[复制链接]
发表于 2009-4-13 00:18:18 | 显示全部楼层 |阅读模式
请问一下在ListView中选中随意一项之后使用鼠标滚轮控制选中高亮上下移动应该如何做?

[ 本帖最后由 eddielove 于 2009-4-13 22:27 编辑 ]
发表于 2009-4-13 08:36:16 | 显示全部楼层
想法不错的,可以练练手

靠au3无法获取滚轮事件

[ 本帖最后由 顽固不化 于 2009-4-13 09:06 编辑 ]
 楼主| 发表于 2009-4-13 14:37:14 | 显示全部楼层
感谢解答!!
发表于 2009-4-13 17:07:19 | 显示全部楼层
#include <WinAPI.au3>
#include <GUIListView.au3>

If not IsDeclared("WM_MOUSEWHEEL") Then $WM_MOUSEWHEEL = 0x20A
If not IsDeclared("WM_VSCROLL") Then $WM_VSCROLL = 0x115


$hGUI = GUICreate("Test", 400, 300)

$iStyle = bitOr($LVS_SINGLESEL, $LVS_REPORT)
$iExStyle = bitOr($LVS_EX_FULLROWSELECT, $LVS_EX_DOUBLEBUFFER, _
                $LVS_EX_GRIDLINES, 0x200)

$iListView = GUICtrlCreateListView("Test|MouseWheel", 5, 5, 390, 240, $iStyle, $iExStyle)

For $o = 1 to 10
        $sItem = "Item " & $o & "|Sub Item " & $o & " - 1"
        GUICtrlCreateListViewItem($sItem, $iListView)
Next


Global $iCurrentSelection, $iOldSelection, $iScrollPos
$hListView = GUICtrlGetHandle($iListView)
$hListViewProc = DllCallbackRegister("_ListViewProc", "int", "hwnd;uint;wparam;lparam")
$pListViewProc = DllCallbackGetPtr($hListViewProc)
$hOldProc = _WinAPI_SetWindowLong($hListView, -4, $pListViewProc)


$iCount = _GUICtrlListView_GetItemCount($hListView)
GUISetState()

Do
Until guiGetMsg() = -3

Func _ListViewProc($hWnd, $iMsg, $wParam, $lparam)
        Local $iCurSel, $iDirect, $iY

        If $iMsg = $WM_MOUSEWHEEL Then
                $iCurSel = _GUICtrlListView_GetSelectedIndices($hWnd, True)
                If $iCurSel[0] = 0 Then Return _WinAPI_CallWindowProc($hOldProc, $hWnd, $iMsg, $wParam, $lparam)
                $iCurrentSelection = $iCurSel[1]
                $iDirect = bitShift($wparam, 0x10) + 120
                If $iDirect Then
                        $iCurrentSelection -= 1
                Else
                        $iCurrentSelection += 1
                EndIf
                If $iCurrentSelection = -1 Then
                        $iCurrentSelection = 0
                ElseIf $iCurrentSelection = $iCount Then
                        $iCurrentSelection -= 1
                EndIf
                _GUICtrlListView_SetItemSelected($hWnd, $iOldSelection, False)
                _GUICtrlListView_SetItemSelected($hWnd, $iCurrentSelection, True)
                $iOldSelection = $iCurrentSelection
                Return 1
        EndIf
        Return _WinAPI_CallWindowProc($hOldProc, $hWnd, $iMsg, $wParam, $lparam)
EndFunc        ;==>_ListViewProc()

评分

参与人数 1金钱 +6 贡献 +6 收起 理由
顽固不化 + 6 + 6

查看全部评分

发表于 2009-4-13 17:11:29 | 显示全部楼层
只能移动高亮,选中项目好像不能移动渥。。。
 楼主| 发表于 2009-4-13 22:15:55 | 显示全部楼层
感谢4楼,回复5楼我的意思就是移动高亮
发表于 2014-5-15 10:36:19 | 显示全部楼层
雷锋精神传天下!谢谢分享!
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-6-26 19:11 , Processed in 0.085267 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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