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

📄 mswin.h

📁 图像处理的压缩算法
💻 H
📖 第 1 页 / 共 4 页
字号:
		}		
*/
UINT WINAPI GetTickCount();// Retrieve number of milliseconds elapsed since the system was started

/** >System
		Retrieve current version number of the operating system.
	Parameters:
		None.
	Return:
		the version number. The low byte of the low word is the major OS version, the high byte
		of the low word is the minor OS version. The highest bit determines the platform: it is
		on for Windows 95, 98, and Me, it is off for Windows NT, 2000, XP.
	Example:
		// This example checks if the operating system is of "NT-type"
		// (which means Windows NT, 2000, XP).
		bool is_OS_NT_type()
		{
			DWORD	dwVersion = GetVersion();
			// Get major and minor version numbers of Windows
			WORD loword = LOWORD(dwVersion);
			int lowbyte = LOBYTE(loword);
			int hibyte =  HIBYTE(loword);
				
			printf("Window major version = %d and minor version = %d\n", lowbyte, hibyte);
			
			if(!(dwVersion & 0x80000000))                // Windows NT, 2000, XP
				return TRUE;
			else         // Windows 95, 98, ME
				return FALSE;
		}
*/
UINT WINAPI GetVersion();

/** >System
		It puts the application to a halt for the specified number of milliseconds.
	Parameters:
		dwMilliseconds - the number of milliseconds to sleep.
	Return:
		none
	Example:
		void	run_Sleep()
		{
			out_str("Before Sleep");
			Sleep(1000);	// sleep for one second
			out_str("After Sleep");
		}
*/
void WINAPI Sleep(DWORD dwMilliseconds);

////////////////////////////////////////////////////////
////// begin Global memory functions
////////////////////////////////////////////////////////
typedef HANDLE HGLOBAL;
#define GMEM_FIXED          0x0000
#define GMEM_MOVEABLE       0x0002
#define GMEM_NOCOMPACT      0x0010
#define GMEM_NODISCARD      0x0020
#define GMEM_ZEROINIT       0x0040
#define GMEM_MODIFY         0x0080
#define GMEM_DISCARDABLE    0x0100
#define GMEM_NOT_BANKED     0x1000
#define GMEM_SHARE          0x2000
#define GMEM_DDESHARE       0x2000
#define GMEM_NOTIFY         0x4000
#define GMEM_LOWER          GMEM_NOT_BANKED
#define GMEM_VALID_FLAGS    0x7F72
#define GMEM_INVALID_HANDLE 0x8000

#define GHND                (GMEM_MOVEABLE | GMEM_ZEROINIT)

/** >Memory Management
	Parameters:
		uFlags = Memory allocation attributes. If zero is specified, the default is GMEM_FIXED. 
		This parameter can be one or more of the following values, except for the incompatible combinations that are specifically noted. 
		dwBytes = Number of bytes to allocate. 	If this parameter is zero and the uFlags parameter specifies GMEM_MOVEABLE, 
		the function returns a handle to a memory object that is marked as discarded. 
		
	Return:
		If the function succeeds, the return value is a handle to the newly allocated memory object.
		If the function fails, the return value is NULL.
		
	Example:
		void Test_Global_Memory()
		{	
			string 		strTemp = "Test GlobalAlloc!";
			int nMemSize = strTemp.GetLength() + 1;    
				    
			HANDLE hData = GlobalAlloc(GHND,nMemSize);
			if( !hData )
			{
				out_str("failed!");
				return;
			}
					
			DWORD	dSize = GlobalSize(hData);
			if( dSize != nMemSize )
			{
				out_str("failed!");
			}
			
			LPSTR lpData = (LPSTR)GlobalLock(hData);	
			lstrcpyn(lpData, strTemp, nMemSize);
			GlobalUnlock(hData);
			
			if( NULL == GlobalReAlloc(hData, nMemSize*2, GMEM_MOVEABLE) )
			{
				out_str("failed");
				return;
			}
			else
			{
				if( nMemSize*2 != GlobalSize(hData))
				{
					out_str("failed!");
				}
			}	
					
			if( NULL != GlobalFree(hData) )
			{
				out_str("failed!");
			}
		}
*/
HGLOBAL WINAPI GlobalAlloc(UINT uFlags, DWORD dwBytes);

