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

📄 sys_utils.c

📁 图像处理的压缩算法
💻 C
📖 第 1 页 / 共 4 页
字号:
		in dialog box is clicked. Also returns the number of files selected.
*/
int GetMultiOpenBox( StringArray& saFilePaths, LPCSTR lpcszFileType, LPCSTR lpcszPath, LPCSTR lpcszFilename,
	 LPCSTR lpcszDialogName, bool bMultiSelection ) // lpcszFileType = "*.* All Files", lpcszPath = NULL, lpcszFileName = NULL, lpcszDialogName = NULL, bMultiSelection = true
{
	if( bMultiSelection )
		return GetFileDialogBox( saFilePaths, lpcszFileType, FDLOG_TYPE_OPEN_MULTISEL, lpcszPath, lpcszFilename, lpcszDialogName );
	else
		return GetFileDialogBox( saFilePaths, lpcszFileType, FDLOG_TYPE_MULTI_OPEN, lpcszPath, lpcszFilename, lpcszDialogName );
}
//------------------- QA70-4078

/**
		Compute a LabTalk (1 based) index from a C (0 based) index and add an offset.
	Parameters:
		iCindex=Input 0 based C index
		nOffset=Input offset, default is 0
	Return:
		Returns a LabTalk 1 based index with added offset.
*/
int c_index_to_labtalk_index(int iCindex, int nOffset) // nOffset = 0
{
	return iCindex + 1 + nOffset;	
}

/**
		Compute a C (0 based) index from a LabTalk (1 based) index and add an offset.
	Parameters:
		iLTindex=Input 1 based LabTalk index
		nOffset=Input offset, default is 0
	Return:
		Returns a C 0 based index with added offset.
*/
int labtalk_index_to_c_index(int iLTindex, int nOffset) // nOffset = 0
{
	return iLTindex - 1 + nOffset;
}


int ExportActiveGraphPageToImage()
{
	PageBase pbActive;
	pbActive = Project.Pages();
	if( EXIST_PLOT != pbActive.GetType() && EXIST_LAYOUT != pbActive.GetType() )
		return 1; // invalid page type
	string strPgName = pbActive.GetName();
	
	using FDlog = LabTalk.FDLog;
	using Image = LabTalk.Image;

	FDLogInit(); // call sys_utils func		

	FDlog.CheckName$ = SHOW_EXPORT_OPTIONS;
	FDlog.CheckStatus = Image.ShowOptions;
	FDlog.Default$ = strPgName;
	FDlog.UseGroup("Image");
	Image.GetExtList("z","e");

	char szUseType[MAX_PATH];
	if( !LT_get_str( "%z", szUseType, sizeof(szUseType) ) )
		return 1;
	FDlog.UseType(szUseType);

	if( FDlog.SaveAs("a") )
		return 1; // user canceled or error

	string strFileName;
	strFileName.Format("%s%s", FDlog.Path$, FDlog.Default$);

	bool bShowOptions = (FDlog.CheckStatus ? true : false);
	
	Page pg(strPgName);
	if( !export_page_to_image(pg, strFileName, FDlog.DefTypeExt$, bShowOptions) )
	{
		/// EJP 11-20-2003 v7.5764 QA70-5587 FAIL_TO_EXPORT_1200DPI_BITMAP
		double dErr;
		if( LT_get_var("imgexp", &dErr) )
			ImageExportErrorMessageBox((int)dErr);
		/// end FAIL_TO_EXPORT_1200DPI_BITMAP
		return 1;
	}

	// Copy export settings into page.info
	Tree trSettings;
	if( !tree_read_image_export_settings(trSettings, FDlog.DefTypeExt$) )
		return 1;
	if( !tree_set_page_image_export_settings(trSettings, pg, FDlog.DefTypeExt$) )
		return 1;
	return 0;
}

/// EJP 11-20-2003 v7.5764 QA70-5587 FAIL_TO_EXPORT_1200DPI_BITMAP
int ImageExportErrorMessageBox(int iErr)
{
	string strFormat = _L("Error %d\n%s");
	string strDescrip;
	switch( iErr )
	{
	case 301: // OERR_ORIGIN_INTERNAL_BMP
		strDescrip = _L("Internal bitmap error");
		break;
	case 302: // OERR_ORIGIN_CREATE_BMP_FILE
		strDescrip = _L("Error creating bitmap file");
		break;
	case 309: // OERR_ORIGIN_INTERNAL_BMP_COLOR_DEPTH
		strDescrip = _L("Internal bitmap color depth error");
		break;
	}

	string strMsg;
	strMsg.Format(strFormat, iErr, strDescrip);
	MessageBox(GetWindow(), strMsg, _L("Origin Image Export"));
	return iErr;
}
/// end FAIL_TO_EXPORT_1200DPI_BITMAP

