/contextmenu.ahk

http://7plus.googlecode.com/ · AutoHotKey · 33 lines · 19 code · 1 blank · 13 comment · 4 complexity · 7d1188d599f5de551b720a3f26caebac MD5 · raw file

  1. ;Checks if a context menu is active and has focus
  2. ;Need to check if other context menus are active (trillian, browsers,...)
  3. IsContextMenuActive()
  4. {
  5. GuiThreadInfoSize := 24 + 6 * A_PtrSize
  6. VarSetCapacity(GuiThreadInfo, GuiThreadInfoSize)
  7. NumPut(GuiThreadInfoSize, GuiThreadInfo, 0)
  8. if not DllCall("GetGUIThreadInfo", uint, 0, "Ptr", &GuiThreadInfo)
  9. {
  10. ;MsgBox GetGUIThreadInfo() indicated a failure.
  11. return
  12. }
  13. ; GuiThreadInfo contains a DWORD flags at byte 4
  14. ; Bit 4 of this flag is set if the thread is in menu mode. GUI_INMENUMODE = 0x4
  15. if (NumGet(GuiThreadInfo, 4) & 0x4)
  16. return true
  17. return false
  18. }
  19. ;This stuff doesn't properly use COM.ahk yet :(
  20. /*
  21. Executes context menu entries of shell items without showing their menus
  22. Usage:
  23. ShellContextMenu("Desktop",1) ;Calls "Next Desktop background" in Win7
  24. 1st parameter can be "Desktop" for empty selection desktop menu, a path, or an idl
  25. Leave 2nd parameter empty to show context menu and extract idn by clicking on an entry (shows up in debugview)
  26. */
  27. ShellContextMenu(sPath,idn=0)
  28. {
  29. result := DllCall(Settings.DllPath "\Explorer.dll\ExecuteContextMenuCommand", "Str", sPath, "Int", idn, "PTR", A_ScriptHwnd)
  30. if(Errorlevel != 0)
  31. Notify("Couldn't execute context menu command!", "Error Calling ExecuteContextMenuCommand() in Explorer.dll!", 5, NotifyIcons.Error)
  32. }