-
Notifications
You must be signed in to change notification settings - Fork 0
/
methods.cpp
128 lines (119 loc) · 2.54 KB
/
methods.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#include "stdafx.h"
#include "Header.h"
extern ID2D1HwndRenderTarget *pRT;
HRESULT LoadBitmapFromFile(
PCWSTR uri,
UINT dweight,
UINT dheight,
ID2D1Bitmap **bitmap
)
{
HRESULT hr = S_OK;
IWICImagingFactory* pWICFactory = NULL;
IWICBitmapDecoder* pDecoder = NULL;
IWICBitmapScaler* pScaler = NULL;
IWICBitmapFrameDecode* pSource = NULL;
IWICFormatConverter* pConverter = NULL;
hr = CoCreateInstance(
CLSID_WICImagingFactory,
NULL,
CLSCTX_INPROC_SERVER,
IID_IWICImagingFactory,
(LPVOID*)&pWICFactory);
if (SUCCEEDED(hr))
{
hr = pWICFactory->CreateDecoderFromFilename(
uri,
NULL,
GENERIC_READ,
WICDecodeMetadataCacheOnLoad,
&pDecoder);
}
if (SUCCEEDED(hr))
{
hr = pDecoder->GetFrame(0, &pSource);
}
if (SUCCEEDED(hr))
{
hr = pWICFactory->CreateFormatConverter(&pConverter);
}
if (SUCCEEDED(hr))
{
UINT oWeight, oHeight;
hr = pSource->GetSize(&oWeight, &oHeight);
if (SUCCEEDED(hr))
{
hr = pWICFactory->CreateBitmapScaler(&pScaler);
if (SUCCEEDED(hr))
{
hr = pScaler->Initialize(
pSource,
dweight,
dheight,
WICBitmapInterpolationModeCubic);
}
if (SUCCEEDED(hr))
{
hr = pConverter->Initialize(
pScaler,
GUID_WICPixelFormat32bppPBGRA,
WICBitmapDitherTypeNone,
NULL,
0.f,
WICBitmapPaletteTypeMedianCut
);
}
}
}
if (SUCCEEDED(hr))
{
hr = pRT->CreateBitmapFromWicBitmap(pConverter, bitmap);
}
Safe_Release(pWICFactory);
Safe_Release(pDecoder);
Safe_Release(pScaler);
Safe_Release(pSource);
Safe_Release(pConverter);
return hr;
}
RECT moveRect(RECT rc, int dx, int dy)
{
RECT res;
res.left = rc.left + dx;
res.right = rc.right + dx;
res.top = rc.top + dy;
res.bottom = rc.bottom + dy;
return res;
}
char* ConvertLPWSTRToLPSTR(LPWSTR lpwszStrIn)
{
LPSTR pszOut = NULL;
if (lpwszStrIn != NULL)
{
int nInputStrLen = wcslen(lpwszStrIn);
// Double NULL Termination
int nOutputStrLen = WideCharToMultiByte(CP_ACP, 0, lpwszStrIn, nInputStrLen, NULL, 0, 0, 0) + 2;
pszOut = new char[nOutputStrLen];
if (pszOut)
{
memset(pszOut, 0x00, nOutputStrLen);
WideCharToMultiByte(CP_ACP, 0, lpwszStrIn, nInputStrLen, pszOut, nOutputStrLen, 0, 0);
}
}
return pszOut;
}
BOOL isPointInRect(D2D1_POINT_2F point, RECT rec)
{
if (point.x >= rec.left&&point.x <= rec.right&&point.y >= rec.top&&point.y <= rec.bottom)
return true;
return false;
}
D2D1_RECT_F rectToD2D1(RECT rec)
{
D2D1_RECT_F res;
res.left = (FLOAT)rec.left;
res.right = (FLOAT)rec.right;
res.top = (FLOAT)rec.top;
res.bottom = (FLOAT)rec.bottom;
return res;
}