📄 atlmisc.h
字号:
// Windows Template Library - WTL version 7.1
// Copyright (C) 1997-2003 Microsoft Corporation
// All rights reserved.
//
// This file is a part of the Windows Template Library.
// The code and information is provided "as-is" without
// warranty of any kind, either expressed or implied.
#ifndef __ATLMISC_H__
#define __ATLMISC_H__
#pragma once
#ifndef __cplusplus
#error ATL requires C++ compilation (use a .cpp suffix)
#endif
#ifndef __ATLAPP_H__
#error atlmisc.h requires atlapp.h to be included first
#endif
#ifdef _ATL_TMP_NO_CSTRING
#define _WTL_NO_CSTRING
#endif
#if defined(_WTL_USE_CSTRING) && defined(_WTL_NO_CSTRING)
#error Conflicting options - both _WTL_USE_CSTRING and _WTL_NO_CSTRING are defined
#endif //defined(_WTL_USE_CSTRING) && defined(_WTL_NO_CSTRING)
#if !defined(_WTL_USE_CSTRING) && !defined(_WTL_NO_CSTRING)
#define _WTL_USE_CSTRING
#endif //!defined(_WTL_USE_CSTRING) && !defined(_WTL_NO_CSTRING)
#ifndef _WTL_NO_CSTRING
#if defined(_ATL_USE_CSTRING_FLOAT) && defined(_ATL_MIN_CRT)
#error Cannot use CString floating point formatting with _ATL_MIN_CRT defined
#endif //defined(_ATL_USE_CSTRING_FLOAT) && defined(_ATL_MIN_CRT)
#ifndef _DEBUG
#include <stdio.h>
#endif //!_DEBUG
#endif //!_WTL_NO_CSTRING
///////////////////////////////////////////////////////////////////////////////
// Classes in this file:
//
// CSize
// CPoint
// CRect
// CString
//
// CRecentDocumentListBase<T, t_cchItemLen, t_nFirstID, t_nLastID>
// CRecentDocumentList
// CFindFile
//
// Global functions:
// AtlLoadAccelerators()
// AtlLoadMenu()
// AtlLoadBitmap()
// AtlLoadSysBitmap()
// AtlLoadCursor()
// AtlLoadSysCursor()
// AtlLoadIcon()
// AtlLoadSysIcon()
// AtlLoadBitmapImage()
// AtlLoadCursorImage()
// AtlLoadIconImage()
// AtlLoadSysBitmapImage()
// AtlLoadSysCursorImage()
// AtlLoadSysIconImage()
// AtlLoadString()
//
// AtlGetStockPen()
// AtlGetStockBrush()
// AtlGetStockFont()
// AtlGetStockPalette()
//
// AtlCompactPath()
namespace WTL
{
#ifndef _WTL_NO_WTYPES
// forward declarations
class CSize;
class CPoint;
class CRect;
///////////////////////////////////////////////////////////////////////////////
// CSize - Wrapper for Windows SIZE structure.
class CSize : public tagSIZE
{
public:
// Constructors
CSize();
CSize(int initCX, int initCY);
CSize(SIZE initSize);
CSize(POINT initPt);
CSize(DWORD dwSize);
// Operations
BOOL operator ==(SIZE size) const;
BOOL operator !=(SIZE size) const;
void operator +=(SIZE size);
void operator -=(SIZE size);
void SetSize(int CX, int CY);
// Operators returning CSize values
CSize operator +(SIZE size) const;
CSize operator -(SIZE size) const;
CSize operator -() const;
// Operators returning CPoint values
CPoint operator +(POINT point) const;
CPoint operator -(POINT point) const;
// Operators returning CRect values
CRect operator +(const RECT* lpRect) const;
CRect operator -(const RECT* lpRect) const;
};
///////////////////////////////////////////////////////////////////////////////
// CPoint - Wrapper for Windows POINT structure.
class CPoint : public tagPOINT
{
public:
// Constructors
CPoint();
CPoint(int initX, int initY);
CPoint(POINT initPt);
CPoint(SIZE initSize);
CPoint(DWORD dwPoint);
// Operations
void Offset(int xOffset, int yOffset);
void Offset(POINT point);
void Offset(SIZE size);
BOOL operator ==(POINT point) const;
BOOL operator !=(POINT point) const;
void operator +=(SIZE size);
void operator -=(SIZE size);
void operator +=(POINT point);
void operator -=(POINT point);
void SetPoint(int X, int Y);
// Operators returning CPoint values
CPoint operator +(SIZE size) const;
CPoint operator -(SIZE size) const;
CPoint operator -() const;
CPoint operator +(POINT point) const;
// Operators returning CSize values
CSize operator -(POINT point) const;
// Operators returning CRect values
CRect operator +(const RECT* lpRect) const;
CRect operator -(const RECT* lpRect) const;
};
///////////////////////////////////////////////////////////////////////////////
// CRect - Wrapper for Windows RECT structure.
class CRect : public tagRECT
{
public:
// Constructors
CRect();
CRect(int l, int t, int r, int b);
CRect(const RECT& srcRect);
CRect(LPCRECT lpSrcRect);
CRect(POINT point, SIZE size);
CRect(POINT topLeft, POINT bottomRight);
// Attributes (in addition to RECT members)
int Width() const;
int Height() const;
CSize Size() const;
CPoint& TopLeft();
CPoint& BottomRight();
const CPoint& TopLeft() const;
const CPoint& BottomRight() const;
CPoint CenterPoint() const;
// convert between CRect and LPRECT/LPCRECT (no need for &)
operator LPRECT();
operator LPCRECT() const;
BOOL IsRectEmpty() const;
BOOL IsRectNull() const;
BOOL PtInRect(POINT point) const;
// Operations
void SetRect(int x1, int y1, int x2, int y2);
void SetRect(POINT topLeft, POINT bottomRight);
void SetRectEmpty();
void CopyRect(LPCRECT lpSrcRect);
BOOL EqualRect(LPCRECT lpRect) const;
void InflateRect(int x, int y);
void InflateRect(SIZE size);
void InflateRect(LPCRECT lpRect);
void InflateRect(int l, int t, int r, int b);
void DeflateRect(int x, int y);
void DeflateRect(SIZE size);
void DeflateRect(LPCRECT lpRect);
void DeflateRect(int l, int t, int r, int b);
void OffsetRect(int x, int y);
void OffsetRect(SIZE size);
void OffsetRect(POINT point);
void NormalizeRect();
// absolute position of rectangle
void MoveToY(int y);
void MoveToX(int x);
void MoveToXY(int x, int y);
void MoveToXY(POINT point);
// operations that fill '*this' with result
BOOL IntersectRect(LPCRECT lpRect1, LPCRECT lpRect2);
BOOL UnionRect(LPCRECT lpRect1, LPCRECT lpRect2);
BOOL SubtractRect(LPCRECT lpRectSrc1, LPCRECT lpRectSrc2);
// Additional Operations
void operator =(const RECT& srcRect);
BOOL operator ==(const RECT& rect) const;
BOOL operator !=(const RECT& rect) const;
void operator +=(POINT point);
void operator +=(SIZE size);
void operator +=(LPCRECT lpRect);
void operator -=(POINT point);
void operator -=(SIZE size);
void operator -=(LPCRECT lpRect);
void operator &=(const RECT& rect);
void operator |=(const RECT& rect);
// Operators returning CRect values
CRect operator +(POINT point) const;
CRect operator -(POINT point) const;
CRect operator +(LPCRECT lpRect) const;
CRect operator +(SIZE size) const;
CRect operator -(SIZE size) const;
CRect operator -(LPCRECT lpRect) const;
CRect operator &(const RECT& rect2) const;
CRect operator |(const RECT& rect2) const;
CRect MulDiv(int nMultiplier, int nDivisor) const;
};
///////////////////////////////////////////////////////////////////////////////
// CSize, CPoint, CRect Implementation
// CSize
inline CSize::CSize()
{ /* random filled */ }
inline CSize::CSize(int initCX, int initCY)
{ cx = initCX; cy = initCY; }
inline CSize::CSize(SIZE initSize)
{ *(SIZE*)this = initSize; }
inline CSize::CSize(POINT initPt)
{ *(POINT*)this = initPt; }
inline CSize::CSize(DWORD dwSize)
{
cx = (short)LOWORD(dwSize);
cy = (short)HIWORD(dwSize);
}
inline BOOL CSize::operator ==(SIZE size) const
{ return (cx == size.cx && cy == size.cy); }
inline BOOL CSize::operator !=(SIZE size) const
{ return (cx != size.cx || cy != size.cy); }
inline void CSize::operator +=(SIZE size)
{ cx += size.cx; cy += size.cy; }
inline void CSize::operator -=(SIZE size)
{ cx -= size.cx; cy -= size.cy; }
inline void CSize::SetSize(int CX, int CY)
{ cx = CX; cy = CY; }
inline CSize CSize::operator +(SIZE size) const
{ return CSize(cx + size.cx, cy + size.cy); }
inline CSize CSize::operator -(SIZE size) const
{ return CSize(cx - size.cx, cy - size.cy); }
inline CSize CSize::operator -() const
{ return CSize(-cx, -cy); }
inline CPoint CSize::operator +(POINT point) const
{ return CPoint(cx + point.x, cy + point.y); }
inline CPoint CSize::operator -(POINT point) const
{ return CPoint(cx - point.x, cy - point.y); }
inline CRect CSize::operator +(const RECT* lpRect) const
{ return CRect(lpRect) + *this; }
inline CRect CSize::operator -(const RECT* lpRect) const
{ return CRect(lpRect) - *this; }
// CPoint
inline CPoint::CPoint()
{ /* random filled */ }
inline CPoint::CPoint(int initX, int initY)
{ x = initX; y = initY; }
inline CPoint::CPoint(POINT initPt)
{ *(POINT*)this = initPt; }
inline CPoint::CPoint(SIZE initSize)
{ *(SIZE*)this = initSize; }
inline CPoint::CPoint(DWORD dwPoint)
{
x = (short)LOWORD(dwPoint);
y = (short)HIWORD(dwPoint);
}
inline void CPoint::Offset(int xOffset, int yOffset)
{ x += xOffset; y += yOffset; }
inline void CPoint::Offset(POINT point)
{ x += point.x; y += point.y; }
inline void CPoint::Offset(SIZE size)
{ x += size.cx; y += size.cy; }
inline BOOL CPoint::operator ==(POINT point) const
{ return (x == point.x && y == point.y); }
inline BOOL CPoint::operator !=(POINT point) const
{ return (x != point.x || y != point.y); }
inline void CPoint::operator +=(SIZE size)
{ x += size.cx; y += size.cy; }
inline void CPoint::operator -=(SIZE size)
{ x -= size.cx; y -= size.cy; }
inline void CPoint::operator +=(POINT point)
{ x += point.x; y += point.y; }
inline void CPoint::operator -=(POINT point)
{ x -= point.x; y -= point.y; }
inline void CPoint::SetPoint(int X, int Y)
{ x = X; y = Y; }
inline CPoint CPoint::operator +(SIZE size) const
{ return CPoint(x + size.cx, y + size.cy); }
inline CPoint CPoint::operator -(SIZE size) const
{ return CPoint(x - size.cx, y - size.cy); }
inline CPoint CPoint::operator -() const
{ return CPoint(-x, -y); }
inline CPoint CPoint::operator +(POINT point) const
{ return CPoint(x + point.x, y + point.y); }
inline CSize CPoint::operator -(POINT point) const
{ return CSize(x - point.x, y - point.y); }
inline CRect CPoint::operator +(const RECT* lpRect) const
{ return CRect(lpRect) + *this; }
inline CRect CPoint::operator -(const RECT* lpRect) const
{ return CRect(lpRect) - *this; }
// CRect
inline CRect::CRect()
{ /* random filled */ }
inline CRect::CRect(int l, int t, int r, int b)
{ left = l; top = t; right = r; bottom = b; }
inline CRect::CRect(const RECT& srcRect)
{ ::CopyRect(this, &srcRect); }
inline CRect::CRect(LPCRECT lpSrcRect)
{ ::CopyRect(this, lpSrcRect); }
inline CRect::CRect(POINT point, SIZE size)
{
right = (left = point.x) + size.cx;
bottom = (top = point.y) + size.cy;
}
inline CRect::CRect(POINT topLeft, POINT bottomRight)
{
left = topLeft.x; top = topLeft.y;
right = bottomRight.x; bottom = bottomRight.y;
}
inline int CRect::Width() const
{ return right - left; }
inline int CRect::Height() const
{ return bottom - top; }
inline CSize CRect::Size() const
{ return CSize(right - left, bottom - top); }
inline CPoint& CRect::TopLeft()
{ return *((CPoint*)this); }
inline CPoint& CRect::BottomRight()
{ return *((CPoint*)this + 1); }
inline const CPoint& CRect::TopLeft() const
{ return *((CPoint*)this); }
inline const CPoint& CRect::BottomRight() const
{ return *((CPoint*)this + 1); }
inline CPoint CRect::CenterPoint() const
{ return CPoint((left + right) / 2, (top + bottom) / 2); }
inline CRect::operator LPRECT()
{ return this; }
inline CRect::operator LPCRECT() const
{ return this; }
inline BOOL CRect::IsRectEmpty() const
{ return ::IsRectEmpty(this); }
inline BOOL CRect::IsRectNull() const
{ return (left == 0 && right == 0 && top == 0 && bottom == 0); }
inline BOOL CRect::PtInRect(POINT point) const
{ return ::PtInRect(this, point); }
inline void CRect::SetRect(int x1, int y1, int x2, int y2)
{ ::SetRect(this, x1, y1, x2, y2); }
inline void CRect::SetRect(POINT topLeft, POINT bottomRight)
{ ::SetRect(this, topLeft.x, topLeft.y, bottomRight.x, bottomRight.y); }
inline void CRect::SetRectEmpty()
{ ::SetRectEmpty(this); }
inline void CRect::CopyRect(LPCRECT lpSrcRect)
{ ::CopyRect(this, lpSrcRect); }
inline BOOL CRect::EqualRect(LPCRECT lpRect) const
{ return ::EqualRect(this, lpRect); }
inline void CRect::InflateRect(int x, int y)
{ ::InflateRect(this, x, y); }
inline void CRect::InflateRect(SIZE size)
{ ::InflateRect(this, size.cx, size.cy); }
inline void CRect::DeflateRect(int x, int y)
{ ::InflateRect(this, -x, -y); }
inline void CRect::DeflateRect(SIZE size)
{ ::InflateRect(this, -size.cx, -size.cy); }
inline void CRect::OffsetRect(int x, int y)
{ ::OffsetRect(this, x, y); }
inline void CRect::OffsetRect(POINT point)
{ ::OffsetRect(this, point.x, point.y); }
inline void CRect::OffsetRect(SIZE size)
{ ::OffsetRect(this, size.cx, size.cy); }
inline BOOL CRect::IntersectRect(LPCRECT lpRect1, LPCRECT lpRect2)
{ return ::IntersectRect(this, lpRect1, lpRect2);}
inline BOOL CRect::UnionRect(LPCRECT lpRect1, LPCRECT lpRect2)
{ return ::UnionRect(this, lpRect1, lpRect2); }
inline void CRect::operator =(const RECT& srcRect)
{ ::CopyRect(this, &srcRect); }
inline BOOL CRect::operator ==(const RECT& rect) const
{ return ::EqualRect(this, &rect); }
inline BOOL CRect::operator !=(const RECT& rect) const
{ return !::EqualRect(this, &rect); }
inline void CRect::operator +=(POINT point)
{ ::OffsetRect(this, point.x, point.y); }
inline void CRect::operator +=(SIZE size)
{ ::OffsetRect(this, size.cx, size.cy); }
inline void CRect::operator +=(LPCRECT lpRect)
{ InflateRect(lpRect); }
inline void CRect::operator -=(POINT point)
{ ::OffsetRect(this, -point.x, -point.y); }
inline void CRect::operator -=(SIZE size)
{ ::OffsetRect(this, -size.cx, -size.cy); }
inline void CRect::operator -=(LPCRECT lpRect)
{ DeflateRect(lpRect); }
inline void CRect::operator &=(const RECT& rect)
{ ::IntersectRect(this, this, &rect); }
inline void CRect::operator |=(const RECT& rect)
{ ::UnionRect(this, this, &rect); }
inline CRect CRect::operator +(POINT pt) const
{
CRect rect(*this);
::OffsetRect(&rect, pt.x, pt.y);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -