Beispiel #1
0
    def GetData(self, fe):
        ret_stg = None
        cf, target, aspect, index, tymed = fe
        if aspect & pythoncom.DVASPECT_CONTENT and tymed == pythoncom.TYMED_HGLOBAL:
            if cf == win32con.CF_TEXT:
                ret_stg = pythoncom.STGMEDIUM()
                ret_stg.set(pythoncom.TYMED_HGLOBAL, self.bytesval)
            elif cf == win32con.CF_UNICODETEXT:
                ret_stg = pythoncom.STGMEDIUM()
                ret_stg.set(pythoncom.TYMED_HGLOBAL, self.bytesval.decode("latin1"))

        if ret_stg is None:
            raise COMException(hresult=winerror.E_NOTIMPL)
        return ret_stg
Beispiel #2
0
    def GetData(self, fe):
        ret_stg = None
        cf, target, aspect, index, tymed = fe
        if aspect & pythoncom.DVASPECT_CONTENT and \
                tymed == pythoncom.TYMED_HGLOBAL:
            if cf == win32con.CF_TEXT:
                ret_stg = pythoncom.STGMEDIUM()
                # ensure always 'bytes' by encoding string.
                ret_stg.set(pythoncom.TYMED_HGLOBAL, str2bytes(self.strval))
            elif cf == win32con.CF_UNICODETEXT:
                ret_stg = pythoncom.STGMEDIUM()
                ret_stg.set(pythoncom.TYMED_HGLOBAL, str(self.strval))

        if ret_stg is None:
            raise COMException(hresult=winerror.E_NOTIMPL)
        return ret_stg
Beispiel #3
0
def clip_files(file_list):
    offset = ctypes.sizeof(DROPFILES)
    length = sum(len(p) + 1 for p in file_list) + 1
    size = offset + length * ctypes.sizeof(ctypes.c_wchar)
    buf = (ctypes.c_char * size)()
    df = DROPFILES.from_buffer(buf)
    df.pFiles, df.fWide = offset, True
    for path in file_list:
        path = path.decode('gbk')
        array_t = ctypes.c_wchar * (len(path) + 1)
        path_buf = array_t.from_buffer(buf, offset)
        path_buf.value = path
        offset += ctypes.sizeof(path_buf)
    stg = pythoncom.STGMEDIUM()
    stg.set(pythoncom.TYMED_HGLOBAL, buf)
    win32clipboard.OpenClipboard()
    win32clipboard.EmptyClipboard()
    try:
        win32clipboard.SetClipboardData(win32clipboard.CF_HDROP, stg.data)
    finally:
        win32clipboard.CloseClipboard()
Beispiel #4
0
def set_clipboard_file_old(content):
    ret_stg = pythoncom.STGMEDIUM()
    fname_buf=str2bytes(content)

    fname_ba=bytearray(fname_buf)
    fname_ba.append('\0')
    fname_ba.append('\0')
    fmt="lllll%ss" %len(fname_ba)
    df=struct.pack(fmt, 20, 0, 0, 0, 0, str(fname_ba))
    ret_stg.set(pythoncom.TYMED_HGLOBAL, df)
    try:
        cb.OpenClipboard()
        cb.EmptyClipboard()
    except:
        print ("open failed, exception=%s"%FormatMessage(GetLastError()))
    else: 
        try:
            cb.SetClipboardData(cb.CF_HDROP, ret_stg.data)
        except:
            print ("set failed, exception = %s"%FormatMessage(GetLastError()))
        finally:
            cb.CloseClipboard()