How to copy files to clipboard

xiaoxiao2021-03-14  198

How to determine the content in the current clipboard as a file, how to copy the specified file (not the file content) into the clipboard. Excuse me: How to determine the content in the current clipboard as a file, how to copy the specified file (not the file content) into the clipboard.

INT getClipboardFormatName

Uint format, // clipboard format to retrieve

LPTSTR LPSZFORMATNAME, / / ​​Address of Buffer for Name

INT cchmaxcount // length of name string in characters

);

If format = cf_hdrop is the file

Handle setClipboardData

Uint uformat, // clipboard format

Handle HMEM // Data Handle

);

Menxin's solution is feasible .delphi defines two formats: CF_PICTURE and CF_Component.

Users can define their own format. But because Formats are Word format, there can only be in the system.

16 formats. Open the Clipbrd unit, you can find it.

CF_PICTURE: = RegisterClipboardFormat ('Delphi Picture');

Cf_component: = RegisterClipboardFormat ('Delphi Component');

You add:

Cf_myfile: = registerclipboardFormat ('my file format');

Clipboard operation:

turn on ;

Empty;

SetFormator (CF_Text) ---> File Name;

SetFormatdata (cf_myfile) ---> file content

shut down ;

If you are interested in file names, it is just a text format. Remove the content, query by fileexists

Whether it exists.

RegisterClipboardFormat function registration new clipboard format

Format value in the range of OXC000 and 0xFFFFFF

IsclipboardFormatavailable function determines if the clipboard contains specified formatted data

Format available returns non-zero value

Windows is defined:

Can use cf_hdrop;

Uses shlobj, activex, clipbrd;

Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT);

VAR

Fe: tFormatetc;

Medium: TSTGMEDIUM;

FILENAME: STRING;

Dropfiles: pdropfiles;

Pfile: pchar;

Begin

FileName: = 'c: /1.bmp';

Fe.cfformat: = cf_hdrop;

Fe.dwaspect: = DVASPECT_CONTENT;

Fe.Tymed: = TYMED_HGLOBAL;

Medium.hglobal: = GMEM_SHARE OR GMEM_ZEROINIT, SIZEOF (TDROPFILES) Length (filename) 1);

IF Medium.hglobal <> 0 THEN Begin

Medium.Tymed: = TYMED_HGLOBAL;

Dropfiles: = Globalock (Medium.hglobal);

Try

Dropfiles ^ .pfiles: = sizeof (TDROPFILES);

Dropfiles ^ .fwide: = false;

Longint (pfile): = longint (drop refiles) sizeof (TDROPFILES); Strpcopy (Pfile, FileName);

INC (Pfile, Length (filename) 1);

Pfile ^: = # 0;

Finally

GlobalUnlock (Medium.hglobal);

END;

Clipboard.Setashandle (CF_HDROP, Medium.hglobal);

END;

END;

Refer to DragDrop, it is not bad.

The above example puts the filename this file on the CLIPBOARD

转载请注明原文地址:https://www.9cbs.com/read-129449.html

New Post(0)