⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sys_utils.c

📁 图像处理的压缩算法
💻 C
📖 第 1 页 / 共 4 页
字号:
	{
		if( IsClipboardFormatAvailable( CF_TEXT ) )           // If the clipboard contains text data...
		{
			HANDLE hData = GetClipboardData( CF_TEXT );       // Get text data from clipboard
			if( hData )                                       // If handle to clipboard good...
			{
				LPCSTR lpData = (LPCSTR) GlobalLock( hData ); // Lock clipboard
				if( lpData )                                  // If lock successful...
				{
					strData = lpData;                         // Put clipboard data in string
					bRet = TRUE;                              // Tell user about success!
					GlobalUnlock( hData );                    // Unlock clipboard
				}
			}
		}
		CloseClipboard();                                     // Close the clipboard
	}

	return bRet;                                              // Return, strData contains clipboard text
}


//construct a temporary file name in the Windows Temp path
BOOL GetTempFileName(string &strFile, LPCSTR lpcszPrefix)// = NULL)
{
	char sz[MAXFULLPATH];
	/// SY 09-12-2003 QA70-5158 v7.0694 OC_NEED_ROBUST_GET_TEMP_PATH_FUNCTION
	///	DWORD dw = GetTempPath(MAXFULLPATH, sz);
	///	if( dw )
	DWORD dw = get_temp_path(sz, MAXFULLPATH);
	if( 2 != dw )
	/// end OC_NEED_ROBUST_GET_TEMP_PATH_FUNCTION
	{
		strFile = sz;
		string strSignature = lpcszPrefix==NULL? "OTF" : lpcszPrefix;
		
		dw = GetTempFileName(strFile, strSignature, 0, sz);
		if( dw )
		{
			strFile = sz;
			return TRUE;
		}
	}
	return FALSE;
}

/**
		Get the file modification date of a file from an input string containing
		a path and filename.
	Example:
		string strFileDate, strDataFile = "C:\\Origin80\\Origin.ini";
		strFileDate = auGetFileSize(strDataFile);
	Parameters:
		lpcstrPathAndFilename=Input string containing a path and filename with filetype extension
	Return:
		Returns a Windows like file modification date formatted for display. 
*/
string GetFileModificationDate(LPCSTR lpcstrPathAndFilename, WORD wFormat)
{
	string strFileModDate;
	
	WIN32_FILE_ATTRIBUTE_DATA fileInfo;
	if( GetFileAttributesEx(lpcstrPathAndFilename, 0, &fileInfo) )
	{
		FILETIME localFileTime;
		if( FileTimeToLocalFileTime(&fileInfo.ftLastWriteTime, &localFileTime) )
		{
			SYSTEMTIME sysTime;
			if( FileTimeToSystemTime(&localFileTime, &sysTime) )
			{
				LPSTR lpstr = strFileModDate.GetBuffer(MAXFULLPATH);
				if( lpstr )
				{
					systemtime_to_date_str(&sysTime, lpstr, wFormat);
					strFileModDate.ReleaseBuffer();
				}
			}
		}
	}

	return strFileModDate;
}


/**
	List all files of a specified file type found in a folder

Example:
	string strExePath = GetAppPath();
	StringArray saResult;
	FindFiles(saResult, strExePath, "otw");
	
Parameters:
	saResult = the referrence of string array will receive the finding results
	lpcszPath = the file path to search for files
	bCheckExist = true will check the given saReult to see if the file is already in that array
Return:
	Returns TRUE for success, otherwise failure.
*/	
BOOL FindFiles(StringArray& saResult, LPCSTR lpcszPath, LPCSTR lpcszExt, bool bCheckExist)// = false);
{	
	WIN32_FIND_DATAA FileData;
	string strFilePath = lpcszPath;
	string strFileExt = lpcszExt;
	
	if(strFileExt.IsEmpty())
		strFileExt = "*.*";
	else
	{
		if(strFileExt[0] != '*')
		{
			if(strFileExt[0] == '.')
				strFileExt = "*" + strFileExt;
			else	
				strFileExt = "*." + strFileExt;
		}
	}
			
		
	HANDLE hFind = FindFirstFile( strFilePath + strFileExt, &FileData);

	if(INVALID_HANDLE_VALUE != hFind)
	{
		saResult.Add(FileData.cFileName); // the first file name found
		
		int ii; 
		// start the loop
		while(FindNextFile(hFind, &FileData)) 
		{ 
			bool bExist = false; // may need to determin the string existed in the array or not
			if(bCheckExist)
			{
				for(ii = 0; ii < saResult.GetSize(); ii++)
				{				
					if( 0 == saResult[ii].CompareNoCase(FileData.cFileName))
						bExist = true;
				}
			}
	
			if(!bExist)
				saResult.Add(FileData.cFileName);
		}

		FindClose(hFind);	
		return TRUE;
	}
	return FALSE;
}

