def OnItemRightClick(self, notify_data, extra):
# First select the item we right-clicked on.
pt = self.ScreenToClient(win32api.GetCursorPos())
flags, hItem = self.HitTest(pt)
if hItem==0 or commctrl.TVHT_ONITEM & flags==0:
return None
self.Select(hItem, commctrl.TVGN_CARET)
menu = win32ui.CreatePopupMenu()
menu.AppendMenu(win32con.MF_STRING|win32con.MF_ENABLED,1000, "Add Key")
menu.AppendMenu(win32con.MF_STRING|win32con.MF_ENABLED,1001, "Add Value")
menu.AppendMenu(win32con.MF_STRING|win32con.MF_ENABLED,1002, "Delete Key")
self.HookCommand(self.OnAddKey, 1000)
self.HookCommand(self.OnAddValue, 1001)
self.HookCommand(self.OnDeleteKey, 1002)
menu.TrackPopupMenu(win32api.GetCursorPos()) # track at mouse position.
return None
评论列表
文章目录