📄 atluser.h
字号:
ATLASSERT(m_hIcon == NULL);
ATLASSERT(pbBits != NULL);
ATLASSERT(cbBits > 0);
m_hIcon = ::CreateIconFromResourceEx(pbBits, cbBits, TRUE, dwVersion, cxDesired, cyDesired, uFlags);
return m_hIcon;
}
#endif // !_WIN32_WCE
HICON CreateIconIndirect(PICONINFO pIconInfo)
{
ATLASSERT(m_hIcon == NULL);
ATLASSERT(pIconInfo != NULL);
m_hIcon = ::CreateIconIndirect(pIconInfo);
return m_hIcon;
}
#ifndef _WIN32_WCE
HICON ExtractIcon(LPCTSTR lpszExeFileName, UINT nIconIndex)
{
ATLASSERT(m_hIcon == NULL);
ATLASSERT(lpszExeFileName != NULL);
#if (_ATL_VER >= 0x0700)
m_hIcon = ::ExtractIcon(ATL::_AtlBaseModule.GetModuleInstance(), lpszExeFileName, nIconIndex);
#else // !(_ATL_VER >= 0x0700)
m_hIcon = ::ExtractIcon(ATL::_pModule->GetModuleInstance(), lpszExeFileName, nIconIndex);
#endif // !(_ATL_VER >= 0x0700)
return m_hIcon;
}
HICON ExtractAssociatedIcon(HINSTANCE hInst, LPTSTR lpIconPath, LPWORD lpiIcon)
{
ATLASSERT(m_hIcon == NULL);
ATLASSERT(lpIconPath != NULL);
ATLASSERT(lpiIcon != NULL);
m_hIcon = ::ExtractAssociatedIcon(hInst, lpIconPath, lpiIcon);
return m_hIcon;
}
#endif // !_WIN32_WCE
BOOL DestroyIcon()
{
ATLASSERT(m_hIcon != NULL);
BOOL bRet = ::DestroyIcon(m_hIcon);
if(bRet != FALSE)
m_hIcon = NULL;
return bRet;
}
// Operations
#ifndef _WIN32_WCE
HICON CopyIcon()
{
ATLASSERT(m_hIcon != NULL);
return ::CopyIcon(m_hIcon);
}
HICON DuplicateIcon()
{
ATLASSERT(m_hIcon != NULL);
return ::DuplicateIcon(NULL, m_hIcon);
}
#endif // !_WIN32_WCE
BOOL DrawIcon(HDC hDC, int x, int y)
{
ATLASSERT(m_hIcon != NULL);
#ifndef _WIN32_WCE
return ::DrawIcon(hDC, x, y, m_hIcon);
#else // CE specific
return ::DrawIconEx(hDC, x, y, m_hIcon, 0, 0, 0, NULL, DI_NORMAL);
#endif // _WIN32_WCE
}
BOOL DrawIcon(HDC hDC, POINT pt)
{
ATLASSERT(m_hIcon != NULL);
#ifndef _WIN32_WCE
return ::DrawIcon(hDC, pt.x, pt.y, m_hIcon);
#else // CE specific
return ::DrawIconEx(hDC, pt.x, pt.y, m_hIcon, 0, 0, 0, NULL, DI_NORMAL);
#endif // _WIN32_WCE
}
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);
}
#ifndef _WIN32_WCE
BOOL GetIconInfo(PICONINFO pIconInfo)
{
ATLASSERT(m_hIcon != NULL);
ATLASSERT(pIconInfo != NULL);
return ::GetIconInfo(m_hIcon, pIconInfo);
}
#endif // !_WIN32_WCE
};
typedef CIconT<false> CIconHandle;
typedef CIconT<true> CIcon;
///////////////////////////////////////////////////////////////////////////////
// CCursor
// protect template member from a winuser.h 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();
}
CCursorT<t_bManaged>& operator =(HCURSOR hCursor)
{
Attach(hCursor);
return *this;
}
void Attach(HCURSOR hCursor)
{
if(t_bManaged && m_hCursor != NULL)
DestroyCursor();
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/destroy methods
HCURSOR LoadCursor(ATL::_U_STRINGorID cursor)
{
ATLASSERT(m_hCursor == NULL);
#if (_ATL_VER >= 0x0700)
m_hCursor = ::LoadCursor(ATL::_AtlBaseModule.GetResourceInstance(), cursor.m_lpstr);
#else // !(_ATL_VER >= 0x0700)
m_hCursor = ::LoadCursor(ATL::_pModule->GetResourceInstance(), cursor.m_lpstr);
#endif // !(_ATL_VER >= 0x0700)
return m_hCursor;
}
HCURSOR LoadOEMCursor(LPCTSTR lpstrCursorName)
{
ATLASSERT(m_hCursor == NULL);
ATLASSERT(lpstrCursorName == IDC_ARROW || lpstrCursorName == IDC_IBEAM || lpstrCursorName == IDC_WAIT ||
lpstrCursorName == IDC_CROSS || lpstrCursorName == IDC_UPARROW || lpstrCursorName == IDC_SIZE ||
lpstrCursorName == IDC_ICON || lpstrCursorName == IDC_SIZENWSE || lpstrCursorName == IDC_SIZENESW ||
lpstrCursorName == IDC_SIZEWE || lpstrCursorName == IDC_SIZENS || lpstrCursorName == IDC_SIZEALL ||
lpstrCursorName == IDC_NO || lpstrCursorName == IDC_APPSTARTING || lpstrCursorName == IDC_HELP);
m_hCursor = ::LoadCursor(NULL, lpstrCursorName);
return m_hCursor;
}
HCURSOR LoadCursor(ATL::_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 // !(_ATL_VER >= 0x0700)
m_hCursor = (HCURSOR) ::LoadImage(ATL::_pModule->GetResourceInstance(), cursor.m_lpstr, IMAGE_CURSOR, cxDesired, cyDesired, fuLoad);
#endif // !(_ATL_VER >= 0x0700)
return m_hCursor;
}
#ifndef _WIN32_WCE
HCURSOR LoadCursorFromFile(LPCTSTR pstrFilename)
{
ATLASSERT(m_hCursor == NULL);
ATLASSERT(pstrFilename != NULL);
m_hCursor = ::LoadCursorFromFile(pstrFilename);
return m_hCursor;
}
#endif // !_WIN32_WCE
#if !defined(_WIN32_WCE) || ((_WIN32_WCE >= 0x400) && !(defined(WIN32_PLATFORM_PSPC) || defined(WIN32_PLATFORM_WFSP)))
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 // !(_ATL_VER >= 0x0700)
m_hCursor = ::CreateCursor(ATL::_pModule->GetResourceInstance(), xHotSpot, yHotSpot, nWidth, nHeight, pvANDPlane, pvXORPlane);
#endif // !(_ATL_VER >= 0x0700)
return m_hCursor;
}
#endif // !defined(_WIN32_WCE) || ((_WIN32_WCE >= 0x400) && !(defined(WIN32_PLATFORM_PSPC) || defined(WIN32_PLATFORM_WFSP)))
#ifndef _WIN32_WCE
HCURSOR CreateCursorFromResource(PBYTE pBits, DWORD dwResSize, DWORD dwVersion = 0x00030000)
{
ATLASSERT(m_hCursor == NULL);
ATLASSERT(pBits != NULL);
m_hCursor = (HCURSOR)::CreateIconFromResource(pBits, dwResSize, FALSE, dwVersion);
return m_hCursor;
}
HCURSOR CreateCursorFromResourceEx(PBYTE pbBits, DWORD cbBits, DWORD dwVersion = 0x00030000, int cxDesired = 0, int cyDesired = 0, UINT uFlags = LR_DEFAULTCOLOR)
{
ATLASSERT(m_hCursor == NULL);
ATLASSERT(pbBits != NULL);
ATLASSERT(cbBits > 0);
m_hCursor = (HCURSOR)::CreateIconFromResourceEx(pbBits, cbBits, FALSE, dwVersion, cxDesired, cyDesired, uFlags);
return m_hCursor;
}
#endif // !_WIN32_WCE
BOOL DestroyCursor()
{
ATLASSERT(m_hCursor != NULL);
#if !defined(_WIN32_WCE) || ((_WIN32_WCE >= 0x400) && !(defined(WIN32_PLATFORM_PSPC) || defined(WIN32_PLATFORM_WFSP)))
BOOL bRet = ::DestroyCursor(m_hCursor);
if(bRet != FALSE)
m_hCursor = NULL;
return bRet;
#else // !(!defined(_WIN32_WCE) || ((_WIN32_WCE >= 0x400) && !(defined(WIN32_PLATFORM_PSPC) || defined(WIN32_PLATFORM_WFSP))))
ATLTRACE2(atlTraceUI, 0, _T("Warning: This version of Windows CE does not have ::DestroyCursor()\n"));
return FALSE;
#endif // !(!defined(_WIN32_WCE) || ((_WIN32_WCE >= 0x400) && !(defined(WIN32_PLATFORM_PSPC) || defined(WIN32_PLATFORM_WFSP))))
}
// Operations
#ifndef _WIN32_WCE
HCURSOR CopyCursor()
{
ATLASSERT(m_hCursor != NULL);
return (HCURSOR)::CopyIcon((HICON)m_hCursor);
}
#endif // !_WIN32_WCE
#if (WINVER >= 0x0500) && !defined(_WIN32_WCE)
BOOL GetCursorInfo(LPCURSORINFO pCursorInfo)
{
ATLASSERT(m_hCursor != NULL);
ATLASSERT(pCursorInfo != NULL);
return ::GetCursorInfo(pCursorInfo);
}
#endif // (WINVER >= 0x0500) && !defined(_WIN32_WCE)
};
typedef CCursorT<false> CCursorHandle;
typedef CCursorT<true> CCursor;
///////////////////////////////////////////////////////////////////////////////
// CResource - Wraps a generic Windows resource.
// Use it with custom resource types other than the
// standard RT_CURSOR, RT_BITMAP, etc.
class CResource
{
public:
HGLOBAL m_hGlobal;
HRSRC m_hResource;
// Constructor/destructor
CResource() : m_hGlobal(NULL), m_hResource(NULL)
{ }
~CResource()
{
Release();
}
// Load methods
bool Load(ATL::_U_STRINGorID Type, ATL::_U_STRINGorID ID)
{
ATLASSERT(m_hResource == NULL);
ATLASSERT(m_hGlobal == NULL);
#if (_ATL_VER >= 0x0700)
m_hResource = ::FindResource(ATL::_AtlBaseModule.GetResourceInstance(), ID.m_lpstr, Type.m_lpstr);
#else // !(_ATL_VER >= 0x0700)
m_hResource = ::FindResource(ATL::_pModule->GetResourceInstance(), ID.m_lpstr, Type.m_lpstr);
#endif // !(_ATL_VER >= 0x0700)
if(m_hResource == NULL)
return false;
#if (_ATL_VER >= 0x0700)
m_hGlobal = ::LoadResource(ATL::_AtlBaseModule.GetResourceInstance(), m_hResource);
#else // !(_ATL_VER >= 0x0700)
m_hGlobal = ::LoadResource(ATL::_pModule->GetResourceInstance(), m_hResource);
#endif // !(_ATL_VER >= 0x0700)
if(m_hGlobal == NULL)
{
m_hResource = NULL;
return false;
}
return true;
}
#ifndef _WIN32_WCE
bool LoadEx(ATL::_U_STRINGorID Type, ATL::_U_STRINGorID ID, WORD wLanguage)
{
ATLASSERT(m_hResource == NULL);
ATLASSERT(m_hGlobal == NULL);
#if (_ATL_VER >= 0x0700)
m_hResource = ::FindResourceEx(ATL::_AtlBaseModule.GetResourceInstance(), ID.m_lpstr, Type.m_lpstr, wLanguage);
#else // !(_ATL_VER >= 0x0700)
m_hResource = ::FindResourceEx(ATL::_pModule->GetResourceInstance(), ID.m_lpstr, Type.m_lpstr, wLanguage);
#endif // !(_ATL_VER >= 0x0700)
if(m_hResource == NULL)
return false;
#if (_ATL_VER >= 0x0700)
m_hGlobal = ::LoadResource(ATL::_AtlBaseModule.GetResourceInstance(), m_hResource);
#else // !(_ATL_VER >= 0x0700)
m_hGlobal = ::LoadResource(ATL::_pModule->GetResourceInstance(), m_hResource);
#endif // !(_ATL_VER >= 0x0700)
if(m_hGlobal == NULL)
{
m_hResource = NULL;
return false;
}
return true;
}
#endif // !_WIN32_WCE
// Misc. operations
DWORD GetSize() const
{
ATLASSERT(m_hResource != NULL);
#if (_ATL_VER >= 0x0700)
return ::SizeofResource(ATL::_AtlBaseModule.GetResourceInstance(), m_hResource);
#else // !(_ATL_VER >= 0x0700)
return ::SizeofResource(ATL::_pModule->GetResourceInstance(), m_hResource);
#endif // !(_ATL_VER >= 0x0700)
}
LPVOID Lock()
{
ATLASSERT(m_hResource != NULL);
ATLASSERT(m_hGlobal != NULL);
LPVOID pVoid = ::LockResource(m_hGlobal);
ATLASSERT(pVoid != NULL);
return pVoid;
}
void Release()
{
if(m_hGlobal != NULL)
{
FreeResource(m_hGlobal);
m_hGlobal = NULL;
m_hResource = NULL;
}
}
};
}; // namespace WTL
#endif // __ATLUSER_H__
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -