[python-win32] Files in clipboard with DropEffect?

Stuart Axon stuaxo2 at yahoo.com
Mon Dec 21 18:53:58 CET 2009


Cheers, that works great :)

CF_PREFERREDDROPEFFECT = win32clipboard.RegisterClipboardFormat(
        shellcon.CFSTR_PREFERREDDROPEFFECT)
    effect_str = win32clipboard.GetClipboardData(CF_PREFERREDDROPEFFECT)
    de = struct.unpack("i", effect_str[:4])[0]



----- Original Message ----
From: Mark Hammond <mhammond at skippinet.com.au>
To: Stuart Axon <stuaxo2 at yahoo.com>
Sent: Thu, December 17, 2009 9:59:22 PM
Subject: Re: [python-win32] Files in clipboard with DropEffect?

Yeah - something like:

CF_PREFERREDDROPEFFECT = win32clipboard.RegisterClipboardFormat( 
shellcon.CFSTR_PREFERREDDROPEFFECT)
effect_str = GetClipboardData(CFSTR_PREFERREDDROPEFFECT)
de = struct.unpack("i", effect_str[:4])[0]

Cheers,

Mark

On 18/12/2009 12:50 AM, Stuart Axon wrote:
> Cheers, I'll try the first way as I'm a bit new to win32 programming
> (I'm guessing your saying I could get do something along the lines of...
>
> effect = GetClipboardData(CFSTR_PREFERREDDROPEFFECT)  ?
>
> I wasn't quite sure how to get this working though).
>
>
>
>
> ----- Original Message ----
> From: Mark Hammond<skippy.hammond at gmail.com>
> To: mhammond at skippinet.com.au
> Cc: Stuart Axon<stuaxo2 at yahoo.com>; python-win32 at python.org
> Sent: Fri, December 11, 2009 12:35:12 AM
> Subject: Re: [python-win32] Files in clipboard with DropEffect?
>
> 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
>
>
>


      


More information about the python-win32 mailing list