关于操作剪切板的问题

bean11222 2013-02-22 11:09:46
在MFC中 下面操作剪切板的代码不成功 不晓得问题出现在哪,麻烦有知道的说下,多谢。

CString TotalStr = "123456";

char* Buffer;
HGLOBAL ClipBuffer;
EmptyClipboard();
ClipBuffer = GlobalAlloc(GMEM_MOVEABLE, TotalStr.GetLength() + 1);
Buffer = (char*)GlobalLock(ClipBuffer);
memcpy(Buffer, TotalStr.GetBuffer(), TotalStr.GetLength());
GlobalUnlock(ClipBuffer);
SetClipboardData(CF_TEXT, ClipBuffer);
CloseClipboard();
GlobalFree(ClipBuffer);
...全文
192 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
bean11222 2013-02-23
  • 打赏
  • 举报
回复
多谢,已经解决了。
赵4老师 2013-02-23
  • 打赏
  • 举报
回复
EmptyClipboard The EmptyClipboard function empties the clipboard and frees handles to data in the clipboard. The function then assigns ownership of the clipboard to the window that currently has the clipboard open. BOOL EmptyClipboard(VOID) Parameters This function has no parameters. Return Values If the function succeeds, the return value is nonzero. If the function fails, the return value is zero. To get extended error information, call GetLastError. Remarks Before calling EmptyClipboard, an application must open the clipboard by using the OpenClipboard function. If the application specifies a NULL window handle when opening the clipboard, EmptyClipboard succeeds but sets the clipboard owner to NULL. QuickInfo Windows NT: Requires version 3.1 or later. Windows: Requires Windows 95 or later. Windows CE: Requires version 1.0 or later. Header: Declared in winuser.h. Import Library: Use user32.lib. See Also Clipboard Overview, Clipboard Functions, OpenClipboard, SetClipboardData, WM_DESTROYCLIPBOARD

64,654

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