reference:plugins:viewer_plugins:file_identification:dvp_identifyfile

DVP_IdentifyFile(
     HWND:hWnd,
     LPTSTR:lpszName,
     LPVIEWERPLUGINFILEINFO:lpVPFileInfo,
     HANDLE:hAbortEvent
)
→ BOOL

Arguments

hWnd

This parameter specifies the parent window handle that should be used to display any error messages if appropriate.

lpszName

Supplies the name of the file, including the full path.

lpVPFileInfo

This parameter points to a VIEWERPLUGINFILEINFO structure that must be filled out if the plugin recognizes and can view the file. See below for a description of this structure.

hAbortEvent

This may be a handle to a Windows event object which is used to abort the identification of a file if the user, for example, closes the Viewer Pane while file identification is taking place. See below for a description of how to use this handle.

Return value

If your plugin can support this file, you should fill in as much of the VIEWERPLUGINFILEINFO as possible and return TRUE to indicate that you can view this file. If the plugin returns FALSE, Directory Opus will then continue the identification process with the next plugin.

Description

The DVP_IdentifyFile function is called to determine whether the plugin can identify and view a disk file.

This function is called to identify a disk-based file. This function is always called, unless:

  • the plugin specified the DVPFIF_CanHandleBytes flag, in which case the DVP_IdentifyFileBytes function is called, or
  • the plugin specified the DVPFIF_CanHandleStreams flag, and the file is not disk-based (it is on an FTP site or within a ZIP file) in which case the DVP_IdentifyFileStream function is called.

Ordinarily, when this function is called your plugin should examine the file specified by lpszName to determine whether it can be viewed or not. If your plugin can support this file, you should fill in as much of the VIEWERPLUGINFILEINFO as possible and return TRUE to indicate that you can view this file. If the plugin returns FALSE, Directory Opus will then continue the identification process with the next plugin.

Note that even if you specified one of the DVPFIF_ExtensionsOnly flags, your DVP_IdentifyFile function will still be called, but only for files that match the file name extensions you specified. In this instance, you may wish to skip the actual file identification step and simply fill out as much of the VIEWERPLUGINFILEINFO as you can and return.

Also note that the VIEWERPLUGINFILEINFO structure is used by both the VFS_IdentifyFile function and the VFS_LoadBitmap functions. Many of the flags in the structure are only applicable in VFS_LoadBitmap (for example, DVPFIF_NoThumbnailBorder.) Generally, VFS_IdentifyFile does not need to set anything other than the DVPFIF_CanXXXXXX flags (can return bitmap, can return viewer, etc.) - although setting the other flags here will not hurt, you do not need to set the others until VFS_LoadBitmap is called.

The VIEWERPLUGINFILEINFO structure contains the following fields:

  • [in] UINT cbSize
    Directory Opus initializes this field to the size of the structure before passing it to your function. You must only fill in fields in the structure up to the size supplied by Directory Opus. This allows your plugin to be compatible with future versions of Directory Opus that may support more fields in this structure.
  • [in,out] DWORD dwFlags
    Fill out the dwFlags field to indicate the type of action that your plugin supports for this specific file. The available flags are:
    • DVPFIF_CanReturnBitmap
      This flag indicates that your plugin can generate an HBITMAP image for this file, and that Directory Opus should call your DVP_LoadBitmap function to load the image.
    • DVPFIF_CanReturnViewer
      This flag indicates that your plugin can create a custom viewer window for this file, and that Directory Opus should call your DVP_CreateViewer function to create this viewer. If you specify both this flag and the DVPFIF_CanReturnBitmap flag, then Directory Opus will call the function most appropriate to the situation. For example, DVP_CreateViewer will be called when the file is to be viewed in the image viewer or the Lister Viewer Pane, and DVP_LoadBitmap will be called to generate a thumbnail image or an image for use as a Lister background picture.
    • DVPFIF_CanReturnThumbnail
      This flag indicates that your plugin can generate a bitmap image for use in thumbnails mode. If specified, Directory Opus will call your DVP_LoadBitmap function to generate the thumbnail image.
    • DVPFIF_CanShowProperties
      This flag indicates that your plugin can display its own Properties dialog for the specified file. If this flag is specified, Directory Opus will call your DVP_ShowProperties function (or send your viewer window a DVPLUGINMSG_PROPERTIES message) when the user selects the Properties function from the image context menu in the Lister Viewer Pane. If you don't provide a custom properties dialog, Directory Opus will display a standard dialog unless your plugin specified the DVPFIF_NoProperties flag.
    • DVPFIF_ResolutionInch
      Set this flag if the values supplied in szResolution refer to dots per inch.
    • DVPFIF_ResolutionCM
      Set this flag if the values supplied in szResolution refer to dots per centimeter.
    • DVPFIF_WantFileInfo
      You do not set this flag - it will be set by Directory Opus to indicate that you are being called in order to retrieve file information rather than an image.
    • DVPFIF_ReturnsText
      Set this flag if you can only return data in text format (via DVP_LoadText) for the specified file.
    • DVPFIF_CanReturnFileInfo
      Set this flag if you are able to return information about this file via DVP_GetFileInfoFile.
    • DVPFIF_NoThumbnailBorder
      Set this flag to prevent Opus from displaying a border around thumbnails generated by your plugin.
    • DVPFIF_NoShowThumbnailIcon
      Set this flag to prevent Opus from displaying a filetype icon overlaid on thumbnails generated by your plugin.
    • DVPFIF_FolderThumbnail
      You do not set this flag - it will be set by Directory Opus to indicate that you are being called in order to generate a thumbnail for a folder.
    • DVPFIF_RegenerateOnResize
      Set this flag if thumbnails generated by your plugin need to be regenerated when the thumbnail size changes, rather than scaled.
    • DVPFIF_JPEGStream
      Set this flag if you are returning a raw JPEG stream rather than an HBITMAP. The stream must be allocated with LocalAlloc(LMEM_FIXED).
    • DVPFIF_PNGStream
      Set this flag if you are returning a raw PNG stream rather than an HBITMAP.
    • DVPFIF_InFolderThumbnail
      You do not set this flag - it will be set by Directory Opus to indicate that you are being called in order to generate thumbnails for files within a sub-folder.
  • [out] WORD wMajorType
    Set this field to the 'major' type of the current file. For example, DVPMajorType_Image for a picture file.
  • [out] WORD wMinorType
    This must be set to 0 for now.
  • [out] SIZE szImageSize
    If applicable, set this field to the image size of the current file. If the file does not represent an image, or the size is indeterminate, set the value of this field to 0.
  • [out] int iNumBits
    If applicable, set this field to the image bit depth of the current file (for example, 24 for a 24-bit color image). If the file does not represent an image, or the bit depth is indeterminate, set the value of this field to 0.
  • [in,out] LPTSTR lpszInfo
    Use this field to supply an information string that is displayed to the user in the standard Properties dialog box for this file. This string will also appear in the status bar of the image viewer and in the Description field in a Lister.

    When Directory Opus calls your plugin, this field may point to a buffer into which you can copy your information. The size of this buffer is given by the cchInfoMax field. You can either use this supplied buffer or change the address of the lpszInfo field to point to your own buffer. You must check before copying into this field that the buffer pointer is valid; if set to 0 it indicates that Directory Opus does not want this information at this time.
  • [in] UINT cchInfoMax
    This field specifies the supplied buffer size for the lpszInfo field in the structure. You must make sure you do not copy more data into the supplied buffer than is specified in this field. The size specified is given in characters, not bytes.
  • [in,out] DWORD dwPrivateData[8]
    This field represents 32 bytes of private data storage that you can use to pass information from your DVP_IdentifyFile function to your DVP_LoadBitmap and DVP_ShowProperties functions. The values you specify here will be preserved by Directory Opus and passed to your other functions intact.
  • [out] SIZE szResolution
    If applicable, set this field to the resolution of the image. Use the DVPFIF_ResolutionInch or DVPFIF_ResolutionCM flags to indicate the meaning of this field.
  • [out] int iTypeHint
    If you can return text data for a file, this field allows you to provide a "hint" as to the type of data. Valid values include DVPFIFITypeHint_PlainText, DVPFIFITypeHint_RichText and DVPFIFITypeHint_HTML.
  • [out] COLORREF crTransparentColor
    Use this to specify a color value in the returned bitmap that will be displayed as transparent. Set to CLR_NONE for no transparent color.
  • [in] WORD wThumbnailQuality
    This field is set by Opus to indicate the desired thumbnail quality (the value corresponds to a parameter to SetStretchBltMode)
  • [in] DWORDLONG dwlFileSize
    This field is set by Opus to the size of the file when DVP_IdentifyFileStream is called. It will be set to -1 if the size could not be determined.
  • [out] int iColorSpace
    If applicable, set this field to indicate the color space of the image. Valid values include DVPColorSpace_Grayscale, DVPColorSpace_RGB, DVPColorSpace_YCBCR, DVPColorSpace_CMYK and DVPColorSpace_YCCK.

The hAbortEvent parameter to the DVP_IdentifyFile is used by Directory Opus to allow the user to abort a potentially lengthy file identification process. The same technique is also used in the DVP_LoadBitmap and other functions. If you wish to allow the user to abort your plugin (which is highly recommended), you should make sure that you check the event for signaled status at regular intervals. For example,

if ( hAbortEvent && WaitForSingleObject( hAbortEvent, 0 ) == WAIT_OBJECT_0 )
{
    // aborted
}