Jump to content
Sign in to follow this  
dabus

No context-menu?

Recommended Posts

dabus

I used LazyCats icon-script to do some guessing which icon is selected.

It just gets the positions and calculates the current item (that is selected).

As you can see, I select an item, the script puts a square around the selection, creates a context-menu, and shows the selection in console (scite).

It seems to work fine ;) , but I don't get the contextmenu if I do a click with my right button. Any idea why that's the case? :lmao:

Thx.

;===============================================================================
;
; Description:    Show all icons in the given file
; Requirement(s):   Autoit 3.0.103+
; Author(s):        YDY (Lazycat)
;
;===============================================================================

#include <GUIConstants.au3>
#include <Misc.au3>

AutoItSetOption ( "TrayIconDebug", 1 )

; Setting variables
Global $ahIcons[30], $ahLabels[30] 
Global $iStartIndex = 0, $iCntRow, $iCntCol, $iCurIndex
Global $sFilename = @SystemDir & "\shell32.dll"; Default file is "shell32.dll"

$dll = DllOpen("user32.dll")

; Creating GUI and controls
GUICreate("Icon Selector", 385, 435, @DesktopWidth/2 - 192, _
@DesktopHeight/2 - 235, -1, $WS_EX_ACCEPTFILES)
GUICtrlCreateGroup("", 5, 1, 375, 40)
GUICtrlCreateGroup("", 5, 50, 375, 380)
$hFile = GUICtrlCreateEdit($sFilename, 12,  15, 325, 16, $ES_READONLY, $WS_EX_STATICEDGE)
GUICtrlSetCursor(-1, 2) 
GUICtrlSetState(-1, $GUI_ACCEPTFILES)
GUICtrlSetTip(-1, "You can drop files from shell here...")
$hFileSel = GUICtrlCreateButton("...", 345,  14, 26, 18)
$hPrev = GUICtrlCreateButton("Previous", 10,  45, 60, 24, $BS_FLAT)
GUICtrlSetState(-1, $GUI_DISABLE)
$hNext = GUICtrlCreateButton("Next", 75,  45, 60, 24, $BS_FLAT)

; This code build two arrays of ID's of icons and labels for easily update
For $iCntRow = 0 to 4
    For $iCntCol = 0 to 5
        $iCurIndex = $iCntRow * 6 + $iCntCol
        $ahIcons[$iCurIndex] = GUICtrlCreateIcon($sFilename, $iCurIndex, _
        60 * $iCntCol + 25, 70 * $iCntRow + 80)
        $ahLabels[$iCurIndex] = GUICtrlCreateLabel($iCurIndex, _
        60 * $iCntCol+11, 70 * $iCntRow + 115, 60, 20, $SS_CENTER)
    Next
Next
$Test=GUICtrlCreateLabel ( "", -100, -100, 10, 10 )
GUISetState()

While 1
    $iMsg = GUIGetMsg()


   ; Changes (My code) start here !!!! 


    $mPos=MouseGetPos ()
    $wPos=WinGetPos ("Icon Selector")
    ToolTip ( $mPos[0]-$wPos[0]&" / "&$mPos[1]-$wPos[1] )
    If _IsPressed ( 01, $dll ) Then
        $mPos=MouseGetPos ()
        $wPos=WinGetPos ("Icon Selector")
        If $mPos[1]-$wPos[1] > 80 Then
            $xCounter=0
            $yCounter=0
            While 1
                If $xCounter=5 Then ExitLoop
                If ( $mPos[0]-$wPos[0])-(($xCounter+1)*60)>=25-16 Then
                    $xCounter=$xCounter+1
                Else
                    ExitLoop
                EndIf   
            WEnd
            While 1
                If $yCounter=4 Then ExitLoop
                If ( $mPos[1]-$wPos[1])-(($yCounter+1)*70)>=80-16 Then
                    $yCounter=$yCounter+1
                Else
                    ExitLoop
                EndIf   
            WEnd
        ; ConsoleWrite ( $xCounter & @CR )
        ; ConsoleWrite ( $yCounter & @CR )
            ConsoleWrite ( $yCounter * 6 + $xCounter & @CR )
            GUICtrlDelete ( $Test )
            $Test=GUICtrlCreateLabel ( "Test", $xCounter*60+25-16 , $yCounter*70+80-16 , 70, 80, $SS_BLACKFRAME)
        ; MouseClick ("Right", $mPos[0], $mPos[1] )
            $Menu=GUICtrlCreateMenu ( "Test", $Test )
            $Delete=GUICtrlCreateMenuitem ( "Delete", $Menu)
            $Rename=GUICtrlCreateMenuitem ( "Rename", $Menu)
            $Open=GUICtrlCreateMenuitem ( "Open", $Menu)
        ; ConsoleWrite('@@ Debug(73) : $yCounter*60+80 = ' & $yCounter*60+80 & @lf & '>Error code: ' & @error & @lf);### Debug Console
        ; ConsoleWrite('@@ Debug(73) : $xCounter*70+25 = ' & $xCounter*70+25 & @lf & '>Error code: ' & @error & @lf);### Debug Console
            Sleep (250 )
        EndIf
    EndIf


