Operation Programming of clipboard

Source: Internet
Author: User

// The following code copies the "Hello World" string to the clipboard. After the code is executed, paste it at another address and you will see "Hello World"

# Include <windows. h>

Void copystringclipboard (hwnd, char * Str) // Save the string to the clipboard:
{
Hglobal hclip;
// Define an hglobal handle variable to point to the allocated memory block
If (openclipboard (hwnd ))
{
Emptyclipboard (); // clear the clipboard content
Hclip = globalalloc (gmem_moveable, strlen (STR) + 1 );
// Allocate removable memory blocks on the heap. The program returns a memory handle.
Char * Buff; // defines the pointer variable pointing to the struct type
Buff = (char *) globallock (hclip );
// Lock the allocated memory block, convert the memory block handle into a pointer, and Add 1
Strcpy_s (buff, strlen (STR) + 1, STR );
// Wcscpy (buff, STR );
// Copy the user input data to the pointer variable, which is actually copied to the allocated memory block.
Globalunlock (hclip );
// After the data is written, unlock the data and reduce the number of the referenced counter by 1.
Setclipboarddata (cf_text, hclip );
// Put the memory block containing data into the resource management of the clipboard
Closeclipboard ();
// Close the clipboard and release the occupied resources of the clipboard.
// MessageBox (L "data has been saved to the Clipboard ");
}
}

Int _ tmain (INT argc, _ tchar * argv [])
{
Copystringclipboard (null, "Hello World ");
Return 0;
}

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.