 |
|
 |
That's what the IShellIconOverlayIdentifier.GetOverlayInfo method does. You return the icon file path in the first parameter (it's a native out parameter) - either a path to an .ico file or a PE/COFF executable (.dll, .exe, .ocx, etc.) and optionally an index in the third parameter. If you specify a .ico file you need to specify ISIOI_ICONFILE as the last parameter:string currentPath;
int IShellIconOverlayIdentifier.IsMemberOf(string path, int attributes)
{
currentPath = path;
}
void IShellIconOverlayIdentifier.GetOverlayInfo(
string path, int max, out int index, out ISIOI flags)
{
if (Path.GetExtension(currentPath).ToLower() == ".xls")
{
path = "c:\excel.ico".Substring(max - 1); }
else
{
path = "c:\other.ico".Substring(max - 1); }
index = 0;
flags = ISIOI.ISIOI_ICONFILE;
}This is just a very basic example, but it's how you can control what icon is returned based on a path. These two methods are called in order as you see them above so just save the path when IsMemberOf is called.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Customer Product-lifecycle Experience
Microsoft
[My Articles] [My Blog]
|
|
|
|
 |
|
 |
As i said im not a C++ shark. Amazing, thank you very much for your big help on this issue.
|
|
|
|
 |
|
 |
Nice job. Weldone.
I am afraid if there is a way to set the location of the icon? Like by default it is at right bottom, what if I want to put that on top left or top right or bottom left corner?
Any idea?
Best wishes,
Sameers
|
|
|
|
 |
|
 |
My extension is not configurable like that. You can change the overlay icon to change the position of the overlay, however. It's just a regular icon with both transparent and non-transparent bitmaps.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Customer Product-lifecycle Experience
Microsoft
[My Articles] [My Blog]
|
|
|
|
 |
|
 |
YEs, your extension is not. But I was trying on such extension in C# but I couldnt find anyway int the interface methods/parameters etc to set the location of overlay icon nor the MSDN documentation discuss on this. I know one method could be to have a transparent icon as per location need so we have four different icons which are transparent but icon image is on either corner. But any good solution would be better.
Also, is there anyway to load icon from the application resources and then return that as overlay icon? Currently the interface structure forces to return icon location file name and it's index. Any idea would be appreciated.
Thanks,
Sameers
|
|
|
|
 |
|
 |
Again, you can change your icon that you plan on using for the overlay. Look at my icon in the project. It's toward the bottom left. For your icon, move it somewhere else. Your icon dimensions must still be the same as the size of the icon you plan on overlaying, i.e. a 16x16 icon to overlay over 16x16 icons, 32x32 over 32x32 icons, etc. You might also consider different pixel depths that must match up too, including alpha channels for 32-bit icons.
I highly recommend not using managed code for shell extensions. The CLR doesn't require a large working set and when that's loaded into the Explorer process you've increased the working set by many megabytes. Since Explorer is a ubiqitous process that working set will be constant unless the CLR crashes and is unloaded by the default host (mscoree.dll) or a custom host if you're using one. Writing your extensions natively is simple in this case (most shell extensions are) and don't require you to create and deploy interop assemblies because the interfaces are already defined in headers for native compilation (or even for Managed C++, but then you're still utilizing the CLR).
If you insist on using managed code, then you'll need to do one of the following for an overlay extnesions:- Store the .ico separate from your assembly and return the path to it.
- Store the icon in a separate native resource DLL.
- Build your managed assembly, disassemble it using ildasm.exe, add your icon to the RC file, then re-assemble it using ilasm.exe with the appropriate parameters.
If you don't change the assembly attributes that constitute the default RC file you could just make that part of the build process, using the same RC file over and over again. That will embed the icon in the .rsrc section of the PE/COFF executable. You will not be able to use the icon straight from your resources because they are stored in a completely separate fashion.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Customer Product-lifecycle Experience
Microsoft
[My Articles] [My Blog]
|
|
|
|
 |
|
 |
Thank you very much for your information. I have written this code in C# .NET (2005) and your descriptions says that there is no way to point icon on specific location (like original icon is of 32*32 and my overlay icon is of 8*8 which I wanted to point on bottom left corner). It also looked to me the same as well as I couldnt find any hint in MSDN and other locations on the net. However, your idea looks interesting regarding getting icon from resource. Thanks again,
Sameers
|
|
|
|
 |
|
 |
You need to make the overlay icon 32x32 and then you can position your non-transparent pixels anywhere. Open my overlay icon in VS and view the 32x32 pixel icon and you'll see the ".net" portion is in the corner. Move that to another portion of the 32x32 icon.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Customer Product-lifecycle Experience
Microsoft
[My Articles] [My Blog]
|
|
|
|
 |
|
 |
Yes, that is the same I got from your last reply. We need to design our icon in such way so that it displayed on the desired location (as your current icon of ".net" is displayed on bottom right, but the icon should be changed to display it on top left, no change in the code itself).
Sameers
|
|
|
|
 |
|
 |
And I'm not telling you to change your code, just change the position of the non-transparent pixels. Your overlay icons should match in size to the icon you're overlaying, so that if the current icon for a file type is 32x32, you'd have a 32x32 icon resource. If it's both 32x32 and 24x24, then you'd use a .ico file with both sizes. Windows will pick the correct size or default to the next smaller size if the right size is not provided. If all you're using is an 8x8 icon then you won't have control over where it's position. Make a .ico file with different sizes of icons; remember that a single .ico can contain different resolutions and pixel depths. Open my .ico up in VS or another icon editor. If in VS, use the Image -> Current Icon Image Types menu to change the size and depth of the displayed icon.
By defining different icon types that match the size of the icon on which you want to overlay your icon you can control how your overlay displays because you can control where within its bounding region the non-transparent pixels are.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Customer Product-lifecycle Experience
Microsoft
[My Articles] [My Blog]
|
|
|
|
 |
|
 |
Software Design Engineer
Developer Division Customer Product-lifecycle Experience
Does that fit on a standard business card? Really, your title sounds interesting, what do you really do at MS?
Regards,
-bill
|
|
|
|
 |
|
 |
Most developers here are called "Software Design Engineers", or simply "SDEs". DDCPX focuses on post-RTM releases (patches, services packs, etc.) as well as post-release tools for enterprise customers as well as home users. We also include the folks that bring you things like http://forums.microsoft.com/msdn[^].
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Customer Product-lifecycle Experience
Microsoft
[My Articles] [My Blog]
|
|
|
|
 |
|
 |
Hi,
I would like to add an icon overlay to selected files? I was hoping I would be able to reference it such as...
1, SetIconOverlay("MyFile.txt", "myOverlay.ico") ' to set the overlay icon.
2, GetIconOverlay("MyFile.txt") ' to get the overlay icon name associated with a file.
3, RemIconOverlay("MyFile.txt") ' to remove the overlay icon associated with a file.
Can I accomplish this with your shell extention?
Any Assistance would be greatly appreciated.
Zenly,
|
|
|
|
 |
|
 |
