gpt4 book ai didi

c++ - 特定资源语言的 LoadAccelerators

转载 作者:可可西里 更新时间:2023-11-01 11:55:54 25 4
gpt4 key购买 nike

我想打电话LoadAccelerators但对于资源中的特定语言。有办法吗?

最佳答案

我做了一些逆向工程,下面是如何从内存中为特定的 LCID 加载它:

#pragma pack(push, 1) // exact fit - no padding
struct ACCEL_MEM{
BYTE fVirt;
BYTE byteReserved;
WORD wKey;
WORD wCmd;
WORD wReserved;
};
#pragma pack(pop)

HACCEL LoadAcceleratorsIndirectWithLCID(UINT nResourceID, LCID lcid)
{
//Open accelerators table with the 'nResourceID'
//'nResourceID' = Resource ID to use
//'lcid' = LCID to load resources for, or NULL to use the one from current thread
//RETURN:
// = HACCEL loaded -- must be removed with DestroyAcceleratorTable(), or
// = NULL if error
ASSERT(nResourceID);

HACCEL hAccel = NULL;

HINSTANCE hInst = ::GetModuleHandle(NULL);
if(hInst)
{
//Do we have a LCID?
if(lcid == NULL)
lcid = ::GetThreadLocale();

//Get language ID
LANGID langid = LANGIDFROMLCID(lcid);

//Try to load for specified resource
HRSRC hResource = ::FindResourceEx(hInst, RT_ACCELERATOR, MAKEINTRESOURCE(nResourceID), langid);
if(hResource == NULL)
{
//If failed, use default lcid
hResource = ::FindResource(hInst, MAKEINTRESOURCE(nResourceID), RT_ACCELERATOR);
}

if(hResource)
{
HGLOBAL hglb = LoadResource(hInst, hResource);
if(hglb)
{
LPVOID lpsz = LockResource(hglb);
DWORD dwcbSz = ::SizeofResource(hInst, hResource);
if(lpsz &&
dwcbSz)
{
ACCEL_MEM* pMem = (ACCEL_MEM*)lpsz;

//Count items in the table
int nCnt = 0;
ACCEL_MEM* pTest = pMem;
for(;; pTest++)
{
nCnt++;
if(pTest->fVirt & 0x80)
break;
}

//Reserve mem
ACCEL* pAccels = new ACCEL[nCnt];

//Parse data
for(int i = 0; i < nCnt; i++)
{
pAccels[i].fVirt = pMem[i].fVirt & 0x7f;
pAccels[i].key = pMem[i].wKey;
pAccels[i].cmd = pMem[i].wCmd;
}

//Create accel table
hAccel = ::CreateAcceleratorTable(pAccels, nCnt);

//Free mem
delete[] pAccels;
pAccels = NULL;
}
}
}
}

return hAccel;
}

关于c++ - 特定资源语言的 LoadAccelerators,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16975808/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com