// Returns a new filename using the timestamp: img_YYYYMMDD_HHMMSSuuu. // Verifies if a file already exists with the generated filename, if it does we increment the filename. CString GenerateAutoFileName() { GlobalSettings gs; CString timeStr; CString path; SYSTEMTIME tNow; CString ext; path = gs.bAutoName ? gs.getOutputDir() : _T("\\"); GetLocalTime(&tNow); timeStr.Format(_T("img_%u%02u%02u_%02u%02u%02u%03u"), tNow.wYear, tNow.wMonth, tNow.wDay, tNow.wHour, tNow.wMinute, tNow.wSecond, tNow.wMilliseconds); // We check which encoder is selected to know what extension to use switch (gs.sEnc) { case sEncBMP: ext = _T(".bmp"); break; case sEncJPEG: ext = _T(".jpg"); break; case sEncPNG: ext = _T(".png"); break; default: ext = _T(""); break; } // Check if the file already exists while( CheckFileExists(path + timeStr + ext) ) { if (tNow.wMilliseconds == 999) { break; } else { tNow.wMilliseconds += 1; timeStr.Format(_T("img_%u%02u%02u_%02u%02u%02u%03u"), tNow.wYear, tNow.wMonth, tNow.wDay, tNow.wHour, tNow.wMinute, tNow.wSecond, tNow.wMilliseconds); } } return timeStr + ext; }