다음은 미리 정의된 리소스 종류입니다.
| Constant/value | 설명 |
|---|---|
|
액셀러레이터 테이블입니다. |
|
애니메이션 커서. |
|
애니메이션 아이콘. |
|
비트맵 리소스입니다. |
|
하드웨어 종속 커서 리소스입니다. |
|
대화 상자. |
|
리소스 편집 도구에서 문자열을 .rc 파일과 연결할 수 있습니다. 일반적으로 문자열은 기호 이름을 제공하는 헤더 파일의 이름입니다. 리소스 컴파일러는 문자열을 구문 분석하지만 그렇지 않으면 값을 무시합니다. 을 예로 들 수 있습니다.1 DLGINCLUDE "MyFile.h" |
|
글꼴 리소스입니다. |
|
글꼴 디렉터리 리소스입니다. |
|
하드웨어 독립적 커서 리소스입니다. |
|
하드웨어 독립적 아이콘 리소스입니다. |
|
HTML 리소스입니다. |
|
하드웨어 종속 아이콘 리소스입니다. |
|
Side-by-Side 어셈블리 매니페스트입니다. |
|
메뉴 리소스입니다. |
|
메시지 테이블 항목입니다. |
|
리소스를 플러그 앤 플레이. |
|
애플리케이션 정의 리소스(원시 데이터). |
|
문자열 테이블 항목입니다. 자세한 내용은 아래 의 비고 를 참조하세요. |
|
버전 리소스입니다. |
|
VXD. |
비고
문자열 테이블 리소스
EnumResourceNamesW와 같은 함수를 사용하여 문자열 테이블 리소스(RT_STRING 형식)를 열거하는 경우 시스템은 각 개별 문자열 리소스 ID를 열거하지 않습니다. 대신 리소스 블록을 열거합니다. 이러한 블록을 검사하여 실제로 포함된 문자열 리소스 ID를 확인해야 합니다.
문자열 리소스는 블록으로 패키지되며, 각각에는 16개의 연속 ID를 나타내는 16개의 길이 접두사 문자열이 포함됩니다(일부는 사용되지 않을 수 있습니다. 아래 참조). 문자열 리소스 ID X가 지정되면 리소스 블록 번호 (X \ 16) + 1 ( \ 정수 나누기를 나타냄)에 배치됩니다. 해당 블록 내에서 리소스를 th 항목N = X % 16으로 N찾을 수 있습니다.
다음 표에서는 몇 가지 예제 문자열 리소스 ID와 위치의 블록 번호(및 오프셋)를 보여 줍니다.
| 리소스 ID | 차단(Block) # | Offset |
|---|---|---|
| 1 |
(1 \ 16) + 1 = 1 |
1 % 16 = 1 |
| 2 |
(2 \ 16) + 1 = 1 |
2 % 16 = 2 |
| 5 |
(5 \ 16) + 1 = 1 |
5 % 16 = 5 |
| 15 |
(15 \ 16) + 1 = 1 |
15 % 16 = 15 |
| 20 |
(20 \ 16) + 1 = 2 |
20 % 16 = 4 |
| 32 |
(32 \ 16) + 1 = 3 |
32 % 16 = 0 |
| 50 |
(50 \ 16) + 1 = 4 |
50 % 16 = 2 |
| 100 |
(100 \ 16) + 1 = 7 |
100 % 16 = 4 |
사용되지 않은(누락된) 리소스 ID는 길이가 0인 문자열로 표시됩니다. 따라서 위의 예제에서 블록 #1에는 ID 0, 3, 4 및 6 - 14를 나타내는 길이가 0인 문자열이 있습니다. 문자열 리소스에 포함된 NULL 을 포함할 수 있으므로 블록의 문자열 중 어느 것도 NULL 문자를 종료하지 않습니다. 따라서 각 문자열의 값이 "Hello world"(11자 길이)이고 꺾쇠 괄호 안의 숫자가 정수를 나타내는 경우(리터럴 문자가 아님) 블록 #1의 메모리 레이아웃은 다음과 같습니다.
<0><11>Hello world<11>Hello world<0><0>
<11>Hello world<0><0><0><0><0><0><0><0>
<0><11>Hello world
다음 코드 조각은 블록이 아닌 다른 형식(예: RT_ICON )과 마찬가지로 개별 RT_STRING 리소스를 열거하는 열거형 콜백 함수를 보여 줍니다.
// Number of entries in the string table.
constexpr UINT STRING_TABLE_SIZE{ 16 };
// Returns the original resource ID from a given block / offset.
inline UINT GetStringResourceIdFromStringTable(LPCWSTR lpName, const unsigned int index)
{
_ASSERT(index < STRING_TABLE_SIZE);
return ((reinterpret_cast<UINT>(lpName) - 1) * STRING_TABLE_SIZE) + index;
}
// Helper function that will enumerate string table blocks, looking for resources.
BOOL EnumerateResourceNamesWrapperForStrings(HMODULE hModule, LPWSTR lpName, LONG_PTR lParam, ENUMRESNAMEPROCW lpEnumFunc)
{
// No need to free or unlock resources in Win32, so OK to throw away intermediates
auto ptr = (wchar_t*)LockResource(LoadResource(hModule, FindResource(hModule, lpName, RT_STRING)));
if (ptr)
{
for (unsigned int i = 0; i < STRING_TABLE_SIZE; ++i)
{
wchar_t size = *ptr;
if (size > 0)
{
auto id = GetStringResourceIdFromStringTable(lpName, i);
// Invoke the callback for this string resource ID.
auto callbackResult = lpEnumFunc(hModule, RT_STRING, MAKEINTRESOURCE(id), lParam);
if (!callbackResult)
{
return callbackResult;
}
}
// Skip to next potential string in the block
ptr += size + 1;
}
return TRUE;
}
// Couldn't load the string table entry; something is wrong.
return FALSE;
}
// Wrapper function for EnumResourceNamesW that will enumerate individual string resources.
BOOL EnumResourceNamesIncludingStringsW(HMODULE hModule, LPCWSTR lpType, ENUMRESNAMEPROCW lpEnumFunc, LONG_PTR lParam)
{
struct param_wrapper { ENUMRESNAMEPROCW lpEnumFunc; LONG_PTR lParam; } params{ lpEnumFunc, lParam };
// Use a simple lambda to either call our String helper, or directly call the user's callback
return EnumResourceNamesW(hModule, lpType, [](auto hModule, auto lpType, auto lpName, auto lParam)
{
auto params = reinterpret_cast<param_wrapper*>(lParam);
if (lpType == RT_STRING)
{
return EnumerateResourceNamesWrapperForStrings(hModule, lpName, params->lParam, params->lpEnumFunc);
}
return params->lpEnumFunc(hModule, lpType, lpName, params->lParam);
}, reinterpret_cast<LONG_PTR>(¶ms));
};
//////////
// Sample callback that just increments a counter.
BOOL CountResources(HMODULE, LPCWSTR, LPWSTR, LONG_PTR lParam)
{
// Add one to the count...
(*(reinterpret_cast<UINT*>(lParam)))++;
return TRUE;
}
// Sample usage:
void CountStringsInExplorer()
{
auto lib = LoadLibraryExW(LR"(c:\windows\explorer.exe)", nullptr, LOAD_LIBRARY_AS_DATAFILE);
if (!lib)
{
return;
}
UINT nStringBlocks{ 0 };
UINT nStrings{ 0 };
// Count the number of string blocks using raw Win32 API.
EnumResourceNamesW(lib, RT_STRING, CountResources, (LONG_PTR)&nStringBlocks);
// Count the number of actual strings, using the wrapper.
EnumResourceNamesIncludingStringsW(lib, RT_STRING, CountResources, (LONG_PTR)&nStrings);
// Outputs something like:
//
// Explorer.exe contains 44 strings (in 17 blocks).
//
std::wcout << L"Explorer.exe contains " << nStrings << L" strings (in " << nStringBlocks
<< L" blocks)." << std::endl;
}
Requirements
| 요구 사항 | Value |
|---|---|
| Header |
|