; Changes (My code) end here


  ; Code below will check if the file is dropped (or selected)
    $sCurFilename = GUICtrlRead($hFile) 
    If $sCurFilename <> $sFilename Then
        $iStartIndex = 0
        $sFilename = $sCurFilename
        _GUIUpdate()
    Endif
  ; Main "Select" statement that handles other events
    Select
        Case $iMsg = $hFileSel
            $sTmpFile = FileOpenDialog("Select file:", "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}", "Executables & dll's (*.exe;*.dll;*.ocx;*.icl)")
            If @error Then ContinueLoop
            GUICtrlSetData($hFile, $sTmpFile); GUI will be updated at next iteration
        Case $iMsg = $hPrev
            $iStartIndex = $iStartIndex - 30
            _GUIUpdate()
        Case $iMsg = $hNext
            $iStartIndex = $iStartIndex + 30
            _GUIUpdate()
        Case $iMsg = $GUI_EVENT_CLOSE
            DllClose($dll)
            Exit
    EndSelect
Wend
    
; Just updates GUI icons, labels and set state of "Previous" button
Func _GUIUpdate() 
    For $iCntRow = 0 to 4
        For $iCntCol = 0 to 5
            $iCurIndex = $iCntRow * 6 + $iCntCol
            GUICtrlSetImage($ahIcons[$iCurIndex], $sFilename, $iCurIndex + $iStartIndex)
            GUICtrlSetData($ahLabels[$iCurIndex], $iCurIndex + $iStartIndex)
        Next
    Next
  ; This is because we don't want negative values
    If $iStartIndex = 0 Then
        GUICtrlSetState($hPrev, $GUI_DISABLE)
    Else
        GUICtrlSetState($hPrev, $GUI_ENABLE)
    Endif       
EndFunc

Share this post


Link to post
Share on other sites
GaryFrost

Use GUICreateContextMenu instead of GUICreateMenu, and use the control id you have saved in the array

;===============================================================================
;
; Description:    Show all icons in the given file
; Requirement(s):   Autoit 3.0.103+
; Author(s):        YDY (Lazycat)
;
;===============================================================================

#include <GUIConstants.au3>
#include <Misc.au3>

AutoItSetOption("TrayIconDebug", 1)

; Setting variables
Global $ahIcons[30], $ahLabels[30]
Global $iStartIndex = 0, $iCntRow, $iCntCol, $iCurIndex
Global $sFilename = @SystemDir & "\shell32.dll"; Default file is "shell32.dll"

$dll = DllOpen("user32.dll")

; Creating GUI and controls
GUICreate("Icon Selector", 385, 435, @DesktopWidth / 2 - 192, _
        @DesktopHeight / 2 - 235, -1, $WS_EX_ACCEPTFILES)
GUICtrlCreateGroup("", 5, 1, 375, 40)
GUICtrlCreateGroup("", 5, 50, 375, 380)
$hFile = GUICtrlCreateEdit($sFilename, 12, 15, 325, 16, $ES_READONLY, $WS_EX_STATICEDGE)
GUICtrlSetCursor(-1, 2)
GUICtrlSetState(-1, $GUI_ACCEPTFILES)
GUICtrlSetTip(-1, "You can drop files from shell here...")
$hFileSel = GUICtrlCreateButton("...", 345, 14, 26, 18)
$hPrev = GUICtrlCreateButton("Previous", 10, 45, 60, 24, $BS_FLAT)
GUICtrlSetState(-1, $GUI_DISABLE)
$hNext = GUICtrlCreateButton("Next", 75, 45, 60, 24, $BS_FLAT)

