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

📄 atlgdix.h

📁 These listed libraries are written in WTL. But it s really hard to mix both MFC & WTL together. Obvi
💻 H
📖 第 1 页 / 共 2 页
字号:
#ifndef __ATLGDIX_H__
#define __ATLGDIX_H__

/////////////////////////////////////////////////////////////////////////////
// Additional GDI/USER wrappers
//
// Written by Bjarke Viksoe (bjarke@viksoe.dk)
// Copyright (c) 2001-2002 Bjarke Viksoe.
// Thanks to Daniel Bowen for COffscreenDrawRect.
//
// This code may be used in compiled form in any way you desire. This
// file may be redistributed by any means PROVIDING it is 
// not sold for profit without the authors written consent, and 
// providing that this notice and the authors name is included. 
//
// This file is provided "as is" with no expressed or implied warranty.
// The author accepts no liability if it causes any damage to you or your
// computer whatsoever. It's free, so don't hassle me about it.
//
// Beware of bugs.
//

#pragma once

#ifndef __cplusplus
   #error ATL requires C++ compilation (use a .cpp suffix)
#endif

#ifndef __ATLGDI_H__
   #error atlgdix.h requires atlgdi.h to be included first
#endif

namespace WTL
{

/////////////////////////////////////////////////////////////////////////////
// Macros

// The GetXValue macros below are badly designed and emit
// compiler warnings e.g. when using RGB(255,255,255)...
#pragma warning(disable : 4310)

#ifndef BlendRGB
   #define BlendRGB(c1, c2, factor) \
      RGB( GetRValue(c1) + ((GetRValue(c2) - GetRValue(c1)) * factor / 100L), \
           GetGValue(c1) + ((GetGValue(c2) - GetGValue(c1)) * factor / 100L), \
           GetBValue(c1) + ((GetBValue(c2) - GetBValue(c1)) * factor / 100L) )
#endif

#ifndef COLOR_INVALID
   #define COLOR_INVALID  (COLORREF) CLR_INVALID
#endif


#if _WTL_VER < 0x0750

/////////////////////////////////////////////////////////////////////////////
// CIcon

template< bool t_bManaged >
class CIconT
{
public:
   HICON m_hIcon;

   // Constructor/destructor/operators

   CIconT(HICON hIcon = NULL) : m_hIcon(hIcon)
   { 
   }

   ~CIconT()
   {
      if( t_bManaged && m_hIcon != NULL ) ::DestroyIcon(m_hIcon);
   }

   CIconT<t_bManaged>& operator=(HICON hIcon)
   {
      m_hIcon = hIcon;
      return *this;
   }

   void Attach(HICON hIcon)
   {
      if( t_bManaged && m_hIcon != NULL ) ::DestroyIcon(m_hIcon);
      m_hIcon = hIcon;
   }  
   HICON Detach()
   {
      HICON hIcon = m_hIcon;
      m_hIcon = NULL;
      return hIcon;
   }

   operator HICON() const { return m_hIcon; }

   bool IsNull() const { return m_hIcon == NULL; }

   // Create methods

