找回密码
 加入
搜索
查看: 6403|回复: 14

[AU3基础] 获取鼠标点击事件的地址[已解决]

 火.. [复制链接]
发表于 2010-4-23 13:56:23 | 显示全部楼层 |阅读模式
本帖最后由 cdrobin 于 2010-4-23 23:56 编辑

水木子 大哥写的一段代码  我试了很就都没有办法 获取到 $Index 的坐标 鼠标点击后会提示鼠标所在的数字号!

怎么可以把鼠标点击所在的坐标 返回出来 给别的窗口调用!

意思是我点击鼠标 $ListView1 里面的内容 就打开另外的窗口或事件!

就是有什么方法可以调用 鼠标事件 里获取的鼠标坐标 $Index 的坐标!
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <GUIListView.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$Form1 = GUICreate("Form1", 516, 398, 192, 114)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
$ListView1 = GUICtrlCreateListView("111", 40, 32, 129, 313)
$ListView2 = GUICtrlCreateListView("222", 216, 32, 257, 313)

GUISetState(@SW_SHOW)

For $I = 1 To 10
        GUICtrlCreateListViewItem($I, $ListView1)
Next

Do
Until GUIGetMsg() = -3

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
        Local $tNMTV, $iCode, $hItem
        $tNMTV = DllStructCreate($tagNMTVDISPINFO, $ilParam)
        $iCode = DllStructGetData($tNMTV, "Code")
        $Index = _GUICtrlListView_GetSelectedIndices($ListView1)
        If $iCode = $NM_DBLCLK And StringLen($Index) <> 0 Then MsgBox(0, 0, _GUICtrlListView_GetItemText($ListView1, Number($Index), 0))
        If $iCode = $NM_RCLICK And StringLen($Index) <> 0 Then _GUICtrlListView_DeleteItem($ListView1, Number($Index))
                
EndFunc   ;==>WM_NOTIFY

评分

参与人数 1金钱 +10 收起 理由
afan + 10 感谢主动将修改帖子分类为[已解决],请继续 ...

查看全部评分

发表于 2010-4-23 16:19:32 | 显示全部楼层
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <GUIListView.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$Form1 = GUICreate("Form1", 516, 398, 192, 114)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
$ListView1 = GUICtrlCreateListView("111", 40, 32, 129, 313)
$ListView2 = GUICtrlCreateListView("222", 216, 32, 257, 313)

GUISetState(@SW_SHOW)

For $I = 1 To 10
        GUICtrlCreateListViewItem($I, $ListView1)
Next

Do
Until GUIGetMsg() = -3

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
        Local $tNMTV, $iCode, $hItem
        $tNMTV = DllStructCreate($tagNMTVDISPINFO, $ilParam)
        $iCode = DllStructGetData($tNMTV, "Code")
        $Index = _GUICtrlListView_GetSelectedIndices($ListView1)
        If $iCode = $NM_DBLCLK And StringLen($Index) <> 0 Then
                $mousepos = MouseGetPos()
                MsgBox(4096, "test", "x=" & $mousepos[0] & ",y=" & $mousepos[1]);MsgBox(0, 0, _GUICtrlListView_GetItemText($ListView1, Number($Index), 0))
        EndIf
        If $iCode = $NM_RCLICK And StringLen($Index) <> 0 Then _GUICtrlListView_DeleteItem($ListView1, Number($Index))

EndFunc   ;==>WM_NOTIFY
 楼主| 发表于 2010-4-23 16:25:51 | 显示全部楼层
回复二楼我不是这个意思 !!!!  我的意思是 列表里有 1 到 10 的数字! 我要在另外一个窗口调用鼠标点击 所在的数字!  如!我点了  数字 5        我想在另外一个窗口调用这 数字5!!
发表于 2010-4-23 16:48:24 | 显示全部楼层
你要获取鼠标点击的列表中的元素是什么 只需要看2楼代码中的这句就可以了
 $Index = _GUICtrlListView_GetSelectedIndices($ListView1)
