Click here to Skip to main content
Click here to Skip to main content
 
Add your own
alternative version
Go to top

An Image Decoder Based on IImgCtx

, 25 May 2004
This article shows how to decode image with IImgCtx interface provided by IE
// SrchDir.cpp : implementation of the CSrchDir class
//

#include "stdafx.h"
#include "SrchDir.h"
#include "DirMng.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CSrchDir

IMPLEMENT_DYNCREATE(CSrchDir, CObject)

/////////////////////////////////////////////////////////////////////////////
// CSrchDir construction/destruction

CSrchDir::CSrchDir()
{
	// TODO: add construction code here
}

CSrchDir::~CSrchDir()
{
	m_arrayFiles.RemoveAll();
}

/////////////////////////////////////////////////////////////////////////////
// CSrchDir diagnostics

#ifdef _DEBUG
void CSrchDir::Dump(CDumpContext& dc) const
{
	CObject::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
void CSrchDir::Initialize(const char* pszFiles, void* pParam)
{
	m_arrayFiles.RemoveAll();

	if (pszFiles)
	{
		char szFiles[_MAX_PATH];
		lstrcpy(szFiles, pszFiles);
		for(char* token = strtok(szFiles, " ;*");
			token != NULL;
			token = strtok( NULL, " ;*"))
		{
			m_arrayFiles.Add(token);
		}
	}
}

void CSrchDir::ChkDir(const char* pszPath)
{
	if (pszPath == NULL || *pszPath == '\0')
		return;

	char szNewPath[MAX_PATH];
	lstrcpy(szNewPath, pszPath);

	if (*(strrchr(szNewPath, '\\') + 1) != '\0')
		strcat(szNewPath, "\\");		// C:\;

	ChkDirForMultiExt(szNewPath);
}

void CSrchDir::ChkDirForMultiExt(const char* pszPath)
{
	WIN32_FIND_DATA fData;
	char szNewPath[MAX_PATH];

	strcpy(szNewPath, pszPath);
	strcat(szNewPath, "*.*");

	HANDLE h = ::FindFirstFile(szNewPath, &fData);
	if (h != (HANDLE) 0xFFFFFFFF)
	{
		do
		{
			if ((fData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0)
			{
				if (IsValidFile(fData))
				{
					strcpy(szNewPath, pszPath);
					strcat(szNewPath, fData.cFileName);
					ChkFile(szNewPath, fData);
				}
			}
		} while (::FindNextFile(h, &fData));

		::FindClose(h);
	}
}

BOOL CSrchDir::IsValidFile(WIN32_FIND_DATA& fData)
{
	const char* p = strrchr(fData.cFileName, '.');
	if (p == NULL) return FALSE;
	for (int i = 0; i < m_arrayFiles.GetSize(); i++)
	{
		if (lstrcmpi(m_arrayFiles[i], p) == 0)
			return TRUE;
	}
	return FALSE;
}

/////////////////////////////////////////////////////////////////////////////
// CDirCounter
int CDirCounter::GetFilesInDir(const char* pszStartPath, const char* pszFiles)
{
	m_uiFiles = 0;

	Initialize(pszFiles, NULL);
	ChkDir(pszStartPath);

	return m_uiFiles;
}

void CDirCounter::ChkFile(const char* pszPath, WIN32_FIND_DATA& fData)
{
	m_uiFiles++;
}

/////////////////////////////////////////////////////////////////////////////
// CDirInfo
void CDirInfo::GetDirInfo(const char* pszStartPath, const char* pszFiles, void* pPara)
{
	m_pInfo = (FILE_INFO*) pPara;

	Initialize(pszFiles, NULL);
	ChkDir(pszStartPath);
}

void CDirInfo::ChkFile(const char* pszPath, WIN32_FIND_DATA& fData)
{
	m_pInfo->strFileName = pszPath;
	m_pInfo++;
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

strnghrs
Web Developer
China China
No Biography provided

| Advertise | Privacy | Mobile
Web04 | 2.8.140921.1 | Last Updated 26 May 2004
Article Copyright 2004 by strnghrs
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid