delphi cannot open clipboard错误

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了delphi cannot open clipboard错误相关的知识,希望对你有一定的参考价值。

我做一个小程序,用到了模拟CTRL+C,CTRL+V等操作,总是报cannot open clipboard,第一次还能复制成功,复制第二次就报错,我Open,close,free都试了都不管事,希望大家帮帮忙

有时候是系统问题,
你用编译好的程序到别的电脑上试试
参考技术A 用 CopyToClipboard 试试 参考技术B 代码放出来看看

delphi 写的程序报cannot open clipboard错误,直接上代码,希望大家帮忙看一下

ctrl+A
keybd_event(VK_CONTROL,MapVirtualKey(VK_CONTROL,0),0,0);
keybd_event(Ord('A'),MapVirtualKey(Ord('A'),0),0,0);
keybd_event(Ord('A'),MapVirtualKey(Ord('A'),0),KEYEVENTF_KEYUP,0);
keybd_event(VK_CONTROL,MapVirtualKey(VK_CONTROL,0),KEYEVENTF_KEYUP,0);
ctrl+C
keybd_event(VK_CONTROL,MapVirtualKey(VK_CONTROL,0),0,0);
keybd_event(Ord('C'),MapVirtualKey(Ord('C'),0),0,0);
keybd_event(Ord('C'),MapVirtualKey(Ord('C'),0),KEYEVENTF_KEYUP,0);
keybd_event(VK_CONTROL,MapVirtualKey(VK_CONTROL,0),KEYEVENTF_KEYUP,0);

Form1.RichEdit1.Clear;
Form1.RichEdit1.PasteFromClipboard;

m:=Form1.subStr(str); //得到的是一个字符串 比如“你好”
Clipboard.AsText:=m;
SetForeGroundWindow(hwnd);
sendMessage(hwnd,messages.WM_LBUTTONDOWN,VK_LBUTTON, MakeLParam(50,r.Bottom-60));
sendMessage(hwnd,messages.WM_LBUTTONUP,VK_LBUTTON, MakeLParam(50,r.Bottom-60));
keybd_event(VK_CONTROL,MapVirtualKey(VK_CONTROL,0),0,0);
keybd_event(Ord('V'),MapVirtualKey(Ord('V'),0),0,0);
keybd_event(Ord('V'),MapVirtualKey(Ord('V'),0),KEYEVENTF_KEYUP,0);
keybd_event(VK_CONTROL,MapVirtualKey(VK_CONTROL,0),KEYEVENTF_KEYUP,0);

参考技术A Clipboard单元引用了吗追问

不引用,编译就过不去,我这是在运行的过程中出现的问题

以上是关于delphi cannot open clipboard错误的主要内容,如果未能解决你的问题,请参考以下文章

解决Delphi 2010启动时出现cannot create xxxxEditorLineEnds.ttr问题

Delphi程序问题:adoquery1:cannot perform this operation on a closed dataset.

Cannot open URL…

gedit:cannot open display

cannot open clipboard

markdown 灵感来自StackOverflow问题http://stackoverflow.com/questions/18600638/google-script-copy-to-clipbo