1 | #include "stdafx.h"
|
---|
2 | #include <map>
|
---|
3 | #include <tuple>
|
---|
4 | #include <Resource/Load.h>
|
---|
5 |
|
---|
6 | namespace ActiveBasic { namespace Resource {
|
---|
7 |
|
---|
8 | namespace {
|
---|
9 |
|
---|
10 | template<typename Map, typename Key, typename AddValueFunctor>
|
---|
11 | typename Map::iterator GetCacheFromMap(Map& map, Key key, AddValueFunctor f)
|
---|
12 | {
|
---|
13 | auto low = map.lower_bound(key);
|
---|
14 | if (low != map.end() && map.key_comp()(key, low->first))
|
---|
15 | {
|
---|
16 | return low;
|
---|
17 | }
|
---|
18 | else
|
---|
19 | {
|
---|
20 | typedef typename Map::key_type key_type;
|
---|
21 | typedef typename Map::value_type value_type;
|
---|
22 | return map.insert(low, std::make_pair(std::move(key), f()));
|
---|
23 | }
|
---|
24 | }
|
---|
25 |
|
---|
26 | HICON LoadIconCursorImpl(HINSTANCE hinst, USHORT id, int cxDesired, int cyDesired, UINT load, bool isIcon)
|
---|
27 | {
|
---|
28 | auto hrsrc = FindResource(hinst, MAKEINTRESOURCE(id), isIcon ? RT_GROUP_ICON : RT_GROUP_CURSOR);
|
---|
29 | auto pResource = LockResource(LoadResource(hinst, hrsrc));
|
---|
30 |
|
---|
31 | auto idIcon = LookupIconIdFromDirectoryEx(reinterpret_cast<PBYTE>(pResource), isIcon, cxDesired, cyDesired, load);
|
---|
32 | auto hrsrcIcon = FindResource(hinst, MAKEINTRESOURCE(idIcon), isIcon ? RT_ICON : RT_CURSOR);
|
---|
33 | auto pResourceIcon = LockResource(LoadResource(hinst, hrsrcIcon));
|
---|
34 |
|
---|
35 | return CreateIconFromResourceEx(reinterpret_cast<PBYTE>(pResourceIcon),
|
---|
36 | SizeofResource(hinst, hrsrcIcon), isIcon, 0x00030000, cxDesired, cyDesired, load);
|
---|
37 | }
|
---|
38 |
|
---|
39 | }
|
---|
40 |
|
---|
41 | HICON LoadIcon(HINSTANCE hinst, USHORT id, int cxDesired, int cyDesired, UINT load)
|
---|
42 | {
|
---|
43 | return LoadIconCursorImpl(hinst, id, cxDesired, cyDesired, load, true);
|
---|
44 | }
|
---|
45 |
|
---|
46 | HICON LoadIcon(HINSTANCE hinst, USHORT id)
|
---|
47 | {
|
---|
48 | return LoadIconCursorImpl(hinst, id, 32, 32, LR_SHARED, true);
|
---|
49 | }
|
---|
50 |
|
---|
51 | HCURSOR LoadCursor(HINSTANCE hinst, USHORT id)
|
---|
52 | {
|
---|
53 | return LoadIconCursorImpl(hinst, id, 32, 32, LR_SHARED, false);
|
---|
54 | }
|
---|
55 |
|
---|
56 | }}
|
---|
57 |
|
---|