📄 atlgdi.h
字号:
Attach(hBitmap);
return *this;
}
void Attach(HBITMAP hBitmap)
{
if(t_bManaged && m_hBitmap != NULL&& m_hBitmap != hBitmap)
::DeleteObject(m_hBitmap);
m_hBitmap = hBitmap;
}
HBITMAP Detach()
{
HBITMAP hBitmap = m_hBitmap;
m_hBitmap = NULL;
return hBitmap;
}
operator HBITMAP() const { return m_hBitmap; }
bool IsNull() const { return (m_hBitmap == NULL); }
// Create and load methods
HBITMAP LoadBitmap(ATL::_U_STRINGorID bitmap)
{
ATLASSERT(m_hBitmap == NULL);
#if (_ATL_VER >= 0x0700)
m_hBitmap = ::LoadBitmap(ATL::_AtlBaseModule.GetResourceInstance(), bitmap.m_lpstr);
#else //!(_ATL_VER >= 0x0700)
m_hBitmap = ::LoadBitmap(_Module.GetResourceInstance(), bitmap.m_lpstr);
#endif //!(_ATL_VER >= 0x0700)
return m_hBitmap;
}
HBITMAP LoadOEMBitmap(UINT nIDBitmap) // for OBM_/OCR_/OIC_
{
ATLASSERT(m_hBitmap == NULL);
m_hBitmap = ::LoadBitmap(NULL, MAKEINTRESOURCE(nIDBitmap));
return m_hBitmap;
}
#ifndef _WIN32_WCE
HBITMAP LoadMappedBitmap(UINT nIDBitmap, UINT nFlags = 0, LPCOLORMAP lpColorMap = NULL, int nMapSize = 0)
{
ATLASSERT(m_hBitmap == NULL);
#if (_ATL_VER >= 0x0700)
m_hBitmap = ::CreateMappedBitmap(ATL::_AtlBaseModule.GetResourceInstance(), nIDBitmap, (WORD)nFlags, lpColorMap, nMapSize);
#else //!(_ATL_VER >= 0x0700)
m_hBitmap = ::CreateMappedBitmap(_Module.GetResourceInstance(), nIDBitmap, (WORD)nFlags, lpColorMap, nMapSize);
#endif //!(_ATL_VER >= 0x0700)
return m_hBitmap;
}
#endif //!_WIN32_WCE
HBITMAP CreateBitmap(int nWidth, int nHeight, UINT nPlanes, UINT nBitcount, const void* lpBits)
{
ATLASSERT(m_hBitmap == NULL);
m_hBitmap = ::CreateBitmap(nWidth, nHeight, nPlanes, nBitcount, lpBits);
return m_hBitmap;
}
#ifndef _WIN32_WCE
HBITMAP CreateBitmapIndirect(LPBITMAP lpBitmap)
{
ATLASSERT(m_hBitmap == NULL);
m_hBitmap = ::CreateBitmapIndirect(lpBitmap);
return m_hBitmap;
}
#endif //!_WIN32_WCE
HBITMAP CreateCompatibleBitmap(HDC hDC, int nWidth, int nHeight)
{
ATLASSERT(m_hBitmap == NULL);
m_hBitmap = ::CreateCompatibleBitmap(hDC, nWidth, nHeight);
return m_hBitmap;
}
#ifndef _WIN32_WCE
HBITMAP CreateDiscardableBitmap(HDC hDC, int nWidth, int nHeight)
{
ATLASSERT(m_hBitmap == NULL);
m_hBitmap = ::CreateDiscardableBitmap(hDC, nWidth, nHeight);
return m_hBitmap;
}
#endif //!_WIN32_WCE
BOOL DeleteObject()
{
ATLASSERT(m_hBitmap != NULL);
BOOL bRet = ::DeleteObject(m_hBitmap);
if(bRet)
m_hBitmap = NULL;
return bRet;
}
// Attributes
int GetBitmap(BITMAP* pBitMap) const
{
ATLASSERT(m_hBitmap != NULL);
return ::GetObject(m_hBitmap, sizeof(BITMAP), pBitMap);
}
bool GetBitmap(BITMAP& bm) const
{
ATLASSERT(m_hBitmap != NULL);
return (::GetObject(m_hBitmap, sizeof(BITMAP), &bm) == sizeof(BITMAP));
}
bool GetSize(SIZE& size) const
{
ATLASSERT(m_hBitmap != NULL);
BITMAP bm = { 0 };
if(!GetBitmap(&bm))
return false;
size.cx = bm.bmWidth;
size.cy = bm.bmHeight;
return true;
}
#ifndef _WIN32_WCE
DWORD GetBitmapBits(DWORD dwCount, LPVOID lpBits) const
{
ATLASSERT(m_hBitmap != NULL);
return ::GetBitmapBits(m_hBitmap, dwCount, lpBits);
}
#endif //!_WIN32_WCE
#if !defined(_WIN32_WCE) || (_WIN32_WCE >= 410)
DWORD SetBitmapBits(DWORD dwCount, const void* lpBits)
{
ATLASSERT(m_hBitmap != NULL);
return ::SetBitmapBits(m_hBitmap, dwCount, lpBits);
}
#endif //!defined(_WIN32_WCE) || (_WIN32_WCE >= 410)
#ifndef _WIN32_WCE
BOOL GetBitmapDimension(LPSIZE lpSize) const
{
ATLASSERT(m_hBitmap != NULL);
return ::GetBitmapDimensionEx(m_hBitmap, lpSize);
}
BOOL SetBitmapDimension(int nWidth, int nHeight, LPSIZE lpSize = NULL)
{
ATLASSERT(m_hBitmap != NULL);
return ::SetBitmapDimensionEx(m_hBitmap, nWidth, nHeight, lpSize);
}
// DIB support
HBITMAP CreateDIBitmap(HDC hDC, CONST BITMAPINFOHEADER* lpbmih, DWORD dwInit, CONST VOID* lpbInit, CONST BITMAPINFO* lpbmi, UINT uColorUse)
{
ATLASSERT(m_hBitmap == NULL);
m_hBitmap = ::CreateDIBitmap(hDC, lpbmih, dwInit, lpbInit, lpbmi, uColorUse);
return m_hBitmap;
}
#endif //!_WIN32_WCE
HBITMAP CreateDIBSection(HDC hDC, CONST BITMAPINFO* lpbmi, UINT uColorUse, VOID** ppvBits, HANDLE hSection, DWORD dwOffset)
{
ATLASSERT(m_hBitmap == NULL);
m_hBitmap = ::CreateDIBSection(hDC, lpbmi, uColorUse, ppvBits, hSection, dwOffset);
return m_hBitmap;
}
#ifndef _WIN32_WCE
int GetDIBits(HDC hDC, UINT uStartScan, UINT cScanLines, LPVOID lpvBits, LPBITMAPINFO lpbmi, UINT uColorUse) const
{
ATLASSERT(m_hBitmap != NULL);
return ::GetDIBits(hDC, m_hBitmap, uStartScan, cScanLines, lpvBits, lpbmi, uColorUse);
}
int SetDIBits(HDC hDC, UINT uStartScan, UINT cScanLines, CONST VOID* lpvBits, CONST BITMAPINFO* lpbmi, UINT uColorUse)
{
ATLASSERT(m_hBitmap != NULL);
return ::SetDIBits(hDC, m_hBitmap, uStartScan, cScanLines, lpvBits, lpbmi, uColorUse);
}
#endif //!_WIN32_WCE
};
typedef CBitmapT<false> CBitmapHandle;
typedef CBitmapT<true> CBitmap;
///////////////////////////////////////////////////////////////////////////////
// CPalette
template <bool t_bManaged>
class CPaletteT
{
public:
// Data members
HPALETTE m_hPalette;
// Constructor/destructor/operators
CPaletteT(HPALETTE hPalette = NULL) : m_hPalette(hPalette)
{ }
~CPaletteT()
{
if(t_bManaged && m_hPalette != NULL)
DeleteObject();
}
CPaletteT<t_bManaged>& operator =(HPALETTE hPalette)
{
Attach(hPalette);
return *this;
}
void Attach(HPALETTE hPalette)
{
if(t_bManaged && m_hPalette != NULL && m_hPalette != hPalette)
::DeleteObject(m_hPalette);
m_hPalette = hPalette;
}
HPALETTE Detach()
{
HPALETTE hPalette = m_hPalette;
m_hPalette = NULL;
return hPalette;
}
operator HPALETTE() const { return m_hPalette; }
bool IsNull() const { return (m_hPalette == NULL); }
// Create methods
HPALETTE CreatePalette(LPLOGPALETTE lpLogPalette)
{
ATLASSERT(m_hPalette == NULL);
m_hPalette = ::CreatePalette(lpLogPalette);
return m_hPalette;
}
#ifndef _WIN32_WCE
HPALETTE CreateHalftonePalette(HDC hDC)
{
ATLASSERT(m_hPalette == NULL);
ATLASSERT(hDC != NULL);
m_hPalette = ::CreateHalftonePalette(hDC);
return m_hPalette;
}
#endif //!_WIN32_WCE
BOOL DeleteObject()
{
ATLASSERT(m_hPalette != NULL);
BOOL bRet = ::DeleteObject(m_hPalette);
if(bRet)
m_hPalette = NULL;
return bRet;
}
// Attributes
int GetEntryCount() const
{
ATLASSERT(m_hPalette != NULL);
WORD nEntries = 0;
::GetObject(m_hPalette, sizeof(WORD), &nEntries);
return (int)nEntries;
}
UINT GetPaletteEntries(UINT nStartIndex, UINT nNumEntries, LPPALETTEENTRY lpPaletteColors) const
{
ATLASSERT(m_hPalette != NULL);
return ::GetPaletteEntries(m_hPalette, nStartIndex, nNumEntries, lpPaletteColors);
}
UINT SetPaletteEntries(UINT nStartIndex, UINT nNumEntries, LPPALETTEENTRY lpPaletteColors)
{
ATLASSERT(m_hPalette != NULL);
return ::SetPaletteEntries(m_hPalette, nStartIndex, nNumEntries, lpPaletteColors);
}
// Operations
#ifndef _WIN32_WCE
void AnimatePalette(UINT nStartIndex, UINT nNumEntries, LPPALETTEENTRY lpPaletteColors)
{
ATLASSERT(m_hPalette != NULL);
::AnimatePalette(m_hPalette, nStartIndex, nNumEntries, lpPaletteColors);
}
BOOL ResizePalette(UINT nNumEntries)
{
ATLASSERT(m_hPalette != NULL);
return ::ResizePalette(m_hPalette, nNumEntries);
}
#endif //!_WIN32_WCE
UINT GetNearestPaletteIndex(COLORREF crColor) const
{
ATLASSERT(m_hPalette != NULL);
return ::GetNearestPaletteIndex(m_hPalette, crColor);
}
};
typedef CPaletteT<false> CPaletteHandle;
typedef CPaletteT<true> CPalette;
///////////////////////////////////////////////////////////////////////////////
// CRgn
template <bool t_bManaged>
class CRgnT
{
public:
// Data members
HRGN m_hRgn;
// Constructor/destructor/operators
CRgnT(HRGN hRgn = NULL) : m_hRgn(hRgn)
{ }
~CRgnT()
{
if(t_bManaged && m_hRgn != NULL)
DeleteObject();
}
CRgnT<t_bManaged>& operator =(HRGN hRgn)
{
Attach(hRgn);
return *this;
}
void Attach(HRGN hRgn)
{
if(t_bManaged && m_hRgn != NULL && m_hRgn != hRgn)
::DeleteObject(m_hRgn);
m_hRgn = hRgn;
}
HRGN Detach()
{
HRGN hRgn = m_hRgn;
m_hRgn = NULL;
return hRgn;
}
operator HRGN() const { return m_hRgn; }
bool IsNull() const { return (m_hRgn == NULL); }
// Create methods
HRGN CreateRectRgn(int x1, int y1, int x2, int y2)
{
ATLASSERT(m_hRgn == NULL);
m_hRgn = ::CreateRectRgn(x1, y1, x2, y2);
return m_hRgn;
}
HRGN CreateRectRgnIndirect(LPCRECT lpRect)
{
ATLASSERT(m_hRgn == NULL);
m_hRgn = ::CreateRectRgnIndirect(lpRect);
return m_hRgn;
}
#ifndef _WIN32_WCE
HRGN CreateEllipticRgn(int x1, int y1, int x2, int y2)
{
ATLASSERT(m_hRgn == NULL);
m_hRgn = ::CreateEllipticRgn(x1, y1, x2, y2);
return m_hRgn;
}
HRGN CreateEllipticRgnIndirect(LPCRECT lpRect)
{
ATLASSERT(m_hRgn == NULL);
m_hRgn = ::CreateEllipticRgnIndirect(lpRect);
return m_hRgn;
}
HRGN CreatePolygonRgn(LPPOINT lpPoints, int nCount, int nMode)
{
ATLASSERT(m_hRgn == NULL);
m_hRgn = ::CreatePolygonRgn(lpPoints, nCount, nMode);
return m_hRgn;
}
HRGN CreatePolyPolygonRgn(LPPOINT lpPoints, LPINT lpPolyCounts, int nCount, int nPolyFillMode)
{
ATLASSERT(m_hRgn == NULL);
m_hRgn = ::CreatePolyPolygonRgn(lpPoints, lpPolyCounts, nCount, nPolyFillMode);
return m_hRgn;
}
HRGN CreateRoundRectRgn(int x1, int y1, int x2, int y2, int x3, int y3)
{
ATLASSERT(m_hRgn == NULL);
m_hRgn = ::CreateRoundRectRgn(x1, y1, x2, y2, x3, y3);
return m_hRgn;
}
HRGN CreateFromPath(HDC hDC)
{
ATLASSERT(m_hRgn == NULL);
ATLASSERT(hDC != NULL);
m_hRgn = ::PathToRegion(hDC);
return m_hRgn;
}
HRGN CreateFromData(const XFORM* lpXForm, int nCount, const RGNDATA* pRgnData)
{
ATLASSERT(m_hRgn == NULL);
m_hRgn = ::ExtCreateRegion(lpXForm, nCount, pRgnData);
return m_hRgn;
}
#endif //!_WIN32_WCE
BOOL DeleteObject()
{
ATLASSERT(m_hRgn != NULL);
BOOL bRet = ::DeleteObject(m_hRgn);
if(bRet)
m_hRgn = NULL;
return bRet;
}
// Operations
void SetRectRgn(int x1, int y1, int x2, int y2)
{
ATLASSERT(m_hRgn != NULL);
::SetRectRgn(m_hRgn, x1, y1, x2, y2);
}
void SetRectRgn(LPCRECT lpRect)
{
ATLASSERT(m_hRgn != NULL);
::SetRectRgn(m_hRgn, lpRect->left, lpRect->top, lpRect->right, lpRect->bottom);
}
int CombineRgn(HRGN hRgnSrc1, HRGN hRgnSrc2, int nCombineMode)
{
ATLASSERT(m_hRgn != NULL);
return ::CombineRgn(m_hRgn, hRgnSrc1, hRgnSrc2, nCombineMode);
}
int CombineRgn(HRGN hRgnSrc, int nCombineMode)
{
ATLASSERT(m_hRgn != NULL);
return ::CombineRgn(m_hRgn, m_hRgn, hRgnSrc, nCombineMode);
}
int CopyRgn(HRGN hRgnSrc)
{
ATLASSERT(m_hRgn != NULL);
return ::CombineRgn(m_hRgn, hRgnSrc, NULL, RGN_COPY);
}
BOOL EqualRgn(HRGN hRgn) const
{
ATLASSERT(m_hRgn != NULL);
return ::EqualRgn(m_hRgn, hRgn);
}
int OffsetRgn(int x, int y)
{
ATLASSERT(m_hRgn != NULL);
return ::OffsetRgn(m_hRgn, x, y);
}
int OffsetRgn(POINT point)
{
ATLASSERT(m_hRgn != NULL);
return ::OffsetRgn(m_hRgn, point.x, point.y);
}
int GetRgnBox(LPRECT lpRect) const
{
ATLASSERT(m_hRgn != NULL);
return ::GetRgnBox(m_hRgn, lpRect);
}
BOOL PtInRegion(int x, int y) const
{
ATLASSERT(m_hRgn != NULL);
return ::PtInRegion(m_hRgn, x, y);
}
BOOL PtInRegion(POINT point) const
{
ATLASSERT(m_hRgn != NULL);
return ::PtInRegion(m_hRgn, point.x, point.y);
}
BOOL RectInRegion(LPCRECT lpRect) const
{
ATLASSERT(m_hRgn != NULL);
return ::RectInRegion(m_hRgn, lpRect);
}
int GetRegionData(LPRGNDATA lpRgnData, int nDataSize) const
{
ATLASSERT(m_hRgn != NULL);
return (int)::GetRegionData(m_hRgn, nDataSize, lpRgnData);
}
};
typedef CRgnT<false> CRgnHandle;
typedef CRgnT<true> CRgn;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -