2010年1月7日 星期四

CuSize - Similar to the Windows SIZE structure

// Similar to the Windows SIZE structure

// CuSize.h

class CuSize : public tagSIZE
{
public:

// Constructors
    // construct an uninitialized size
    CuSize() throw();
    // create from two integers
    CuSize(int initCX, int initCY) throw();
    // create from another size
    CuSize(SIZE initSize) throw();
    // create from a point
    CuSize(POINT initPt) throw();
    // create from a DWORD: cx = LOWORD(dw) cy = HIWORD(dw)
    CuSize(DWORD dwSize) throw();

// Operations
    BOOL operator==(SIZE size) const throw();
    BOOL operator!=(SIZE size) const throw();
    void operator+=(SIZE size) throw();
    void operator-=(SIZE size) throw();
    void SetSize(int CX, int CY) throw();

// Operators returning CuSize values
    CuSize operator+(SIZE size) const throw();
    CuSize operator-(SIZE size) const throw();
    CuSize operator-() const throw();

// Operators returning CuPoint values
    CuPoint operator+(POINT point) const throw();
    CuPoint operator-(POINT point) const throw();

// Operators returning CuRect values
    CuRect operator+(const RECT* lpRect) const throw();
    CuRect operator-(const RECT* lpRect) const throw();
};

inline CuSize::CuSize()
    { /* random filled */ }
inline CuSize::CuSize(int initCX, int initCY)
    { cx = initCX; cy = initCY; }
inline CuSize::CuSize(SIZE initSize)
    { *(SIZE*)this = initSize; }
inline CuSize::CuSize(POINT initPt)
    { *(POINT*)this = initPt; }
inline CuSize::CuSize(DWORD dwSize)
    {
        cx = (short)LOWORD(dwSize);
        cy = (short)HIWORD(dwSize);
    }
inline BOOL CuSize::operator==(SIZE size) const
    { return (cx == size.cx && cy == size.cy); }
inline BOOL CuSize::operator!=(SIZE size) const
    { return (cx != size.cx || cy != size.cy); }
inline void CuSize::operator+=(SIZE size)
    { cx += size.cx; cy += size.cy; }
inline void CuSize::operator-=(SIZE size)
    { cx -= size.cx; cy -= size.cy; }
inline void CuSize::SetSize(int CX, int CY)
    { cx = CX; cy = CY; }   
inline CuSize CuSize::operator+(SIZE size) const
    { return CuSize(cx + size.cx, cy + size.cy); }
inline CuSize CuSize::operator-(SIZE size) const
    { return CuSize(cx - size.cx, cy - size.cy); }
inline CuSize CuSize::operator-() const
    { return CuSize(-cx, -cy); }
inline CuPoint CuSize::operator+(POINT point) const
    { return CuPoint(cx + point.x, cy + point.y); }
inline CuPoint CuSize::operator-(POINT point) const
    { return CuPoint(cx - point.x, cy - point.y); }
inline CuRect CuSize::operator+(const RECT* lpRect) const
    { return CuRect(lpRect) + *this; }
inline CuRect CuSize::operator-(const RECT* lpRect) const
    { return CuRect(lpRect) - *this; }

1 則留言:

  1. CuSize 從MFC來的, 我自己本身很少使用, 這個是為了CuRect, CuPoint 會用到所以順便弄出來.

    回覆刪除