I think I made that more complicated than necessary - you can probably
perform the exact same steps using just win32clipboard - the key is
checking is that clipboard format is available, getting the data, then
using struct to convert it to an int.
Mark
On 11/12/2009 11:28 AM, Mark Hammond wrote:
On 10/12/2009 5:05 PM, Stuart Axon wrote:
Hi,
I made the a script to manipulate files copied into the clipboard from
explorer.
To know if the file was cut or copied it seems need to get information
about the DropEffect - is there a way to do this from win32clipboard ?
I think you want to look at pythoncom.OleGetClipboard(), then using the
IDataObject returned. IIRC, you will need to query for the clipboard
format CFSTR_PREFERREDDROPEFFECT and do other non-obvious stuff.
The following code seems to work (although note various errors may be
raised if what you expect isn't in the clipboard.
Note that you don't need to jump through these hoops when you are the
"drop target" - the drop target is passed this flag as a param as it is
dropped.
HTH,
Mark
from win32com.shell import shellcon
import pythoncom
import win32clipboard
import struct
CF_PREFERREDDROPEFFECT = win32clipboard.RegisterClipboardFormat(
shellcon.CFSTR_PREFERREDDROPEFFECT)
data_obj = pythoncom.OleGetClipboard()
# Make a FORMATETC
fe = (CF_PREFERREDDROPEFFECT, None, pythoncom.DVASPECT_CONTENT, -1,
pythoncom.TYMED_HGLOBAL)
medium = data_obj.GetData(fe)
de = struct.unpack("i", medium.data[:4])[0]
print "Drop effect is", de
_______________________________________________
python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32