Jump to content

Highlight next item in listview of emule and analyze context menu


 Share

Recommended Posts

Hi,

I wanna highlight one item to the next on listview of users on queue in emule v0.49c.

WinActivate('eMule v0.49c', '')
Sleep(1500)
MsgBox(4096, 'Show me', ControlListView ('eMule v0.49c', '', '[CLASS:SysListView32; INSTANCE:8]', 'GetItemCount') )

works fine, it give the number of all users on queue. But e.g. I can't highlight the first item of the listview.

$o=ControlListView ('eMule v0.49c', '', '[CLASS:SysListView32; INSTANCE:8]', 'Select', 1, 1)
MsgBox(4096, 'Return Value', 'Return Value (ControlListView)=' & $o)

doesn't work. Return Value is 1.

ControlClick ('eMule v0.49c', '', '[CLASS:SysListView32; INSTANCE:8]', 'right')

works correctly. It show me the context menu of the item. But I can't check, if the fifth entry:"View shared files" is enabled" and I can't activate this option, if it is enabled. AutoIt shows me only a "handle"= 0x00010764" for this context menu.

So how can I highlight the first item in this listview (amd then one after one) and how can I access on the context menu of these items? Thanks in advance Johannes

Posted Image

Johannes LorenzBensheim, Germanyjlorenz1@web.de[post="12602"]Highlightning AutoIt Syntax in Notepad++ - Just copy in your Profile/application data/notepad++[/post]

Link to comment
Share on other sites

Try this one:

#include <GUIListView.au3>

Const $sTitle = "eMule v0.49c"

WinActivate($sTitle)
$hListView = ControlGetHandle($sTitle, "", "SysListView328")

MsgBox(0x40, "Item Count", _GUICtrlListView_GetItemCount($hListView))
__GUICtrlListView_SetItemSelected($hListView, 0, True, True)


; #FUNCTION# ====================================================================================================================
; Name...........: _GUICtrlListView_SetItemSelected
; Description ...: Sets whether the item is selected
; Syntax.........: _GUICtrlListView_SetItemSelected($hWnd, $iIndex[, $fSelected = True[, $fFocused = False]])
; Parameters ....: $hWnd        - Handle to the control
;                  $iIndex      - Zero based index of the item, -1 to set selected state of all items
;                  $fSelected   - If True the item(s) are selected, otherwise not.
;                  $fFocused    - If True the item has focus, otherwise not.
; Return values .: Success      - True
;                  Failure      - False
; Author ........: Gary Frost
; Modified.......:
; Remarks .......:
; Related .......: _GUICtrlListView_GetItemSelected
; Link ..........;
; Example .......; Yes
; ===============================================================================================================================
Func __GUICtrlListView_SetItemSelected($hWnd, $iIndex, $fSelected = True, $fFocused = False)
    If $Debug_LV Then _GUICtrlListView_ValidateClassName($hWnd)
    Local $tstruct = DllStructCreate($tagLVITEM)
    Local $pItem = DllStructGetPtr($tstruct)
    Local $iResult, $iSelected = 0, $iFocused = 0, $iSize, $tMemMap, $pMemory
    If ($fSelected = True) Then $iSelected = $LVIS_SELECTED
    If ($fFocused = True And $iIndex <> -1) Then $iFocused = $LVIS_FOCUSED
    DllStructSetData($tstruct, "Mask", $LVIF_STATE)
    DllStructSetData($tstruct, "Item", $iIndex)
    DllStructSetData($tstruct, "State", BitOR($iSelected, $iFocused))
    DllStructSetData($tstruct, "StateMask", BitOR($LVIS_SELECTED, $iFocused))
    $iSize = DllStructGetSize($tstruct)
    If IsHWnd($hWnd) Then
        $pMemory = _MemInit($hWnd, $iSize, $tMemMap)
        _MemWrite($tMemMap, $pItem, $pMemory, $iSize)
        $iResult = _SendMessage($hWnd, $LVM_SETITEMSTATE, $iIndex, $pMemory, 0, "wparam", "ptr")
        _MemFree($tMemMap)
    Else
        $iResult = GUICtrlSendMsg($hWnd, $LVM_SETITEMSTATE, $iIndex, $pItem)
    EndIf
    Return $iResult <> 0
EndFunc   ;==>_GUICtrlListView_SetItemSelected

This is a copy of the original function from GUIListView.au3 but the original is causing an access violation exception because of a wrong pointer in _SendMessage().

Refer to this topic to see how to determine if a menu item is enabled or not.

Link to comment
Share on other sites

Hallo Authenticity ,

thanks for your response. I've tried all your suggestions. Yes, I can highlight the first item of the listview. With hook.au3 I can read the context menu. But regardless, what items are disabled or not, in EMULE it shows me all items always enabled, but in SCITE or NOTEPAD it works fine with the context menu and the results are correct. Strange - isn't it?

