L_BrowseDir

#include "l_bitmap.h"

L_LTTMB_API L_INT L_BrowseDir( pszPath, pszFilter, pThumbOptions, bStopOnError, bIncludeSubDirs, bExpandMultipage, lSizeDisk, lSizeMem, pfnBrowseDirCB, pUserData)

L_TCHAR *pszPath;

/* directory to browse */ 

L_TCHAR *pszFilter;

/* file filter, ex *.jpg */ 

pTHUMBOPTIONS pThumbOptions;

/* pointer to a thumbnail options structure */

L_BOOL bStopOnError;

/* stop on error flag */ 

L_BOOL bIncludeSubDirs;

/* True/False to recurse sub directories */ 

L_BOOL bExpandMultipage;

/* True/False to expand multi-page files */ 

L_SSIZE_T lSizeDisk;

/* maximum size of file to load */ 

L_SSIZE_T lSizeMem;

/* maximum size of image to load */ 

BROWSEDIRCALLBACK pfnBrowseDirCB;

/* required callback function */ 

L_VOID* pUserData;

/* pointer to more parameters for the callback */ 

Browses the specified directory for supported images, and generates thumbnails for each image file that is found.

Parameter

Description

pszPath

Character string containing the name of the directory to browse for images

pszFilter

Character string containing the file filter to use for browsing. Ex. *.jpg

pThumbOptions

Pointer to a structure containing the thumbnail creation options for the browser.

bStopOnError

Flag that indicates whether or not to stop generating thumbnails when an error occurs. Possible values are:

 

Value

Meaning

 

TRUE

Stop generating thumbnails if an error occurs.

 

FALSE

Do not stop generating thumbnails if an error occurs.

bIncludeSubDirs

Flag that indicates whether or not to recurse subdirectories when looking for files. Possible values are:

 

Value

Meaning

 

TRUE

Recurse subdirectories.

 

FALSE

Do not recurse subdirectories.

bExpandMultipage

Flag that indicates whether or not to expand multi-page files. If True, each page from a multi-page file will be loaded. Possible values are:

 

Value

Meaning

 

TRUE

Expand multi-page files, loading each page from a multi-page file.

 

FALSE

Do not expand multi-page files.

lSizeDisk

Maximum size of file to load. Use this to limit the size of images that the browse will attempt to load. Pass 0 for no limit.

lSizeMem

Maximum size of image in memory to load. Use this to limit the size of images that the browse will attempt to load. Pass 0 for no limit.

pfnBrowseDirCB

Callback function required for handling each of the generated thumbnails. You must specify a callback in order to process the thumbnails.The callback function must adhere to the function prototype described in BROWSEDIRCALLBACK Function.

pUserData

Void pointer that you can use to pass one or more additional parameters that the callback function needs. To use this feature, assign a value to a variable or create a structure that contains as many fields as you need. Then, in this parameter, pass the address of the variable or structure, casting it to L_VOID  *. The callback function, which receives the address in its own pUserData parameter, can cast it to a pointer of the appropriate data type to access your variable or structure. If the additional parameters are not needed, you can pass NULL in this parameter.

Returns

SUCCESS

The function was successful.

< 1

An error occurred. Refer to Return Codes.

Comments

Use this function to browse a directory for image files that LEADTOOLS supports. Each supported file that is found will be loaded, and a thumbnail will be generated for the image. In the callback function, you can process the thumbnail in any manner your application requires. For example, you can add the thumbnails to the LEADTOOLS ImageList Control.

If 0 is specified for either nThumbHeight or nThumbWidth, the image will not be resized. The whole image will be returned in the BROWSEDIRCALLBACK function.

If -1 is specified for either the nThumbHeight or nThumbWidth, the image will not be loaded at all. The BROWSEDIRCALLBACK function will be called for each file, but will only receive file information, not a valid image.

Required DLLs and Libraries

LTIMG
LTFIL
LTTMB

For a listing of the exact DLLs and Libraries needed, based on the toolkit version, refer to Files To Be Included With Your Application.

Platforms

Win32, x64, Mobile.

See Also

Functions:

L_CreateThumbnailFromFile,

L_LoadBitmap, L_ReadFileStamp,

 

L_SetLoadResolution,

 

L_SetPCDResolution, L_SetWMFResolution,

 

BROWSEDIRCALLBACK
For Vector files: L_2DGetViewMode L_2DSetViewMode,, L_2DGetViewPort, L_2DSetViewPort

Topics:

Thumbnail Browser

Example

L_INT EXT_CALLBACK BrowseDirCallback( pBITMAPHANDLE /*pBitmap*/,
                                      L_TCHAR* pszFile,
                                      pFILEINFO /*pFileInfo*/,
                                      L_INT nStatusCode,
                                      L_INT /*nPercent*/,
                                      L_VOID* /*pUserData*/)
{
   L_TCHAR buf[200];
   
   if(nStatusCode == SUCCESS)/* successful thumbnail generation */
   {
      /* Do something with the thumbnail, i.e. insert into ImageList Control */
      /* ... */
   }
   else if(nStatusCode == BROWSE_LOADING)/* in the process of loading an image */
      return SUCCESS;
   else if(nStatusCode == BROWSE_SKIPPED)/* skipped a large file */
   {
      /* report error to user */
      wsprintf(buf, TEXT("Skipped File: %s !"), pszFile);
      MessageBox(NULL, buf, TEXT("Skipped"), MB_OK);
   }
   else/* error during thumbnail generation */
   {
      /* report error to user */
      wsprintf(buf, TEXT("Error: %d - Generating Thumbnail!\n%s\nPress OK to Continue!"), nStatusCode, pszFile);
      if(MessageBox(NULL, buf, TEXT("Error"), MB_OKCANCEL|MB_ICONERROR) == IDCANCEL)
         return(ERROR_USER_ABORT);
   }

   return SUCCESS;
}

L_VOID BrowseDirExample(L_TCHAR * pszDir)
{
   L_INT nRet;
   THUMBOPTIONS Opt;
   memset(&Opt, 0, sizeof(THUMBOPTIONS));
   Opt.uStructSize = sizeof(THUMBOPTIONS);
   Opt.nWidth = 115; /* thumbnail width                          */
   Opt.nHeight = 115; /* thumbnail height                          */
   Opt.nBits = 24; /* 24-bit                                   */
   Opt.uCRFlags = 0; /* ignored, b/c we specified 24-bit         */
   Opt.bMaintainAspect = TRUE; /* maintain aspect when creating thumbnails */
   Opt.bForceSize = FALSE; /* don't force size                         */
   Opt.crBackColor = RGB(0,0,0); /* background color is ignored              */
   Opt.bLoadStamp = TRUE; /* try to load stamp if present in file     */
   Opt.bResample = TRUE; /* resample, for better quality thumbnails  */
   nRet = L_BrowseDir( pszDir,
                       TEXT("*.*"),
                       &Opt,
                       FALSE, /* don't stop on error                      */
                       FALSE, /* do not recurse subdirectories            */
                       FALSE, /* do not expand multi-page files            */
                       0,     /* no limit on file size                    */
                       4000*1024,/* set limit on image size to 4MB        */
                       (BROWSEDIRCALLBACK) BrowseDirCallback,/* callback  */
                       NULL );/* no user data                             */
   return;
}