1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
| int textflag;
#ifdef _UNICODE
textflag = CF_UNICODETEXT;
#else
textflag = CF_TEXT;
#endif
if (!IsClipboardFormatAvailable(textflag)) //非unicode为CF_TEXT,unicode 为CF_UNICODETEXT
{
MessageBox(hWnd, _T("剪贴板上无文本数据,不能粘贴!"), _T("OpenFC"), MB_OK);
return false;
}
if (!OpenClipboard(hWnd))
{
MessageBox(hWnd, _T("剪贴板打开失败!"), L"OpenFC", MB_OK);
return false;
}
(TCHAR *)hClipboardText = GetClipboardData(textflag); //非unicode为CF_TEXT,unicode 为CF_UNICODETEXT
if (!hClipboardText)
{
MessageBox(hWnd, _T("无法读取剪贴板数据!"), _T("OpenFC"), MB_OK);
CloseClipboard();
break;
}
if (GetFocus() == hwndEditCode)
SendMessage(hwndEditCode, EM_REPLACESEL, 1, (LPARAM)GlobalLock(hClipboardText)); //发送到窗口
if (GetFocus() == hwndEditOut)
SendMessage(hwndEditOut, EM_REPLACESEL, 1, (LPARAM)GlobalLock(hClipboardText));
GlobalUnlock(hClipboardText);
CloseClipboard();
|