SuperMonkey

Clipboard.cpp

Jul 14th, 2012
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.99 KB | None | 0 0
  1. #include "clipboard.h"
  2.  
  3. Clipboard::Clipboard()
  4. {
  5.  
  6. }
  7.  
  8. bool Clipboard::clear()
  9. {
  10.     return EmptyClipboard();
  11. }
  12.  
  13. bool Clipboard::open()
  14. {
  15.     return OpenClipboard(0);
  16. }
  17.  
  18. bool Clipboard::close()
  19. {
  20.     return CloseClipboard();
  21. }
  22.  
  23. QString Clipboard::readData() const
  24. {
  25.     return QString((char*) GlobalLock(GetClipboardData(CF_TEXT)));
  26. }
  27.  
  28. bool Clipboard::setData(QString str)
  29. {
  30.     HGLOBAL hText;
  31.     char *pText;
  32.  
  33.     hText = GlobalAlloc(GMEM_DDESHARE|GMEM_MOVEABLE, 100);
  34.     pText = (char*) GlobalLock(hText);
  35.  
  36.     strcpy(pText, (char*) str.toStdString().c_str());
  37.     GlobalUnlock(hText);
  38.  
  39.     SetClipboardData(CF_TEXT, hText);
  40. }
  41.  
  42. //-------------------------EXAMPLE-------------------------
  43. #include <QApplication>
  44. #include <QLabel>
  45.  
  46. int main(int argc, char* argv[])
  47. {
  48.     QApplication app(argc, argv);
  49.  
  50.     Clipboard* c = new Clipboard();
  51.     c->open();
  52.  
  53.     QLabel *label = new QLabel(c->readData());
  54.     label->show();
  55.  
  56.     c->close();
  57.     delete c;
  58.    
  59.     return app.exec();
  60. }
Advertisement
Add Comment
Please, Sign In to add comment