MFC - 获取剪切板上的内容
1 // 获取剪切板上的字符串 2 CString CLogic::fnGetStrFromClipboard(void) 3 { 4 CString strTmp; 5 strTmp.Empty(); 6 if ( ::OpenClipboard(NULL) ) 7 { 8 UINT nFormat = (sizeof(TCHAR) == sizeof(WCHAR) ? CF_UNICODETEXT:CF_TEXT); 9 HGLOBAL hClip = GetClipboardData(nFormat); // typedef HANDLE HGLOBAL 10 if ( hClip ) 11 { 12 char *pBuff = ( char* )GlobalLock( hClip ); 13 GlobalUnlock( hClip ); 14 strTmp.Format( _T("%s"), pBuff ); 15 } 16 CloseClipboard(); 17 } 18 return strTmp; 19 }