Sign in to follow this  
Followers 0
riteshtechie

How to disable context menu item in windows 7

3 posts in this topic

#1 ·  Posted (edited)

I used the following code to disable "Rename" Right click context menu in Windows 7 in Autohotkey. But I would like to do the same in Autoit, as am new to it, I don't know, can anyone help.

#SingleInstance Force
#NoTrayIcon 
#NoEnv

 
MF_BYPOSITION := 0x0400, MF_GRAYED := 0x01
 
Loop {

        WinWait, ahk_class #32770
        WinGetClass, class, A
        If class in Progman,CabinetWClass,ExploreWClass
        {
                SendMessage, 0x01E1
                MenuID := ErrorLevel
                Loop, % DllCall("GetMenuItemCount", UInt, MenuID)
                {
                                if RegExReplace(GetMenuItemText(MenuID, A_Index-1), "&")="Rename"
                                DllCall("EnableMenuItem", "UInt", MenuID, "UInt", A_Index-1, "UInt", MF_BYPOSITION | MF_GRAYED)
                }
        }
        WinWaitClose
}
 
GetMenuItemText(ByRef MenuID, i, MenuStrlen=0){
        global MF_BYPOSITION
        VarSetCapacity(MenuStr, MenuStrLen)
        Len := DllCall("GetMenuString", "UInt", MenuID, "UInt", i, "str", MenuStr, "UInt", MenuStrLen, "UInt", MF_BYPOSITION)
        if(MenuStrLen=0 and Len!=0)
                return GetMenuItemText(MenuID, i, Len+1)
        Else
                return MenuStr
}




#F8::ExitApp

Also if any one can tell me similar functions for

#NoTrayIcon

it hides tray icon.

Edited by riteshtechie

Share this post


Link to post
Share on other sites



I just can say that #NoTrayIcon is the same in AutoIt. :x

AutoHotKey is confusing to me!


Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Share this post


Link to post
Share on other sites

AutoHotKey is confusing to me!

Yeah and your annoying avatar deserves a line in my urlfilter.ini.

@riteshtechie

Explorer right click menu does (always) have Class #32768 for me, so you may need to change it back to your #32770.

#NoTrayIcon
#Include <SendMessage.au3>


Global Const $MF_BYPOSITION = 0x0400
Global Const $MF_GRAYED = 0x1
HotKeySet("{F8}", "Terminate")

$itemtext = 'Rename'


while 1

    $wnd = WinWait('[CLASS:#32768]')
    $hwnd = _SendMessage($wnd, 0x01E1)
    $MenuCount = GetMenuItemCount($hwnd)

    For $x = 0 To $MenuCount
        $text = _GUICtrlMenuGetString($hwnd, GetMenuItemID($hwnd, $x))
        IF StringReplace($text, '&', '') == $itemtext Then DllCall("User32.dll", "Int", "EnableMenuItem", "HWND", $hwnd, "UInt", $x, "UInt", BitOR($MF_BYPOSITION, $MF_GRAYED))
    Next

WEnd



Func Terminate()
    Exit 0
EndFunc

Func GetMenuItemCount($hMenu)
    Local $nCount = DllCall('user32.dll', "int", "GetMenuItemCount", "hwnd", $hMenu)
    Return $nCount[0]
EndFunc

Func GetMenuItemID($hMenu, $nPos)
    Local $nID = DllCall('user32.dll', "int", "GetMenuItemID", "hwnd", $hMenu, "int", $nPos)
    Return $nID[0]
EndFunc

;http://my-autoit.googlecode.com/svn-history/r29/trunk/Scripts/MkCabSFX/Includes/GuiMenu1.au3
Func _GUICtrlMenuGetString($GMS_hWnd, $GMS_id, $GMS_Opt=0)
  If $GMS_hWnd <= 0 Or $GMS_id < 0 Then Return 0
  Local $MF_BYCOMMAND = 0x00000000
  Local $MF_BYPOSITION = 0x00000400
  If $GMS_Opt = 0 Then
     $GMS_Opt = $MF_BYCOMMAND
  Else
     $GMS_Opt = $MF_BYPOSITION
  EndIf
  Local $GMS_r = DllCall("user32.dll","int","GetMenuString", _
                   "hwnd",$GMS_hWnd, _
                   "int",$GMS_id, _
                   "str","","int",0, _
                   "int",$GMS_Opt)
  If @error Then Return 0
  $GMS_r = DllCall("user32.dll","int","GetMenuString", _
                   "hwnd",$GMS_hWnd, _
                   "int",$GMS_id, _
                   "str","","int",$GMS_r[0]+1, _
                   "int",$GMS_Opt)
  If @error Then Return 0
  Return $GMS_r[3]
EndFunc

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