gpt4 book ai didi

visual-c++ - 如何更改某些文件类型的图标?

转载 作者:行者123 更新时间:2023-12-02 03:48:05 27 4
gpt4 key购买 nike

我有 IconHandler 来更改某些文件的图标。但其他文件图标变为空白。如何为其他文件保留默认图标?

 HRESULT CSimpleShlExt::GetIconLocation(UINT uFlags,
PTSTR pszIconFile,
UINT cchMax,
int *piIndex,
UINT *pwFlags)
{
if (condition)){
// works well
lstrcpyn(pszIconFile, L"C:\\Windows\\System32\\shell32.dll", cchMax);
*piIndex = 5;
*pwFlags = 0;
} else {
// blank icon :(
*pwFlags = GIL_PERINSTANCE | GIL_NOTFILENAME;// | GIL_DONTCACHE ;
}
return S_OK;
}

这是我的 .rgs 文件:

HKCR  
{
NoRemove CLSID
{
ForceRemove {B70B7A24-5180-4092-B3BA-6266F914C053} = s 'My Shell Extension'
{
InprocServer32 = s '%MODULE%'
{
val ThreadingModel = s 'Apartment'
}
TypeLib = s '{62C6D1EB-C172-4E05-BFD2-5F9313832CC3}'
Version = s '1.0'
}
}
NoRemove txtfile
{
NoRemove ShellEx
{
ForceRemove IconHandler = s '{B70B7A24-5180-4092-B3BA-6266F914C053}'
}
}
}

最佳答案

此代码有效:

 HRESULT CSimpleShlExt::GetIconLocation(UINT uFlags,
PTSTR pszIconFile,
UINT cchMax,
int *piIndex,
UINT *pwFlags)
{

if (condition))
{
lstrcpyn(pszIconFile, L"C:\\Windows\\System32\\Test.dll", cchMax);

*piIndex = 0;
}
else
{
*piIndex = 1;

}

*pwFlags = 0;
return S_OK;

}

HRESULT CSimpleShlExt::Extract(
LPCTSTR pszFile,
UINT nIconIndex,
HICON *phiconLarge,
HICON *phiconSmall,
UINT nIconSize)
{
return S_FALSE;
}

更改的 .rgs 文件:

HKCR  
{
NoRemove CLSID
{
ForceRemove {B70B7A24-5180-4092-B3BA-6266F914C053} = s 'My Shell Extension'
{
InprocServer32 = s '%MODULE%'
{
val ThreadingModel = s 'Apartment'
}
TypeLib = s '{62C6D1EB-C172-4E05-BFD2-5F9313832CC3}'
Version = s '1.0'
}
}
NoRemove txtfile
{
NoRemove DefaultIcon = s '%%1'
NoRemove ShellEx
{
ForceRemove IconHandler = s '{B70B7A24-5180-4092-B3BA-6266F914C053}'
}
}
}

来自“MSDN”- How to Create Icon Handlers :

Registering Icon Handlers

When you statically register an icon for a file type, you create a DefaultIcon subkey under the ProgID for the file type. Its default value is set to the file that contains the icon. To register an icon handler, you must still have the DefaultIcon subkey, but its default value must be set to "%1".

关于visual-c++ - 如何更改某些文件类型的图标?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15610991/

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