forked from Open-Shell/Open-Shell-Menu
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringSet.cpp
More file actions
75 lines (65 loc) · 1.53 KB
/
StringSet.cpp
File metadata and controls
75 lines (65 loc) · 1.53 KB
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
// Classic Shell (c) 2009-2017, Ivo Beltchev
// Open-Shell (c) 2017-2018, The Open-Shell Team
// Confidential information of Ivo Beltchev. Not for disclosure or distribution without prior written consent from the author
#include <stdafx.h>
#include "StringSet.h"
static CString CreateString( const WORD *data )
{
int len=*data;
data++;
if (len==0) return NULL;
CString str;
wchar_t *ptr=str.GetBuffer(len);
if (ptr)
{
memcpy(ptr,data,len*2);
ptr[len]=0;
str.ReleaseBufferSetLength(len);
}
return str;
}
BOOL CALLBACK CStringSet::EnumResNameProc( HMODULE hModule, LPCTSTR lpszType, LPTSTR lpszName, LONG_PTR lParam )
{
CStringSet *set=(CStringSet*)lParam;
// find resource
HRSRC hr=FindResource(hModule,lpszName,RT_STRING);
if (!hr) return TRUE;
HGLOBAL hg=LoadResource(hModule,hr);
if (hg)
{
const WORD *res=(WORD*)LockResource(hg);
if (res)
{
for (int i=0;i<16;i++)
{
int id=(((int)(intptr_t)lpszName)<<4)+i-16;
CString str=CreateString(res);
if (!str.IsEmpty())
(*set)[id]=str;
res+=(*res)+1;
}
UnlockResource(hg);
}
}
return TRUE;
}
// Initializes the string database
void CStringSet::Init( HINSTANCE hInstance )
{
clear();
m_hInstance=hInstance;
if (hInstance)
EnumResourceNames(hInstance,RT_STRING,EnumResNameProc,(LONG_PTR)this);
}
// Returns a string by ID (returns "" if the string is missing)
CString CStringSet::GetString( UINT uID )
{
// search in the database
const_iterator it=find(uID);
if (it!=end())
{
if (it->second)
return it->second;
}
return CString();
}