Jump to content

how to get if user selected item or not


name15
 Share

Recommended Posts

how to get if user selected item or not

if user no item selected then will _GUICtrlMenu_SetItemDisabled

if user selected a item then will _GUICtrlMenu_SetItemEnabled

like my function

Func menu($FileView,$hmenu,$Name1)
$p  = _GUICtrlListView_GetItemCount($FileView)
For $i = 0 to $p
$Name = _GUICtrlListView_GetItemSelected(GUICtrlGetHandle($FileView),$i)
If $Name = False Then 
For $i = 1 To $Name1
        _GUICtrlMenu_SetItemDisabled(GUICtrlGetHandle($hmenu), $i)
    Next
EndIf
ExitLoop
If $Name = True Then
    For $i = 1 To $Name1
    _GUICtrlMenu_SetItemEnabled(GUICtrlGetHandle($hmenu), $i)
    Next
EndIf
Next
EndFunc
Link to comment
Share on other sites

To got an event in the moment of listview item are checked/unchecked with mouse or spacebar the following code works fine. You can combine it with your menu-settings.

#include <WinAPI.au3>
#Include <WindowsConstants.au3>

OnAutoItExitRegister('OnAutoItExit')
Opt("GUIOnEventMode", 1)

Global $hHookKeyboard, $pStub_KeyProc, $active = False, $ctrl2effect = 'SysListView321'
$pStub_KeyProc = DllCallbackRegister("_KeyProc", "int", "int;ptr;ptr")
$hHookKeyboard = _WinAPI_SetWindowsHookEx($WH_KEYBOARD_LL, DllCallbackGetPtr($pStub_KeyProc), _WinAPI_GetModuleHandle(0), 0)

Global $hGui = GUICreate("Listview", 520, 600, -1, -1)
GUISetOnEvent(-3, "_Exit")

Global $hLV = GUICtrlCreateListView("Index", 10, 10, 500, 582, -1, 0x00000004)
For $i = 1 To 100
    GUICtrlCreateListViewItem($i, $hLV)
    GUICtrlSetOnEvent(-1, "_CheckState")
Next

GUISetState()

While 1
    Sleep(100)
     ; has only effect, if GUI is active and listview has focus (for several listview also compare hWnd of listview)
    If BitAND(WinGetState($hGui), 8) And ControlGetFocus($hGui) = $ctrl2Effect Then
        $active = True
    Else
        $active = False
    EndIf
WEnd

Func _Exit()
    Exit
EndFunc

Func _CheckState()
    Local $state = 'unchecked'
    If BitAND(GUICtrlRead(@GUI_CtrlId, 1), $GUI_CHECKED) Then $state = 'checked'
    ConsoleWrite(@GUI_CtrlId & " - " & $state & @CR)
EndFunc

Func OnAutoItExit()
    DllCallbackFree($pStub_KeyProc)
    _WinAPI_UnhookWindowsHookEx($hHookKeyboard)
EndFunc  ;==>OnAutoITExit

Func _KeyProc($nCode, $wParam, $lParam)
    If $nCode < 0 Or Not $active Then Return _WinAPI_CallNextHookEx($hHookKeyboard, $nCode, $wParam, $lParam)
    Local $tKEYHOOKS = DllStructCreate($tagKBDLLHOOKSTRUCT, $lParam)
    Local $vkCode = DllStructGetData($tKEYHOOKS, "vkCode")
    If ($wParam = $WM_KEYUP) And ($vkCode = 0x20) Then
        _CheckStatus()
    EndIf
    Return _WinAPI_CallNextHookEx($hHookKeyboard, $nCode, $wParam, $lParam)
EndFunc  ;==>_KeyProc

Best Regards BugFix  

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...