wxpython 树菜单单击_请教怎么在wxpython调用windows系统的右键菜单(context menu)?

我在学习使用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)

结果触发的时候,没有异常报出,整个程序直接崩溃了...

请问那位朋友了解有相关的问题... 谢谢了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值