This shell extension looks for PE/COFF data that determines whether the file is a managed assembly. It does not set overlay icons and is not a general purpose overlay icon.
To implement such an overlay would not be a good idea. Every file class (that is, "*" in the registry) would require registration for your overlay icon, which means Explorer would query your icon handler for EVERY SINGLE FILE on the file system that appears in Explorer for the default folder views (other view servers may not query for such information). You would have to index file paths efficiently, too, using - perhaps - a Trie (pronounced "try") data structure for efficient lookups. Using managed code for such a task would additionally be a bad idea since you have several MBs of RAM in overhead and many more instructions to process (even once JIT'd to native code).
If you want overlay icons then I suggest you implement them for your file classes (types). If you want to write a general purpose text editor than save your files as text but with a different extension. Or, save them using ".txt" and write an overlay icon handler for ".txt" but not for all file classes. Even in native code this would drag-down a system.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
 |
|
 |
Thanks for that insite. I didn't realize that adding an overlay to a file could so taxing on a system.
If I did this, as you suggested, to my own file type could you give me an example or tell me where I could find an example of this?
Thanks,
Zenly
|
|
|
|
 |
|
|
 |
|
 |
Surely your ShellExtension is being called for EVERY SINGLE FILE?
The reason I ask is that I am considering doing something like TortoiseCVS to produce Overlays on the file system based upon some additional meta-data that I will apply to them (the method or storing which is TBD). Although TortoiseCVS is very slow so I plan to build in some caching to improve performance as it does slow the file system down a lot.
If you are saying that performing this sort of operation is a bad thing then surely what you are doing is bad? Maybe just less bad as it is a quick operation. Ultimately you are querying the file everytime explore wants to draw it.
I have also noted your repeated points about not going through the CLR - I too am considering using it as my overlaying will be part of a larger system. Should a Microsoft employee really be playing down use of .NET? I can appreciate the additional memory overhead (a few megs?) but it isn't something that people usually worry about on a modern machine. As it is you aren't actually using what I would count as Native code it is still going through COM which is in itself a 'slow' technology. Ultimately COM and .NET are both built very heavily ontop of win32 which is what I would count as real native code.
That said I have been looking for a example of how to apply an overlay icon for a while, this gives me it and is EASY to follow. BUT where is the msi produced? Surely to be complete the source code download should include the setup project to allow us to recreate the msi files and also see how to do it ourselves for our own extensions - I have tried "regsvr32" and it installs but I don't get any overlays so I assume there are some additional steps that I can't see...
Thanks...
--
Phil
"No plan survive contact with the enemy"
|
|
|
|
 |
|
 |
I never said that parsing every single file was bad - at least when using native code. If you can avoid handling every file on the system do so, but in your case you'd have to (although try to limit checking VCS if the files' directories don't appear to be related to any CVS projects).
I saw the CLR is bad for shell extensions because of the hugely increased working set added to the explorer.exe (or any shell host, like iexplore.exe can be) process. If you open folders in separate processes (good when testing extensions so your main shell doesn't crash, although I recommend using Virtual PC if you can) your memory will quickly be exhausted.
Every process that loads the CLR incurs a larger footprint and if you managed multiple application domains every non-neutral assembly is loaded into each application domain. When managed code is more common throughout the operating system I would certainly change my recommendation. For a good book on this read Customizing the .NET Framework Common Language Runtime[^]. It's got lots of great information for hosting .NET 2.0 and much is relevant to hosting previous runtimes.
I also recommend that you don't use the CLR because of all the interop that is required. Many times certain interface method parameters or structs aren't easy to define or handle (like VARIANT) though nothing's impossible. It's easy - especially with shell programming - to spend almost as much time just defining and testing your interface and related type definitions than it is programming the meat and potatoes of your solution.
You can run regsvr32 but you will have to log off and back on (or kill your shell and restart it). The setup doesn't change that. I didn't include the source because I don't want people redistributing a setup that is not my own because of how Windows Installer handles upgrades and patches (which you can check out much more on my blog at http://blogs.msdn.com/heaths[^]). I don't mind if people redistribute my extensions but I don't want different installer packages out there (changes to the ProductCode, ProductVersion, UpgradeCode, and ProductLanguage affects everything with Windows Installer packages).
Regarding the shell problem, with my next version I plan on adding a custom action to call SHLoadNonloadedIconOverlayIdentifiers on Win2K and up which should mean you don't have to logoff or restart to see the overlay icons.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Customer Product-lifecycle Experience
Microsoft
[My Articles] [My Blog]
|
|
|
|
 |
|
 |
Even though this article lists Windows 9x as being supported, the installer says that it is only supported on Windows 2000 and up.
|
|
|
|
 |
|
 |
Thanks, I'll change that. Mostly, I didn't support non-Unicode OS's because most of the functions I have to use take Unicode strings. Honestly, I didn't feel like detecting different encodings and converting. I also didn't think it'd be an issue because I figured most people weren't developing with .NET on anything older than Win2K! Actually, I thought the .NET Framework SDK wouldn't even install on WinNT4sp(5?) or older (or Windows, for that matter).
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
 |
|
 |
Heath Stewart wrote:
I figured most people weren't developing with .NET on anything older than Win2K!
Yeah, well, hopefully I won't be developing on Win98 for very much longer.
Heath Stewart wrote:
I thought the .NET Framework SDK wouldn't even install on WinNT4sp(5?) or older
It's not supposed to, but you can trick it into installing on Win98 (which I did).
|
|
|
|
 |
|
 |
Just wanted to let you know that I've updated the code to support Windows Me. Windows 98 doesn't support IShellOverlayIdentifier or IColumnProvider shell interfaces so Windows 98 is not supported.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Customer Product-lifecycle Experience
Microsoft
[My Articles] [My Blog]
|
|
|
|
 |