我有下面的问题,希望大家帮助解决:1。如何顺序取得一个窗口的所有菜单项的Capation字符串,并修改它。
2。怎么顺序获得vc资源中的String Table中所有资源,并修改它。
3。怎么顺序获得vc资源中的Toolbar中的所有按钮的Prompt值的字符串,并修改它。
4。如何修改vc资源中的Version资源值,如Comments等。
2。怎么顺序获得vc资源中的String Table中所有资源,并修改它。
3。怎么顺序获得vc资源中的Toolbar中的所有按钮的Prompt值的字符串,并修改它。
4。如何修改vc资源中的Version资源值,如Comments等。
1.HRSRC hrSRC=::FindResource(AfxGetResourceHandle(),MAKEINTRESOURCE(id),RESOURCEENTRY)
其中,id是你的资源id,RESOURCEENTRY是你资源文件目录结构中的分类项,例如RT_MENU,就是菜单目录的根,RT_TOOLBAR就是工具条,RT_STRINGTABLE就是...
2.调用LoadResource(AfxGetResourceHandle(),hrSRC)装载资源;返回一个HGLOBAL的全局句柄,就叫hGlb吧
3.调用LockResource来锁住资源,并进行强制转化,例如,如果你是为取得工具条资源,就可以ToolBarData* = (ToolBarData*)::LockResource(hGlb);
4.拿到资源,为所欲为;
5.::UnlockResource(hGlb);
6.::FreeResource(hGlb);
至于什么样的资源使用什么样的数据结构,请参阅MSDN
Updating Resources:1。 The following example copies a dialog box resource from one executable file, Hand.exe, to another, Foot.exe, by following these steps: 2。Use the LoadLibrary function to load the executable file Hand.exe.
3。Use the FindResource and LoadResource functions to locate and load the dialog 4。box resource.
5。Use the LockResource function to retrieve a pointer to the dialog box resource data.
6。Use the BeginUpdateResource function to open an update handle to Foot.exe.
7。Use the UpdateResource function to copy the dialog box resource from Hand.exe to Foot.exe.
8。Use the EndUpdateResource function to complete the update. The following code implements these steps. HRSRC hResLoad; // handle to loaded resource
HANDLE hExe; // handle to existing .EXE file
HRSRC hRes; // handle/ptr. to res. info. in hExe
HANDLE hUpdateRes; // update resource handle
char *lpResLock; // pointer to resource data
BOOL result;
// Load the .EXE file that contains the dialog box you want to copy.
hExe = LoadLibrary("hand.exe");
if (hExe == NULL)
{
ErrorHandler("Could not load exe.");
}
// Locate the dialog box resource in the .EXE file.
hRes = FindResource(hExe, "AboutBox", RT_DIALOG);
if (hRes == NULL)
{
ErrorHandler("Could not locate dialog box.");
}
// Load the dialog box into global memory.
hResLoad = LoadResource(hExe, hRes);
if (hResLoad == NULL)
{
ErrorHandler("Could not load dialog box.");
}
// Lock the dialog box into global memory.
lpResLock = LockResource(hResLoad);
if (lpResLock == NULL)
{
ErrorHandler("Could not lock dialog box.");
}
// Open the file to which you want to add the dialog box resource.
hUpdateRes = BeginUpdateResource("foot.exe", FALSE);
if (hUpdateRes == NULL)
{
ErrorHandler("Could not open file for writing.");
}
// Add the dialog box resource to the update list.
result = UpdateResource(hUpdateRes, // update resource handle
RT_DIALOG, // change dialog box resource
"AboutBox", // dialog box name
MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), // neutral language
lpResLock, // ptr to resource info
SizeofResource(hExe, hRes)); // size of resource info.
if (result == FALSE)
{
ErrorHandler("Could not add resource.");
}
// Write changes to FOOT.EXE and then close it.
if (!EndUpdateResource(hUpdateRes, FALSE))
{
ErrorHandler("Could not write changes to file.");
}
// Clean up.
if (!FreeLibrary(hExe))
{
ErrorHandler("Could not free executable.");
}