使用OpenClipboard()需要包含哪些内容?

时间:2015-09-04 13:49:06

标签: 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);
               ^

1 个答案:

答案 0 :(得分:4)

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

  

Winuser.h(包括Windows.h)