Changeset 1369


Ignore:
Timestamp:
11/30/2009 1:03:00 AM (5 years ago)
Author:
lowjoel
Message:

Manually parse the string table to get the language resource we want when calling CCtxMenu::LoadString? as we separate the string tables according to language in our module resource. This allows us to specify the language we want the resources to load in (to be implemented).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/eraser6/ShellExt/CtxMenu.cpp

    r1360 r1369  
    664664    std::wstring CCtxMenu::LoadString(UINT stringID) 
    665665    { 
    666         //Get a pointer to the buffer containing the string (we're copying it anyway) 
    667         wchar_t* buffer = NULL; 
    668         DWORD lastCount = ::LoadString(theApp.m_hInstance, stringID, 
    669             reinterpret_cast<wchar_t*>(&buffer), 0); 
    670  
    671         if (lastCount > 0) 
    672             return std::wstring(buffer, lastCount); 
    673         return std::wstring(); 
     666        //Convert the resource ID to the block and item IDs. 
     667        UINT stringBlockId = (stringID >> 4) + 1; 
     668        UINT stringItemId = stringID % 16; 
     669 
     670        //Obtain a pointer to the memory holding the string table. 
     671        HRSRC resourceHandle = FindResourceEx(theApp.m_hInstance, 
     672            RT_STRING, MAKEINTRESOURCE(stringBlockId), MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL)); 
     673        if (!resourceHandle) 
     674            AfxMessageBox(FormatError().c_str()); 
     675 
     676        DWORD sizeOfResource = SizeofResource(theApp.m_hInstance, resourceHandle); 
     677        HGLOBAL resourceBlock = LoadResource(theApp.m_hInstance, resourceHandle); 
     678        if (!sizeOfResource || !resourceBlock) 
     679            AfxMessageBox(FormatError().c_str()); 
     680 
     681        wchar_t* stringTable = reinterpret_cast<wchar_t*>(LockResource(resourceBlock)); 
     682 
     683        //Iterate over the string table. The string table is null-delimited with 
     684        //the first byte storing the length of the string entry. 
     685        for ( ; stringItemId != 0; --stringItemId) 
     686        { 
     687            if (*stringTable == L'\0') 
     688                ++stringTable; 
     689            else 
     690                stringTable += *stringTable + 1; 
     691        } 
     692 
     693        return std::wstring(stringTable + 1, *stringTable); 
    674694    } 
    675695 
Note: See TracChangeset for help on using the changeset viewer.