   HICON LoadIcon(_U_STRINGorID icon)
   {
      ATLASSERT(m_hIcon==NULL);
#if (_ATL_VER >= 0x0700)
      m_hIcon = ::LoadIcon(ATL::_AtlBaseModule.GetResourceInstance(), icon.m_lpstr);
#else
      m_hIcon = ::LoadIcon(_Module.GetResourceInstance(), icon.m_lpstr);
#endif
      return m_hIcon;
   }
   HICON LoadIcon(_U_STRINGorID icon, int cxDesired, int cyDesired, UINT fuLoad = 0)
   {
      ATLASSERT(m_hIcon==NULL);
#if (_ATL_VER >= 0x0700)
      m_hIcon = (HICON) ::LoadImage(ATL::_AtlBaseModule.GetResourceInstance(), icon.m_lpstr, IMAGE_ICON, cxDesired, cyDesired, fuLoad);
#else
      m_hIcon = (HICON) ::LoadImage(_Module.GetResourceInstance(), icon.m_lpstr, IMAGE_ICON, cxDesired, cyDesired, fuLoad);
#endif
      return m_hIcon;
   }
   HICON LoadOEMIcon(UINT nIDIcon) // for IDI_ types
   {
      ATLASSERT(m_hIcon==NULL);
      m_hIcon = ::LoadIcon(NULL, MAKEINTRESOURCE(nIDIcon));
      return m_hIcon;
   }
   HICON CreateIcon(int nWidth, int nHeight, BYTE cPlanes, BYTE cBitsPixel, CONST BYTE* lpbANDButs, CONST BYTE *lpbXORbits)
   {
      ATLASSERT(m_hIcon==NULL);
      ATLASSERT(lpbANDbits);
      ATLASSERT(lpbXORbits);
#if (_ATL_VER >= 0x0700)
      m_hIcon = ::CreateIcon(ATL::_AtlBaseModule.GetResourceInstance(), nWidth, nHeight, cPlanes, cBitsPixel, lpbANDbits, lpbXORbits);
#else
      m_hIcon = ::CreateIcon(_Module.GetResourceInstance(), nWidth, nHeight, cPlanes, cBitsPixel, lpbANDbits, lpbXORbits);
#endif
      return m_hIcon;
   }
   HICON CreateIconFromResource(PBYTE pBits, DWORD dwResSize, DWORD dwVersion = 0x00030000)
   {
      ATLASSERT(m_hIcon==NULL);
      ATLASSERT(pBits);
      m_hIcon = ::CreateIconFromResource(pBits, dwResSize, TRUE, dwVersion);
      return m_hIcon;
   }
   HICON CreateIconFromResourceEx(PBYTE pbBits, DWORD cbBits, DWORD dwVersion = 0x00030000, int cxDesired = 0, int cyDesired = 0, UINT uFlags = LR_DEFAULTCOLOR)
   {
      ATLASSERT(m_hIcon==NULL);
      ATLASSERT(pbBits);
      ATLASSERT(cbBits>0);
      m_hIcon = ::CreateIconFromResourceEx(pbBits, cbBits, TRUE, dwVersion, cxDesired,  cyDesired, uFlags);
      return m_hIcon;
   }
   HICON CreateIconIndirect(PICONINFO pIconInfo)
   {
      ATLASSERT(m_hIcon==NULL);
      ATLASSERT(pIconInfo);
      m_hIcon = ::CreateIconIndirect(pIconInfo);
      return m_hIcon;
   }
   HICON ExtractIcon(LPCTSTR lpszExeFileName, UINT nIconIndex)
   {
      ATLASSERT(m_hIcon==NULL);
      ATLASSERT(!::IsBadStringPtr(lpszExeFileName,-1));
#if (_ATL_VER >= 0x0700)      
      m_hIcon = ::ExtractIcon(ATL::_AtlBaseModule.GetModuleInstance(), lpszExeFileName, nIconIndex);
#else
      m_hIcon = ::ExtractIcon(_Module.GetModuleInstance(), lpszExeFileName, nIconIndex);
#endif
      return m_hIcon;
   }
   HICON ExtractAssociatedIcon(HINSTANCE hInst, LPCTSTR lpIconPath, LPWORD lpiIcon)
   {
      ATLASSERT(m_hIcon==NULL);
      ATLASSERT(!::IsBadStringPtr(lpIconPath,-1));
      ATLASSERT(lpiIcon);
      m_hIcon = ::ExtractAssociatedIcon(hInst, lpIconPath, lpiIcon);
      return m_hIcon;
   }

   // Operations

   BOOL DestroyIcon()
   {
      ATLASSERT(m_hIcon!=NULL);
      BOOL bRet = ::DestroyIcon(m_hIcon);
      if( bRet ) m_hIcon = NULL;
      return bRet;
   }
   HICON CopyIcon()
   {
      ATLASSERT(m_hIcon!=NULL);
      return ::CopyIcon(m_hIcon);
   }
   HICON DuplicateIcon()
   {
      ATLASSERT(m_hIcon!=NULL);
      return ::DuplicateIcon(NULL, m_hIcon);
   }

   BOOL DrawIcon(HDC hDC, int x, int y)
   {
      ATLASSERT(m_hIcon!=NULL);
      return ::DrawIcon(hDC, x, y, m_hIcon);
   }
   BOOL DrawIcon(HDC hDC, POINT pt)
   {
      ATLASSERT(m_hIcon!=NULL);
      return ::DrawIcon(hDC, pt.x, pt.y, m_hIcon);
   }
   BOOL DrawIconEx(HDC hDC, int x, int y, int cxWidth, int cyWidth, UINT uStepIfAniCur = 0, HBRUSH hbrFlickerFreeDraw = NULL, UINT uFlags = DI_NORMAL)
   {
      ATLASSERT(m_hIcon!=NULL);
      return ::DrawIconEx(hDC, x, y, m_hIcon, cxWidth, cyWidth, uStepIfAniCur, hbrFlickerFreeDraw, uFlags);
   }
   BOOL DrawIconEx(HDC hDC, POINT pt, SIZE size, UINT uStepIfAniCur = 0, HBRUSH hbrFlickerFreeDraw = NULL, UINT uFlags = DI_NORMAL)
   {
      ATLASSERT(m_hIcon!=NULL);
      return ::DrawIconEx(hDC, pt.x, pt.y, m_hIcon, size.cx, size.cy, uStepIfAniCur, hbrFlickerFreeDraw, uFlags);
   }

