windows 在哪里可以找到用于文件夹和应用程序的默认图标?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/460980/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Where can I find the default icons used for folders and applications?
提问by Scott Langham
I'm trying to load the default HICON that explorer displays for:
我正在尝试加载资源管理器显示的默认 HICON:
- An open folder
- An exe that has no embedded default icon of its own. This can also be seen in 'Add/Remove Programs' or 'Programs and Features' as it's called on Vista.
- 打开的文件夹
- 一个没有自己嵌入的默认图标的 exe。这也可以在“添加/删除程序”或“程序和功能”中看到,因为它在 Vista 上被调用。
Do you know where these can be found? I think the folder icon might be in the resources of explorer.exe. But have no idea where the default application icon can be retrieved from.
你知道哪里可以找到这些吗?我认为文件夹图标可能在 explorer.exe 的资源中。但是不知道可以从哪里检索默认应用程序图标。
And additionally, do you have any sample code that could load them into HICONs.
此外,您是否有任何可以将它们加载到 HICON 中的示例代码。
I really need this to work on multiple Windows OSs: 2000, XP, Vista, 2008
我真的需要它在多个 Windows 操作系统上工作:2000、XP、Vista、2008
Thanks for the help so far. I'm on Vista and have looked through Shell32.dll. I don't see an icon in there that looks the same as the default one displayed by an application in explorer. I could be missing it - there are 278 icons to look through - is it definitely in there, or is there some other location I should look?
感谢你目前的帮助。我在 Vista 上并查看了 Shell32.dll。我没有在其中看到与资源管理器中应用程序显示的默认图标相同的图标。我可能会错过它 - 有 278 个图标可以查看 - 它肯定在那里,还是我应该查看其他一些位置?
采纳答案by Xn0vv3r
I think they are in %windir%\system32\SHELL32.dll
我认为他们在 %windir%\system32\SHELL32.dll
Found some code in the internet, try if that works:
在网上找到了一些代码,试试看是否有效:
HINSTANCE hDll;
hDll = LoadLibrary ( "SHELL32.dll" );
wincl.hIcon = LoadIcon (hDll , MAKEINTRESOURCE ( 1 ));
wincl.hIconSm = LoadIcon (hDll, MAKEINTRESOURCE ( 2 ));
Edit: Windows has a lot more icons in the "moricons.dll", but I think the file and folder icons should all be in the shell32.dll. Remind, that icons in Vista have different resolutions, up to 256x256, so the icon you are looking at a resolution 32x32 might look different then the full resolution version of the same icon.
编辑:Windows 在“moricons.dll”中有更多的图标,但我认为文件和文件夹图标应该都在 shell32.dll 中。请注意,Vista 中的图标具有不同的分辨率,最高可达 256x256,因此您看到的分辨率为 32x32 的图标可能与同一图标的全分辨率版本不同。
回答by Stefan
Use the SHGetFileInfoAPI.
使用SHGetFileInfoAPI。
SHFILEINFO sfi;
SecureZeroMemory(&sfi, sizeof sfi);
SHGetFileInfo(
_T("Doesn't matter"),
FILE_ATTRIBUTE_DIRECTORY,
&sfi, sizeof sfi,
SHGFI_ICON | SHGFI_SMALLICON | SHGFI_USEFILEATTRIBUTES);
will get you the icon handle to the folder icon.
将为您提供文件夹图标的图标句柄。
To get the 'open' icon (i.e., the icon where the folder is shown as open), also pass SHGFI_OPENICON in the last parameter to SHGetFileInfo().
要获得“打开”图标(即文件夹显示为打开的图标),还要将最后一个参数中的 SHGFI_OPENICON 传递给 SHGetFileInfo()。
[edit]
[编辑]
ignore all answers which tell you to poke around in the registry! Because that won't work reliably, will show the wrong icons if they're customized/skinned and might not work in future windows versions. Also, if you extract the icons from system dlls/exes you could get into legal troubles because they're copyrighted.
忽略所有告诉您在注册表中闲逛的答案!因为这不会可靠地工作,如果它们被自定义/换肤会显示错误的图标,并且可能在未来的 Windows 版本中不起作用。此外,如果您从系统 dll/exe 中提取图标,您可能会遇到法律问题,因为它们是受版权保护的。
回答by Anders
Vista added SHGetStockIconInfoand so on NT6+ its the best way.
Vista 添加SHGetStockIconInfo等 NT6+ 是最好的方法。
Archiveof MSDN documentation that shows the available icons
显示可用图标的 MSDN 文档存档
On older platforms, SHGetFileInfolike Stefan says.
在旧平台上,SHGetFileInfo就像 Stefan 所说的那样。
If you want to use undocumented stuff, the first 5 or so icons in the system image list includes the default folder and application icon (system image list is NOT shared on NT, but for some reason, all the copies get the first 5 or so icons without asking for them with SHGetFileInfo)
如果您想使用未记录的东西,系统映像列表中的前 5 个左右图标包括默认文件夹和应用程序图标(系统映像列表不在 NT 上共享,但出于某种原因,所有副本都获得前 5 个左右图标而不用SHGetFileInfo要求它们)
These default icons come from shell32.dll by default, but can be changed in the registry:
这些默认图标默认来自 shell32.dll,但可以在注册表中更改:
HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Icons
HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Icons
回答by Ferruccio
In Visual Studio:
在 Visual Studio 中:
- click on File|Open
- select C:\WINDOWS\System32\Shell32.dll
- 点击文件|打开
- 选择 C:\WINDOWS\System32\Shell32.dll
VS will open the file using the resource explorer. You can now look at all the icon & other resources embedded in shell32.dll.
VS 将使用资源浏览器打开文件。您现在可以查看嵌入在 shell32.dll 中的所有图标和其他资源。
回答by Rowland Shaw
The user's selected icon can be found in the registry at HKEY_CLASSES_ROOT\Folder\DefaultIcon
用户选择的图标可以在注册表中找到 HKEY_CLASSES_ROOT\Folder\DefaultIcon
By looking up the value here, you'll also pick up if they've changed it for whatever reason.
通过在此处查找值,您还可以了解他们是否出于任何原因更改了它。
For folders where a desktop.ini file exists, you'd need to read the IconFile
and IconIndex
entries.
对于存在 desktop.ini 文件的文件夹,您需要阅读IconFile
和IconIndex
条目。
回答by Aamir
If you are in MFC, following code for loading icons should work.
如果您在 MFC 中,以下用于加载图标的代码应该可以工作。
HICON hicon; hicon = LoadIcon(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ICON1));
In the above example, AfxGetResourceHandle() is the only thing where MFC is used, otherwise LoadIcon is an API call as far as I remember.
在上面的例子中,AfxGetResourceHandle() 是唯一使用 MFC 的东西,否则 LoadIcon 是我记得的 API 调用。
Icons are available in windows\system32\shell32.dll
图标在 windows\system32\shell32.dll 中可用
If you have visual studio installed, then visual studio is also shipped with a set of icons at a path like this "C:\Program Files\Microsoft Visual Studio 9.0\Common7\VS2008ImageLibrary"
如果您安装了 Visual Studio,则 Visual Studio 还附带一组图标,位于类似“C:\Program Files\Microsoft Visual Studio 9.0\Common7\VS2008ImageLibrary”的路径中
回答by Aamir
it's much easier, just open the shell32.dll with resource hacker and right-click on "ICONS" and save all icons resource in a directory.
它更容易,只需使用资源黑客打开shell32.dll并右键单击“图标”并将所有图标资源保存在目录中。
and you'll get all the windows default icons in that directory.
您将获得该目录中的所有 Windows 默认图标。
回答by Rob K
It's probably in explorer.exe.
它可能在 explorer.exe 中。