#define IS_CHAR_LETTER(_ch)		(('A' <= (_ch) && (_ch) <= 'Z') || ('a' <= (_ch) && (_ch) <= 'z'))
#define IS_CHAR_NUMBER(_ch)		('0' <= (_ch) && (_ch) <= '9')
bool validate_identifier_name(string &strName)
{
	/// JCG 06/17/03 QA70-4575 IMP_WIZD_BUG_45_AND_28
	/// if( !IS_CHAR_LETTER(strName[0]) && strName[0] != '_' )
	///	strName.Delete(0);
	//
	// when scan header lines, the identifier name can be only a number such "1"
	// so shouldn't remove it, otherwise, this line can not be scanned.
	if( !IS_CHAR_LETTER(strName[0]) && strName[0] != '_' )
	{
		if( strName.GetLength() > 1 ) // keep it if only a number
			strName.Delete(0);
	}
	/// end IMP_WIZD_BUG_45_AND_28
	int n = 0;
	while( n < strName.GetLength() )
	{
		if( IS_CHAR_LETTER(strName[n]) || IS_CHAR_NUMBER(strName[n]) || '_' == strName[n] )
			n++;
		else
			strName.Delete(n);
	}
	return true;
}


/**
		Makes sure that a Note window with the name strNoteWnd exists. If not, it will be created
		and given that name. If strNoteWnd is empty, it will just create a new Note window.  
	Example:
	Parameters:
		lpcszName=the Note window name
	Return:
		Returns TRUE if OK, otherwise FALSE.
*/
bool	get_create_Note(string &strNoteWnd)
{
	BOOL		bDone = FALSE;
	if (!strNoteWnd.IsEmpty())	// specified?
	{
		Note		nt(strNoteWnd);
		if (nt)
		{
			return true;
		}
	}
	
	// does not exist, must be created:
	Note		ntNew;
	if (ntNew.Create())
	{
		if (!strNoteWnd.IsEmpty())
			ntNew.Rename(strNoteWnd);
		
		strNoteWnd = ntNew.GetName();
	}
	else
		return false;

	return true;
}


BOOL	worksheets_are_same(Worksheet &wks1, Worksheet &wks2)
{
	if (!wks1 || !wks2)
		return FALSE;	// one not attached consider the different
	
	WorksheetPage	wp1;
	wks1.GetParent(wp1);
	
	WorksheetPage	wp2;
	wks2.GetParent(wp2);
	
	if (!wp1 || !wp2)
		return FALSE;
	
	string		strName1 = wp1.GetName();
	string		strName2 = wp2.GetName();
	
	BOOL		bSame = strName1.CompareNoCase(strName2) == 0;
	
	return bSame;
}

/// EJP 07-10-2003 v7.0622 QA70-4745 SET_PAGE_IMPORT_INFO_ON_123_ASC_IMPORT
BOOL set_page_import_info(Page &pgTarget, LPCSTR lpcszFile, int iDataType)
{
	if( !pgTarget )
		return FALSE;
	
	// file date
	double dJulianDate = 0.0;
	WIN32_FILE_ATTRIBUTE_DATA fad;
	if( GetFileAttributesEx(lpcszFile, 0, &fad) )
	{
		SYSTEMTIME st;
		if( FileTimeToSystemTime(&fad.ftLastWriteTime, &st) )
			SystemTimeToJulianDate(&dJulianDate, &st);
	}
	pgTarget.Info.System.Import.FileDate = dJulianDate;

	pgTarget.Info.System.Import.FileName$ = GetFileName(lpcszFile);
	pgTarget.Info.System.Import.FilePath$ = lpcszFile;
	pgTarget.Info.System.Import.Filter$ = ""; // filter file unknown
	pgTarget.Info.System.Import.FileType = iDataType;
	return TRUE;
}
/// end SET_PAGE_IMPORT_INFO_ON_123_ASC_IMPORT

//--------------------------------------------------------- CPY 8/12/03 QA70-4999
bool add_file_extension(string& strFilename, LPCSTR lpcszExt)
{
	LPSTR lpstr = strFilename.GetBuffer(MAXFULLPATH);
	char	szTemp[20];// file ext only 3 chars
	bool	bRet = false;
	if(check_add_file_ext(lpstr, NULL, szTemp) || lstrcmpi(szTemp, lpcszExt) != 0) // NO file extension, or is diff
	{
		lstrcat(lpstr, ".");
		lstrcat(lpstr, lpcszExt);
		bRet = true;
	}
	strFilename.ReleaseBuffer();
	return bRet;
}
//---------------------------------------------------------