   BOOL GetIconInfo(PICONINFO pIconInfo)
   {
      ATLASSERT(m_hIcon!=NULL);
      ATLASSERT(pIconInfo);
      return ::GetIconInfo(m_hIcon, pIconInfo);
   }
};

typedef CIconT<true> CIcon;
typedef CIconT<false> CIconHandle;


/////////////////////////////////////////////////////////////////////////////
// CCursor

// Protect template against silly macro
#ifdef CopyCursor
   #undef CopyCursor
#endif

template< bool t_bManaged >
class CCursorT
{
public:
   HCURSOR m_hCursor;

   // Constructor/destructor/operators

   CCursorT(HCURSOR hCursor = NULL) : m_hCursor(hCursor)
   { 
   }

   ~CCursorT()
   {
      if( t_bManaged && m_hCursor != NULL ) ::DestroyCursor(m_hCursor);
   }

   CCursorT<t_bManaged>& operator=(HCURSOR hCursor)
   {
      m_hCursor = hCursor;
      return *this;
   }

   void Attach(HCURSOR hCursor)
   {
      if( t_bManaged && m_hCursor != NULL ) ::DestroyCursor(m_hCursor);
      m_hCursor = hCursor;
   }
   HCURSOR Detach()
   {
      HCURSOR hCursor = m_hCursor;
      m_hCursor = NULL;
      return hCursor;
   }

   operator HCURSOR() const { return m_hCursor; }

   bool IsNull() const { return m_hCursor == NULL; }

   // Create methods

   HCURSOR LoadCursor(_U_STRINGorID cursor)
   {
      ATLASSERT(m_hCursor==NULL);
#if (_ATL_VER >= 0x0700)
      m_hCursor = ::LoadCursor(ATL::_AtlBaseModule.GetResourceInstance(), cursor.m_lpstr);
#else
      m_hCursor = ::LoadCursor(_Module.GetResourceInstance(), cursor.m_lpstr);
#endif
      return m_hCursor;
   }
   HCURSOR LoadOEMCursor(UINT nIDCursor) // for IDC_ types
   {
      ATLASSERT(m_hCursor==NULL);
      m_hCursor = ::LoadCursor(NULL, MAKEINTRESOURCE(nIDCursor));
      return m_hCursor;
   }
   HICON LoadCursor(_U_STRINGorID cursor, int cxDesired, int cyDesired, UINT fuLoad = 0)
   {
      ATLASSERT(m_hCursor==NULL);
#if (_ATL_VER >= 0x0700)
      m_hCursor = (HCURSOR) ::LoadImage(ATL::_AtlBaseModule.GetResourceInstance(), cursor.m_lpstr, IMAGE_CURSOR, cxDesired, cyDesired, fuLoad);
#else
      m_hCursor = (HCURSOR) ::LoadImage(_Module.GetResourceInstance(), cursor.m_lpstr, IMAGE_CURSOR, cxDesired, cyDesired, fuLoad);
#endif
      return m_hCursor;
   }
   HCURSOR LoadCursorFromFile(LPCTSTR pstrFilename)
   {
      ATLASSERT(m_hCursor==NULL);
      ATLASSERT(!::IsBadStringPtr(pstrFilename,-1));
      m_hCursor = ::LoadCursorFromFile(pstrFilename);
      return m_hCursor;
   }
   HCURSOR CreateCursor(int xHotSpot, int yHotSpot, int nWidth, int nHeight, CONST VOID *pvANDPlane, CONST VOID *pvXORPlane)
   {
      ATLASSERT(m_hCursor==NULL);
#if (_ATL_VER >= 0x0700)
      m_hCursor = ::CreateCursor(ATL::_AtlBaseModule.GetResourceInstance(), xHotSpot, yHotSpot, nWidth, nHeight, pvANDPlane, pvXORPlane);
#else
      m_hCursor = ::CreateCursor(_Module.GetResourceInstance(), xHotSpot, yHotSpot, nWidth, nHeight, pvANDPlane, pvXORPlane);
#endif
      return m_hCursor;
   }
   HICON CreateCursorFromResource(PBYTE pBits, DWORD dwResSize, DWORD dwVersion = 0x00030000)
   {
      ATLASSERT(m_hIcon==NULL);
      ATLASSERT(pBits);
      m_hIcon = ::CreateIconFromResource(pBits, dwResSize, FALSE, dwVersion);
      return m_hIcon;
   }
   HICON CreateCursorFromResourceEx(PBYTE pbBits, DWORD cbBits, DWORD dwVersion = 0x00030000, int cxDesired = 0, int cyDesired = 0, UINT uFlags = LR_DEFAULTCOLOR)
   {
      ATLASSERT(m_hIcon==NULL);
      ATLASSERT(pbBits);
      ATLASSERT(cbBits>0);
      m_hIcon = ::CreateIconFromResourceEx(pbBits, cbBits, FALSE, dwVersion, cxDesired,  cyDesired, uFlags);
      return m_hIcon;
   }
  
