Windows 95 interface components such as Windows Explorer strip off the file extension by default when displaying the name of a file. (You can set an option to display the MS-DOS file extensions.) If you run Windows Explorer in details view, you will see a file type, but this is not necessarily the file extension. For example, in the Type column for a Microsoft Word file, you'll see the more explanatory phrase Microsoft Word Document rather than the DOC extension.
An application can get the filename to display (that is, the filename with the extension stripped off)through various methods, such as the SHGetFileInfo function. This function provides an easy way to get the attributes of a file, given the full path. SHGetFileInfo uses a structure called SHFILEINFO that contains the handle to the icon, the index to the icon, the file attributes, the display name (or the path for a folder), and the file type. Table 8-1 lists the flags that you can specify when calling SHGetFileInfo.
Flag | Description |
SHGFI_ICON | Retrieves the icon associated with the file. |
SHGFI_DISPLAYNAME | Retrieves the file's display name. |
SHGFI_TYPENAME | Retrieves the file's type name. |
SHGFI_ATTRIBUTES | Retrieves the attributes of the file. |
SHGFI_ICONLOCATION | Retrieves the icon location. |
SHGFI_EXETYPE | Retrieves the executable type of the file. |
SHGFI_SYSICONINDEX | Retrieves the system icon index. |
SHGFI_LINKOVERLAY | Places a link overlay on the icon. |
SHGFI_SELECTED | Displays the icon in selected state. |
SHGFI_LARGEICON | Retrieves the large icon. |
SHGFI_SMALLICON | Retrieves the small icon. |
SHGFI_OPENICON | Retrieves the open icon. |
SHGFI_SHELLICONSIZE | Retrieves the icon size used by the shell. |
SHGFI_PIDL | The path specified in the pszPath parameter is a pointer to an ITEMID list. |
SHGFI_USEFILEATTRIBUTES | The file attributes passed in the dwFileAttributes parameter should be used. |
Table 8-1.
File information flags.
Although generally you should not display file extensions, they are nevertheless useful to the application programmer. An application designer can use unique file extensions to differentiate his or her files from other files in the system. So feel free to employ thembut don't show them to the user unless you must.