string get_system_font_name(int nType, int* lpnCharSet) // = ANSI_VAR_FONT, NULL);
{
	int nFontSize;
	byte nCharSet = ANSI_CHARSET;
	
	string str;
	char	szTemp[LF_FACESIZE + 1];
	if(get_system_font_info(nType, &nFontSize, &nCharSet, szTemp, LF_FACESIZE))
		str = szTemp;
	if(lpnCharSet)
		*lpnCharSet = nCharSet;
	
	return str;
}

bool is_win2k(bool bAndLater) // true
{
	DWORD	dwVersion = GetVersion();
	// Get major and minor version numbers of Windows
	WORD loword = LOWORD(dwVersion);
	int lowbyte = LOBYTE(loword);
	int hibyte =  HIBYTE(loword);
	if(!(dwVersion & 0x80000000))                // Windows NT, 2000, XP
	{
		if(bAndLater)
			return lowbyte >= 5? true:false;
		
		return (5 == lowbyte && 0 == hibyte)? true:false;
	}
	// Windows 95, 98, ME
	return false;
}

static void separate_file_name_ext(string& strFileName, string& strExt)
{
	char	szExt[20];// file ext only 3 chars
	char	szTemp[MAXFULLPATH];
	lstrcpyn(szTemp, strFileName, MAXFULLPATH);
	if(check_add_file_ext(szTemp, NULL, szExt))
		strExt.Empty();
	else
	{
		strExt = szExt;
		int nExtLen = strExt.GetLength();
		strFileName.Delete(strFileName.GetLength() - nExtLen-1, nExtLen+1);
	}
}

//Check to find the strPathFilename that does not already exist 
bool get_next_file_name(string& strPathFilename, bool bCheckCreatePath) /// = true
{
	string strPath = GetFilePath(strPathFilename);
	if(bCheckCreatePath && !CheckMakePath(strPath))
		return false;

	if(!bCheckCreatePath && !strPath.IsPath())
		return false;
	
	string strFilename = GetFileName(strPathFilename);
	string strExt;
	separate_file_name_ext(strFilename, strExt);
	int nn = 1;
	while(strPathFilename.IsFile())
	{
		string strTemp = strPath + strFilename + (nn++);
		if(!strExt.IsEmpty())
			strTemp += "." + strExt;
		strPathFilename = strTemp;
	}
	return true;
}

bool is_str_valid_for_filename(LPCSTR lpcszFilename)
{
	string strPath = GetFilePath(lpcszFilename);
	if(!strPath.IsEmpty())
		return false;
	//IsFile seems not able to handle filename with * and ?, so better check first
	string strTest = lpcszFilename;
	if(strTest.IsEmpty() || strTest.Find('*') >=0 || strTest.Find('?') >= 0)
		return false;
	
	char szTempPath[MAXFULLPATH];
	DWORD dw = GetTempPath(MAXFULLPATH, szTempPath);
	if( dw )
	{
		strTest = szTempPath;
		strTest += lpcszFilename;
		if(strTest.IsFile())
			return true; // already existed in temp folder, must be good filename
		
		// not a file in temp folder, safe to create and delete
		HANDLE hFile = CreateFile(strTest,GENERIC_READ, FILE_SHARE_READ,// share for reading
						NULL,                      // no security
						CREATE_NEW,             // new file only
						FILE_ATTRIBUTE_NORMAL,     // normal file
						NULL);                     // no attr. template
		if (hFile == INVALID_HANDLE_VALUE)
			return false;
		CloseHandle(hFile);// must close file after reading	
		DeleteFile(strTest);
		return true;
	}
	return false;
}

// for used in LatTalk to access to this path
// example:
// get_project_attached_files_path %A;
// %Z=%Atest.dat; 
bool get_project_attached_files_path(string& strPath)
{
	strPath = GetProjectAttachedFilesPath();
	return strPath.IsEmpty()? false:true;
}

string	BuildBitwiseORSeparatedString(vector<string> &vInput)
{
	string		str;
	int			nSize = vInput.GetSize();
	for (int ii = 0; ii < nSize; ii++)
	{
		string		strTemp = vInput[ii];
		str += strTemp;
		if (ii < nSize - 1)
			str += "|";
	}
	
	return str;
}


	
	
	

⌨️ 快捷键说明

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