   // Operations

   BOOL DestroyCursor()
   {
      ATLASSERT(m_hCursor!=NULL);
      BOOL bRet = ::DestroyCursor(m_hCursor);
      if( bRet ) m_hCursor = NULL;
      return bRet;
   }

   HCURSOR CopyCursor()
   {
      ATLASSERT(m_hCursor!=NULL);
      return (HCURSOR) ::CopyIcon( (HICON) m_hCursor );
   }

#if(WINVER >= 0x0500)
   BOOL GetCursorInfo(LPCURSORINFO pCursorInfo)
   {
      ATLASSERT(m_hCursor!=NULL);
      ATLASSERT(pCursorInfo);
      return ::GetCursorInfo(pCursorInfo);
   }
#endif
};

typedef CCursorT<true> CCursor;
typedef CCursorT<false> CCursorHandle;


/////////////////////////////////////////////////////////////////////////////
// CAccelerator

template< bool t_bManaged >
class CAcceleratorT
{
public:
   HACCEL m_hAccel;

   // Constructor/destructor/operators

   CAcceleratorT(HACCEL hAccel = NULL) : m_hAccel(hAccel)
   { 
   }

   ~CAcceleratorT()
   {
      if( t_bManaged && m_hAccel != NULL ) ::DestroyAcceleratorTable(m_hAccel);
   }

   CAcceleratorT<t_bManaged>& operator=(HACCEL hAccel)
   {
      m_hAccel = hAccel;
      return *this;
   }

   void DestroyObject()
   {
      if( m_hAccel != NULL ) {
         ::DestroyAcceleratorTable(m_hAccel);
         m_hAccel = NULL;
      }
   }

   void Attach(HACCEL hAccel)
   {
      if( t_bManaged && m_hAccel != NULL ) ::DestroyAcceleratorTable(m_hAccel);
      m_hAccel = hAccel;
   }  
   HCURSOR Detach()
   {
      HACCEL hAccel = m_hAccel;
      m_hAccel = NULL;
      return hAccel;
   }

   operator HACCEL() const { return m_hAccel; }

   bool IsNull() const { return m_hAccel == NULL; }

   // Create methods

   HACCEL LoadAccelerators(_U_STRINGorID accel)
   {
      ATLASSERT(m_hAccel==NULL);
#if (_ATL_VER >= 0x0700)
      m_hAccel = ::LoadAccelerators(ATL::_AtlBaseModule.GetResourceInstance(), accel.m_lpstr);
#else
      m_hAccel = ::LoadAccelerators(_Module.GetResourceInstance(), accel.m_lpstr);
#endif
      return m_hAccel;
   }
   HACCEL CreateAcceleratorTable(LPACCEL pAccel, int cEntries)
   {
      ATLASSERT(m_hAccel==NULL);
      ATLASSERT(!::IsBadReadPtr(lpAccelDst, sizeof(ACCEL)*cEntries));
      m_hAccel = ::CreateAcceleratorTable(pAccel, cEntries);
      return m_hAccel;
   }

   // Operations

   int CopyAcceleratorTable(LPACCEL lpAccelDst, int cEntries)
   {
      ATLASSERT(m_hAccel!=NULL);
      ATLASSERT(!::IsBadWritePtr(lpAccelDst, sizeof(ACCEL)*cEntries));
      return ::CopyAcceleratorTable(m_hAccel, lpAccelDst, cEntries);
   }

   BOOL TranslateAccelerator(HWND hWnd, LPMSG pMsg)
   {
      ATLASSERT(m_hAccel!=NULL);
      ATLASSERT(::IsWindow(hWnd));
      ATLASSERT(pMsg);
      return ::TranslateAccelerator(hWnd, m_hAccel, pMsg);

⌨️ 快捷键说明

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