Copy and paste data using clipboard in BCB

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.