Jump to content
Sign in to follow this  
QingZi

Getting Windows Context Menu Items

Recommended Posts

QingZi

hi guys,

i am trying to obtain the list of items in my windows context menu. i have done extensive research on windows api calls and the closest i got was http://www.autoitscript.com/forum/index.php?showtopic=33677&st=15. however the code is already outdated. can anyone point me in the right direction? i tried looking at _winapi_enumwindowspopup but the sample script doesn't seem to work.

Share this post


Link to post
Share on other sites
rajeshontheweb
QingZi

thanks. i am really at my wits ends. i even tried doing searches on registry only to find out disappointingly that they are all over the place and it is different for every pc. no one seem to ask this question here before too so couldn't find any usable sample codings to tweak and modify

Share this post


Link to post
Share on other sites
UritOR

Well, now I got stuck on the same thing =( Can anyone help me? 

Share this post


Link to post
Share on other sites
MilesAhead

The static items that will load in the Context Menu are in the Registry.  For dynamic items Windows has 3 COM interfaces, IContextMenu, IContextMenu2, IContextMenu3.  You do not know what the COM dll or ocx is going to add to the menu until it responds to the QueryContextMenu

Basically it is a nightmare.

Edit:  My comment refers to Explorer Context Menu.  Regular context menus in applications are another matter.  Someone on another forum is trying to figure out how to filter dynamic Explorer Context Menu items so I made that connection.  My bad.  :)

 

Edited by MilesAhead
clarification

Share this post


Link to post
Share on other sites
LarsJ

If it's a standard #32768 class context menu it's pretty easy:

#include <GuiMenu.au3>
#include <SendMessage.au3>
#include <WindowsConstants.au3>

Opt( "MustDeclareVars", 1 )

Example()


Func Example()

  Local Static $hLastMenu = 0

  HotKeySet( "{ESC}", "Quit" )

  While Sleep( 100 )

    Local $hDesktop = _WinAPI_GetDesktopWindow(), $hMenu = 0
    Local $hChild = _WinAPI_GetWindow( $hDesktop, $GW_CHILD ), $i = 0
    While $hChild And $i < 5
      If _WinAPI_GetClassName( $hChild ) = "#32768" Then
        $hMenu = _SendMessage( $hChild, $MN_GETHMENU )
        ExitLoop
      EndIf
      $hChild = _WinAPI_GetWindow( $hChild, $GW_HWNDNEXT )
      $i += 1
    WEnd

    If $hMenu And $hLastMenu <> $hMenu Then
      Local $iCount = _GUICtrlMenu_GetItemCount( $hMenu ), $sText
      ConsoleWrite( "Menu:" & @CRLF )
      For $i = 0 To $iCount - 1
        $sText = _GUICtrlMenu_GetItemText( $hMenu, $i )
        If $sText <> "" Then ConsoleWrite( "  " & $sText & @CRLF )
      Next
      ConsoleWrite( @CRLF )
      $hLastMenu = $hMenu
    EndIf

  WEnd

EndFunc


Func Quit()
  Exit
EndFunc

1. Run the script in SciTE
2. Open the context menu
3. Names of menu items should be printed in console
4. Esc to exit script

Edited by LarsJ

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.