Coerce Windows to show a thumbnail for my custom file type - windows-vista

I want to use the windows OpenFileDialog class in C# to browse files for my application. I would then like the files to show up with previews in Windows' "thumbnails" view.
Is there a simple way to make this happen? I'm thinking there should be a way to encode the files so that Windows simply reads and displays the thumbnail information, even though it's an unsupported file type?
I know Windows Vista has a different interface (IThumbnailProvider as opposed to IExtractImage) than Windows XP, but I need it to work across platforms.
Thanks!
/ Jakob

You have to write a Shell Extension Handler Thumbnail Image Extractor. This is unmanaged c++ code that extracts the image from your custom filetype to display within explorer shell. You can find more about Shell Extension Handlers at the following link:
Creating Shell Extension Handlers

Related

How to Create/Edit a text file (.rtf) for Mac Osx in fireMonkey Rad studio XE2?

I have created a Fire Monkey HD app in Rad Studio xe2.I have created text file for windows in my application using AssignFile() method.Now I want to create text file for MAC OSx.How can I do it??
Delphi includes the System.IOUtils.TFile this is a record containing methods used to perform various operations on files, So to create a text file you can use the TFile.WriteAllText passing the content of the file directly or use the TFile.Create method that create a file and return a TFileStream. Also you can use the TFileStream class directly.
All the above methods works in Windows and OSX.
AssignFile is a seriously outdated function.
In modern (and cross platform) apps you should be using streams.

Shell namespace extension adding barricade

I implemented namespace extension using default shell view in Windows XP.
Everything works fine, but I want add barricade (A Description of Protected Folders - also applicable to Windows XP).
Is possible this using documented/undocumented functions (SFVM messages), or this feature is hard-coded ?
If you fill all data for your extension view yourself, then you can read contents of hidden (or any other) folders on your own and display them straightaway, or hide if it needs to.
Your extension uses its own namespace, which is not controlled by the built-in shell protection options.
P.S. Starting from Windows 7+ it should not be a problem.

Show icon for creator code on OSX

How could I display a custom icon depending on a files creator code/type code. For example I have an application that opens files with the creator code 'TSTx', how would I set the icon for that creator code?
I'm guessing that's how apps like Cyberduck show a progress icon when a file is being downloaded without changing the file extension and that's the behaviour I'm trying to replicate.
Thanks,
J
You shouldn’t rely on creator and type codes for this. Not all files have them assigned. In fact, not even all apps have unique creator codes, so that’s guaranteed to break.
If they files do exist in the file system and have proper path extensions, -[NSWorkspace iconForFile:] should do the trick. (I think that will also work with custom icons.) If the file doesn’t exist in the file system (e. g. because it’s stored in a database), -[NSWorkspace iconForFileType:] is the way to go. You can supply it with a path extension or, if you insist, with an HFS type code (which you must wrap in a string with the NSFileTypeForHFSTypeCode function).
To set a custom icon to be used by the Finder, you don’t need type and creator codes. Use -[NSWorkspace setIcon:forFile:options:].

How to start to write a Windows context menu

I would like to write a context menu for Markdown files for Windows XP, when I right click on a Markdown file it should display "View in browser" option. It could use MardownSharp or Discount to convert it in HTML and show it using the default browser. I guess that building such feature shouldn't require too much knowledge of the Windows platform. My question is: where should I start considering the fact that I would want to write this tool without using MS Visual Studio (I would like to use opensource software)? Could it be possible to use Mono?
See this answer on how to convert Markdown to HTML. As far as adding this as a context menu, this is a built-in feature of the Windows registry:
Browse to or create the following key. This assumes the file extension is .mdml (as I am unfamiliar with any set standard on this file format). If that's not the case, replace .mdml with the file extension(s) you are looking for, or * for all files, regardless of extension.
HKEY_CLASSES_ROOT\.mdml\Shell\
Browse to or create a new sub-key called something like "View in browser" and a sub-sub-key called "Command" (must be this word). In that key, modify the default to display the program and arguments to launch (e.g. C:\WINDOWS\SYSTEM32\NOTEPAD.EXE "%1").
You should now be able to browse to
HKEY_CLASSES_ROOT\.mdml\Shell\View in browser\Command\
and see the launch parameters in (Default).

How does Windows associate icons to files in explorer shell?

I have both InDesign CS2 and CS3 installed. Both use files with .indd extension. How does Windows know which icon to use? It uses correct icons i.e. CS2 files have cs2 icon and CS3 files have CS3 icon.
How does Windows know how to do this?
And how can I extract or use this version-detection system in my programs?
Edit:
Thank you for your shell-extension-icon-handler answers. Something new to me. But is there any way I could connect to IconHandler that InDesign provides and use it to detect version of the InDesign file?
You need to write an Icon Handler shell extension. See the MSDN documentation for IExtractIcon. The basic mechanism is that you create a shell extension and register the icon handler for the file type you want (look in HKEY_CLASSES_ROOT/.indd) and then the shell loads your handler, passes the file information and requests an icon in return. There's also the IExtractImage method if you want to provide a thumbnail bitmap rather than just an icon.
Note that you need to be especially careful writing shell extension handlers as any memory leaks or crashes can nuke the explorer and any other applications that display a file open/save dialog.
For some files it's HKEY_CLASSES_ROOT\<file extension here>\DefaultIcon registry entry, but most files map to a more friendly name, e.g. .pdf\(Default) -> AcroExch.Document (if Adobe Reader is installed).
In that case you have to go along the registry to AcroExch.Document and see that either
DefaultIcon is right there or
AcroExch.Document\CLSID\(Default) is some GUID. Then, follow HKEY_CLASSES_ROOT\CLSID\<insert that guid here> and you'll notice that this key contains DefaultIcon
... and DefaultIcon is where the icon is loaded from.
Hope that was clear enough ;). I don't know about your special case but there should be a distinction in the registry.
It almost certainly installs a shell icon extension handler. Writing your own and knowing how to detect the version in a file format that isn't documented well or at all is quite tricky.

Resources