Sign in to follow this  
Followers 0
jakalspop

how to check if user selecte item form listview or

13 posts in this topic

how to check if user selecte item form listview or not the right menu will enable or disable

Share this post


Link to post
Share on other sites



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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

thank but how enable or disable menu item

Share this post


Link to post
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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

You can just combine the contents of the two WM_Notify functions.

Share this post


Link to post
Share on other sites

how please

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

i do that be for but it not work

Share this post


Link to post
Share on other sites

Then post your attempt.

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

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

Share this post


Link to post
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.

Share this post


Link to post
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
Sign in to follow this  
Followers 0