-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcb2emf.cpp
51 lines (44 loc) · 934 Bytes
/
cb2emf.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
#define WINVER 0x0400
#define _WIN32_WINNT 0x0400
#define _WIN32_IE 0x0400
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <shlwapi.h>
void PrintError(LPCSTR s)
{
DWORD writtenBytes;
WriteFile(GetStdHandle(STD_ERROR_HANDLE), s, strlen(s), &writtenBytes, NULL);
}
bool ClipboardToEmf(LPCTSTR dstFile)
{
if (HENHMETAFILE hemfSrc = static_cast<HENHMETAFILE>(GetClipboardData(CF_ENHMETAFILE)))
{
if (HENHMETAFILE hemf = CopyEnhMetaFile(hemfSrc, dstFile))
{
DeleteEnhMetaFile(hemf);
return true;
}
else
{
PrintError("Failed to save EMF file.\r\n");
}
}
else
{
PrintError("Cannot get EMF from clipboard.\r\n");
}
return false;
}
int main()
{
LPCTSTR args = PathGetArgs(GetCommandLine());
if (args[0] == TEXT('\0'))
{
PrintError("Usage: cb2emf output-filename.emf\r\n");
return 1;
}
OpenClipboard(0);
bool ret = ClipboardToEmf(args);
CloseClipboard();
ExitProcess(ret ? 0 : 1);
}