Doppelklick

  • Hallo Leute ich hab mal eine Frage:
    Weiß jemand wie ich es machen kann, das etwas pasiert, wenn ich einen Doppelklick auf einen Button oder so was in der Gui mache, und nicht wenn ich nur einen mache? Und geht sowas auch bei Einer ListBox wenn ich da auf einen Item doppelt klicke?

    mfg. Jam00

    • Offizieller Beitrag

    Eine Möglichkeit wäre dieses etwas angestaubte Skript von mir: Doppelklick für (fast) jedes Control
    Eine andere Variante ist das Auswerten der Message Doppelklick (für Listview z.B. $NM_DBLCLK über GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") ). Mußt du dir die für das entsprechende Control zuständigen Messagecodes mal raussuchen.

  • Müsst ihr für die jeweiligen befehle anpassen wo das auf gehn soll

    Spoiler anzeigen
    [autoit]

    #cs ----------------------------------------------------------------------------

    [/autoit] [autoit][/autoit] [autoit]

    AutoIt Version: 3.3.0.0
    Author: myName

    [/autoit] [autoit][/autoit] [autoit]

    Script Function:
    Template AutoIt script.

    [/autoit] [autoit][/autoit] [autoit]

    #ce ----------------------------------------------------------------------------

    [/autoit] [autoit][/autoit] [autoit]

    ; Script Start - Add your code below here
    #Region ### START Koda GUI section ### Form=H:\Projeckte\CDN Argentur\Programm\New\Form\Terminplanung.kxf
    #EndRegion ### END Koda GUI section ###

    [/autoit] [autoit][/autoit] [autoit]

    _FillListView()

    [/autoit] [autoit][/autoit] [autoit]

    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func _LeftDblClick($info) ; Inhalt der angeklickten Zeile (alle Spalten) wird in GUI gezeigt
    GUICtrlSetData($dd_datum , _GUICtrlListView_GetItemText(GUICtrlGetHandle($Listview1), $Info[3], 1))
    GUICtrlSetData($Input14, _GUICtrlListView_GetItemText(GUICtrlGetHandle($Listview1), $Info[3], 2))
    GUICtrlSetData($Input1 , _GUICtrlListView_GetItemText(GUICtrlGetHandle($Listview1), $Info[3], 3))
    GUICtrlSetData($Input15 , _GUICtrlListView_GetItemText(GUICtrlGetHandle($Listview1), $Info[3], 4))
    GUICtrlSetData($Input2 , _GUICtrlListView_GetItemText(GUICtrlGetHandle($Listview1), $Info[3], 5))
    GUICtrlSetData($Input3 , _GUICtrlListView_GetItemText(GUICtrlGetHandle($Listview1), $Info[3], 6))
    GUICtrlSetData($Input4 , _GUICtrlListView_GetItemText(GUICtrlGetHandle($Listview1), $Info[3], 7))
    GUICtrlSetData($Input5, _GUICtrlListView_GetItemText(GUICtrlGetHandle($Listview1), $Info[3], 8))
    GUICtrlSetData($Input6 , _GUICtrlListView_GetItemText(GUICtrlGetHandle($Listview1), $Info[3], 9))
    GUICtrlSetData($Input7 , _GUICtrlListView_GetItemText(GUICtrlGetHandle($Listview1), $Info[3], 10))
    GUICtrlSetData($Input8 , _GUICtrlListView_GetItemText(GUICtrlGetHandle($Listview1), $Info[3], 11))
    GUICtrlSetData($Edit1 , _GUICtrlListView_GetItemText(GUICtrlGetHandle($Listview1), $Info[3], 12))
    GUICtrlSetData($Input9 , _GUICtrlListView_GetItemText(GUICtrlGetHandle($Listview1), $Info[3], 13))
    GUICtrlSetData($Input10 , _GUICtrlListView_GetItemText(GUICtrlGetHandle($Listview1), $Info[3], 14))
    GUICtrlSetData($Input11 , _GUICtrlListView_GetItemText(GUICtrlGetHandle($Listview1), $Info[3], 15))
    GUICtrlSetData($Input12 , _GUICtrlListView_GetItemText(GUICtrlGetHandle($Listview1), $Info[3], 16))
    GUICtrlSetData($Input13 , _GUICtrlListView_GetItemText(GUICtrlGetHandle($Listview1), $Info[3], 17))
    GUICtrlSetData($Edit2 , _GUICtrlListView_GetItemText(GUICtrlGetHandle($Listview1), $Info[3], 18))
    GUISetState(@SW_SHOW, $hGui2)
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView
    $hWndListView = $ListView1
    If Not IsHWnd($ListView1) Then $hWndListView = GUICtrlGetHandle($ListView1)

    [/autoit] [autoit][/autoit] [autoit]

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
    Case $hWndListView
    Switch $iCode
    Case $NM_DBLCLK ; Sent by a list-view control when the user double-clicks an item with the left mouse button
    Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
    Local $aInfo[12] = [$hWndFrom, _
    $iIDFrom, _
    $iCode, _
    DllStructGetData($tInfo, "Index"), _
    DllStructGetData($tInfo, "SubItem"), _
    DllStructGetData($tInfo, "NewState"), _
    DllStructGetData($tInfo, "OldState"), _
    DllStructGetData($tInfo, "Changed"), _
    DllStructGetData($tInfo, "ActionX"), _
    DllStructGetData($tInfo, "ActionY"), _
    DllStructGetData($tInfo, "lParam"), _
    DllStructGetData($tInfo, "KeyFlags")]
    _LeftDblClick($aInfo)
    Case $NM_RCLICK ; Sent by a list-view control when the user clicks an item with the right mouse button
    Return $GUI_RUNDEFMSG ; allow the default processing
    EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
    EndFunc ;==>WM_NOTIFY

    [/autoit]
    • Offizieller Beitrag

    Es stehen zum Thema Listview mehrere Bsp. in der Hilfe, aus denen das ersichtlich ist.
    Ich habe es mal zusammengefaßt:

    Spoiler anzeigen
    [autoit]

    #include<GUIConstantsEx.au3>
    #include<WindowsConstants.au3>
    #include <GUIListView.au3>

    [/autoit] [autoit][/autoit] [autoit]

    $gui = GUICreate('test')
    $hListView = GUICtrlCreateListView('Spalte1|Spalte2', 10, 10, 300, 200)
    _GUICtrlListView_SetColumnWidth($hListView, 0, 146)
    _GUICtrlListView_SetColumnWidth($hListView, 1, $LVSCW_AUTOSIZE_USEHEADER)
    For $i = 1 To 10
    GUICtrlCreateListViewItem('Zeile ' & $i & ' Spalte 1|Zeile ' & $i & ' Spalte 2', $hListView)
    Next
    GUISetState()
    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
    Do
    $msg = GUIGetMsg()
    Until $msg = $GUI_EVENT_CLOSE

    [/autoit] [autoit][/autoit] [autoit]

    Func _LeftDblClick($Info)
    MsgBox(0, 'Text in Spalte', _GUICtrlListView_GetItemText($Info[1], $Info[3], $Info[4]) )
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView
    $hWndListView = $hListView
    If Not IsHWnd($hListView) Then $hWndListView = GUICtrlGetHandle($hListView)

    [/autoit] [autoit][/autoit] [autoit]

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
    Case $hWndListView
    Switch $iCode
    Case $LVN_COLUMNCLICK ; A column was clicked
    Local $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam)
    Local $aInfo[11] = [$hWndFrom, _
    $iIDFrom, _
    $iCode, _
    DllStructGetData($tInfo, "Index"), _
    DllStructGetData($tInfo, "SubItem"), _
    DllStructGetData($tInfo, "NewState"), _
    DllStructGetData($tInfo, "OldState"), _
    DllStructGetData($tInfo, "Changed"), _
    DllStructGetData($tInfo, "ActionX"), _
    DllStructGetData($tInfo, "ActionY"), _
    DllStructGetData($tInfo, "Param")]
    ;~ _ColumnClick($aInfo)
    Case $LVN_DELETEITEM ; An item is about to be deleted
    Local $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam)
    Local $aInfo[11] = [$hWndFrom, _
    $iIDFrom, _
    $iCode, _
    DllStructGetData($tInfo, "Index"), _
    DllStructGetData($tInfo, "SubItem"), _
    DllStructGetData($tInfo, "NewState"), _
    DllStructGetData($tInfo, "OldState"), _
    DllStructGetData($tInfo, "Changed"), _
    DllStructGetData($tInfo, "ActionX"), _
    DllStructGetData($tInfo, "ActionY"), _
    DllStructGetData($tInfo, "Param")]
    ;~ _ItemDeleted($aInfo)
    Case $LVN_HOTTRACK ; Sent by a list-view control when the user moves the mouse over an item
    Local $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam)
    Local $aInfo[11] = [$hWndFrom, _
    $iIDFrom, _
    $iCode, _
    DllStructGetData($tInfo, "Index"), _
    DllStructGetData($tInfo, "SubItem"), _
    DllStructGetData($tInfo, "NewState"), _
    DllStructGetData($tInfo, "OldState"), _
    DllStructGetData($tInfo, "Changed"), _
    DllStructGetData($tInfo, "ActionX"), _
    DllStructGetData($tInfo, "ActionY"), _
    DllStructGetData($tInfo, "Param")]
    Return 0 ; allow the list view to perform its normal track select processing.
    ;Return 1 ; the item will not be selected.
    ;~ _HottTrackItem($aInfo)
    Case $LVN_KEYDOWN ; A key has been pressed
    Local $tInfo = DllStructCreate($tagNMLVKEYDOWN, $ilParam)
    Local $aInfo[5] = [$hWndFrom, _
    $iIDFrom, _
    $iCode, _
    DllStructGetData($tInfo, "VKey"), _
    DllStructGetData($tInfo, "KeyFlags")]
    ;~ _KeyDown($aInfo)
    Case $NM_CLICK ; Sent by a list-view control when the user clicks an item with the left mouse button
    Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
    Local $aInfo[12] = [$hWndFrom, _
    $iIDFrom, _
    $iCode, _
    DllStructGetData($tInfo, "Index"), _
    DllStructGetData($tInfo, "SubItem"), _
    DllStructGetData($tInfo, "NewState"), _
    DllStructGetData($tInfo, "OldState"), _
    DllStructGetData($tInfo, "Changed"), _
    DllStructGetData($tInfo, "ActionX"), _
    DllStructGetData($tInfo, "ActionY"), _
    DllStructGetData($tInfo, "lParam"), _
    DllStructGetData($tInfo, "KeyFlags")]
    ;~ _LeftClick($aInfo)
    Case $NM_DBLCLK ; Sent by a list-view control when the user double-clicks an item with the left mouse button
    Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
    Local $aInfo[12] = [$hWndFrom, _
    $iIDFrom, _
    $iCode, _
    DllStructGetData($tInfo, "Index"), _
    DllStructGetData($tInfo, "SubItem"), _
    DllStructGetData($tInfo, "NewState"), _
    DllStructGetData($tInfo, "OldState"), _
    DllStructGetData($tInfo, "Changed"), _
    DllStructGetData($tInfo, "ActionX"), _
    DllStructGetData($tInfo, "ActionY"), _
    DllStructGetData($tInfo, "lParam"), _
    DllStructGetData($tInfo, "KeyFlags")]
    _LeftDblClick($aInfo)
    Case $NM_KILLFOCUS ; The control has lost the input focus
    Local $aInfo[3] = [$hWndFrom, _
    $iIDFrom, _
    $iCode]
    ;~ _LostFocus($aInfo)
    Case $NM_RCLICK ; Sent by a list-view control when the user clicks an item with the right mouse button
    Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
    Local $aInfo[12] = [$hWndFrom, _
    $iIDFrom, _
    $iCode, _
    DllStructGetData($tInfo, "Index"), _
    DllStructGetData($tInfo, "SubItem"), _
    DllStructGetData($tInfo, "NewState"), _
    DllStructGetData($tInfo, "OldState"), _
    DllStructGetData($tInfo, "Changed"), _
    DllStructGetData($tInfo, "ActionX"), _
    DllStructGetData($tInfo, "ActionY"), _
    DllStructGetData($tInfo, "lParam"), _
    DllStructGetData($tInfo, "KeyFlags")]
    ; Return 1 ; not to allow the default processing
    Return 0 ; allow the default processing
    ;~ _RightClick($aInfo)
    Case $NM_RDBLCLK ; Sent by a list-view control when the user double-clicks an item with the right mouse button
    Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
    Local $aInfo[12] = [$hWndFrom, _
    $iIDFrom, _
    $iCode, _
    DllStructGetData($tInfo, "Index"), _
    DllStructGetData($tInfo, "SubItem"), _
    DllStructGetData($tInfo, "NewState"), _
    DllStructGetData($tInfo, "OldState"), _
    DllStructGetData($tInfo, "Changed"), _
    DllStructGetData($tInfo, "ActionX"), _
    DllStructGetData($tInfo, "ActionY"), _
    DllStructGetData($tInfo, "lParam"), _
    DllStructGetData($tInfo, "KeyFlags")]
    ;~ _RightDblClick($aInfo)
    Case $NM_RETURN ; The control has the input focus and that the user has pressed the ENTER key
    Local $aInfo[3] = [$hWndFrom, _
    $iIDFrom, _
    $iCode]
    ;~ _InputFocusReturn($aInfo)
    Case $NM_SETFOCUS ; The control has received the input focus
    Local $aInfo[3] = [$hWndFrom, _
    $iIDFrom, _
    $iCode]
    ;~ _SetFocus($aInfo)
    EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
    EndFunc ;==>WM_NOTIFY

    [/autoit]
    • Offizieller Beitrag

    Und warum guckst du dann nicht in die Hilfe zu ListBox? Steht dort genauso - hier mal ohne die DebugPrint-Aufrufe:

    Spoiler anzeigen
    [autoit]

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

    [/autoit] [autoit][/autoit] [autoit]

    Opt('MustDeclareVars', 1)

    [/autoit] [autoit][/autoit] [autoit]

    $Debug_LB = False ; Check ClassName being passed to ListBox functions, set to True and use a handle to another control to see it work

    [/autoit] [autoit][/autoit] [autoit]

    Global $hListBox

    [/autoit] [autoit][/autoit] [autoit]

    _Main()

    [/autoit] [autoit][/autoit] [autoit]

    Func _Main()
    Local $hGUI

    [/autoit] [autoit][/autoit] [autoit]

    ; Create GUI
    $hGUI = GUICreate("(UDF Created) List Box Create", 400, 296)
    $hListBox = _GUICtrlListBox_Create($hGUI, "String upon creation", 2, 2, 396, 296)
    GUISetState()

    [/autoit] [autoit][/autoit] [autoit]


    GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

    [/autoit] [autoit][/autoit] [autoit]

    ; Add files
    _GUICtrlListBox_BeginUpdate($hListBox)
    _GUICtrlListBox_ResetContent($hListBox)
    _GUICtrlListBox_InitStorage($hListBox, 100, 4096)
    _GUICtrlListBox_Dir($hListBox, @WindowsDir & "\win*.exe")
    _GUICtrlListBox_AddFile($hListBox, @WindowsDir & "\Notepad.exe")
    _GUICtrlListBox_Dir($hListBox, "", $DDL_DRIVES)
    _GUICtrlListBox_Dir($hListBox, "", $DDL_DRIVES, False)
    _GUICtrlListBox_EndUpdate($hListBox)

    [/autoit] [autoit][/autoit] [autoit]

    ; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    EndFunc ;==>_Main

    [/autoit] [autoit][/autoit] [autoit]

    Func _ListDblClick()
    Local $indx = _GUICtrlListBox_GetCurSel($hListBox)
    MsgBox(0, 'Doppelklick auf:', _GUICtrlListBox_GetText($hListBox, $indx))
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    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

    [/autoit] [autoit][/autoit] [autoit]

    Switch $hWndFrom
    Case $hListBox, $hWndListBox
    Switch $iCode
    Case $LBN_DBLCLK ; Sent when the user double-clicks a string in a list box
    Return _ListDblClick()
    Case $LBN_ERRSPACE ; Sent when a list box cannot allocate enough memory to meet a specific request
    ;~ Return _ListErrSpace()
    Case $LBN_KILLFOCUS ; Sent when a list box loses the keyboard focus
    ;~ Return _ListKillFocus()
    Case $LBN_SELCANCEL ; Sent when the user cancels the selection in a list box
    ;~ Return _ListSelCancel()
    Case $LBN_SELCHANGE ; Sent when the selection in a list box has changed
    ;~ Return _ListSelChange()
    Case $LBN_SETFOCUS ; Sent when a list box receives the keyboard focus
    ;~ Return _ListSetFocus()
    EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
    EndFunc ;==>WM_COMMAND

    [/autoit]
    • Offizieller Beitrag

    Noch ein Hinweis:
    Wenn die Listbox mit GUICtrlCreateList() erstellt wurde, solltest du sicherheitshalber für die UDF das Handle verwenden. Dann ist gesichert, dass die Func's aus der UDF auch wirksam sind.

    [autoit]

    $ListBox = GUICtrlCreateList()
    $hListBox = GUICtrlGetHandle($ListBox)

    [/autoit]