找回密码
 加入
搜索
查看: 1992|回复: 3

[AU3基础] 在Tab中的listbox的双击事件触发问题

[复制链接]
发表于 2011-9-13 11:31:47 | 显示全部楼层 |阅读模式
如何双击某listbox中项目时触发事件
http://www.autoitx.com/forum.php ... p;highlight=listbox
这个帖子5楼中给的例子很好用:)
不过我把listbox放在Tab中后, 貌似就不管用了, 对Tab的使用不是很了解, 帮助!
#include <GUIListBox.au3>
#include <WindowsConstants.au3>

 $hGUI = GUICreate("ListBox test", 401, 297, 192, 125)
$Tab1 = GUICtrlCreateTab(24, 16, 313, 249)
$TabSheet1 = GUICtrlCreateTabItem("TabSheet1")
$hListBox = GUICtrlCreateList("", 40, 48, 273, 188)
GUICtrlCreateTabItem("")
GUISetState(@SW_SHOW)

;~ $hGUI = GUICreate("ListBox test", 400, 296)
;~ $hListBox = _GUICtrlListBox_Create($hGUI, "", 2, 2, 396, 296, $LBS_EXTENDEDSEL)
;~ GUISetState()

GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
_GUICtrlListBox_Dir($hListBox, @WindowsDir & "\win*.exe")
_GUICtrlListBox_AddFile($hListBox, @WindowsDir & "\Notepad.exe")
Do
Until GUIGetMsg() = -3

Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
        #forceref $hWnd, $iMsg
        Local $hWndFrom, $iIDFrom, $iCode, $hWndListBox
        If Not IsHWnd($hListBox) Then $hWndListBox = GUICtrlGetHandle($hListBox)
        $hWndFrom = $ilParam
        $iIDFrom = BitAND($iwParam, 0xFFFF) ; Low Word
        $iCode = BitShift($iwParam, 16) ; Hi Word
        Switch $hWndFrom
                Case $hListBox, $hWndListBox
                        Switch $iCode
                                Case $LBN_DBLCLK
                                        $txt = _GUICtrlListBox_GetSelItemsText($hListBox)
                                        If $txt[0] > 0 Then MsgBox(0, '高亮项目', $txt[1])
                        EndSwitch
        EndSwitch
        Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND
发表于 2011-9-13 11:44:57 | 显示全部楼层
本帖最后由 水木子 于 2011-9-13 11:46 编辑

#include <GUIListBox.au3>
#include <WindowsConstants.au3>

$hGUI = GUICreate('ListBox test', 400, 300)
$Tab1 = GUICtrlCreateTab(5, 5, 390, 290)
$TabSheet1 = GUICtrlCreateTabItem('TabSheet1')
$hListBox = _GUICtrlListBox_Create($hGUI, '', 15, 35, 370, 250, $LBS_EXTENDEDSEL)
GUICtrlCreateTabItem('')
GUISetState()
GUIRegisterMsg($WM_COMMAND, 'WM_COMMAND')

_GUICtrlListBox_Dir($hListBox, @WindowsDir & '\win*.exe')
_GUICtrlListBox_AddFile($hListBox, @WindowsDir & '\Notepad.exe')

Do
Until GUIGetMsg() = -3

Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
        Local $hWndFrom, $iIDFrom, $iCode, $hWndListBox
        If Not IsHWnd($hListBox) Then $hWndListBox = GUICtrlGetHandle($hListBox)
        $hWndFrom = $ilParam
        $iIDFrom = BitAND($iwParam, 0xFFFF) ; Low Word
        $iCode = BitShift($iwParam, 16) ; Hi Word
        Switch $hWndFrom
                Case $hListBox, $hWndListBox
                        Switch $iCode
                                Case $LBN_DBLCLK
                                        $txt = _GUICtrlListBox_GetSelItemsText($hListBox)
                                        If $txt[0] > 0 Then MsgBox(0, '高亮项目', $txt[1])
                        EndSwitch
        EndSwitch
        Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND
 楼主| 发表于 2011-9-13 14:09:03 | 显示全部楼层
本帖最后由 runtium 于 2011-9-13 14:10 编辑

谢谢了, 水木子

这个的确可行,

不过如果有tab有多个page, 每个page有不同的控件时, 界面显示貌似会有问题啊
发表于 2011-9-13 14:14:29 | 显示全部楼层
还是水版热心.....
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-9-21 01:44 , Processed in 0.086611 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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