source: dev/branches/egtra/ab5.0/abdev/abdev-impl/Resource/Load.cpp@ 786

Last change on this file since 786 was 786, checked in by イグトランス (egtra), 13 years ago

abdevにおいて、resについてアイコン・カーソルを自前関数での読込へ変更。

File size: 1.7 KB
Line 
1#include "stdafx.h"
2#include <map>
3#include <tuple>
4#include <Resource/Load.h>
5
6namespace ActiveBasic { namespace Resource {
7
8namespace {
9
10template<typename Map, typename Key, typename AddValueFunctor>
11typename 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
26HICON 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
41HICON LoadIcon(HINSTANCE hinst, USHORT id, int cxDesired, int cyDesired, UINT load)
42{
43 return LoadIconCursorImpl(hinst, id, cxDesired, cyDesired, load, true);
44}
45
46HICON LoadIcon(HINSTANCE hinst, USHORT id)
47{
48 return LoadIconCursorImpl(hinst, id, 32, 32, LR_SHARED, true);
49}
50
51HCURSOR LoadCursor(HINSTANCE hinst, USHORT id)
52{
53 return LoadIconCursorImpl(hinst, id, 32, 32, LR_SHARED, false);
54}
55
56}}
57
Note: See TracBrowser for help on using the repository browser.