找回密码
 加入
搜索
查看: 2048|回复: 7

[AU3基础] 如何得知 LISTVIEW 的可见范围内的 SubItem 各是多少??[已解決]

[复制链接]
发表于 2020-8-2 22:45:15 | 显示全部楼层 |阅读模式
本帖最后由 kk_lee69 于 2020-8-6 19:54 编辑

LISTVIEW 比较小 项目比较多时,通常我们会移动下面的滚动条
此时  如何得知 最左边 与最右边的 subItem 是哪个??
有人研究过这个吗??











#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Example()
Func Example()
    Local $listview, $button, $item1, $item2, $item3, $msg
    GUICreate("列表視圖項目", 220, 250, 100, 200, -1, $WS_EX_ACCEPTFILES)
    GUISetBkColor(0x00E0FFFF) ; 改變背景顏色
    $listview = GUICtrlCreateListView("列0    |列1   |列2   |列3   |列4    |列5    |列6    |列7   |列8  ", 10, 10, 200, 150);,$LVS_SORTDESCENDING)
    $button = GUICtrlCreateButton(" LISTVIEW可見範圍的SUBITEM 為: ", 10, 170, 200, 20)
    $item1 = GUICtrlCreateListViewItem ("項目 2|列22|列23", $listview)
    $item2 = GUICtrlCreateListViewItem ("............項目 1|列12|列13", $listview)
    $item3 = GUICtrlCreateListViewItem ("項目 3|列32|列33", $listview)
    GUICtrlCreateInput("", 20, 200, 150)
    GUICtrlSetState(-1, $GUI_DROPACCEPTED) ; 允許拖放
    GUISetState()
    GUICtrlSetData($item2, "|項目 1")
    GUICtrlSetData($item3, "||列33")
    GUICtrlDelete($item1)
    Do
        $msg = GUIGetMsg()
        Select
            Case $msg = $button
               
            Case $msg = $listview
                MsgBox(0, "列表視圖", "點擊列=" & GUICtrlGetState($listview), 2)
        EndSelect
    Until $msg = $GUI_EVENT_CLOSE
EndFunc   ;==>Example



本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2020-8-2 23:03:18 | 显示全部楼层
用 _GUICtrlListView_GetSubItemRect() 试试~
 楼主| 发表于 2020-8-2 23:56:54 | 显示全部楼层
afan 发表于 2020-8-2 23:03
用 _GUICtrlListView_GetSubItemRect() 试试~

這個有試過  只能判斷出 左邊的 因為 超出  可視範圍的 subitem 的座標會是 負的  可以判斷

但是右邊的 就無法理解跟判斷了
发表于 2020-8-3 00:02:48 | 显示全部楼层
#include <WindowsConstants.au3>
#include <GuiListView.au3>

Example()
Func Example()
        Local $listview, $button, $item1, $item2, $item3, $msg, $iInput
        GUICreate("列表視圖項目", 220, 250, 100, 200, -1, $WS_EX_ACCEPTFILES)
        $listview = GUICtrlCreateListView("列0    |列1   |列2   |列3   |列4    |列5    |列6    |列7   |列8  ", 10, 10, 200, 150);,$LVS_SORTDESCENDING)
        $button = GUICtrlCreateButton(" LISTVIEW可見範圍的SUBITEM 為: ", 10, 170, 200, 20)
        $item1 = GUICtrlCreateListViewItem("項目 2|列22|列23", $listview)
        $item2 = GUICtrlCreateListViewItem("............項目 1|列12|列13", $listview)
        $item3 = GUICtrlCreateListViewItem("項目 3|列32|列33", $listview)
        $iInput = GUICtrlCreateInput("", 20, 200, 150)
        GUISetState()
        Do
                Switch GUIGetMsg()
                        Case $button
                                GUICtrlSetData($iInput, _GetLVWSubVisible($listview, 200))
                        Case -3
                                Exit
                EndSwitch
        Until 0
EndFunc   ;==>Example
Func _GetLVWSubVisible($idListview, $iW)
        Local $ii, $aRect, $ixL = -1, $ixR
        Local $iCC = _GUICtrlListView_GetColumnCount($idListview)
        For $ii = 1 To $iCC - 1
                $aRect = _GUICtrlListView_GetSubItemRect($idListview, 0, $ii)
                If ($aRect[0] + $aRect[2]) < 1 Then ContinueLoop
                If $ixL < 0 Then
                        If $aRect[0] > 1 Then
                                $ixL = $ii - 1
                        Else
                                $ixL = $ii
                        EndIf
                EndIf
                If $aRect[2] >= $iW Or $ii = ($iCC - 1) Then
                        $ixR = $ii
                        ExitLoop
                EndIf
        Next
        Return $ixL & ' - ' & $ixR
EndFunc   ;==>_GetLVWSubVisible
发表于 2020-8-3 00:07:22 | 显示全部楼层
另外你可以设置露出的阈值,比如露出20才算。根据你的程序用途自行调节吧。
 楼主| 发表于 2020-8-3 00:22:51 | 显示全部楼层
afan 发表于 2020-8-3 00:07
另外你可以设置露出的阈值,比如露出20才算。根据你的程序用途自行调节吧。

ㄟ  厲害喔

我研究一下  感謝 afan 老大   幫了大忙!!
 楼主| 发表于 2020-8-3 00:51:39 | 显示全部楼层
afan 发表于 2020-8-3 00:07
另外你可以设置露出的阈值,比如露出20才算。根据你的程序用途自行调节吧。

老大  這個方法可用 細節我在處理  不過我現在 遇到一個困難 就是  $iW  參數 我需鰾變成活動的,因為我的程式裡面 會有各式各樣的 LISTVIEW 每個大小都不一定

我如何從  LISTVIEW 的句柄 知道 他的 可視範圍寬度
发表于 2020-8-3 00:59:36 | 显示全部楼层
kk_lee69 发表于 2020-8-3 00:51
老大  這個方法可用 細節我在處理  不過我現在 遇到一個困難 就是  $iW  參數 我需鰾變成活動的,因為我 ...

句柄的话用 WinGetPos() 就行了...
WinGetPos(GUICtrlGetHandle($listview))
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-4-20 10:11 , Processed in 0.085000 second(s), 20 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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