剪贴板怎么操作
答案:2 悬赏:10 手机版
解决时间 2021-02-18 11:30
- 提问者网友:活着好累
- 2021-02-17 17:19
剪贴板怎么操作
最佳答案
- 五星知识达人网友:渊鱼
- 2021-02-17 18:09
// 复制数据至剪切板
BOOL CopyToClipboard(const char* pszData, const int nDataLen)
{
if(::OpenClipboard(NULL))
{
::EmptyClipboard();
HGLOBAL clipbuffer;
char *buffer;
clipbuffer = ::GlobalAlloc(GMEM_DDESHARE, nDataLen+1);
buffer = (char *)::GlobalLock(clipbuffer);
strcpy(buffer, pszData);
::GlobalUnlock(clipbuffer);
::SetClipboardData(CF_TEXT, clipbuffer);
::CloseClipboard();
return TRUE;
}
return FALSE;
}
// 从剪切板中取得数据
BOOL GetTextFromClipboard()
{
if(::OpenClipboard(NULL))
{
//获得剪贴板数据
HGLOBAL hMem = GetClipboardData(CF_TEXT);
if(NULL != hMem)
{
char* lpStr = (char*)::GlobalLock(hMem);
if(NULL != lpStr)
{
//MessageBox(0, lpStr, "", 0);
::GlobalUnlock(hMem);
}
}
::CloseClipboard();
return TRUE;
}
return FALSE;
}
//////////////////////////////////////////////////////////////////
模拟Ctrl+V
keybd_event(VK_CONTROL,0,0,0);
keybd_event('V',0,0,0);
keybd_event('V',0,KEYEVENTF_KEYUP,0);
keybd_event(VK_CONTROL,0,KEYEVENTF_KEYUP,0);
BOOL CopyToClipboard(const char* pszData, const int nDataLen)
{
if(::OpenClipboard(NULL))
{
::EmptyClipboard();
HGLOBAL clipbuffer;
char *buffer;
clipbuffer = ::GlobalAlloc(GMEM_DDESHARE, nDataLen+1);
buffer = (char *)::GlobalLock(clipbuffer);
strcpy(buffer, pszData);
::GlobalUnlock(clipbuffer);
::SetClipboardData(CF_TEXT, clipbuffer);
::CloseClipboard();
return TRUE;
}
return FALSE;
}
// 从剪切板中取得数据
BOOL GetTextFromClipboard()
{
if(::OpenClipboard(NULL))
{
//获得剪贴板数据
HGLOBAL hMem = GetClipboardData(CF_TEXT);
if(NULL != hMem)
{
char* lpStr = (char*)::GlobalLock(hMem);
if(NULL != lpStr)
{
//MessageBox(0, lpStr, "", 0);
::GlobalUnlock(hMem);
}
}
::CloseClipboard();
return TRUE;
}
return FALSE;
}
//////////////////////////////////////////////////////////////////
模拟Ctrl+V
keybd_event(VK_CONTROL,0,0,0);
keybd_event('V',0,0,0);
keybd_event('V',0,KEYEVENTF_KEYUP,0);
keybd_event(VK_CONTROL,0,KEYEVENTF_KEYUP,0);
全部回答
- 1楼网友:污到你湿
- 2021-02-17 18:33
写了一个例子,其中的slxcopysinglefiletoclipboard函数可以将一个文件拷贝到剪切板。代码如下:
#include
#include
#include
bool slxcopysinglefiletoclipboard(lpcstr lpfiletocopy)
{
dword dwlength = lstrlen(lpfiletocopy) + 1;
dword dwbuffersize = dwlength + 1 + sizeof(dropfiles);
char *lpbufferall = new char[dwbuffersize];
if(lpbufferall != null)
{
dropfiles *pslxdropfiles = (dropfiles *)lpbufferall;
pslxdropfiles->fnc = false;
pslxdropfiles->pt.x = 0;
pslxdropfiles->pt.y = 0;
pslxdropfiles->fwide = false;
pslxdropfiles->pfiles = sizeof(dropfiles);
lpstr lpfile = lpbufferall + sizeof(dropfiles);
lstrcpy(lpfile, lpfiletocopy);
lpfile[dwlength] = '\0';
hglobal hgblfiles = globalalloc(gmem_zeroinit | gmem_moveable | gmem_ddeshare, dwbuffersize);
if(hgblfiles != null)
{
lpstr lpgbldata = (char *)globallock(hgblfiles);
if(lpgbldata != null)
{
memcpy(lpgbldata, lpbufferall, dwbuffersize);
globalunlock(hgblfiles);
}
}
if(openclipboard(null))
{
emptyclipboard();
setclipboarddata(cf_hdrop, hgblfiles);
closeclipboard();
}
delete []lpbufferall;
return true;
}
return false;
}
int main()
{
slxcopysinglefiletoclipboard("c:\\windows\\notepad.exe");
return 0;
}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