Jump to content

how to check if user selecte item form listview or


Recommended Posts

You could use _GUICtrlListView_GetSelectedCount() to get the number of selected items.

Or _GUICtrlListView_GetSelectedIndices() to get the indices of selected item(s).

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Please check this post. I've taken this code snippet for my own scripts and it works great.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

#Include <GUIConstantsEx.au3>
#Include <GUIListView.au3>
#Include <ListViewConstants.au3>
#Include <WindowsConstants.au3>
#Include <WinAPI.au3>

Global $hForm, $hListView, $Dummy1, $Dummy2
Global $Accel[1][2] = [['{ENTER}', 0]]

$Form = GUICreate('MyGUI', 400, 400)

GUICtrlCreateListView('Column', 10, 10, 380, 380, BitOR($LVS_NOSORTHEADER, $LVS_SINGLESEL), $WS_EX_CLIENTEDGE)
$hListView = GUICtrlGetHandle(-1)

For $i = 0 To 9
    _GUICtrlListView_AddItem($hListView, 'Item ' & $i)
Next

$Dummy1 = GUICtrlCreateDummy()
$Dummy2 = GUICtrlCreateDummy()

$Accel[0][1] = GUICtrlCreateDummy()
GUISetAccelerators($Accel)

GUIRegisterMsg($WM_NOTIFY, 'WM_NOTIFY')

GUISetState(@SW_SHOW)

While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $Dummy1
            ConsoleWrite('Item' & GUICtrlRead($Dummy1) & ' - selected!' & @CR)
        Case $Dummy2
            ConsoleWrite('Item' & GUICtrlRead($Dummy2) & ' - activated by double click!' & @CR)
        Case $Accel[0][1]
            If _WinAPI_GetFocus() = $hListView Then
                $Index = _GUICtrlListView_GetSelectedIndices($hListView)
                If $Index Then
                    ConsoleWrite('Item' & $Index & ' - activated by ENTER!' & @CR)
;                   GUICtrlSendToDummy($Dummy2, Number($Index))
                EndIf
            EndIf
    EndSwitch
WEnd

Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)

    Local $tNMITEMACTIVATE = DllStructCreate($tagNMITEMACTIVATE, $lParam)
    Local $hFrom = DllStructGetData($tNMITEMACTIVATE, 'hWndFrom')
    Local $Index = DllStructGetData($tNMITEMACTIVATE, 'Index')
    Local $ID = DllStructGetData($tNMITEMACTIVATE, 'Code')

    Switch $hFrom
        Case $hListView
            Switch $ID
                Case $LVN_ITEMACTIVATE
                    GUICtrlSendToDummy($Dummy2, $Index)
                Case $LVN_ITEMCHANGED
                    If (BitAND(DllStructGetData($tNMITEMACTIVATE, 'Changed'), $LVIF_STATE)) And (BitAND(DllStructGetData($tNMITEMACTIVATE, 'NewState'), $LVIS_SELECTED)) And (Not BitAND(DllStructGetData($tNMITEMACTIVATE, 'OldState'), $LVIS_FOCUSED)) Then
                        GUICtrlSendToDummy($Dummy1, $Index)
                    EndIf
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

Link to comment
Share on other sites

thank for example but i ready use this function for double click on tree

Func MY_WM_NOTIFY($hWnd, $Msg, $wParam, $ilParam)
    Switch $wParam
        Case $regmanagers
            Local $tagNMHDR = DllStructCreate("int;int;int", $ilParam)
            If @error Then Return
            If DllStructGetData($tagNMHDR, 3) = $NM_DBLCLK Then $fDblClk = True
        Case $FILEmanagers1
            Local $tagNMHDR = DllStructCreate("int;int;int", $ilParam)
            If @error Then Return
            If DllStructGetData($tagNMHDR, 3) = $NM_DBLCLK Then $fDblClk = True
        Case $Tre
            Local $tagNMHDR = DllStructCreate("int;int;int", $ilParam)
            If @error Then Return
            If DllStructGetData($tagNMHDR, 3) = $NM_DBLCLK Then $fDblClk = True
    EndSwitch
EndFunc
Link to comment
Share on other sites

Paste the contents of your "MY_WM_NOTIFY" into Yashieds "WM_NOTIFY".

Change $Msg to $iMsg, and $ilParam to $lParam. (change $tagNMHDR to something else while you're at it. It's already used by a Global Const)

Check if it behaves as desired.

Link to comment
Share on other sites

ok like

Func MY_WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)

    Local $tNMITEMACTIVATE = DllStructCreate($tagNMITEMACTIVATE, $lParam)
    Local $hFrom = DllStructGetData($tNMITEMACTIVATE, 'hWndFrom')
    Local $Index = DllStructGetData($tNMITEMACTIVATE, 'Index')
    Local $ID = DllStructGetData($tNMITEMACTIVATE, 'Code')

    Switch $wParam
        Case $regmanagers
            Local $tagNMHDR = DllStructCreate("int;int;int", $lParam)
            If @error Then Return
            If DllStructGetData($tagNMHDR, 3) = $NM_DBLCLK Then $fDblClk = True
        Case $FILEmanagers1
            Local $tagNMHDR = DllStructCreate("int;int;int", $lParam)
            If @error Then Return
            If DllStructGetData($tagNMHDR, 3) = $NM_DBLCLK Then $fDblClk = True
        Case $Tre
            Local $tagNMHDR = DllStructCreate("int;int;int", $lParam)
            If @error Then Return
            If DllStructGetData($tagNMHDR, 3) = $NM_DBLCLK Then $fDblClk = True
       Case $listview
           Switch $ID
                Case $LVN_ITEMACTIVATE
                    GUICtrlSendToDummy($Dummy2, $Index)
                Case $LVN_ITEMCHANGED
                    If (BitAND(DllStructGetData($tNMITEMACTIVATE, 'Changed'), $LVIF_STATE)) And (BitAND(DllStructGetData($tNMITEMACTIVATE, 'NewState'), $LVIS_SELECTED)) And (Not BitAND(DllStructGetData($tNMITEMACTIVATE, 'OldState'), $LVIS_FOCUSED)) Then
                        GUICtrlSendToDummy($Dummy1, $Index)
                    EndIf
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
    EndSwitch