&Details... is enabled.

&Add To Friends is enabled.

Send &Message is enabled.

&View Shared Files is enabled.

Find... is enabled.

&Details... is enabled.

&Add To Friends is enabled.

Send &Message is enabled.

&View Shared Files is enabled.

Find... is enabled.

Undo is enabled.

Redo is disabled.

Cut is enabled.

Copy is enabled.

Paste is disabled.

Delete is enabled.

Select All is enabled.

Hide is enabled.

Add as Snippet is enabled.

More important for me is now to make a click on &View Shared Files Have you an idear? Thanks in advance Johannes

Edited by jlorenz1

Johannes LorenzBensheim, Germanyjlorenz1@web.de[post="12602"]Highlightning AutoIt Syntax in Notepad++ - Just copy in your Profile/application data/notepad++[/post]

Link to comment
Share on other sites

I'm suspecting this menu's items are somewhat owner-drawn but don't count on my word. Try this handler instead. It's somewhat not correct way because it can be either 8 or 4 but 12 is masking it nicely.

Func _WinEventProc($hHook, $iEvent, $hWnd, $iObjectID, $iChildID, $iEventThread, $imsEventTime)
    Local $hMenu, $sItemText, $fStateMask
    
    If $iEvent =  $EVENT_SYSTEM_MENUPOPUPSTART Then
        $hMenu = _SendMessage($hWnd, 0x01E1)
        If _GUICtrlMenu_IsMenu($hMenu) Then
            
            For $i = 0 To _GUICtrlMenu_GetItemCount($hMenu)-1
                $sItemText = _GUICtrlMenu_GetItemText($hMenu, $i)
                If $sItemText = '' Then ContinueLoop
                
                ConsoleWrite($sItemText & ' is ')
                $fStateMask = _GUICtrlMenu_GetItemState($hMenu, $i)
                
                If Not BitAND($fStateMask, 12) Then
                    ConsoleWrite('enabled.' & @CRLF)
                Else
                    ConsoleWrite('disabled.' & @CRLF)
                EndIf
            Next
        EndIf
        ConsoleWrite(@CRLF)
    EndIf
EndFunc
Link to comment
Share on other sites

I'm suspecting this menu's items are somewhat owner-drawn but don't count on my word. Try this handler instead. It's somewhat not correct way because it can be either 8 or 4 but 12 is masking it nicely.

Func _WinEventProc($hHook, $iEvent, $hWnd, $iObjectID, $iChildID, $iEventThread, $imsEventTime)
    Local $hMenu, $sItemText, $fStateMask
    
    If $iEvent =  $EVENT_SYSTEM_MENUPOPUPSTART Then
        $hMenu = _SendMessage($hWnd, 0x01E1)
        If _GUICtrlMenu_IsMenu($hMenu) Then
            
            For $i = 0 To _GUICtrlMenu_GetItemCount($hMenu)-1
                $sItemText = _GUICtrlMenu_GetItemText($hMenu, $i)
                If $sItemText = '' Then ContinueLoop
                
                ConsoleWrite($sItemText & ' is ')
                $fStateMask = _GUICtrlMenu_GetItemState($hMenu, $i)
                
                If Not BitAND($fStateMask, 12) Then
                    ConsoleWrite('enabled.' & @CRLF)
                Else
                    ConsoleWrite('disabled.' & @CRLF)
                EndIf
            Next
        EndIf
        ConsoleWrite(@CRLF)
    EndIf
EndFunc

Hi Authenticity, this funtion works correctly in Emule. Sorry, but how can I make indirectly a click on one of the items e.g. #5 &view shared files, which can I see in the context menu? Greetings from Germany Johannes Edited by jlorenz1

Johannes LorenzBensheim, Germanyjlorenz1@web.de[post="12602"]Highlightning AutoIt Syntax in Notepad++ - Just copy in your Profile/application data/notepad++[/post]

Link to comment
Share on other sites

You can try a few ways. You can get the item rect and click it, or you can send {down 4}{enter} or send the message directly but it requires to see what this menu item sends using Spy++ or other similar tool:

Func _WinEventProc($hHook, $iEvent, $hWnd, $iObjectID, $iChildID, $iEventThread, $imsEventTime)
    Local $hMenu, $fStateMask
    If WinActive("eMule v0.49c") = 0 Then Return

    If $iEvent =  $EVENT_SYSTEM_MENUPOPUPSTART Then
        $hMenu = _SendMessage($hWnd, 0x01E1)
        If _GUICtrlMenu_IsMenu($hMenu) Then
            $fStateMask = _GUICtrlMenu_GetItemState($hMenu, 3)
            
            If Not BitAND($fStateMask, 12) Then
                _GUICtrlMenu_SetItemHighlighted($hMenu, 3)
                ControlSend($hWnd, "", "", "{ENTER}")
            EndIf
        EndIf
    EndIf
EndFunc
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...