-
Notifications
You must be signed in to change notification settings - Fork 0
/
Clipboard.cpp
100 lines (75 loc) · 1.48 KB
/
Clipboard.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include "stdafx.h"
#include "Clipboard.h"
Clipboard::Clipboard()
{
}
Clipboard::~Clipboard()
{
}
void Clipboard::Open()
{
OpenClipboard(NULL);
}
void Clipboard::Close()
{
CloseClipboard();
}
void Clipboard::Clear()
{
EmptyClipboard();
}
char* Clipboard::GetText()
{
Open();
HANDLE hClipboard = GetClipboardData(CF_TEXT);
Close();
m_szText = (char*)hClipboard;
return m_szText;
}
void Clipboard::SetText(const char *szText)
{
Open();
Clear();
HGLOBAL hMem = GlobalAlloc(GMEM_DDESHARE, strlen(szText)+1);
char *buffer;
buffer = (char*)GlobalLock(hMem);
strcpy(buffer, szText);
GlobalUnlock(hMem);
SetClipboardData(CF_TEXT, hMem);
Close();
}
void Clipboard::SaveImage(char *szFileName)
{
Open();
HBITMAP hBitmap = (HBITMAP)GetClipboardData(CF_BITMAP);
Close();
CImage cImage;
cImage.Attach(hBitmap);
cImage.Save(szFileName, Gdiplus::ImageFormatJPEG);
}
char* Clipboard::GetFileDirectory()
{
Open();
HANDLE hData = GetClipboardData(CF_HDROP);
Close();
if( DragQueryFile((HDROP)hData, 0xFFFFFFFF, NULL, 0) == 1 )
{
DragQueryFile((HDROP)hData, 0, m_szFileName, MAX_PATH);
return m_szFileName;
}
return NULL;
}
unsigned int Clipboard::GetFormat()
{
Open();
if( IsClipboardFormatAvailable(CF_TEXT) )
return CF_TEXT;
else if( IsClipboardFormatAvailable(CF_UNICODETEXT) )
return CF_UNICODETEXT;
else if( IsClipboardFormatAvailable(CF_DIB) )
return CF_DIB;
else if( IsClipboardFormatAvailable(CF_HDROP) )
return CF_HDROP;
Close();
return 0;
}