-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUtility.cpp
66 lines (54 loc) · 1.61 KB
/
Utility.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
#include "Utility.h"
UTILITY_NAMESPACE_BEGIN
Texture LoadTexture(PCWSTR pszFile, ID2D1DeviceContext* pDC)
{
auto pFactory = App->m_pWicFactory;
IWICBitmap* pBitmap;
IWICBitmapDecoder* pDecoder;
IWICBitmapFrameDecode* pFrameDecoder;
IWICFormatConverter* pConverter;
HRESULT hr = pFactory->CreateDecoderFromFilename(pszFile, NULL, GENERIC_READ, WICDecodeMetadataCacheOnDemand, &pDecoder);
pFactory->CreateFormatConverter(&pConverter);
pDecoder->GetFrame(0, &pFrameDecoder);
pConverter->Initialize(pFrameDecoder, GUID_WICPixelFormat32bppPBGRA,
WICBitmapDitherTypeNone, NULL, 0.0f, WICBitmapPaletteTypeMedianCut);
pFactory->CreateBitmapFromSource(pConverter, WICBitmapNoCache, &pBitmap);
pFrameDecoder->Release();
pDecoder->Release();
pConverter->Release();
ID2D1Bitmap1* pD2dBitmap;
pDC->CreateBitmapFromWicBitmap(pBitmap, &pD2dBitmap);
UINT cx, cy;
pBitmap->GetSize(&cx, &cy);
return { pD2dBitmap,pBitmap,(int)cx,(int)cy };
}
void Sleep(int iTime)
{
HANDLE hTimer = CreateWaitableTimerW(NULL, FALSE, NULL);
LARGE_INTEGER llDueTime;
llDueTime.QuadPart = -10 * iTime * 1000LL;
SetWaitableTimer(hTimer, &llDueTime, 0, NULL, NULL, 0);
MSG msg;
DWORD dwRet;
while ((dwRet = MsgWaitForMultipleObjects(1, &hTimer, FALSE, INFINITE, QS_ALLEVENTS)) != WAIT_OBJECT_0)
{
if (dwRet == WAIT_OBJECT_0 + 1)
{
while (PeekMessageW(&msg, NULL, 0u, 0u, PM_REMOVE))
{
if (msg.message == WM_QUIT)
{
PostQuitMessage((int)msg.wParam);
return;
}
TranslateMessage(&msg);
DispatchMessageW(&msg);
}
}
else
break;
}
CancelWaitableTimer(hTimer);
CloseHandle(hTimer);
}
UTILITY_NAMESPACE_END