def OnContextMenu(self, hwnd, msg, wparam, lparam):
# Get the selected items.
pidls = []
n = -1
while 1:
n = win32gui.SendMessage(self.hwnd_child,
commctrl.LVM_GETNEXTITEM,
n,
commctrl.LVNI_SELECTED)
if n==-1:
break
pidls.append(self.children[n][-1:])
spt = win32api.GetCursorPos()
if not pidls:
print "Ignoring background click"
return
# Get the IContextMenu for the items.
inout, cm = self.folder.GetUIObjectOf(self.hwnd_parent, pidls, shell.IID_IContextMenu, 0)
hmenu = win32gui.CreatePopupMenu()
sel = None
# As per 'Q179911', we need to determine if the default operation
# should be 'open' or 'explore'
try:
flags = 0
try:
self.browser.GetControlWindow(shellcon.FCW_TREE)
flags |= shellcon.CMF_EXPLORE
except pythoncom.com_error:
pass
id_cmd_first = 1 # TrackPopupMenu makes it hard to use 0
cm.QueryContextMenu(hmenu, 0, id_cmd_first, -1, flags)
tpm_flags = win32con.TPM_LEFTALIGN | win32con.TPM_RETURNCMD | \
win32con.TPM_RIGHTBUTTON
sel = win32gui.TrackPopupMenu(hmenu,
tpm_flags,
spt[0], spt[1],
0, self.hwnd, None)
print "TrackPopupMenu returned", sel
finally:
win32gui.DestroyMenu(hmenu)
if sel:
ci = 0, self.hwnd_parent, sel-id_cmd_first, None, None, 0, 0, 0
cm.InvokeCommand(ci)
评论列表
文章目录