c++ - 我需要包括什么才能使用 OpenClipboard()?

标签 c++ windows clipboard

我写了一个简短的程序来测试 OpenClipboard 功能。我从 here 复制而来而且看起来您不需要包含任何内容。我正在使用记事本和命令提示符进行编程,所以我没有第三方程序告诉我出了什么问题。错误消息只是代码片段中使用的所有内容未在此范围内声明:

programm1.cpp: In function 'void toClipboard(const string&)':
programm1.cpp:65:17: error: 'OpenClipboard' was not declared in this scope
  OpenClipboard(0);
                 ^
programm1.cpp:66:17: error: 'EmptyClipboard' was not declared in this scope
  EmptyClipboard();
                 ^
programm1.cpp:67:2: error: 'HGLOBAL' was not declared in this scope
  HGLOBAL hg=GlobalAlloc(GMEM_MOVEABLE,s.size());
  ^
programm1.cpp:67:10: error: expected ';' before 'hg'
  HGLOBAL hg=GlobalAlloc(GMEM_MOVEABLE,s.size());
          ^
programm1.cpp:68:7: error: 'hg' was not declared in this scope
  if (!hg){
       ^
programm1.cpp:69:18: error: 'CloseClipboard' was not declared in this scope
   CloseClipboard();
                  ^
programm1.cpp:72:20: error: 'hg' was not declared in this scope
  memcpy(GlobalLock(hg),s.c_str(),s.size());
                    ^
programm1.cpp:72:22: error: 'GlobalLock' was not declared in this scope
  memcpy(GlobalLock(hg),s.c_str(),s.size());
                      ^
programm1.cpp:72:42: error: 'memcpy' was not declared in this scope
  memcpy(GlobalLock(hg),s.c_str(),s.size());
                                          ^
programm1.cpp:73:17: error: 'GlobalUnlock' was not declared in this scope
  GlobalUnlock(hg);
                 ^
programm1.cpp:74:19: error: 'CF_TEXT' was not declared in this scope
  SetClipboardData(CF_TEXT,hg);
                   ^
programm1.cpp:74:29: error: 'SetClipboardData' was not declared in this scope
  SetClipboardData(CF_TEXT,hg);
                             ^
programm1.cpp:75:17: error: 'CloseClipboard' was not declared in this scope
  CloseClipboard();
                 ^
programm1.cpp:76:15: error: 'GlobalFree' was not declared in this scope
  GlobalFree(hg);
               ^

最佳答案

OpenClipboard文档说明要使用的头文件是

Winuser.h (include Windows.h)

关于c++ - 我需要包括什么才能使用 OpenClipboard()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32399765/

相关文章:

c++ - 如何获取指向函数第一个参数的指针?

c++ - 如何获取使用标准库创建的线程的 winapi id?

c++ - 使用共享指针将调用链接在一起

windows - MFC:对哪个线程负责导致崩溃进行故障排除

javascript - 如何使用 jQuery 触发 Ctrl+C 按键事件?

flutter - 如何在 flutter 中将图像复制到剪贴板

c++ - 斐波那契数列的负输出

c++ - 哪个编译器最适合刚开始学习 C++ 的人?

windows - 如何移动到某个选项卡上某个窗口中存在的非隐藏缓冲区?

java - 从非 ui 线程设置剪贴板