我在学习使用wxpython制作一款windows下的文件管理器,树形菜单已经实现,现在想实现在文件树节点上单击右键,弹出Explorer的上下文菜单,查阅资料无数..... wxpython没有内置的实现,看了一些别的语言的介绍,写出下面的代码片段
def GetFolderAndPIDLForPath(filename):
desktop = shell.SHGetDesktopFolder()
info = desktop.ParseDisplayName(0, None, os.path.abspath(filename))
cchEaten, pidl, attr = info
# We must walk the ID list, looking for one child at a time.
folder = desktop
while len(pidl) > 1:
this = pidl.pop(0)
folder = folder.BindToObject([this], None, shell.IID_IShellFolder)
# We are left with the pidl for the specific item. Leave it as
# a list, so it remains a valid PIDL.
return folder, pidl
def OnItemRightClick(self, evt):
hwnd = self.GetHandle()
folder, pidl = self.GetFolderAndPIDLForPath('D:\\')
pidls = [pidl]
inout, cm = folder.GetUIObjectOf(hwnd, pidls, shell.IID_IContextMenu, 0)
hmenu = win32gui.CreatePopupMenu()
flags = 0
flags |= shellcon.CMF_EXPLORE
cm.QueryContextMenu(hmenu, 0, 1, -1, flags)
spt = evt.GetPoint()
tpm_flags = win32con.TPM_LEFTALIGN | win32con.TPM_RETURNCMD | win32con.TPM_RIGHTBUTTON
win32gui.TrackPopupMenu(hmenu,tpm_flags,spt[0], spt[1], 0, hwnd, None)
结果触发的时候,没有异常报出,整个程序直接崩溃了...
请问那位朋友了解有相关的问题... 谢谢了