Auto_clipboard, clipboard

Source: Internet
Author: User

Auto_clipboard, clipboard

Huang shansong published in blog Park: http://www.cnblogs.com/tomview/p/6137179.html

# Ifndef _ HSS_AUTO_CLIPBOARD_HSS __
# Define _ HSS_AUTO_CLIPBOARD_HSS __

/*************************************** **************************************** **\
* 2012-10-30
Automatically copy content to clipboard

Usage:

Copy:
Auto_clipboard a (hwnd, psz );

Paste:
CString sz;
Auto_clipboard: GetText (sz );
\*************************************** ************************************/

Class auto_clipboard
{
Public:
Auto_clipboard (HWND hwnd, LPCTSTR pszText)
{
If (: OpenClipboard (hwnd ))
{
: EmptyClipboard ();

HANDLE hMem =: GlobalAlloc (GMEM_MOVEABLE | GMEM_DDESHARE, strlen (pszText) + 1 );
If (hMem)
{
Char * pszMem = (char *) (: GlobalLock (hMem ));
If (pszMem)
{
Strcpy (pszMem, pszText );
: GlobalUnlock (hMem );
SetClipboardData (CF_TEXT, hMem );
}
: GlobalFree (hMem );
}
CloseClipboard ();
}
}

~ Auto_clipboard ()
{
}

/*************************************** **********************************\
* Auto_clipboard: August 1, December 2, 2014
* CString sz:
\*************************************** ***********************************/
# Ifdef _ AFX_H __
Static BOOL GetText (CString & sz)
{
If (! OpenClipboard (0 ))
Return FALSE;

HANDLE hClip = GetClipboardData (CF_TEXT );

If (hClip = 0)
{
CloseClipboard ();
Return FALSE;
}

LPVOID pRes = (LPVOID) GlobalLock (hClip );

If (pRes = 0)
{
CloseClipboard ();
Return FALSE;
}

Sz = (char *) pRes;

GlobalUnlock (hClip );

CloseClipboard ();

Return TRUE;
}
# Endif
};


# Endif

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.