[781] | 1 | #include "stdafx.h"
|
---|
[786] | 2 | #include <Resource/Load.h>
|
---|
[781] | 3 |
|
---|
| 4 | namespace ActiveBasic { namespace Resource {
|
---|
| 5 |
|
---|
[786] | 6 | namespace {
|
---|
| 7 |
|
---|
| 8 | template<typename Map, typename Key, typename AddValueFunctor>
|
---|
| 9 | typename Map::iterator GetCacheFromMap(Map& map, Key key, AddValueFunctor f)
|
---|
[781] | 10 | {
|
---|
[786] | 11 | auto low = map.lower_bound(key);
|
---|
| 12 | if (low != map.end() && map.key_comp()(key, low->first))
|
---|
| 13 | {
|
---|
| 14 | return low;
|
---|
| 15 | }
|
---|
| 16 | else
|
---|
| 17 | {
|
---|
| 18 | typedef typename Map::key_type key_type;
|
---|
| 19 | typedef typename Map::value_type value_type;
|
---|
| 20 | return map.insert(low, std::make_pair(std::move(key), f()));
|
---|
| 21 | }
|
---|
| 22 | }
|
---|
[781] | 23 |
|
---|
[786] | 24 | HICON LoadIconCursorImpl(HINSTANCE hinst, USHORT id, int cxDesired, int cyDesired, UINT load, bool isIcon)
|
---|
| 25 | {
|
---|
| 26 | auto hrsrc = FindResource(hinst, MAKEINTRESOURCE(id), isIcon ? RT_GROUP_ICON : RT_GROUP_CURSOR);
|
---|
| 27 | auto pResource = LockResource(LoadResource(hinst, hrsrc));
|
---|
[781] | 28 |
|
---|
[786] | 29 | auto idIcon = LookupIconIdFromDirectoryEx(reinterpret_cast<PBYTE>(pResource), isIcon, cxDesired, cyDesired, load);
|
---|
| 30 | auto hrsrcIcon = FindResource(hinst, MAKEINTRESOURCE(idIcon), isIcon ? RT_ICON : RT_CURSOR);
|
---|
| 31 | auto pResourceIcon = LockResource(LoadResource(hinst, hrsrcIcon));
|
---|
| 32 |
|
---|
[781] | 33 | return CreateIconFromResourceEx(reinterpret_cast<PBYTE>(pResourceIcon),
|
---|
[786] | 34 | SizeofResource(hinst, hrsrcIcon), isIcon, 0x00030000, cxDesired, cyDesired, load);
|
---|
[781] | 35 | }
|
---|
| 36 |
|
---|
[786] | 37 | }
|
---|
| 38 |
|
---|
| 39 | HICON LoadIcon(HINSTANCE hinst, USHORT id, int cxDesired, int cyDesired, UINT load)
|
---|
| 40 | {
|
---|
| 41 | return LoadIconCursorImpl(hinst, id, cxDesired, cyDesired, load, true);
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | HICON LoadIcon(HINSTANCE hinst, USHORT id)
|
---|
| 45 | {
|
---|
| 46 | return LoadIconCursorImpl(hinst, id, 32, 32, LR_SHARED, true);
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 | HCURSOR LoadCursor(HINSTANCE hinst, USHORT id)
|
---|
| 50 | {
|
---|
| 51 | return LoadIconCursorImpl(hinst, id, 32, 32, LR_SHARED, false);
|
---|
| 52 | }
|
---|
| 53 |
|
---|
[789] | 54 | // 文字列リソースの読み込みについては以下を参照。
|
---|
| 55 | // How To Use LoadResource to Load Strings from a String Table
|
---|
| 56 | // http://support.microsoft.com/kb/200893/en-us
|
---|
| 57 | boost::optional<std::wstring> LoadString(HINSTANCE hinst, USHORT id)
|
---|
| 58 | {
|
---|
| 59 | UINT idRsrcBlk = id / 16 + 1;
|
---|
| 60 | int strIndex = id % 16;
|
---|
| 61 |
|
---|
| 62 | auto hrsrc = FindResourceEx(hinst, RT_STRING, MAKEINTRESOURCE(idRsrcBlk), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT));
|
---|
| 63 | if (hrsrc == nullptr)
|
---|
| 64 | return boost::none;
|
---|
| 65 |
|
---|
| 66 | auto hRes = LoadResource(hinst, hrsrc);
|
---|
| 67 | if (hRes == nullptr)
|
---|
| 68 | return boost::none;
|
---|
| 69 | LPCWSTR p = static_cast<LPCWSTR>(LockResource(hRes));
|
---|
| 70 | if (p == nullptr)
|
---|
| 71 | return boost::none;
|
---|
| 72 |
|
---|
| 73 | for (int i = 0; i < strIndex; ++i)
|
---|
| 74 | {
|
---|
| 75 | UINT length = *p++;
|
---|
| 76 | p += length;
|
---|
| 77 | }
|
---|
| 78 |
|
---|
| 79 | UINT cch = *p++;
|
---|
| 80 | if (cch == 0)
|
---|
| 81 | {
|
---|
| 82 | return boost::none;
|
---|
| 83 | }
|
---|
| 84 | else
|
---|
| 85 | {
|
---|
| 86 | return std::wstring(p, cch);
|
---|
| 87 | }
|
---|
| 88 | }
|
---|
| 89 |
|
---|
[781] | 90 | }}
|
---|
| 91 |
|
---|