找回密码
 加入
搜索
查看: 4722|回复: 15

[GUI管理] 思考,如何取得listview控件的状态(已解决)

  [复制链接]
发表于 2016-7-4 11:44:53 | 显示全部楼层 |阅读模式
本帖最后由 tubaba 于 2016-7-7 09:55 编辑

好吧,其实这个问题还是没解决.重新发一次大家思考一下
以下是函数的解释
GUICtrlGetState ( controlID )

与 GUICtrlRead() 不同, 本函数仅返回控件状态:


enabled = 激活
disabled = 禁用
hidden = 隐藏
show = 显示
dropaccepted = 接受拖放

例外:
对于 ListView 控件, 本函数将返回点击的列号.


那么问题来了:如何取得 ListView 控件的状态.显示?隐藏?禁用?启用?
看起来好象不是问题,但是仔细想一下,还真有点复杂


使用ControlCommand命令,可以得到listview的状态.但是....

但是ControlCommand使用有局限性.必须控件在激活状态.
 楼主| 发表于 2016-7-4 11:45:52 | 显示全部楼层
大家可以猜出GUICtrlGetState是调用了哪个API吗?
发表于 2016-7-4 13:25:43 | 显示全部楼层
ControlListView ( "标题", "文本", 控件ID, "命令" [, 选项1 [, 选项2]] )
命令, 选项1, 选项2 结果
"DeSelect", 从 [, 到] 取消一个或多个项目.
"FindItem", "搜索字符串" [, 子项目] 返回字符串项目索引. 若未找到指定字符串,则返回 -1.
"GetItemCount" 返回列表项目的数量.
"GetSelected" [, 选择] 返回选中项目的索引. 如果"选择" = 0 (默认) 则返回第一个选中的项目.
如果"选择" = 1 则返回由 "|" 分隔的所有选中项目, 例如: "0|3|4|10".
如果没有选中任何项目, 则返回空字符串 "".
"GetSelectedCount" 返回选中项目的数量.
"GetSubItemCount" 返回子项目数量.
"GetText", 项目, 子项目 返回指定项目/子项目的文本.
"IsSelected", 项目 项目选中则返回 1, 否则返回值 0.
"Select", 从[, 到] 选中一或多个项目.
"SelectAll" 选中所有项目.
"SelectClear" 清除所有项目的选中状态.
"SelectInvert" 切换当前选择.
"ViewChange", "视图" 切换当前视图样式. 包括:
"list"(列表), "details"(详细信息),
"smallicons"(小图标), "largeicons"(大图标).
所有项目/子项目基于 0 开始计算. 即第一个项目/子项目为 0, 第二个为 1, 依此类推.
ListView32 的 "details"(详细信息)视图中, 可以将 "行" 看作项目, 将 "列" 看作子项.
发表于 2016-7-4 13:26:32 | 显示全部楼层
返回的结果取决于命令, 如下表所列. 若发生错误(如命令无效或找不到窗口/控件),则 @error = 1.
发表于 2016-7-4 15:23:45 | 显示全部楼层
回复 1# tubaba

比較好奇的是  你要取得自己寫的程式的 LISTVIEW 是 ENABLE  還是 DISABLE

還是 第三方程式的??
 楼主| 发表于 2016-7-4 17:39:46 | 显示全部楼层
回复 5# kk_lee69


    自己程式内的
发表于 2016-7-4 17:54:58 | 显示全部楼层
回复 6# tubaba

自己程式   難道無法判定  這時候 LISTVIEW 狀態是如何嗎??

當然如果你只是純粹想了解 語法問題   當然就無可厚非

不然 實務上 應該很多方法 都可以記錄目前的 LISTVIEW 狀態吧
 楼主| 发表于 2016-7-5 08:42:02 | 显示全部楼层
回复 7# kk_lee69


    哪你有啥好办法呢?在未知此控件状态下如何查询listview状态.
发表于 2016-7-5 08:45:22 | 显示全部楼层
自己写的,定个返回值就好啦
发表于 2016-7-5 09:12:40 | 显示全部楼层
回复 8# tubaba

