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

📄 utilities.h

📁 图像处理的压缩算法
💻 H
📖 第 1 页 / 共 3 页
字号:
/*------------------------------------------------------------------------------*
 * File Name: utilities.h														*
 * Creation: CPY 3/1/2001														*
 * Purpose: Origin C internal utility classes									*
 * Copyright (c) OriginLab Corp.2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007	*
 * All Rights Reserved															*
 * 																				*
 * Modification Log:															*
 *------------------------------------------------------------------------------*/

#ifndef _UTILITIES_H
#define _UTILITIES_H

#include <common.h> // must always include this
#include <mswin.h> // kernel32 functions

#ifndef _STRING_H
#include <string.h> // String Class
#endif // _STRING_H

#ifndef _DATA_H
#include <data.h>   //Dataset handling classes(vector, Dataset, matrix, Matrix ...)
#endif // _DATA_H

//#include <mscomm.h>

#define	PBOX_ENDBUTTON	0x4000	// instead of Cancel button
#define PBOX_NO_BUTTON	0x0200 // no cancel or end button, cannot click to cancel
#define PBOX_NO_BAR		0x2000	// just dialog with title and label, no progress bar and buttons
#define PBOX_OFF_CENTER	0x0400
// Please note that Origin C is not yet a full C++ language. Only internal classes
// can be declared as C++ classes. User C++ classes can only be supported via
// user supplied DLL.

/** >User Interface Controls
		A progress dialog box is a small dialog box used to indicate that a software is busy
		processing data. The dialog box contains a progress bar indicating the fraction of
		processing that has been completed. The progress dialog box is generally used in
		conjunction with some sort of iterative loop. The progressBox class provides methods
		and properties needed to open and control progress dialog boxes.
	Example:
 		int imax = 10;
		progressBox aa("This is an example:");
		aa.SetRange(0,imax);
		for(int ii = 0; ii < imax; ii++)
		{
			if(aa.Set(ii))
				printf("Hello, at %d\n", ii);
			else
			{
				out_str("User abort!");
				break;
			}
			LT_execute("sec -p 0.5"); // wasting some time
		}
*/ 
class progressBox
{
public:
	progressBox(LPCTSTR lpstrTitle, int nStyle = 0);
	/**
			Set the integer range for the progressbox to loop through. 
			If you do not call this method, the default range of 0 to 100 will be used.
		Parameters:
			nMin = beginning value
			nMax = end value
		Return:
			TRUE if the range is reasonable, FALSE otherwise.
		SeeAlso:
			Set
	*/
	BOOL	SetRange(int nMin, int nMax);

	/**
			Set the current position of the progress bar. This value is typically within range set
			by the SetRange method
		Parameters:
			nCurrent = the current progress bar position
		Return:
			TRUE normally, FALSE if user has clicked the Cancel or End button prior to this method was called
		Example:
			void run_progressBox()
			{
					int iMax = 10, iMin = 0;
					progressBox prgbBox("This is a ProgressBox example:");
					prgbBox.SetRange(iMin, iMax);
					for (int ii=iMin; ii<=iMax; ii++)
					{
						if(prgbBox.Set(ii))
							printf("Hi, it is now at %d.\n", ii);
						else 
						{
							out_str("User abort!");
							break;
						}
						LT_execute("sec -p 0.5");
					}
			}
	*/
	BOOL	Set(int nCurrent);

	/**
			the current progress bar position
	*/
	int		m_nCurrent;
};


/** >User Interface Controls
		A wait cursor is a visual cue (such as an hour glass) used to indicate that a software
		is busy processing data. The waitCursor class provides methods and properties needed
		to open and control wait cursors.
	Example:
		int imax = 100000;
		waitCursor junk; // just need to declare this, no need to reference to it
		double	aa = 0.5;
		DWORD	dw1 = GetTickCount();
		for(int ii = 0; ii < imax; ii++)
			aa = sin(aa) + ii * aa;
		printf("It took %d ms for %d loop\n",GetTickCount()-dw1,imax);
*/
class waitCursor
{
public:
	waitCursor();
	waitCursor(int nCursorType);

	/**
	The CheckEsc method allows a program to capture user hitting ESC to abort the current operation
	Return:
		TRUE if user has hit the ESC key, FALSE otherwise
		
	Example:
		Worksheet wks = Project.ActiveLayer();
		if(wks==NULL)
			return;
		
		waitCursor	cur;
		string	str;
		int		nCol = 0;
		for(int ii = 0; ii < 10000 && !cur.CheckEsc();ii++)
		{
			wks.AddCol();
			str.Format("Adding col %d", nCol++);
			SetDataDisplayText(str);
		}
		if(ii < 10000)
			printf("User abort adding columns, only %d columns are added\n", nCol);
	*/
	BOOL CheckEsc();
};

