user.h File Reference


Detailed Description

Useful Macros and Functions, by Peter O., Public domain.

This file is a utility module containing useful macros and functions. It's generally used to replace Windows headers, though it doesn't include windows.h, but rather a very slim subset containing only basic simple and compound data types. It also contains a structure for implementing abstract data streams.

Definition in file user.h.

#include "mwindows.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdarg.h>
#include <math.h>

Go to the source code of this file.

Data Structures

struct  XFORMDBL
struct  RTL_BITMAP
 32-bit bit vector structure. More...
struct  IOSTRUCT
 Structure for an abstract data stream, which can be a file, a memory block, a network resource, etc. More...

Defines

#define floor   floor
#define sqrt   sqrt
#define XFORM   XFORMDBL
#define LPXFORM   XFORMDBL *
#define ANSI_VAR_FONT   DEFAULT_GUI_FONT
#define GetAValue(c)   ((BYTE)((c)>>24))
 Returns the alpha component of a 32-bit color.
#define AddPtr(t, p, b)   ((t)( ((LONG_PTR)(p))+((LONG_PTR)(b)) ))
 Adds to the pointer _p_ by _b_ bytes and casts it to _t_.
#define DiffPtr(t, p, b)   ((t)( ((LONG_PTR)(p))-((LONG_PTR)(b)) ))
 Subtracts the pointer _p_ by _b_ bytes and casts it to _t_.
#define RectWidth(rc)   ((rc)->right-(rc)->left)
 Returns the width of a rectangle.
#define RectHeight(rc)   ((rc)->bottom-(rc)->top)
 Returns the height of a rectangle.
#define SetRect(rc, x, y, x1, y1)
#define IsRectEmpty(rc)   ((rc)->left>=(rc)->right||(rc)->top>=(rc)->bottom)
#define SetRectEmpty(rc)   (rc)->left=(rc)->right=(rc)->top=(rc)->bottom=0
#define OffsetRect(rc, x, y)
#define InflateRect(rc, x, y)
#define SetFrame(rc, x, y, cx, cy)
#define PointInRect(rc, x, y)
#define TransformSetIdentity(m)
#define TOBOOL(x)   ((BOOL)((!!(x))?1:0))
 Returns 1 if _x_ is nonzero, or 0 otherwise.
#define DIMOF(x)   (sizeof(x)/sizeof(x[0]))
 Returns the size of an array.
#define MOD(i, n)   ( (i) % (n) >= 0 ? (i) % (n) : (i) % (n) + (n) )
 Returns the modulus of two numbers.
#define MS_NINT(x)   ((x) >= 0.0 ? ((long) ((x)+.5)) : ((long) ((x)-.5)))
 Rounds a floating point number to the nearest integer.
#define MS_PI   3.14159265358979323846
 Pi.
#define MS_3PI2   4.71238898038468985769
 Pi times 1.5.
#define DEGTORAD   0.017453292519943295769236907684886
 Multiply by this value to convert degrees to radians.
#define RADTODEG   57.295779513082320876798154814105
 Multiply by this value to convert radians to degrees.
#define M_PITIMESTWO   6.283185307179586476925286766559
 Pi times 2.
#define M_HALFPI   1.5707963267948966192313216916398
 Pi divided by 2.
#define SQRT_2   1.4142135623730950488016887242097
 Square root of 2.
#define RADTOGRAD   63.661977236758134307553505349006
 Multiply by this value to convert radians to grad.
#define GRADTORAD   0.015707963267948966192313216916398
 Multiply by this value to convert grad to radians.
#define ITEXTCONST(x)   x
#define ITEXT(x)   x
#define DebugOut
#define DebugOutF
#define ASSERT(x)
#define __xmalloc(s)   calloc(1,s)
#define __malloc(s)   malloc(s)
#define __calloc(e, s)   calloc(e,s)
#define __realloc(p, s)   realloc(p,s)
#define __free(p)   free(s)
#define DebugMallocStatus()
#define xmalloc(s)   __xmalloc(s)
 Like malloc, but the allocated memory is initialized to zero.
#define RectMove(rc, xx, yy)
 Changes the top left corner of a rectangle to _xx_ and _yy_.
#define SWAPWORD(a)
 Swaps the byte order of a 16-bit integer.
#define SWAPDWORD(a)
 Swaps the byte order of a 32-bit integer.