$Index 就是你要的鼠标点击的元素。
发表于 2010-4-23 17:00:39 | 显示全部楼层
这是楼主要的吗?
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <GUIListView.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$Form1 = GUICreate("Form1", 516, 398, 192, 114)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
$ListView1 = GUICtrlCreateListView("111", 40, 32, 129, 313)
$ListView2 = GUICtrlCreateListView("222", 216, 32, 257, 313)

GUISetState(@SW_SHOW)

For $I = 1 To 10
        GUICtrlCreateListViewItem($I, $ListView1)
Next

Do
Until GUIGetMsg() = -3

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
        Local $tNMTV, $iCode, $hItem
        $tNMTV = DllStructCreate($tagNMTVDISPINFO, $ilParam)
        $iCode = DllStructGetData($tNMTV, "Code")
        $Index = _GUICtrlListView_GetSelectedIndices($ListView1)
        If $iCode = $NM_DBLCLK And StringLen($Index) <> 0 Then _GUICtrlListView_AddItem($ListView2,_GUICtrlListView_GetItemText($ListView1, Number($Index), 0));MsgBox(0, 0, _GUICtrlListView_GetItemText($ListView1, Number($Index), 0))                
        If $iCode = $NM_RCLICK And StringLen($Index) <> 0 Then _GUICtrlListView_DeleteItem($ListView1, Number($Index))
                
EndFunc   ;==>WM_NOTIFY
 楼主| 发表于 2010-4-23 17:33:45 | 显示全部楼层
本帖最后由 cdrobin 于 2010-4-23 17:35 编辑

不是这个意思!!很感谢你的帮助!!!!   我从新做了个你看看!!!我的意思是! 鼠标点 列表里面的数 就打开新的窗口!
我这个程序! 你试一下点!  测试点击    这个标题! 我想要这样的效果!!!
#include <Date.au3>
#include <Array.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <GUIListView.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

Local $xun,$xunze,$daan,$xun2,$lujin,$tupian,$i,$w

$Form1 = GUICreate("Form1", 675, 408, 200, 147)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
$ListView1 = GUICtrlCreateListView("测试点击", 32, 40, 113, 279)
$ListView2 = GUICtrlCreateListView("", 200, 40, 449, 273)

GUISetState(@SW_SHOW)
For $I = 1 To 10
        GUICtrlCreateListViewItem($I, $ListView1)
Next

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $ListView1    ;我想这里调用鼠标所点的那个数后打开窗口
        GUISetState(@SW_HIDE,$Form1)
        $Form2 = GUICreate("Form2", 488, 451, 192, 132)
        $Button1 = GUICtrlCreateButton("OK", 108, 200, 181, 41)
        GUISetState(@SW_SHOW)
        
        While 1
                $Msg_about = GUIGetMsg()
                Select
                        Case $Msg_about = $gui_event_close Or $Msg_about = $Button1
                                GUIDelete($Form2) ;关闭窗口
                                GUISetState(@SW_SHOW,$Form1)  ;显示主窗口
                                GUISetState(@SW_ENABLE, $Form1)
                                ExitLoop
                EndSelect
        WEnd
EndSwitch
WEnd

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
        Local $tNMTV, $iCode, $hItem
        $tNMTV = DllStructCreate($tagNMTVDISPINFO, $ilParam)
        $iCode = DllStructGetData($tNMTV, "Code")
        $Index = _GUICtrlListView_GetSelectedIndices($ListView1)
        If $iCode = $NM_DBLCLK And StringLen($Index) <> 0 Then MsgBox(0, 0, _GUICtrlListView_GetItemText($ListView1, Number($Index), 0))
        If $iCode = $NM_RCLICK And StringLen($Index) <> 0 Then _GUICtrlListView_DeleteItem($ListView1, Number($Index))
 EndFunc   ;==>WM_NOTIFY
发表于 2010-4-23 21:19:25 | 显示全部楼层
本帖最后由 shqf 于 2010-4-23 22:50 编辑

窗口form可以有几个,一开始应先建立,只是有的先隐藏而已,需要的时候再显示而已。在6楼程序的基础上稍稍改了一下,双击左边的ITEM,能弹出MSGBOX窗口,已含点击的元素。代码如下(没有用到FORM2,但如果要用的话,如下代码建立在form1后面,While之前):
#include <Date.au3>
#include <Array.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <GUIListView.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

Local $xun, $xunze, $daan, $xun2, $lujin, $tupian, $i, $w

$Form1 = GUICreate("Form1", 675, 408, 200, 147)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
$ListView1 = GUICtrlCreateListView("测试点击", 32, 40, 113, 279)
$ListView2 = GUICtrlCreateListView("", 200, 40, 449, 273)
GUISetState(@SW_SHOW)

$Form2 = GUICreate("Form2", 488, 451, 192, 132)
$Button1 = GUICtrlCreateButton("OK", 108, 200, 181, 41)
GUISetState(@SW_HIDE)

For $i = 1 To 10
        GUICtrlCreateListViewItem($i, $ListView1)
Next

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit                
        EndSwitch
WEnd

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
        Local $tNMTV, $iCode, $hItem
        $tNMTV = DllStructCreate($tagNMTVDISPINFO, $ilParam)
        $iCode = DllStructGetData($tNMTV, "Code")
        $Index = _GUICtrlListView_GetSelectedIndices($ListView1)
        If $iCode = $NM_DBLCLK And StringLen($Index) <> 0 Then MsgBox(0, 0, _GUICtrlListView_GetItemText($ListView1, Number($Index), 0))
        If $iCode = $NM_RCLICK And StringLen($Index) <> 0 Then _GUICtrlListView_DeleteItem($ListView1, Number($Index))
EndFunc   ;==>WM_NOTIFY
 楼主| 发表于 2010-4-23 22:13:34 | 显示全部楼层
感谢 7 楼的回复!! 但我不是这个意思啊!!! 你说的我不是很明白!!!我学习 AU 就一个星期!有很多地方不明白!对不起!如果可以拿例子来说明是做好的!!! 第二个窗口我不是拿来隐藏的!使用完第二个窗口我要关闭! 再打开的时候!要从新写数据到另一个文件的!
点击 测试点击 就调用另一个窗口!
我想 点列表里面的数字 来 调用另一个窗口!
发表于 2010-4-23 22:56:19 | 显示全部楼层
有些不明白

个人猜想一下用子窗口能不能实现你想要的功能
这个例子是不是你想要的。。
#include <GUIConstantsEx.au3>


_Main()

Func _Main()

        ;Initialize variables
        Local $GUIWidth = 250, $GUIHeight = 250
        Local $ParentWin, $ParentWin_Pos, $ChildWin, $msg

        ;Create main/parent window
$ParentWin = GUICreate("父窗体", $GUIWidth, $GUIHeight)
        ;Save the position of the parent window
        $ParentWin_Pos = WinGetPos($ParentWin, "")
        ;Show the parent window/Make the parent window visible
        GUISetState(@SW_SHOW)

        ;Create child window and add the parameter to make it the child of the parent window
