找回密码
 加入
搜索
查看: 3659|回复: 8

请问ListView如何双击项目弹出对话框

[复制链接]
发表于 2008-6-24 23:09:35 | 显示全部楼层 |阅读模式
下面的例子,可以在选中一项后,点击一个按钮得到当前行的数据。
我想实现双击该项,得不到项的数据,看完了帮助还是不会,请会的朋友指导一下。

#include <GUIConstants.au3>

GUICreate("listview items",220,250, 100,200,-1,$WS_EX_ACCEPTFILES)
GUISetBkColor (0x00E0FFFF)  ; will change background color

$listview = GUICtrlCreateListView ("col1  |col2|col3  ",10,10,200,150);,$LVS_SORTDESCENDING)
$button = GUICtrlCreateButton ("Value?",75,170,70,20)
$item1=GUICtrlCreateListViewItem("item2|col22|col23",$listview)
$item2=GUICtrlCreateListViewItem("item1|col12|col13",$listview)
$item3=GUICtrlCreateListViewItem("item3|col32|col33",$listview)
$input1=GUICtrlCreateInput("",20,200, 150)
GUICtrlSetState(-1,$GUI_DROPACCEPTED)   ; to allow drag and dropping
GUISetState()
GUICtrlSetData($item2,"ITEM1")
GUICtrlSetData($item3,"||COL33")
GUICtrlDelete($item1)

Do
  $msg = GUIGetMsg ()
          
   Select
      Case $msg = $button
         MsgBox(0,"listview item",GUICtrlRead(GUICtrlRead($listview)),2)
      Case $msg = $listview
         MsgBox(0,"listview", "clicked="& GUICtrlGetState($listview),2)
   EndSelect
Until $msg = $GUI_EVENT_CLOSE


[ 本帖最后由 itljl 于 2008-6-27 21:31 编辑 ]
发表于 2008-6-24 23:40:23 | 显示全部楼层
这可能需要“鼠标事件”来处理。我也没找到,共同等待高手~
发表于 2008-6-25 00:16:18 | 显示全部楼层
你要的是双击事件吗?

 
#include <GuiConstants.au3>;Inclusion file for the GUI interface controls
#include <GuiListView.au3>
#region Global variables
Global $ListView
Global Const $WM_NOTIFY = 0x004E
Global Const $DebugIt = 1
;ListView Events
Global Const $NM_FIRST = 0
Global Const $NM_CLICK = ($NM_FIRST - 2)
Global Const $NM_DBLCLK = ($NM_FIRST - 3)
#endregion End Global variables
Opt("WinTitleMatchMode", 2)
$main_GUI = GUICreate("GuiRegisterMsg Test", 225, 400, 300, 10, BitOR($WS_THICKFRAME, $WS_SIZEBOX))
$ListView = GUICtrlCreateListView("Entry Name|Category", 5, 75, 195, 280, BitOR($LVS_SORTASCENDING, $LVS_SINGLESEL))
_GUICtrlListViewSetColumnWidth ($ListView, 0, 100)
_GUICtrlListViewSetColumnWidth ($ListView, 1, 100)
GUICtrlSendMsg($ListView, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_GRIDLINES, $LVS_EX_GRIDLINES)
GUICtrlSendMsg($ListView, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_FULLROWSELECT, $LVS_EX_FULLROWSELECT)
GUICtrlCreateListViewItem("Name 1|Category 1", $ListView)
GUICtrlCreateListViewItem("Name 2|Category 2", $ListView)
GUISetState()
;Register WM_NOTIFY events
GUIRegisterMsg($WM_NOTIFY, "WM_Notify_Events")
While 1
$msg = GUIGetMsg()
Switch $msg
;-----------------------------------------------------------------------------------------
;This case statement exits and updates code if needed
Case $GUI_EVENT_CLOSE
Exit
;-----------------------------------------------------------------------------------------
;put all the misc. stuff here
Case Else
;;;
EndSwitch
WEnd
Func ListView_Click()
;----------------------------------------------------------------------------------------------
If $DebugIt Then _DebugPrint("$NM_CLICK")
;----------------------------------------------------------------------------------------------
EndFunc ;==>ListView_Click
Func ListView_DoubleClick()
;----------------------------------------------------------------------------------------------
If $DebugIt Then _DebugPrint ("$NM_DBLCLK")
;----------------------------------------------------------------------------------------------
MsgBox(0,"Double Clicked", _GUICtrlListViewGetItemText ($ListView, _GUICtrlListViewGetSelectedIndices($ListView)))
EndFunc ;==>ListView_DoubleClick
;
; WM_NOTIFY event handler
Func WM_Notify_Events($hWndGUI, $MsgID, $wParam, $lParam)
#forceref $hWndGUI, $MsgID, $wParam
Local $tagNMHDR, $event, $hwndFrom, $code
$tagNMHDR = DllStructCreate("int;int;int", $lParam) ;NMHDR (hwndFrom, idFrom, code)
If @error Then Return
$event = DllStructGetData($tagNMHDR, 3)
Select
Case $wParam = $ListView
Select
Case $event = $NM_CLICK
ListView_Click ()
Case $event = $NM_DBLCLK
ListView_DoubleClick ()
EndSelect
EndSelect
$tagNMHDR = 0
$event = 0
$lParam = 0
EndFunc ;==>WM_Notify_Events
Func _DebugPrint($s_text)
ConsoleWrite( _
"!===========================================================" & @LF & _
"+===========================================================" & @LF & _
"-->" & $s_text & @LF & _
"+===========================================================" & @LF)
EndFunc ;==>_DebugPrint
发表于 2008-6-25 00:33:19 | 显示全部楼层
前期是用判断鼠标移动到该控件的方式来处理。

不过现在更新了,直接注册一个事件来处理了。楼上回答正确。

现在列表非常强大的说。。。。
 楼主| 发表于 2008-6-25 18:16:31 | 显示全部楼层
谢谢解答,但有错误
au3版本:.3.2.9.3.1

本帖子中包含更多资源

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

×
发表于 2008-6-25 19:33:58 | 显示全部楼层
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

GUICreate("listview items",220,250, 100,200,-1,$WS_EX_ACCEPTFILES)
GUISetBkColor (0x00E0FFFF)  ; will change background color

$listview = GUICtrlCreateListView ("col1  |col2|col3  ",10,10,200,150);,$LVS_SORTDESCENDING)
$button = GUICtrlCreateButton ("Value?",75,170,70,20)
$item1=GUICtrlCreateListViewItem("item2|col22|col23",$listview)
$item2=GUICtrlCreateListViewItem("item1|col12|col13",$listview)
$item3=GUICtrlCreateListViewItem("item3|col32|col33",$listview)
$input1=GUICtrlCreateInput("",20,200, 150)
GUICtrlSetState(-1,$GUI_DROPACCEPTED)   ; to allow drag and dropping
GUIRegisterMsg($WM_NOTIFY, "WM_Notify_Events")
GUISetState()
GUICtrlSetData($item2,"ITEM1")
GUICtrlSetData($item3,"||COL33")
GUICtrlDelete($item1)

Do
  $msg = GUIGetMsg ()
         
   Select
      Case $msg = $button
         MsgBox(0,"listview item",GUICtrlRead(GUICtrlRead($listview)),2)
      Case $msg = $listview
         MsgBox(0,"listview", "clicked="& GUICtrlGetState($listview),2)
   EndSelect
Until $msg = $GUI_EVENT_CLOSE
Func WM_Notify_Events($hWndGUI, $MsgID, $wParam, $lParam)
Local $tagNMHDR, $event, $hwndFrom, $code
$tagNMHDR = DllStructCreate("int;int;int", $lParam)
If @error Then Return
$event = DllStructGetData($tagNMHDR, 3)
If $wParam = $ListView And $event = $NM_DBLCLK Then msgbox(0,"","你双击了listview项目")
$tagNMHDR = 0
$event = 0
$lParam = 0
EndFunc


此脚本在3.2.11.10.1测试成功

[ 本帖最后由 mfknui 于 2008-6-25 19:39 编辑 ]
 楼主| 发表于 2008-6-27 21:31:11 | 显示全部楼层
谢谢楼上的朋友。
发表于 2014-4-2 20:29:52 | 显示全部楼层
GUICtrlRead(GUICtrlRead($listview))
还第一次见到这种用法。
发表于 2014-5-10 22:52:27 | 显示全部楼层
第一次见到这种用法
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-11-16 08:24 , Processed in 0.074782 second(s), 20 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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