Update of /cvsroot/pywin32/pywin32/com/win32comext/shell/demos/servers
In directory sc8-pr-cvs1:/tmp/cvs-serv31365
Modified Files:
context_menu.py
Log Message:
Demonstrate how to get the filenames of the selected objects.
Index: context_menu.py
===================================================================
RCS file: /cvsroot/pywin32/pywin32/com/win32comext/shell/demos/servers/context_menu.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** context_menu.py 6 Oct 2003 13:40:09 -0000 1.2
--- context_menu.py 9 Oct 2003 12:34:35 -0000 1.3
***************
*** 26,43 ****
def Initialize(self, folder, dataobj, hkey):
print "Init", folder, dataobj, hkey
def QueryContextMenu(self, hMenu, indexMenu, idCmdFirst, idCmdLast, uFlags):
print "QCM", hMenu, indexMenu, idCmdFirst, idCmdLast, uFlags
idCmd = idCmdFirst
items = []
if (uFlags & 0x000F) == shellcon.CMF_NORMAL: # Check == here, since CMF_NORMAL=0
print "CMF_NORMAL..."
! items.append("&Hello from Python")
elif uFlags & shellcon.CMF_VERBSONLY:
print "CMF_VERBSONLY..."
! items.append("&Hello from Python - shortcut")
elif uFlags & shellcon.CMF_EXPLORE:
print "CMF_EXPLORE..."
! items.append("&Hello from Python - normal file, right-click in Explorer")
elif uFlags & CMF_DEFAULTONLY:
print "CMF_DEFAULTONLY...\r\n"
--- 26,53 ----
def Initialize(self, folder, dataobj, hkey):
print "Init", folder, dataobj, hkey
+ self.dataobj = dataobj
def QueryContextMenu(self, hMenu, indexMenu, idCmdFirst, idCmdLast, uFlags):
print "QCM", hMenu, indexMenu, idCmdFirst, idCmdLast, uFlags
+ # Query the items clicked on
+ format_etc = win32con.CF_HDROP, None, 1, -1, pythoncom.TYMED_HGLOBAL
+ sm = self.dataobj.GetData(format_etc)
+ num_files = shell.DragQueryFile(sm.data_handle, -1)
+ if num_files>1:
+ msg = "&Hello from Python (with %d files selected)" % num_files
+ else:
+ fname = shell.DragQueryFile(sm.data_handle, 0)
+ msg = "&Hello from Python (with '%s' selected)" % fname
idCmd = idCmdFirst
items = []
if (uFlags & 0x000F) == shellcon.CMF_NORMAL: # Check == here, since CMF_NORMAL=0
print "CMF_NORMAL..."
! items.append(msg)
elif uFlags & shellcon.CMF_VERBSONLY:
print "CMF_VERBSONLY..."
! items.append(msg + " - shortcut")
elif uFlags & shellcon.CMF_EXPLORE:
print "CMF_EXPLORE..."
! items.append(msg + " - normal file, right-click in Explorer")
elif uFlags & CMF_DEFAULTONLY:
print "CMF_DEFAULTONLY...\r\n"
|