$ChildWin = GUICreate("子窗体", $GUIWidth, $GUIHeight, $ParentWin_Pos[0] + 100, $ParentWin_Pos[1] + 100, -1, -1, $ParentWin)
        ;Show the child window/Make the child window visible
        GUISetState(@SW_SHOW)

        ;Switch to the parent window
        GUISwitch($ParentWin)

        ;Loop until:
        ;- user presses Esc when focused to the parent window
        ;- user presses Alt+F4 when focused to the parent window
        ;- user clicks the close button of the parent window
        While 1
                ;After every loop check if the user clicked something in the GUI windows
                $msg = GUIGetMsg(1)
                Select
                        ;Check if user clicked on a close button of any of the 2 windows
                        Case $msg[0] = $GUI_EVENT_CLOSE
                                ;Check if user clicked on the close button of the child window
                                If $msg[1] = $ChildWin Then
            MsgBox(64, "测试", "您关闭了子窗体.")
                                        ;Switch to the child window
                                        GUISwitch($ChildWin)
                                        ;Destroy the child GUI including the controls
                                        GUIDelete()
                                        ;Check if user clicked on the close button of the parent window
                                ElseIf $msg[1] = $ParentWin Then
            MsgBox(64, "测试", "您关闭了父窗体.")
                                        ;Switch to the parent window
                                        GUISwitch($ParentWin)
                                        ;Destroy the parent GUI including the controls
                                        GUIDelete()
                                        ;Exit the script
                                        Exit
                                EndIf

                EndSelect

        WEnd
EndFunc   ;==>_Main
 楼主| 发表于 2010-4-23 23:10:41 | 显示全部楼层
感谢 9 楼的朋友! 我不是要这样的效果!!

我是要 鼠标点击 列表里的内容  当鼠标点击列表内容 就打开窗口2   

我的意思!! 是不是我的表达能力有问题啊1!!!!!
发表于 2010-4-23 23:24:33 | 显示全部楼层
本帖最后由 shqf 于 2010-4-23 23:26 编辑

那是这样吗?
#include <GUIConstantsEx.au3>

Local $ITEM[11]
$Form1 = GUICreate("Form1", 675, 408, 200, 147)
$ListView1 = GUICtrlCreateListView("测试点击", 32, 40, 113, 279)
For $i = 1 To 10
        $ITEM[$i] = GUICtrlCreateListViewItem($i, $ListView1)
Next
$ListView2 = GUICtrlCreateListView("", 200, 40, 449, 273)
GUISetState(@SW_SHOW)

$Form2 = GUICreate("Form2", 488, 451, 192, 132)
$LABEL = GUICtrlCreateLabel("", 10, 10, 20, 25)
$Button1 = GUICtrlCreateButton("OK", 108, 200, 181, 41)
GUISetState(@SW_HIDE)

While 1
        $nMsg = GUIGetMsg()
        If $nMsg = $GUI_EVENT_CLOSE Then Exit
        If $nMsg = $Button1 Then GUISetState(@SW_HIDE, $Form2)
        For $i = 1 To 10
                If $nMsg = $ITEM[$i] Then
                        GUICtrlSetData($LABEL, $i)
                        GUISetState(@SW_SHOW, $Form2)
                EndIf
        Next
WEnd

评分

参与人数 1金钱 +20 收起 理由
afan + 20

查看全部评分

 楼主| 发表于 2010-4-23 23:37:26 | 显示全部楼层
感谢 11 楼 我就是要这样的效果!如果要你的代码!请问怎么样在 打开的同时 就删除列表所点 的数呢?

比如 我点了 5号 调用了 窗口! 列表里面的 5 号数就删除了! 你这个怎么可以这样啊! 没有了鼠标事件啊!
发表于 2010-4-23 23:49:20 | 显示全部楼层
本帖最后由 shqf 于 2010-4-23 23:52 编辑

在此句 GUISetState(@SW_SHOW, $Form2) 下面
加上这一句 GUICtrlDelete ($ITEM[$i]) 就行。
另LISTVIEW项目控件单击无需特别定义函数来接收,双击需要。
 楼主| 发表于 2010-4-23 23:56:11 | 显示全部楼层
感谢 shqf  我就是要这样的效果!!再次感谢你!!

继续写我的代码去!!! 新手真是累啊!! 我要一边写一边看帮助啊!!!

感谢你!!!!! 努力学习中!!!!!
发表于 2010-4-24 06:42:24 | 显示全部楼层
真有耐心.....
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-6-18 04:28 , Processed in 0.092224 second(s), 25 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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