#define FOURCC   DWORD
#define MAKEFOURCC(a, b, c, d)
#define RGBA(a, b, c, d)
#define max(a, b)   ( ((a)>(b))?(a):(b) )
#define min(a, b)   ( ((a)<(b))?(a):(b) )
#define abs(a)   ( ((a)<0)?-(a):(a) )
#define BOUND(a, l, h)
#define HISHORT(x)   ((INT)(SHORT)HIWORD(x))
#define LOSHORT(x)   ((INT)(SHORT)LOWORD(x))
#define MASK(Count, Shift)   ((Count) == 32 ? 0xFFFFFFFF : ~(0xFFFFFFFF << (Count)) << (Shift))
 Returns a bit mask with _Count_ bits and shifted left _Shift_ times.
#define SETBIT(DwordBuf, BitNumber)   ((DwordBuf)[(BitNumber)>>5]|=(1<<((BitNumber)&0x1F)))
 Sets the bit numbered _BitNumber_ in a 32-bit bit vector (DwordBuf).
#define CLEARBIT(DwordBuf, BitNumber)   ((DwordBuf)[(BitNumber)>>5]&=~(1<<((BitNumber)&0x1F)))
 Clears the bit numbered _BitNumber_ in a 32-bit bit vector (DwordBuf).
#define TESTBIT(DwordBuf, BitNumber)   (((DwordBuf)[(BitNumber)>>5]&(1<<((BitNumber)&0x1F)))!=0)
 Returns TRUE if the bit numbered _BitNumber_ in a 32-bit bit vector (DwordBuf) is set.
#define INITBITS(bm, size)   do{(bm)->SizeOfBitmap=size;(bm)->Buffer=xmalloc( ((bm)->SizeOfBitmap+7)>>3 );}while(0)
 Initializes the 32-bit bit vector (RTL_BITMAP) with the specified _size_ in bits.
#define CLEARBITS(bm)   ZeroMemory((bm)->Buffer,((bm)->SizeOfBitmap+7)>>3)
 Clears all bits in the 32-bit bit vector (RTL_BITMAP).
#define SETBITS(bm)   memset((bm)->Buffer,0xFF,((bm)->SizeOfBitmap+7)>>3)
 Sets all bits in the 32-bit bit vector (RTL_BITMAP).
#define FILE_READ   1
 The file is opened for reading; the file must exist.
#define FILE_WRITE   0
 The file is opened for writing; if the file exists, its contents are erased; if not, it is created.
#define FILE_APPEND   2
 The file is opened for writing; if the file exists, its contents are preserved and the file pointer is moved at the end, but the file can be written anywhere by setting the file pointer; if the file doesn't exist, it is created.
#define FILE_READWRITE   3
 The file is opened for reading and writing; the file must exist.

Typedefs

typedef struct RTL_BITMAPPRTL_BITMAP
typedef DWORD(* IOPROC )(LPVOID h, LPVOID buffer, DWORD size)
 Procedure for reading or writing from a data stream.
typedef IOPROC WRITEPROC
typedef IOPROC READPROC
typedef LPVOID(* IOOPENPROC )(LPVOID file, int mode)
 Procedure for opening a data stream.
typedef LONG(* IOSEEKPROC )(LPVOID h, LONG seek, int whence)
 Procedure for seeking within a data stream.
typedef BOOL(* IOCLOSEPROC )(LPVOID h)
 Procedure for closing a data stream.
typedef BOOL(* IOFLUSHPROC )(LPVOID h)
 Procedure for flushing a data stream.
typedef DWORD(* IOGETSIZEPROC )(LPVOID h)
 Procedure for getting the size of a data stream.
typedef BOOL(* IOVALIDPROC )(LPVOID h)
 Procedure for determining whether a data stream handle is valid.


Define Documentation

#define __calloc e,
 )     calloc(e,s)
 

Definition at line 178 of file user.h.

#define __free  )     free(s)
 

Definition at line 182 of file user.h.

#define __malloc  )     malloc(s)
 

Definition at line 176 of file user.h.

#define __realloc p,
 )     realloc(p,s)
 

Definition at line 180 of file user.h.

#define __xmalloc  )     calloc(1,s)
 

Definition at line 174 of file user.h.

#define abs  )     ( ((a)<0)?-(a):(a) )
 

Definition at line 261 of file user.h.

#define AddPtr t,
p,
 )     ((t)( ((LONG_PTR)(p))+((LONG_PTR)(b)) ))
 

Adds to the pointer _p_ by _b_ bytes and casts it to _t_.