/** >Memory Management
	Parameters:
		hMem = Handle to the global memory object to be reallocated.
		dwBytes = New size of the memory block, in bytes. If uFlags specifies GMEM_MODIFY, this parameter is ignored.
		uFlags = Reallocation options.
	Return:
		If the function succeeds, the return value is a handle to the reallocated memory object.
		If the function fails, the return value is NULL.
	SeeAlso:
		GlobalAlloc
*/
HGLOBAL WINAPI GlobalReAlloc(HGLOBAL hMem, DWORD dwBytes, UINT uFlags);

/** >Memory Management
	Parameters:
		hMem = Handle to the global memory object.
	Return:
		If the function succeeds, the return value is NULL.
		If the function fails, the return value is equal to a handle to the global memory object.
	SeeAlso:
		GlobalAlloc
*/
HGLOBAL WINAPI GlobalFree(HGLOBAL hMem);

/** >Memory Management
	Parameters:
		hMem = Handle to the global memory object.
	Return:
		If the function succeeds, the return value is the size of the specified global memory object, in bytes.
	SeeAlso:
		GlobalAlloc		
*/
DWORD WINAPI GlobalSize(HGLOBAL hMem);

/** >Memory Management
	Parameters:
		hMem = Handle to the global memory object.
	Return:
		If the function succeeds, the return value is a pointer to the first byte of the memory block.
		If the function fails, the return value is NULL.
	SeeAlso:
		GlobalAlloc
*/
LPVOID WINAPI GlobalLock(HGLOBAL hMem);

/** >Memory Management
	Parameters:
		hMem = Handle to the global memory object.
	Return values:
		If the memory object is still locked after decrementing the lock count, the return value is a nonzero value.
		If the function fails, the return value is zero.
	SeeAlso:
		GlobalAlloc
*/
BOOL WINAPI GlobalUnlock(HGLOBAL hMem);

////////////////////////////////////////////////////////
////// end Global memory functions
////////////////////////////////////////////////////////

#define SetEnvironmentVariable  SetEnvironmentVariableA
#define GetEnvironmentVariable  GetEnvironmentVariableA

/** >System
		This function retrieves the value of the specified variable from the environment block 
		of the calling process. The value is in the form of a null-terminated string of characters.
	Parameters:
		lpcszName = environment variable name
  		lpBuffer = buffer for variable value
  		nSize =    size of buffer
.
	Return:
		If the function succeeds, the return value is the number of characters stored into the buffer 
		pointed to by lpBuffer, not including the terminating null character. 
		If the specified environment variable name was not found in the environment block for the current process, 
		the return value is zero. 

		If the buffer pointed to by lpBuffer is not large enough, the return value is the buffer size, in characters, 
		required to hold the value string and its terminating null character. 

	Example:
	// usage:
	// show_environment_str path;
	// show_environment_str temp;
	void show_environment_str(string strName)
	{
		char szTemp[MAXFULLPATH];
		
		int	nResult = GetEnvironmentVariable(strName, szTemp, MAXFULLPATH);
		
		if(nResult > 0)
		{
			if(nResult == lstrlen(szTemp))
				out_str(szTemp);
			else
				printf("The %s environment variable is too big (%d bytes)\n",strName,nResult);
		}
		else
			out_str("Error: Environment variable not found.");
	}
*/
DWORD WINAPI GetEnvironmentVariable(LPCSTR lpcszName, LPSTR lpBuffer, DWORD nSize);

/** >System
		This function sets the value of an environment variable for the current process. 
	Parameters:
		lpcszName = environment variable name
  		lpcszValue = new value for environment variable
.
	Return:
		TRUE for success
		
	Example:
	// usage:
	// set_environment_str test "A new string for testing";
	// show_environment_str test;
	void set_environment_str(string strName, string strValue)
	{
		if(SetEnvironmentVariable(strName, strValue))
			return;
		out_str("error calling SetEnvironmentVariable");
	}
*/
BOOL WINAPI SetEnvironmentVariable(LPCSTR lpcszName, LPCSTR lpcszValue);

/** >File Management
		This function closes an open object handle. 
	Parameters:
		hObject = [in/out] Handle to an open object. 
	Return:
		TRUE for success
	SeeAlso:
		CreateFile
*/
BOOL WINAPI CloseHandle(HANDLE hObject);

//
//  The following are masks for the predefined standard access types
//
#define DELETE                           (0x00010000L)
#define READ_CONTROL                     (0x00020000L)
#define WRITE_DAC                        (0x00040000L)
#define WRITE_OWNER                      (0x00080000L)
#define SYNCHRONIZE                      (0x00100000L)