///////////////////////

#pragma dll(msvcrt, system)

/** >Memory Management
		Allocates a certain number of bytes on heap.
	Parameters:
    	nBytes =  Bytes to allocate.
    Return:
    	Returns a void pointer to the allocated space, or NULL if there is insufficient memory available. 
	Example:
		void	run_malloc()
		{
			char		*pstr;
			UINT		nNumerOfBytesToAllocate = 200;
			pstr = (char*)malloc(nNumerOfBytesToAllocate);
			if (pstr != NULL)
				out_str("Allocation succesful");
			else
				out_str("Allocation failed!");
			
			// free the allocated memory:
			free(pstr);
		}
*/
void *	malloc(UINT nBytes);

/** >Memory Management
		calloc function is used to allocate an array in memory with elements initialized to 0.
    Parameters:
    	nElements = Number of elements 
		nSize = Length in bytes of each element 
	Return:
		returns a pointer to the allocated space, or NULL if there is insufficient memory available. 
	Example:
		void	run_calloc()
		{
			int			*pn;
			UINT		nNumerOfIntegersToAllocate = 200;
			pn = (int*)calloc(nNumerOfIntegersToAllocate, sizeof(int));
			if (pn != NULL)
				out_str("Allocation succesful");
			else
				out_str("Allocation failed!");
			
			// free the allocated memory:
			free(pn);
		}
*/
void *	calloc(UINT nElements, UINT nSize);

/** >Memory Management
		Deallocates or frees a memory block that was allocated with malloc or calloc.
    Parameter:
    	pmem = Previously allocated memory block to be freed.
    Return:
    	None.
	Example:
		void	run_free()
		{
			char		*pstr;
			UINT		nNumerOfBytesToAllocate = 200;
			pstr = (char*)malloc(nNumerOfBytesToAllocate);
			if (pstr != NULL)
				out_str("Allocation succesful");
			else
				out_str("Allocation failed!");
			
			// free the allocated memory:
			free(pstr);
		}
*/
void	free(void * pmem);

/** >Character/String Manipulation
		Converts string to a double.
	Parameter:
		lpcsz = the string to convert
	Return:
		a double value.
	Example:
		void	run_atof()
		{
			char	szString[] = "-234.789";
			double	rr = atof(szString);
			out_double("value = ", rr);
		}
*/
double	atof(LPCSTR lpcsz);

/** >Character/String Manipulation
		Converts string to an integer.
	Parameter:
		lpcsz = the string to convert.
	Return:
		an integer value.
	Example:
		void	run_atoi()
		{
			char	szString[] = "-234987";
			int		nn = atoi(szString);
			out_int("value = ", nn);
		}
*/
int		atoi(LPCSTR lpcsz);

/** >Character/String Manipulation
		Converts string to a long.
	Parameter:
		lpcsz = the string to convert.
	Return:
		a long value
	Example:
		void	run_atol()
		{
			char	szString[] = "-556677";
			long	nn = atol(szString);
			out_int("value = ", nn);
		}
*/
long	atol(LPCSTR lpcsz);

/** >File Management
		Get the current working directory.
	Parameters:
		buffer = Storage location for path to be returned by the function
		maxlen = Maximum length of path in characters
	Return:
		returns a pointer to buffer. A NULL return value indicates an error.
	Example:
		void	run_getcwd()
		{
			char		szcurDirectory[MAXFULLPATH];
			if ( _getcwd(szcurDirectory, MAXFULLPATH) != NULL )
			{
				out_str(szcurDirectory);
			}
		}
*/
char*	_getcwd( char *buffer, int maxlen );// get the current working path

/** >File Management
		Change the current working directory.
	Parameter:
		*lpcszPath = Path of new working directory.
	Return:
		0 if successful. A return value of -1 indicates that the specified path could not be found
	Example:
		void	run_chdir()
		{
			string		strNewCurrentDir = "c:\\";
			if (0 == _chdir(strNewCurrentDir))
			{
				// If it succeded, display the new current directory:
				char		szcurDirectory[MAXFULLPATH];
				if ( _getcwd(szcurDirectory, MAXFULLPATH) != NULL )
				{
					out_str(szcurDirectory);
				}
			}
		}
*/
int		_chdir( const char *lpcszPath ); // change the current working directory to the specified path


/** >File Management
		Get the current working drive.
	Parameter:
		None.
	Return:
		returns the current (default) drive (1 = A, 2 = B, and so on).
	Example:
		void	run_getdrive()
		{
			int		nCurrentDrive = _getdrive();
			printf("Current drive is %c\n", (char)(nCurrentDrive + 'A' - 1));
		}
*/
int		_getdrive( ); // get the current working drive

/** >File Management
		Changes the current working drive.
	Parameter:
		drive: Number of new working drive, A drive is 1, B drive is 2, C drive is 3, and so on.
	Returns:
		returns a value of 0 if the working drive is successfully changed. A return value of -1 indicates an error.
	Example:
		void	run_chdrive()
		{
			int		nCurrentDrive = _getdrive();
			printf("Current drive is %c\n", (char)(nCurrentDrive + 'A' - 1));
			
			if (0 == _chdrive(4))
			{
				nCurrentDrive = _getdrive();
				printf("Current drive is %c\n", (char)(nCurrentDrive + 'A' - 1));
			}
			else
				out_str("Failed to change current drive!");
		}
*/
int		_chdrive( int drive ); // change the current working drive



// Origin internal functions
// all function prototypes from here on must be implemented from within the Origin OUTL DLL
#pragma dll(@OUTL)
/**	>File Management
		Comare the contents of two files. This function does a byte by byte binary compare
	Parameters:
		lpcszFilename1 = fullpath filename of the first file
		lpcszFilename2 = fullpath filename of the second file
	Returns:
		0 if two files match in contents
		1 if two files are different
		-1 if error
	Example:
		void	run_file_compare()
		{
			string	strPath = GetAppPath();
			string strLineOTP = strPath + "Line.otp";
			string strOriginOTP = strPath + "Origin.otp";
			if(file_compare(strLineOTP, strOriginOTP) == 0)
				out_str("Line graph template is using default template");
			else
				out_str("Line graph template is different from default Origin template");
		}
*/
int file_compare(LPCSTR lpcszFilename1, LPCSTR lpcszFilename2);

// Origin internal functions
// all function prototypes from here on must be implemented from within the Origin OK DLL

/** >Character/String Manipulation
	Replace all occurances of certain characters in given buffer with a new character
	Parameters:
		lpBuff = input and output buffer to replace characters with
		nSize = size in bytes of lpBuff
		chOldList = an array of bytes that we need to replace, zero is allowed
		nOldListSize = size of the chOldList array
		chNew = new character to replace any of the characters in chOldList
	Returns:
		number of replacement, or -1 if error
	Example:
		char szTemp[10] = "A\tB\r\nC";
		char szNonePrintable[] = "\t\r\n";
		memory_replace(szTemp, lstrlen(szTemp),szNonePrintable,lstrlen(szNonePrintable),'.');
		out_str(szTemp);
*/
int memory_replace(LPSTR lpBuff, int nSize, LPSTR chOldList, int nOldListSize, char chNew);

/** >Date Time
	Convert a SYSTEMTIME structure to a formatted string.
	Parameters:
		pSysTime = pointer to the source SYSTEMTIME structure
		lpstr = pointer to the buffer to receive the formatted string
		wFormat = a date format flag to determine the appearance of the formatted string. See LDF_* definitions in OC_Const.h
	Returns:
		If successful then TRUE else FALSE
	Example:
		SYSTEMTIME syst;
		syst.wYear = 2003;
		syst.wMonth = 1;
		syst.wDayOfWeek = 2;
		syst.wDay = 28;
		syst.wHour = 11;
		syst.wMinute = 17;
		syst.wSecond = 33;
		syst.wMilliseconds = 0;
		
		string str;
		LPSTR lpstr = str.GetBuffer(255);
		if( lpstr )
		{
			systemtime_to_date_str(&syst, lpstr, LDF_LONG);
			str.ReleaseBuffer();
		}
*/
BOOL systemtime_to_date_str(SYSTEMTIME *pSysTime, LPSTR lpstr, WORD wFormat=LDF_SHORT);

#if  _OC_VER > 0x0703
/** >Date Time
	Convert a SYSTEMTIME structure to a Julian date value.
	Parameters:
		lpdDate = pointer to the destination value
		lpSysTime = pointer to the source SYSTEMTIME structure
	Example:
		void	test_get_date_str()
		{
			SYSTEMTIME st;
			GetSystemTime(&st);              // gets current time
			double dDate;
			SystemTimeToJulianDate(&dDate, &st);
			out_str(get_date_str(dDate, LDF_LONG));
		}

⌨️ 快捷键说明

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