BOOL SetFileToCurrentTime(LPCSTR lpcszFilename)
{
	BOOL bRet = FALSE;
	HANDLE hFile = CreateFile(lpcszFilename, GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
	if (hFile != INVALID_HANDLE_VALUE)
	{
		FILETIME ft;
		SYSTEMTIME st;
		GetSystemTime(&st);              // gets current time
		SystemTimeToFileTime(&st, &ft);  // converts to file time format
		bRet = SetFileTime(hFile,NULL, NULL, &ft);
		CloseHandle(hFile);
	}
	return bRet;
}

/** >File Management
	Copy file and also set destination file's attribute
Example:
Parameters:
	lpcszSrc = [in] Pointer to a null-terminated string that specifies the name of an existing file. 
	lpcszDest =	[in] Pointer to a null-terminated string that specifies the name of the new file. 
	dwAttribute = the file attribute to set on the new file lpcszDest
	bSetCurrentTime = set the destination file to the current time or not
Return:
	Returns TRUE for success, otherwise failure.
Remark:
	This function will call CopyFile with default bFailIfExists = FALSE
*/
BOOL FileCopy(LPCSTR lpcszSrc, LPCSTR lpcszDest, DWORD dwAttribute, bool bSetCurrentTime)// = FILE_ATTRIBUTE_NORMAL, true);
{
	if(CopyFile(lpcszSrc, lpcszDest))
	{
		SetFileAttributes(lpcszDest, dwAttribute);
		if(bSetCurrentTime)
		{
			SetFileToCurrentTime(lpcszDest);
		}
		return TRUE;
	}
	return FALSE;
}

// export a page to an image using settings from a tree node
bool export_page(Page &pg, LPCSTR lpcszFileName, const TreeNode &trExport)
{
	// get image format
	string str = trExport.tagName;
	
	// backup ini settings
	Tree trIniSettings;
	tree_read_image_export_settings(trIniSettings, str);

	// write tree settings to ini
	tree_write_image_export_settings(trExport, str);
	
	// export page to image
	bool bRet = export_page_to_image(pg, lpcszFileName, str, false);
	
	// restore ini settings
	tree_write_image_export_settings(trIniSettings, str, true);

	return bRet;
}

// export a page to an image using the page's export settings
bool export_page(Page &pg, LPCSTR lpcszFileName, LPCSTR lpcszFormat)
{
	Tree trIniSettings;
	bool bPageSettings = false;

	// get page settings
	Tree trPageSettings;
	if( tree_get_page_image_export_settings(trPageSettings, pg, lpcszFormat) )
	{
		bPageSettings = true;

		// backup ini settings
		tree_read_image_export_settings(trIniSettings, lpcszFormat);

		// write page settings to ini
		tree_write_image_export_settings(trPageSettings, lpcszFormat);
	}
	
	// export page to image
	bool bRet = export_page_to_image(pg, lpcszFileName, lpcszFormat, false);

	if( bPageSettings )
	{
		// restore ini settings
		tree_write_image_export_settings(trIniSettings, lpcszFormat, true);
	}
	
	return bRet;
}

// export a page to an image using current ini settings or prompt user with export options
bool export_page_to_image(Page &pg, LPCSTR lpcszFileName, LPCSTR lpcszFormat, BOOL bShowOptions)
{
	if( EXIST_PLOT != pg.GetType() && EXIST_LAYOUT != pg.GetType() )
		return false; // invalid page type
	string str;
	str.Format("Image.ShowOptions=%d;Image.FileName$=%s;", bShowOptions, lpcszFileName);
	pg.LT_execute(str);

	// LabTalk's Image.Export.PageDPI arguments:
	// 1  File format extension (str)
	// 2  dots per inch (int)
	// 3  bits per pixel (int)
	// 4  compression (int)
	/// EJP 11-20-2003 v7.5764 QA70-5587 FAIL_TO_EXPORT_1200DPI_BITMAP
	///str.Format("Image.Export.PageDPI(%s);", lpcszFormat);
	str.Format("imgexp = Image.Export.PageDPI(%s);", lpcszFormat);
	/// end FAIL_TO_EXPORT_1200DPI_BITMAP
	if( !pg.LT_execute(str) )
		return false;

	return true;
}

// export a page to an image using the specified settings
bool export_page_to_image(LPCSTR lpcszFileName, LPCSTR lpcszFormat, Page &pg, int nWidth, int nHeight, int nBitsPerPixel, int nCompression)
{
	if( EXIST_PLOT != pg.GetType() && EXIST_LAYOUT != pg.GetType() )
		return false; // invalid page type
	
	string str;
	str.Format("Image.ShowOptions=0;Image.FileName$=%s;", lpcszFileName);
	if( !pg.LT_execute(str) )
		return false;
	
	if( 0 == nHeight ) // height not specified, use width as DPI
		str.Format("Image.Export.PageDPI(%s, %d, %d, %d);", lpcszFormat, nWidth, nBitsPerPixel, nCompression);	
	else
		str.Format("Image.Export.PagePixel(%s, %d, %d, %d, %d);", lpcszFormat, nWidth, nHeight, nBitsPerPixel, nCompression);	
	return pg.LT_execute(str) ? true : false;
}

//------------------- GJL v7.0357 QA70-4078 3/17/03 ORIGINC_MULTI_OPEN_SUPPORT
//////////////////////////////////////////////////////////////////////////////////
/**
		Open an FDLog Open dialog box passing the file types to list in an array
		of strings. Optionally uses a simple Open dialog with multiple selection
		enabled or a Multi-Open dialog box.
	Example:
		int iNumSelFiles;
		string strPath;
		StringArray saFiletypes, saFilePaths;
		saFiletypes.SetSize( 3 );
		saFiletypes[0]="[Project (*.OPJ)] *.OPJ";
		saFiletypes[1]="[Old version (*.ORG)] *.ORG";
		saFiletypes[2]="[Worksheets (*.OGW)] *.OGW";
		iNumSelFiles = GetMultiOpenBox( saFilePaths, saFiletypes ); // or
		iNumSelFiles = GetMultiOpenBox( saFilePaths, saFiletypes, "C:\\Program Files\\" ); // or
		iNumSelFiles = GetMultiOpenBox( saFilePaths, saFiletypes, "C:\\Program Files\\", "Origin" ); // or
		iNumSelFiles = GetMultiOpenBox( saFilePaths, saFiletypes, "C:\\Program Files\\", "Origin", "OpenOPJ" ); // or
		iNumSelFiles = GetMultiOpenBox( saFilePaths, saFiletypes, "C:\\Program Files\\", "Origin", "OpenOPJ", true );
	Parameters:
		saFilePaths=Output vector of strings containing path and filename of all selected files
		saFiletypes=Input vector containing file types to list in the dialog box, each element
			of vector must follow syntax of LabTalk FDLog.TypeN$ object property
		lpcszPath=Input initial path when dialog opens, default NULL uses FDLog tracking
		lpcszFileName=Input initial filename when dialog opens, default NULL uses an empty string 
		lpcszDialogName=Input title of the dialog box, default NULL uses "Open"
		bMultiSelection=Input flag specifiying to use multi-selection Open (default true) or Multi-Open (false) dialog box
	Return:
		Returns the path and filename of all selected files or an empty string if Cancel button
		in dialog box is clicked. Also returns the number of files selected.
*/
int GetMultiOpenBox( StringArray& saFilePaths, StringArray &saFiletypes, LPCSTR lpcszPath, LPCSTR lpcszFilename,
	 LPCSTR lpcszDialogName, bool bMultiSelection ) // lpcszPath = NULL, lpcszFilename = NULL, lpcszDialogName = NULL, bMultiSelection = true
{
	if( bMultiSelection )
		return GetFileDialogBox( saFilePaths, saFiletypes, FDLOG_TYPE_OPEN_MULTISEL, lpcszPath, lpcszFilename, lpcszDialogName );
	else
		return GetFileDialogBox( saFilePaths, saFiletypes, FDLOG_TYPE_MULTI_OPEN, lpcszPath, lpcszFilename, lpcszDialogName );
}

/**
		An FDLog.UseGroup version of GetMultiOpenBox that uses an enumerated FDLog.UseGroup
		code to indicate the set of file types to list. See sys_utils.h or the Origin.ini
		file for a list of the enumerated FDLOG.UseGroup codes. Optionally uses a simple
		Open dialog with multiple selection enabled or a Multi-Open dialog box.
	Example:
		int iNumFiles;
		StringArray saFilePaths;
		iNumFiles = GetMultiOpenBox( saFilePaths, FDLOG_ORIGIN ); // or
		iNumFiles = GetMultiOpenBox( saFilePaths, FDLOG_EXCEL, "C:\\Program Files\\" ); // or
		iNumFiles = GetMultiOpenBox( saFilePaths, FDLOG_ASCII, "C:\\Program Files\\", "Origin" ); // or
		iNumFiles = GetMultiOpenBox( saFilePaths, FDLOG_SCRIPT, "C:\\Program Files\\", "Origin", "OpenOGS" );
		iNumFiles = GetMultiOpenBox( saFilePaths, FDLOG_SCRIPT, "C:\\Program Files\\", "Origin", "OpenOGS", false );
	Parameters:
		saFilePaths=Output vector of strings containing path and filename of all selected files
		nFDLogUseGroup=Input LabTalk FDLog.UseGroup code as enumerated in sys_utils.h and in
			the Origin.ini file
		lpcszPath=Input initial path when dialog opens, default NULL uses FDLog tracking
		lpcszFileName=Input initial filename when dialog opens, default NULL uses an empty string 
		lpcszDialogName=Input title of the dialog box, default NULL uses "Open"
		bMultiSelection=Input flag specifiying to use multi-selection Open (default true) or Multi-Open (false) dialog box
	Return:
		Returns the path and filename of all selected files or an empty string if Cancel button
		in dialog box is clicked. Also returns the number of files selected.
*/
int GetMultiOpenBox( StringArray& saFilePaths, FDLogUseGroup nFDLogUseGroup, LPCSTR lpcszPath, LPCSTR lpcszFilename,
	 LPCSTR lpcszDialogName, bool bMultiSelection ) // lpcszPath = NULL, lpcszFilename = NULL, lpcszDialogName = NULL, bMultiSelection = true
{
	if( bMultiSelection )
		return GetFileDialogBox( saFilePaths, nFDLogUseGroup, FDLOG_TYPE_OPEN_MULTISEL, lpcszPath, lpcszFilename, lpcszDialogName );
	else
		return GetFileDialogBox( saFilePaths, nFDLogUseGroup, FDLOG_TYPE_MULTI_OPEN, lpcszPath, lpcszFilename, lpcszDialogName );
}

//////////////////////////////////////////////////////////////////////////////////
/**
		An easier to use version of GetMultiOpenBox that works for a single file type.
		Optionally uses a simple Open dialog with multiple selection enabled or a
		Multi-Open dialog box.
	Example:
		int iNumFiles;
		StringArray saFilePaths;
		iNumFiles = GetMultiOpenBox(saFilePaths); // or
		iNumFiles = GetMultiOpenBox( saFilePaths, "[Old version (*.ORG)] *.ORG" ); // or
		iNumFiles = GetMultiOpenBox( saFilePaths, "*.OPJ"); // or
		iNumFiles = GetMultiOpenBox( saFilePaths, "*.ocw Workspace", GetAppPath() + "OriginC\\" ); // or
		iNumFiles = GetMultiOpenBox( saFilePaths, "*.ocw Workspace", GetAppPath() + "OriginC\\", "Origin" ); // or
		iNumFiles = GetMultiOpenBox( saFilePaths, "*.ocw Workspace", "C:\\Program Files\\", "Origin", "Open Workspace", false );
	Parameters:
		saFilePaths=Output vector of strings containing path and filename of all selected files
		lpcszFileType=Input file type string like "*.ext description", "[decription (*.ext)] *.ext", or just "*.ext"
		lpcszPath=Input initial path when dialog opens, default NULL uses FDLog tracking
		lpcszFileName=Input initial filename when dialog opens, default NULL uses an empty string 
		lpcszDialogName=Input title of the dialog box, default NULL uses "Open"
		bMultiSelection=Input flag specifiying to use multi-selection Open (default true) or Multi-Open (false) dialog box
	Return:
		Returns the path and filename of all selected files or an empty string if Cancel button

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -