Global.cpp
上传用户:gzboli
上传日期:2013-04-10
资源大小:471k
文件大小:2k
- // Global.cpp: implementation of the CGlobal class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "quickimage.h"
- #include "Global.h"
- #ifdef _DEBUG
- #undef THIS_FILE
- static char THIS_FILE[]=__FILE__;
- #define new DEBUG_NEW
- #endif
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- bool g_bShowHide = TRUE;
- CString g_strCurrentDir = _T("");
- CList<CString,CString&> g_strImgFileNames(20);
- int g_iSortColumn;
- CGlobal::CGlobal()
- {
- }
- CGlobal::~CGlobal()
- {
- }
- BOOL CGlobal::IsImgFile(LPCTSTR lpszFileName)
- {
- ASSERT(strlen(lpszFileName) > 0);
- char szExt[20];
- char *pExt = strrchr(lpszFileName, '.');
- if(NULL == pExt)
- {
- return FALSE;
- }
- strcpy(szExt, ++pExt);
- strlwr(szExt);
- if((0 == strcmp(szExt, _T("bmp")))
- || (0 == strcmp(szExt, _T("dib")))
- || (0 == strcmp(szExt, _T("ddb")))
- || (0 == strcmp(szExt, _T("jpg")))
- || (0 == strcmp(szExt, _T("jpeg")))
- || (0 == strcmp(szExt, _T("gif")))
- || (0 == strcmp(szExt, _T("pcx")))
- // || (0 == strcmp(szExt, _T("tif")))
- // || (0 == strcmp(szExt, _T("tiff")))
- // || (0 == strcmp(szExt, _T("raw")))
- // || (0 == strcmp(szExt, _T("")))
- )
- {
- return TRUE;
- }
- return FALSE;
- }
- void CGlobal::ChangeDirectory(LPCTSTR lpszPathName)
- {
- ASSERT(strlen(lpszPathName) > 0);
- g_strCurrentDir = lpszPathName;
- if(g_strCurrentDir.GetAt(g_strCurrentDir.GetLength() -1) != '\')
- g_strCurrentDir += _T("\");
-
- g_strImgFileNames.RemoveAll();
-
- WIN32_FIND_DATA stFindData;
- BOOL bFound = TRUE;
- CString strFind = g_strCurrentDir + _T("*.*");
- HANDLE hFind = FindFirstFile((LPCTSTR)strFind, &stFindData);
- CString strNewFileName;
- if(INVALID_HANDLE_VALUE != hFind)
- {
- while(bFound)
- {
- if((0 != strcmp(stFindData.cFileName, "."))
- && (0 != strcmp(stFindData.cFileName, ".."))
- && !(stFindData.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM)
- && (!(stFindData.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) || g_bShowHide)
- && (CGlobal::IsImgFile(stFindData.cFileName)))
- {
- strNewFileName = stFindData.cFileName;
- g_strImgFileNames.AddTail(strNewFileName);
- }
- bFound = FindNextFile(hFind, &stFindData);
- }
- }
- FindClose(hFind);
- }