#define STANDARD_RIGHTS_REQUIRED         (0x000F0000L)
#define STANDARD_RIGHTS_READ             (READ_CONTROL)
#define STANDARD_RIGHTS_WRITE            (READ_CONTROL)
#define STANDARD_RIGHTS_EXECUTE          (READ_CONTROL)

#define STANDARD_RIGHTS_ALL              (0x001F0000L)
#define SPECIFIC_RIGHTS_ALL              (0x0000FFFFL)
//
// AccessSystemAcl access type
//
#define ACCESS_SYSTEM_SECURITY           (0x01000000L)
//
// MaximumAllowed access type
//
#define MAXIMUM_ALLOWED                  (0x02000000L)
//
//  These are the generic rights.
//
#define GENERIC_READ                     (0x80000000L)
#define GENERIC_WRITE                    (0x40000000L)
#define GENERIC_EXECUTE                  (0x20000000L)
#define GENERIC_ALL                      (0x10000000L)

#define CREATE_NEW          1
#define CREATE_ALWAYS       2
#define OPEN_EXISTING       3
#define OPEN_ALWAYS         4
#define TRUNCATE_EXISTING   5

#define CreateFile  CreateFileA
typedef struct _SECURITY_ATTRIBUTES {
    DWORD nLength;
    LPVOID lpSecurityDescriptor;
    BOOL bInheritHandle;
} SECURITY_ATTRIBUTES;

/** >File Management
		This function creates or opens an objects and returns a handle that can be used to access the object. 
	Parameters:
		lpFileName = [in] A fullpath file name
		dwDesiredAccess = [in] Specifies the type of access to the object. This parameter can be 0, GENERIC_READ, GENERIC_WRITE
		dwShareMode = [in] Specifies how the object can be shared. If dwShareMode is 0, and CreateFile succeeds, the object cannot be shared and cannot be opened again until the handle is closed.
		lpSecurityAttributes = [in] Pointer to a SECURITY_ATTRIBUTES structure that determines whether the returned handle can be inherited by child processes. Use NULL if no need for the handle to be inherited. 
		dwCreationDisposition = [in] Specifies which action to take on files that exist, and which action to take when files do not exist. Can be CREATE_NEW, CREATE_ALWAYS, OPEN_EXISTING, OPEN_ALWAYS, TRUNCATE_EXISTING
		dwFlagsAndAttributes = [in] Specifies the file attributes and flags for the file. 
		hTemplateFile = [in] Specifies a handle with GENERIC_READ access to a template file. The template file supplies file attributes and extended attributes for the file being created. 
	Return:
		If the function succeeds, the return value is an open handle to the specified file. 
		If the function fails, the return value is INVALID_HANDLE_VALUE. 
	Example:
		//opens an existing file for reading.
		bool test_read_file(LPCSTR lpcszFilename)
		{
			HANDLE hFile; 
			hFile = CreateFile(lpcszFilename, 
			                GENERIC_READ,              // open for reading 
			                FILE_SHARE_READ,           // share for reading 
			                NULL,                      // no security 
			                OPEN_EXISTING,             // existing file only 
			                FILE_ATTRIBUTE_NORMAL,     // normal file 
			                NULL);                     // no attr. template 
			if (hFile == INVALID_HANDLE_VALUE) 
			{ 
				out_str("Could not open file.");   // process error
				return false;
			} 
	        // codes to read the file
	        CloseHandle(hFile);// must close file after reading
	        return true;
		}
		
	SeeAlso:
		CloseHandle
*/
HANDLE WINAPI CreateFile(LPCSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, SECURITY_ATTRIBUTES* lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile);

typedef struct _FILETIME {
    DWORD dwLowDateTime;
    DWORD dwHighDateTime;
} FILETIME;

#define INVALID_HANDLE_VALUE (HANDLE)-1

#define FindFirstFile  FindFirstFileA
#define FindNextFile  FindNextFileA
typedef struct _WIN32_FIND_DATAA {
    DWORD dwFileAttributes;
    FILETIME ftCreationTime;
    FILETIME ftLastAccessTime;
    FILETIME ftLastWriteTime;
    DWORD nFileSizeHigh;
    DWORD nFileSizeLow;
    DWORD dwReserved0;
    DWORD dwReserved1;
    char   cFileName[ MAX_PATH ];
    char   cAlternateFileName[ 14 ];
} WIN32_FIND_DATAA;

/** >File Management

⌨️ 快捷键说明

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