Copying Information to the Clipboard1.Opens the clipboard by calling the OpenClipboard function. 2.Empties the clipboard by calling the EmptyClipboard function. 3.Calls the SetClipboardData function once for each clipboard format the application provides. 4.Closes the clipboard by calling the CloseClipboard function. http://msdn.microsoft.com/en-us/library/ms649016(VS.85).aspx#_win32_Copying_Information_to_the_Clipboard
2.Empties the clipboard by calling the EmptyClipboard function.
3.Calls the SetClipboardData function once for each clipboard format the application provides.
4.Closes the clipboard by calling the CloseClipboard function. http://msdn.microsoft.com/en-us/library/ms649016(VS.85).aspx#_win32_Copying_Information_to_the_Clipboard
UINT uFormat, // clipboard format
HANDLE hMem // data handle
);下面是剪切板的一些函数:
OpenClipboard()
CloseClipboard()
EmptyClipboard()
GetClipboardData()
SetClipboardData()
EnumClipboardFormats()
SetClipboardViewer()
ChangeClipboardChain()
GetOpenClipboardWindow()
GetClipboardOwner()
void CMainFrame::ClipText(LPCTSTR psz)
{
HGLOBAL hglbCopy;
LPTSTR lptstrCopy; if (!::OpenClipboard(GetSafeHwnd())) return ;
int nlen = strlen(psz);
hglbCopy = GlobalAlloc(GMEM_DDESHARE, nlen+2); if (hglbCopy == NULL)
{
CloseClipboard();
return ;
} EmptyClipboard(); lptstrCopy = (LPTSTR)GlobalLock(hglbCopy);
strcpy((char *)lptstrCopy,psz);
lptstrCopy[nlen] = 0;
GlobalUnlock(lptstrCopy); SetClipboardData(CF_TEXT, hglbCopy);
CloseClipboard();
//MessageBox("已经将内容复制到剪贴板,\r\n你可以在其它编辑器中粘贴。");
return ;
}
GetDlgItemText(IDC_EDIT1, str);
HGLOBAL hClip;
if(OpenClipboard())
{
EmptyClipboard();
hClip = GlobalAlloc(GMEM_MOVEABLE, str.GetLength()+1);
char *buff;
buff = (char*)GlobalLock(hClip);
strcpy(buff, (char*)(LPCTSTR)str);
GlobalUnlock(hClip);
SetClipboardData(CF_TEXT, hClip);
CloseClipboard();
}