runtium 发表于 2011-9-13 11:31:47

在Tab中的listbox的双击事件触发问题

如何双击某listbox中项目时触发事件
http://www.autoitx.com/forum.php?mod=viewthread&tid=13231&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 Then MsgBox(0, '高亮项目', $txt)
                        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 Then MsgBox(0, '高亮项目', $txt)
                        EndSwitch
        EndSwitch
        Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND

runtium 发表于 2011-9-13 14:09:03

本帖最后由 runtium 于 2011-9-13 14:10 编辑

谢谢了, 水木子

这个的确可行,

不过如果有tab有多个page, 每个page有不同的控件时, 界面显示貌似会有问题啊

紫色风林 发表于 2011-9-13 14:14:29

还是水版热心.....
页: [1]
查看完整版本: 在Tab中的listbox的双击事件触发问题