Definition at line 49 of file user.h.

#define ANSI_VAR_FONT   DEFAULT_GUI_FONT
 

Definition at line 43 of file user.h.

#define ASSERT  ) 
 

Definition at line 158 of file user.h.

#define BOUND a,
l,
 ) 
 

Value:

( ((a)<(l)) ?(l):\
                     ( ((a)>(h)) ?(h):(a) )\
                     )

Definition at line 264 of file user.h.

#define CLEARBIT DwordBuf,
BitNumber   )     ((DwordBuf)[(BitNumber)>>5]&=~(1<<((BitNumber)&0x1F)))
 

Clears the bit numbered _BitNumber_ in a 32-bit bit vector (DwordBuf).

Definition at line 292 of file user.h.

#define CLEARBITS bm   )     ZeroMemory((bm)->Buffer,((bm)->SizeOfBitmap+7)>>3)
 

Clears all bits in the 32-bit bit vector (RTL_BITMAP).

Definition at line 307 of file user.h.

 
#define DebugMallocStatus  ) 
 

Definition at line 209 of file user.h.

#define DebugOut
 

Definition at line 155 of file user.h.

#define DebugOutF
 

Definition at line 156 of file user.h.

#define DEGTORAD   0.017453292519943295769236907684886
 

Multiply by this value to convert degrees to radians.

Definition at line 106 of file user.h.

#define DiffPtr t,
p,
 )     ((t)( ((LONG_PTR)(p))-((LONG_PTR)(b)) ))
 

Subtracts the pointer _p_ by _b_ bytes and casts it to _t_.

Definition at line 52 of file user.h.

#define DIMOF  )     (sizeof(x)/sizeof(x[0]))
 

Returns the size of an array.

Definition at line 94 of file user.h.

#define FILE_APPEND   2
 

The file is opened for writing; if the file exists, its contents are preserved and the file pointer is moved at the end, but the file can be written anywhere by setting the file pointer; if the file doesn't exist, it is created.

Definition at line 394 of file user.h.

#define FILE_READ   1
 

The file is opened for reading; the file must exist.

Definition at line 388 of file user.h.

#define FILE_READWRITE   3
 

The file is opened for reading and writing; the file must exist.

Definition at line 396 of file user.h.

#define FILE_WRITE   0
 

The file is opened for writing; if the file exists, its contents are erased; if not, it is created.

Definition at line 390 of file user.h.

#define floor   floor
 

Definition at line 23 of file user.h.

#define FOURCC   DWORD
 

Definition at line 244 of file user.h.

#define GetAValue  )     ((BYTE)((c)>>24))
 

Returns the alpha component of a 32-bit color.

Definition at line 46 of file user.h.

#define GRADTORAD   0.015707963267948966192313216916398
 

Multiply by this value to convert grad to radians.

Definition at line 118 of file user.h.

#define HISHORT  )     ((INT)(SHORT)HIWORD(x))
 

Definition at line 268 of file user.h.

#define InflateRect rc,
x,
 ) 
 

Value:

do{(rc)->left-=x;(rc)->right+=x;\
     (rc)->top-=y;(rc)->bottom+=y;}while(0)

Definition at line 73 of file user.h.

#define INITBITS bm,
size   )     do{(bm)->SizeOfBitmap=size;(bm)->Buffer=xmalloc( ((bm)->SizeOfBitmap+7)>>3 );}while(0)
 

Initializes the 32-bit bit vector (RTL_BITMAP) with the specified _size_ in bits.

Definition at line 302 of file user.h.

#define IsRectEmpty rc   )     ((rc)->left>=(rc)->right||(rc)->top>=(rc)->bottom)
 

Definition at line 63 of file user.h.

#define ITEXT  )     x
 

Definition at line 122 of file user.h.

#define ITEXTCONST  )     x
 

Definition at line 121 of file user.h.

#define LOSHORT  )     ((INT)(SHORT)LOWORD(x))
 

Definition at line 269 of file user.h.

#define LPXFORM   XFORMDBL *
 

Definition at line 40 of file user.h.

#define M_HALFPI   1.5707963267948966192313216916398
 

Pi divided by 2.

Definition at line 112 of file user.h.

#define M_PITIMESTWO   6.283185307179586476925286766559
 

Pi times 2.

Definition at line 110 of file user.h.

#define MAKEFOURCC a,
b,
c,
 ) 
 

Value:

((DWORD) (((DWORD)(BYTE)(a))   )\
          |(((DWORD)(BYTE)(b))<<8)\
          |(((DWORD)(BYTE)(c))<<16)\
          |(((DWORD)(BYTE)(d))<<24))

Definition at line 246 of file user.h.

#define MASK Count,
Shift   )     ((Count) == 32 ? 0xFFFFFFFF : ~(0xFFFFFFFF << (Count)) << (Shift))
 

Returns a bit mask with _Count_ bits and shifted left _Shift_ times.

Definition at line 282 of file user.h.

#define max a,
 )     ( ((a)>(b))?(a):(b) )
 

Definition at line 258 of file user.h.

#define min a,
 )     ( ((a)<(b))?(a):(b) )
 

Definition at line 259 of file user.h.

#define MOD i,
 )     ( (i) % (n) >= 0 ? (i) % (n) : (i) % (n) + (n) )
 

Returns the modulus of two numbers.

Definition at line 96 of file user.h.

#define MS_3PI2   4.71238898038468985769
 

Pi times 1.5.

Definition at line 104 of file user.h.

#define MS_NINT  )     ((x) >= 0.0 ? ((long) ((x)+.5)) : ((long) ((x)-.5)))
 

Rounds a floating point number to the nearest integer.

Definition at line 100 of file user.h.

#define MS_PI   3.14159265358979323846
 

Pi.

Definition at line 102 of file user.h.

#define OffsetRect rc,
x,
 ) 
 

Value:

do{(rc)->left+=x;(rc)->right+=x;\
     (rc)->top+=y;(rc)->bottom+=y;}while(0)

Definition at line 69 of file user.h.

#define PointInRect rc,
x,
 ) 
 

Value:

((x)>=(rc)->left       \
    &&(y)>=(rc)->top        \
    &&(x)< (rc)->right      \
    &&(y)< (rc)->bottom)

Definition at line 81 of file user.h.

#define RADTODEG   57.295779513082320876798154814105
 

Multiply by this value to convert radians to degrees.

Definition at line 108 of file user.h.

#define RADTOGRAD   63.661977236758134307553505349006
 

Multiply by this value to convert radians to grad.

Definition at line 116 of file user.h.

#define RectHeight rc   )     ((rc)->bottom-(rc)->top)
 

Returns the height of a rectangle.

Definition at line 57 of file user.h.

#define RectMove rc,
xx,
yy   ) 
 

Value:

do{(rc)->right=(xx)+RectWidth(rc);\
    (rc)->bottom=(yy)+RectHeight(rc);\
    (rc)->left=xx;(rc)->top=yy;}while(0)
Changes the top left corner of a rectangle to _xx_ and _yy_.

Definition at line 227 of file user.h.

#define RectWidth rc   )     ((rc)->right-(rc)->left)
 

Returns the width of a rectangle.

Definition at line 55 of file user.h.

#define RGBA a,
b,
c,
 ) 
 

Value:

((DWORD) (((DWORD)(BYTE)(a))   )\
          |(((DWORD)(BYTE)(b))<<8)\
          |(((DWORD)(BYTE)(c))<<16)\
          |(((DWORD)(BYTE)(d))<<24))

Definition at line 252 of file user.h.

#define SETBIT DwordBuf,
BitNumber   )     ((DwordBuf)[(BitNumber)>>5]|=(1<<((BitNumber)&0x1F)))
 

Sets the bit numbered _BitNumber_ in a 32-bit bit vector (DwordBuf).

Definition at line 287 of file user.h.

#define SETBITS bm   )     memset((bm)->Buffer,0xFF,((bm)->SizeOfBitmap+7)>>3)
 

Sets all bits in the 32-bit bit vector (RTL_BITMAP).

Definition at line 313 of file user.h.

#define SetFrame rc,
x,
y,
cx,
cy   ) 
 

Value:

do{(rc)->right=((rc)->left=(x))+(cx);\
    (rc)->bottom=((rc)->top=(y))+(cy);} while(0)

Definition at line 77 of file user.h.

#define SetRect rc,
x,
y,
x1,
y1   ) 
 

Value:

do{(rc)->left=x;(rc)->right=x1;\
     (rc)->top=y;(rc)->bottom=y1;}while(0)

Definition at line 59 of file user.h.

#define SetRectEmpty rc   )     (rc)->left=(rc)->right=(rc)->top=(rc)->bottom=0
 

Definition at line 66 of file user.h.

