Different Methods for copying a string to the clipboard: # include <VCL/clipbrd. HPP> // Method 1: tclipboard * pclipboard = new tclipboard (); pclipboard-> astext = "Copy text data to the Clipboard"; Delete pclipboard; // Method 2: tclipboard * pclipboard = new tclipboard (); pclipboard-> settextbuf ("Copy to clipboard text data"); Delete pclipboard; // method 3: clipboard () -> settextbuf ("Copy text data to the clipboard version"); // Method 4: clipboard ()-> astext = "Copy text data to the clipboard version ";
// Copy the file to the clipboard
Bool copyfiletoclip (lpcstr pcfile)
{
// Sfile is the copy file name. Multiple files are separated by/0 and end with/0/0.
Int nlen;
Byte * pdata;
Hglobal hgbl;
Dropfiles DF;
If (! Pcfile |! Pcfile [0])
Return false;
If (! Openclipboard (0 ))
Return false;
Emptyclipboard ();
DF. FNC = false;
DF. fwide = false;
DF. pfiles = sizeof (DF );
Df.pt. x = df.pt. Y = 0;
For (nlen = 0; pcfile [nlen]! = 0 ;)
Nlen + = strlen (pcfile + nlen) + 1;
Nlen + = 1; // The second ending at the end/0 characters
Hgbl = globalalloc (ghnd, sizeof (DF) + nlen );
Pdata = (byte *) globallock (hgbl );
If (pdata! = NULL)
{
Memcpy (pdata, & DF, sizeof (DF ));
Memcpy (pdata + sizeof (DF), pcfile, nlen );
Globalunlock (hgbl );
If (! Setclipboarddata (cf_hdrop, hgbl ))
{
Globalfree (hgbl );
Hgbl = NULL;
}
}
Else if (hgbl! = NULL)
{
Globalfree (hgbl );
Hgbl = NULL;
}
Closeclipboard ();
Return (hgbl! = NULL );
}
//---------------------------------------------------------------------------
// Extract the file from the clipboard Paste
Bool pastefilefromclip (lpcstr pcdesdir)
{
Int nlen;
Bool breturn;
Lpcstr lpcdata;
Hglobal hgbl;
Ansistring strtemp;
Dropfiles * pdf;
Shfileopstruct Fos;
If (! Pcdesdir |! Pcdesdir [0])
Return false;
If (! Openclipboard (0 ))
Return false;
Hgbl = getclipboarddata (cf_hdrop );
PDF = hgbl? (Dropfiles *) globallock (hgbl): NULL;
If (PDF = NULL)
{
Closeclipboard ();
Return false;
}
Lpcdata = (lpcstr) PDF + PDF-> pfiles;
Memset (& FOS, 0, sizeof (FOS ));
If (PDF-> fwide)
{
Strtemp = widecharlentostring (wchar_t *) lpcdata, globalsize (hgbl)-PDF-> pfiles );
FOS. pfrom = strtemp. c_str ();
}
Else
FOS. pfrom = lpcdata;
FOS. wfunc = fo_copy;
FOS. PTO = pcdesdir;
Breturn = shfileoperation (& FOS) = 0;
Globalunlock (hgbl );
Closeclipboard ();
Return breturn;
}
// If (copyfiletoclip ("C: // 1.txt/ 0C: // test.exe/0 "))
// Pastefilefromclip ("D ://");
Reply:Ccrun (old demon) (www.ccrun.com)() Sweat... # Define no_win32_lean_and_mean // exclude rarely used data from the Windows header # include <shlobj. h> # include <VCL. h> add them to the beginning of the CPP file. Note that it is CPP, not an H file.