; This code build two arrays of ID's of icons and labels for easily update
For $iCntRow = 0 To 4
    For $iCntCol = 0 To 5
        $iCurIndex = $iCntRow * 6 + $iCntCol
        $ahIcons[$iCurIndex] = GUICtrlCreateIcon($sFilename, $iCurIndex, _
                60 * $iCntCol + 25, 70 * $iCntRow + 80)
        $ahLabels[$iCurIndex] = GUICtrlCreateLabel($iCurIndex, _
                60 * $iCntCol + 11, 70 * $iCntRow + 115, 60, 20, $SS_CENTER)
    Next
Next
$Test = GUICtrlCreateLabel("", -100, -100, 10, 10)
GUISetState()

While 1
    $iMsg = GUIGetMsg(1)
    
    
; Changes (My code) start here !!!!
    
    
    $mPos = MouseGetPos()
    $wPos = WinGetPos("Icon Selector")
    ToolTip($mPos[0] - $wPos[0] & " / " & $mPos[1] - $wPos[1])
    If _IsPressed (01, $dll) Or _IsPressed (02, $dll) Then
        $mPos = MouseGetPos()
        $wPos = WinGetPos("Icon Selector")
        If $mPos[1] - $wPos[1] > 80 Then
            $xCounter = 0
            $yCounter = 0
            While 1
                If $xCounter = 5 Then ExitLoop
                If ($mPos[0] - $wPos[0]) - (($xCounter + 1) * 60) >= 25 - 16 Then
                    $xCounter = $xCounter + 1
                Else
                    ExitLoop
                EndIf
            WEnd
            While 1
                If $yCounter = 4 Then ExitLoop
                If ($mPos[1] - $wPos[1]) - (($yCounter + 1) * 70) >= 80 - 16 Then
                    $yCounter = $yCounter + 1
                Else
                    ExitLoop
                EndIf
            WEnd
        ; ConsoleWrite ( $xCounter & @CR )
        ; ConsoleWrite ( $yCounter & @CR )
            ConsoleWrite($yCounter * 6 + $xCounter & @CR)
            GUICtrlDelete($Test)
        ; MouseClick ("Right", $mPos[0], $mPos[1] )
            $Menu = GUICtrlCreateContextMenu($ahIcons[$yCounter * 6 + $xCounter])
            $Delete = GUICtrlCreateMenuItem("Delete", $Menu)
            $Rename = GUICtrlCreateMenuItem("Rename", $Menu)
            $Open = GUICtrlCreateMenuItem("Open", $Menu)
        ; ConsoleWrite('@@ Debug(73) : $yCounter*60+80 = ' & $yCounter*60+80 & @lf & '>Error code: ' & @error & @lf);### Debug Console
        ; ConsoleWrite('@@ Debug(73) : $xCounter*70+25 = ' & $xCounter*70+25 & @lf & '>Error code: ' & @error & @lf);### Debug Console
            Sleep(250)
        EndIf
    EndIf
    
    
; Changes (My code) end here
    
    
; Code below will check if the file is dropped (or selected)
    $sCurFilename = GUICtrlRead($hFile)
    If $sCurFilename <> $sFilename Then
        $iStartIndex = 0
        $sFilename = $sCurFilename
        _GUIUpdate()
    EndIf
; Main "Select" statement that handles other events
    Select
        Case $iMsg[0] = $hFileSel
            $sTmpFile = FileOpenDialog("Select file:", "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}", "Executables & dll's (*.exe;*.dll;*.ocx;*.icl)")
            If @error Then ContinueLoop
            GUICtrlSetData($hFile, $sTmpFile); GUI will be updated at next iteration
        Case $iMsg[0] = $hPrev
            $iStartIndex = $iStartIndex - 30
            _GUIUpdate()
        Case $iMsg[0] = $hNext
            $iStartIndex = $iStartIndex + 30
            _GUIUpdate()
        Case $iMsg[0] = $GUI_EVENT_CLOSE
            DllClose($dll)
            Exit
    EndSelect
WEnd

; Just updates GUI icons, labels and set state of "Previous" button
Func _GUIUpdate()
    For $iCntRow = 0 To 4
        For $iCntCol = 0 To 5
            $iCurIndex = $iCntRow * 6 + $iCntCol
            GUICtrlSetImage($ahIcons[$iCurIndex], $sFilename, $iCurIndex + $iStartIndex)
            GUICtrlSetData($ahLabels[$iCurIndex], $iCurIndex + $iStartIndex)
        Next
    Next
; This is because we don't want negative values
    If $iStartIndex = 0 Then
        GUICtrlSetState($hPrev, $GUI_DISABLE)
    Else
        GUICtrlSetState($hPrev, $GUI_ENABLE)
    EndIf
EndFunc  ;==>_GUIUpdate
Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.