#define sqrt   sqrt
 

Definition at line 24 of file user.h.

#define SQRT_2   1.4142135623730950488016887242097
 

Square root of 2.

Definition at line 114 of file user.h.

#define SWAPDWORD  ) 
 

Value:

((DWORD) ((((a)>>24)&0x000000FF))\
          |((((a)>>8) &0x0000FF00))\
          |((((a)<<8) &0x00FF0000))\
          |((((a)<<24)&0xFF000000)))
Swaps the byte order of a 32-bit integer.

Definition at line 238 of file user.h.

#define SWAPWORD  ) 
 

Value:

((WORD) ((((a)>>8)&0x00FF))\
          |((((a)<<8)&0xFF00)))
Swaps the byte order of a 16-bit integer.

Definition at line 233 of file user.h.

#define TESTBIT DwordBuf,
BitNumber   )     (((DwordBuf)[(BitNumber)>>5]&(1<<((BitNumber)&0x1F)))!=0)
 

Returns TRUE if the bit numbered _BitNumber_ in a 32-bit bit vector (DwordBuf) is set.

Definition at line 297 of file user.h.

#define TOBOOL  )     ((BOOL)((!!(x))?1:0))
 

Returns 1 if _x_ is nonzero, or 0 otherwise.

Definition at line 92 of file user.h.

#define TransformSetIdentity  ) 
 

Value:

do{(m)->eM11=(m)->eM22=1.0;\
      (m)->eM12=(m)->eM21=(m)->eDx=(m)->eDy=0.0;}while(0)

Definition at line 88 of file user.h.

#define XFORM   XFORMDBL
 

Definition at line 38 of file user.h.

#define xmalloc  )     __xmalloc(s)
 

Like malloc, but the allocated memory is initialized to zero.

Definition at line 211 of file user.h.


Typedef Documentation

typedef BOOL(* IOCLOSEPROC)(LPVOID h)
 

Procedure for closing a data stream.

Parameters:
h Handle to the data stream.
Returns:
Whether the close succeeded.

Definition at line 351 of file user.h.

typedef BOOL(* IOFLUSHPROC)(LPVOID h)
 

Procedure for flushing a data stream.

Parameters:
h Handle to the data stream.
Returns:
Whether the flush succeeded.

Definition at line 357 of file user.h.

typedef DWORD(* IOGETSIZEPROC)(LPVOID h)
 

Procedure for getting the size of a data stream.

Parameters:
h Handle to the data stream.
Returns:
Size of the data stream.

Definition at line 363 of file user.h.

typedef LPVOID(* IOOPENPROC)(LPVOID file, int mode)
 

Procedure for opening a data stream.

Parameters:
file A filename.
mode File opening mode.
Returns:
A handle to the data stream. Use IsValid from the data stream's IOSTRUCT to determine whether the handle is valid and the call succeeded.

Definition at line 336 of file user.h.

typedef DWORD(* IOPROC)(LPVOID h, LPVOID buffer, DWORD size)
 

Procedure for reading or writing from a data stream.

After reading or writing data, the file pointer is advanced by the number of bytes read or written.

Parameters:
h Handle to the data stream.
buffer Data to read or write from the data stream.
size Size of the data buffer.
Returns:
The number of bytes read from or written to the stream.

Definition at line 326 of file user.h.

typedef LONG(* IOSEEKPROC)(LPVOID h, LONG seek, int whence)
 

Procedure for seeking within a data stream.

Parameters:
h Handle to the data stream.
seek Offset to seek from the data stream
whence If FILE_BEGIN, the offset is relative to the beginning of the stream; if FILE_CURRENT, the stream's file pointer; and FILE_END, the end of the stream.
Returns:
The stream's new file pointer.

Definition at line 345 of file user.h.

typedef BOOL(* IOVALIDPROC)(LPVOID h)
 

Procedure for determining whether a data stream handle is valid.

It should be called before accessing the stream further. Invalid stream handles need not be closed.

Parameters:
h Handle to a data stream.
Returns:
TRUE if _h_ represents a valid data stream; FALSE otherwise

Definition at line 371 of file user.h.

typedef struct RTL_BITMAP * PRTL_BITMAP
 

typedef IOPROC READPROC
 

Definition at line 328 of file user.h.

typedef IOPROC WRITEPROC
 

Definition at line 327 of file user.h.


Generated on Thu Mar 27 01:46:58 2008 for Item Arrays by  doxygen 1.4.6-NO