所有程式  一開始 都是 ENABLE 的   你設個專屬的變數 設為 0
當你 DISABLE 的時候 就將變數 設為 1  
當你 ENALBE 的時候  就將變數  設為 0
你查那個變數 就知道目前狀態不是
 楼主| 发表于 2016-7-6 14:17:07 | 显示全部楼层
回复 10# kk_lee69


    靠人工计总不是那么可靠,这种方法是下下之策
发表于 2016-7-6 16:48:39 | 显示全部楼层
回复 11# tubaba

那我就不會了 呵呵   我只會最不可靠的方法
发表于 2016-7-6 18:36:25 | 显示全部楼层
本帖最后由 nmgwddj 于 2016-7-6 18:37 编辑

https://msdn.microsoft.com/zh-cn/library/windows/desktop/ms646303(v=vs.85).aspx


#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>

$Form1 = GUICreate("Form1", 267, 223)
$ListView1 = GUICtrlCreateListView("1|2|3", 8, 8, 250, 150)
$Button1 = GUICtrlCreateButton("Button1", 88, 176, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button1
                        MsgBox(0, '', IsWindowEnable(GUICtrlGetHandle($ListView1)) ? "启用" : "禁用")
                        GUICtrlSetState($ListView1, $GUI_DISABLE)
                        MsgBox(0, '', IsWindowEnable(GUICtrlGetHandle($ListView1)) ? "启用" : "禁用")

        EndSwitch
WEnd

Func IsWindowEnable($hWnd)
        Local $bIsEnable = True
        Local $bRet = DllCall('User32.dll', 'bool', 'IsWindowEnabled', 'hwnd', $hWnd)
        If Not @error Then
                $bIsEnable = $bRet[0]
        EndIf
        Return $bIsEnable
EndFunc
发表于 2016-7-6 18:48:21 | 显示全部楼层
https://www.autoitscript.com/aut ... IsWindowEnabled.htm

#include <WinAPISys.au3>
_WinAPI_IsWindowEnabled ( $hWnd )
 楼主| 发表于 2016-7-7 09:53:59 | 显示全部楼层
回复 14# nmgwddj


    谢谢回答,其实这个函数我以前试过的.可能什么地方出错了.没达到预期效果,我以为不行.今天一试又行了,
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>

$Form1 = GUICreate("Form1", 267, 223)
$ListView1 = GUICtrlCreateListView("1|2|3", 8, 8, 250, 150)
$Button1 = GUICtrlCreateButton("查看", 68, 176, 75, 25)
$Button2 = GUICtrlCreateButton("更改状态", 150, 176, 75, 25)
$radio1 = GUICtrlCreateRadio("radio1", 88, 202, 75, 25)
$radio2 = GUICtrlCreateRadio("radio2", 170, 202, 75, 25)
Local $Showhide, $Enabledisable

GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button1
                        MsgBox(0, '', IsWindowEnable(GUICtrlGetHandle($ListView1)) ? "启用" : "禁用")
                        MsgBox(0, '', IsWindowVisible(GUICtrlGetHandle($ListView1)) ? "显示" : "隐藏")
                Case $Button2
                        If Random(0, 1, 1) Then
                                $Showhide = $GUI_SHOW
                        Else
                                $Showhide = $GUI_HIDE
                        EndIf
                        If Random(0, 1, 1) Then
                                $Enabledisable = $GUI_ENABLE
                        Else
                                $Enabledisable = $GUI_DISABLE
                        EndIf
                        GUICtrlSetState($ListView1, BitOR($Showhide,$Enabledisable))
        EndSwitch
WEnd
 
Func IsWindowEnable($hWnd)
        Local $aRet = DllCall('user32.dll', 'bool', 'IsWindowEnabled', 'hwnd', $hWnd)
        If @error Then Return SetError(@error, @extended, False)
        Return $aRet[0]
EndFunc 

Func IsWindowVisible($hWnd)
        Local $aResult = DllCall("user32.dll", "bool", "IsWindowVisible", "hwnd", $hWnd)
        If @error Then Return SetError(@error, @extended, 0)
        Return $aResult[0]
EndFunc 
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-18 12:29 , Processed in 0.089414 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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