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