EndFunc
Edited by jakalspop
Link to comment
Share on other sites

It's all good and well that you want to do things as effective as possible, but when you are combining two functions that work. It's best to first implement them in a way that is likely to work and then start rewriting it to make the code more effecient, or pretty.

With this approach you could go from an embedded function call:

Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    Local $tNMITEMACTIVATE = DllStructCreate($tagNMITEMACTIVATE, $lParam)
    Local $hFrom = DllStructGetData($tNMITEMACTIVATE, 'hWndFrom')
    Local $Index = DllStructGetData($tNMITEMACTIVATE, 'Index')
    Local $ID = DllStructGetData($tNMITEMACTIVATE, 'Code')

    Switch $hFrom
    Case $hListView
    Switch $ID
    Case $LVN_ITEMACTIVATE
    GUICtrlSendToDummy($Dummy2, $Index)
    Case $LVN_ITEMCHANGED
    If (BitAND(DllStructGetData($tNMITEMACTIVATE, 'Changed'), $LVIF_STATE)) And (BitAND(DllStructGetData($tNMITEMACTIVATE, 'NewState'), $LVIS_SELECTED)) And (Not BitAND(DllStructGetData($tNMITEMACTIVATE, 'OldState'), $LVIS_FOCUSED)) Then
    GUICtrlSendToDummy($Dummy1, $Index)
    EndIf
    EndSwitch
    EndSwitch
    MY_WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY

To a crude copy paste:

Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    ;yashieds function
    Local $tNMITEMACTIVATE = DllStructCreate($tagNMITEMACTIVATE, $lParam)
    Local $hFrom = DllStructGetData($tNMITEMACTIVATE, 'hWndFrom')
    Local $Index = DllStructGetData($tNMITEMACTIVATE, 'Index')
    Local $ID = DllStructGetData($tNMITEMACTIVATE, 'Code')

    Switch $hFrom
    Case $hListView
    Switch $ID
    Case $LVN_ITEMACTIVATE
    GUICtrlSendToDummy($Dummy2, $Index)
    Case $LVN_ITEMCHANGED
    If (BitAND(DllStructGetData($tNMITEMACTIVATE, 'Changed'), $LVIF_STATE)) And (BitAND(DllStructGetData($tNMITEMACTIVATE, 'NewState'), $LVIS_SELECTED)) And (Not BitAND(DllStructGetData($tNMITEMACTIVATE, 'OldState'), $LVIS_FOCUSED)) Then
    GUICtrlSendToDummy($Dummy1, $Index)
    EndIf
    EndSwitch
    EndSwitch
    
    ;jakalspops function
     Switch $wParam
    Case $regmanagers
    Local $tNMHDR = DllStructCreate("int;int;int", $lParam)
    If @error Then Return
    If DllStructGetData($tNMHDR, 3) = $NM_DBLCLK Then $fDblClk = True
    Case $FILEmanagers1
    Local $tNMHDR = DllStructCreate("int;int;int", $lParam)
    If @error Then Return
    If DllStructGetData($tNMHDR, 3) = $NM_DBLCLK Then $fDblClk = True
    Case $Tre
    Local $tNMHDR = DllStructCreate("int;int;int", $lParam)
    If @error Then Return
    If DllStructGetData($tNMHDR, 3) = $NM_DBLCLK Then $fDblClk = True
    EndSwitch

    Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY

To something like this:

Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    Local $tNMITEMACTIVATE = DllStructCreate($tagNMITEMACTIVATE, $lParam)
    Local $hFrom = DllStructGetData($tNMITEMACTIVATE, 'hWndFrom')
    Local $ID = DllStructGetData($tNMITEMACTIVATE, 'Code')

    Switch $hFrom
    Case $hListView
    Switch $ID
    Case $LVN_ITEMACTIVATE
    GUICtrlSendToDummy($Dummy2, $Index)
    Case $LVN_ITEMCHANGED
    If (BitAND(DllStructGetData($tNMITEMACTIVATE, 'Changed'), $LVIF_STATE)) And (BitAND(DllStructGetData($tNMITEMACTIVATE, 'NewState'), $LVIS_SELECTED)) And (Not BitAND(DllStructGetData($tNMITEMACTIVATE, 'OldState'), $LVIS_FOCUSED)) Then
    GUICtrlSendToDummy($Dummy1, $Index)
    EndIf
            EndSwitch
    EndSwitch

    Switch $wParam
    Case $regmanagers, $FILEmanagers1, $Tre
    If $ID = $NM_DBLCLK Then $fDblClk = True
    EndSwitch

    Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY

Etc...

None of those functions are tested, but this way you can usually pinpoint what you're doing wrong when combining functions.

Another great tool is consolewriting values, to see if the values you're getting are what you'd expect.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...