LFile::BrowseDir

#include "ltwrappr.h"

virtual L_INT LFile::BrowseDir(pszPath, pszFilter, pThumbOptions, bStopOnError=FALSE, bIncludeSubDirs=FALSE, bExpandMultipage=FALSE, lSizeDisk=0, lSizeMem=0)

L_TCHAR * pszPath;

/* directory to browse */

L_TCHAR * pszFilter;

/* file filter, ex *.jpg */

pTHUMBOPTIONS pThumbOptions;

/* pointer to 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 multipage files */

L_INT32 lSizeDisk;

/* maximum size of file to load */

L_INT32 lSizeMem;

/* maximum size of image to load */

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 multipage files. If True, each page from a multipage file will be loaded. Possible values are:

 

Value

Meaning

 

TRUE

Expand multipage files, loading each page from a multipage file.

 

FALSE

Do not expand multipage 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.

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 LFile::BrowseDirCallBack function.

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

Required DLLs and Libraries

LTFIL
LTIMG
LTTMB
File format DLLs

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

See Also

Functions:

LFile::Load, LFile::ReadStamp, LFileSettings::SetLoadResolution, LFileSettings::SetPCDResolution, LFileSettings::SetWMFResolution, LFile::BrowseDirCallBack, LFileSettings::SetWMFResolution

Topics:

Thumbnail Browser

Example

// define user LFile class to override CallBack
class LMyBrowse : public LFile
{
public:
   HDC m_hDC;
public:
   LMyBrowse();
   virtual ~LMyBrowse();
   virtual L_INT BrowseDirCallBack( LBitmapBase * pLBitmap,
                                    L_TCHAR * pszFilename,
                                    pFILEINFO pFileInfo,
                                    L_INT nStatus,
                                    L_INT nPercent
                                  );
};
LMyBrowse::LMyBrowse()
{
   m_hDC = NULL;
}
LMyBrowse::~LMyBrowse()
{
}
L_INT LMyBrowse::BrowseDirCallBack(LBitmapBase * pLBitmap,
                                   L_TCHAR * pszFilename,
                                   pFILEINFO pFileInfo,
                                   L_INT nStatus, L_INT nPercent)
{
   UNREFERENCED_PARAMETER(pszFilename);
   UNREFERENCED_PARAMETER(pFileInfo);
   UNREFERENCED_PARAMETER(nPercent);
   // we have a thumbnail, do something with it
   if(nStatus == SUCCESS)
   {
      pLBitmap->Paint()->SetDC(m_hDC);
      pLBitmap->Paint()->PaintDC();
   }
   else if(nStatus == BROWSE_LOADING)
   {
      // imaging being loaded
   }
   return SUCCESS ;
}
// Test Function
L_INT LFile__BrowseDirExample(HDC hDC)
{
   L_INT nRet;
   LBase::LoadLibraries(LT_ALL_LEADLIB);
   LMyBrowse myBrowse;
   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  */
   myBrowse.m_hDC = hDC;
   nRet = myBrowse.BrowseDir(TEXT("C:\\Program Files\\LEAD Technologies, Inc\\LEADTOOLS 15.0\\Images\\new"), // path
                             TEXT("*.*"),             // all files
                             &Opt,
                             FALSE,             // do not stop on errors
                             FALSE,             // do not include sub-dirs
                             FALSE,             // do not expand multipage files
                             0,                 // no limit to file sizes
                             4000*1024);        // limit image in memory to 4MB
   if(nRet != SUCCESS)
      return nRet;
   return SUCCESS;
}