📄 atlctrls.h
字号:
BOOL Destroy()
{
if (m_hImageList == NULL)
return FALSE;
BOOL bRet = ImageList_Destroy(m_hImageList);
if(bRet)
m_hImageList = NULL;
return bRet;
}
int Add(HBITMAP hBitmap, HBITMAP hBitmapMask = NULL)
{
ATLASSERT(m_hImageList != NULL);
return ImageList_Add(m_hImageList, hBitmap, hBitmapMask);
}
int Add(HBITMAP hBitmap, COLORREF crMask)
{
ATLASSERT(m_hImageList != NULL);
return ImageList_AddMasked(m_hImageList, hBitmap, crMask);
}
BOOL Remove(int nImage)
{
ATLASSERT(m_hImageList != NULL);
return ImageList_Remove(m_hImageList, nImage);
}
BOOL RemoveAll()
{
ATLASSERT(m_hImageList != NULL);
return ImageList_RemoveAll(m_hImageList);
}
BOOL Replace(int nImage, HBITMAP hBitmap, HBITMAP hBitmapMask)
{
ATLASSERT(m_hImageList != NULL);
return ImageList_Replace(m_hImageList, nImage, hBitmap, hBitmapMask);
}
int AddIcon(HICON hIcon)
{
ATLASSERT(m_hImageList != NULL);
return ImageList_AddIcon(m_hImageList, hIcon);
}
int ReplaceIcon(int nImage, HICON hIcon)
{
ATLASSERT(m_hImageList != NULL);
return ImageList_ReplaceIcon(m_hImageList, nImage, hIcon);
}
HICON ExtractIcon(int nImage)
{
ATLASSERT(m_hImageList != NULL);
return ImageList_ExtractIcon(NULL, m_hImageList, nImage);
}
BOOL Draw(HDC hDC, int nImage, int x, int y, UINT nStyle)
{
ATLASSERT(m_hImageList != NULL);
ATLASSERT(hDC != NULL);
return ImageList_Draw(m_hImageList, nImage, hDC, x, y, nStyle);
}
BOOL Draw(HDC hDC, int nImage, POINT pt, UINT nStyle)
{
ATLASSERT(m_hImageList != NULL);
ATLASSERT(hDC != NULL);
return ImageList_Draw(m_hImageList, nImage, hDC, pt.x, pt.y, nStyle);
}
BOOL DrawEx(int nImage, HDC hDC, int x, int y, int dx, int dy, COLORREF rgbBk, COLORREF rgbFg, UINT fStyle)
{
ATLASSERT(m_hImageList != NULL);
ATLASSERT(hDC != NULL);
return ImageList_DrawEx(m_hImageList, nImage, hDC, x, y, dx, dy, rgbBk, rgbFg, fStyle);
}
BOOL DrawEx(int nImage, HDC hDC, RECT& rect, COLORREF rgbBk, COLORREF rgbFg, UINT fStyle)
{
ATLASSERT(m_hImageList != NULL);
ATLASSERT(hDC != NULL);
return ImageList_DrawEx(m_hImageList, nImage, hDC, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, rgbBk, rgbFg, fStyle);
}
static BOOL DrawIndirect(IMAGELISTDRAWPARAMS* pimldp)
{
return ImageList_DrawIndirect(pimldp);
}
BOOL Copy(int nSrc, int nDst, UINT uFlags = ILCF_MOVE)
{
ATLASSERT(m_hImageList != NULL);
return ImageList_Copy(m_hImageList, nDst, m_hImageList, nSrc, uFlags);
}
#ifdef __IStream_INTERFACE_DEFINED__
#ifndef _WIN32_WCE
static HIMAGELIST Read(LPSTREAM lpStream)
{
return ImageList_Read(lpStream);
}
BOOL Write(LPSTREAM lpStream)
{
ATLASSERT(m_hImageList != NULL);
return ImageList_Write(m_hImageList, lpStream);
}
#endif // !_WIN32_WCE
#if (_WIN32_WINNT >= 0x0501)
static HRESULT ReadEx(DWORD dwFlags, LPSTREAM lpStream, REFIID riid, PVOID* ppv)
{
return ImageList_ReadEx(dwFlags, lpStream, riid, ppv);
}
HRESULT WriteEx(DWORD dwFlags, LPSTREAM lpStream)
{
ATLASSERT(m_hImageList != NULL);
return ImageList_WriteEx(m_hImageList, dwFlags, lpStream);
}
#endif // (_WIN32_WINNT >= 0x0501)
#endif // __IStream_INTERFACE_DEFINED__
// Drag operations
BOOL BeginDrag(int nImage, POINT ptHotSpot)
{
ATLASSERT(m_hImageList != NULL);
return ImageList_BeginDrag(m_hImageList, nImage, ptHotSpot.x, ptHotSpot.y);
}
BOOL BeginDrag(int nImage, int xHotSpot, int yHotSpot)
{
ATLASSERT(m_hImageList != NULL);
return ImageList_BeginDrag(m_hImageList, nImage, xHotSpot, yHotSpot);
}
static void EndDrag()
{
ImageList_EndDrag();
}
static BOOL DragMove(POINT pt)
{
return ImageList_DragMove(pt.x, pt.y);
}
static BOOL DragMove(int x, int y)
{
return ImageList_DragMove(x, y);
}
BOOL SetDragCursorImage(int nDrag, POINT ptHotSpot)
{
ATLASSERT(m_hImageList != NULL);
return ImageList_SetDragCursorImage(m_hImageList, nDrag, ptHotSpot.x, ptHotSpot.y);
}
BOOL SetDragCursorImage(int nDrag, int xHotSpot, int yHotSpot)
{
ATLASSERT(m_hImageList != NULL);
return ImageList_SetDragCursorImage(m_hImageList, nDrag, xHotSpot, yHotSpot);
}
static BOOL DragShowNolock(BOOL bShow = TRUE)
{
return ImageList_DragShowNolock(bShow);
}
static CImageList GetDragImage(LPPOINT lpPoint, LPPOINT lpPointHotSpot)
{
return CImageList(ImageList_GetDragImage(lpPoint, lpPointHotSpot));
}
static BOOL DragEnter(HWND hWnd, POINT point)
{
return ImageList_DragEnter(hWnd, point.x, point.y);
}
static BOOL DragEnter(HWND hWnd, int x, int y)
{
return ImageList_DragEnter(hWnd, x, y);
}
static BOOL DragLeave(HWND hWnd)
{
return ImageList_DragLeave(hWnd);
}
#if (_WIN32_IE >= 0x0400)
CImageList Duplicate() const
{
ATLASSERT(m_hImageList != NULL);
return CImageList(ImageList_Duplicate(m_hImageList));
}
static CImageList Duplicate(HIMAGELIST hImageList)
{
ATLASSERT(hImageList != NULL);
return CImageList(ImageList_Duplicate(hImageList));
}
#endif // (_WIN32_IE >= 0x0400)
};
///////////////////////////////////////////////////////////////////////////////
// CToolTipCtrl
#ifndef _WIN32_WCE
class CToolInfo : public TOOLINFO
{
public:
CToolInfo(UINT nFlags, HWND hWnd, UINT nIDTool = 0, LPRECT lpRect = NULL, LPTSTR lpstrText = LPSTR_TEXTCALLBACK, LPARAM lUserParam = NULL)
{
Init(nFlags, hWnd, nIDTool, lpRect, lpstrText, lUserParam);
}
operator LPTOOLINFO() { return this; }
operator LPARAM() { return (LPARAM)this; }
void Init(UINT nFlags, HWND hWnd, UINT nIDTool = 0, LPRECT lpRect = NULL, LPTSTR lpstrText = LPSTR_TEXTCALLBACK, LPARAM lUserParam = NULL)
{
ATLASSERT(::IsWindow(hWnd));
memset(this, 0, sizeof(TOOLINFO));
cbSize = sizeof(TOOLINFO);
uFlags = nFlags;
if(nIDTool == 0)
{
hwnd = ::GetParent(hWnd);
uFlags |= TTF_IDISHWND;
uId = (UINT_PTR)hWnd;
}
else
{
hwnd = hWnd;
uId = nIDTool;
}
if(lpRect != NULL)
rect = *lpRect;
hinst = ModuleHelper::GetResourceInstance();
lpszText = lpstrText;
lParam = lUserParam;
}
};
template <class TBase>
class CToolTipCtrlT : public TBase
{
public:
// Constructors
CToolTipCtrlT(HWND hWnd = NULL) : TBase(hWnd)
{ }
CToolTipCtrlT< TBase >& operator =(HWND hWnd)
{
m_hWnd = hWnd;
return *this;
}
HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
DWORD dwStyle = 0, DWORD dwExStyle = 0,
ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
{
return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
}
// Attributes
static LPCTSTR GetWndClassName()
{
return TOOLTIPS_CLASS;
}
void GetText(LPTOOLINFO lpToolInfo) const
{
ATLASSERT(::IsWindow(m_hWnd));
::SendMessage(m_hWnd, TTM_GETTEXT, 0, (LPARAM)&lpToolInfo);
}
void GetText(LPTSTR lpstrText, HWND hWnd, UINT nIDTool = 0) const
{
ATLASSERT(::IsWindow(m_hWnd));
ATLASSERT(hWnd != NULL);
CToolInfo ti(0, hWnd, nIDTool, NULL, lpstrText);
::SendMessage(m_hWnd, TTM_GETTEXT, 0, ti);
}
BOOL GetToolInfo(LPTOOLINFO lpToolInfo) const
{
ATLASSERT(::IsWindow(m_hWnd));
return (BOOL)::SendMessage(m_hWnd, TTM_GETTOOLINFO, 0, (LPARAM)lpToolInfo);
}
BOOL GetToolInfo(HWND hWnd, UINT nIDTool, UINT* puFlags, LPRECT lpRect, LPTSTR lpstrText) const
{
ATLASSERT(::IsWindow(m_hWnd));
ATLASSERT(hWnd != NULL);
ATLASSERT(puFlags != NULL);
ATLASSERT(lpRect != NULL);
CToolInfo ti(0, hWnd, nIDTool, NULL, lpstrText);
BOOL bRet = (BOOL)::SendMessage(m_hWnd, TTM_GETTOOLINFO, 0, ti);
if(bRet != FALSE)
{
*puFlags = ti.uFlags;
*lpRect = ti.rect;
}
return bRet;
}
void SetToolInfo(LPTOOLINFO lpToolInfo)
{
ATLASSERT(::IsWindow(m_hWnd));
::SendMessage(m_hWnd, TTM_SETTOOLINFO, 0, (LPARAM)lpToolInfo);
}
void SetToolRect(LPTOOLINFO lpToolInfo)
{
ATLASSERT(::IsWindow(m_hWnd));
::SendMessage(m_hWnd, TTM_NEWTOOLRECT, 0, (LPARAM)lpToolInfo);
}
void SetToolRect(HWND hWnd, UINT nIDTool, LPCRECT lpRect)
{
ATLASSERT(::IsWindow(m_hWnd));
ATLASSERT(hWnd != NULL);
ATLASSERT(nIDTool != 0);
CToolInfo ti(0, hWnd, nIDTool, (LPRECT)lpRect, NULL);
::SendMessage(m_hWnd, TTM_NEWTOOLRECT, 0, ti);
}
int GetToolCount() const
{
ATLASSERT(::IsWindow(m_hWnd));
return (int)::SendMessage(m_hWnd, TTM_GETTOOLCOUNT, 0, 0L);
}
int GetDelayTime(DWORD dwType) const
{
ATLASSERT(::IsWindow(m_hWnd));
return (int)::SendMessage(m_hWnd, TTM_GETDELAYTIME, dwType, 0L);
}
void SetDelayTime(DWORD dwType, int nTime)
{
ATLASSERT(::IsWindow(m_hWnd));
::SendMessage(m_hWnd, TTM_SETDELAYTIME, dwType, MAKELPARAM(nTime, 0));
}
void GetMargin(LPRECT lpRect) const
{
ATLASSERT(::IsWindow(m_hWnd));
::SendMessage(m_hWnd, TTM_GETMARGIN, 0, (LPARAM)lpRect);
}
void SetMargin(LPRECT lpRect)
{
ATLASSERT(::IsWindow(m_hWnd));
::SendMessage(m_hWnd, TTM_SETMARGIN, 0, (LPARAM)lpRect);
}
int GetMaxTipWidth() const
{
ATLASSERT(::IsWindow(m_hWnd));
return (int)::SendMessage(m_hWnd, TTM_GETMAXTIPWIDTH, 0, 0L);
}
int SetMaxTipWidth(int nWidth)
{
ATLASSERT(::IsWindow(m_hWnd));
return (int)::SendMessage(m_hWnd, TTM_SETMAXTIPWIDTH, 0, nWidth);
}
COLORREF GetTipBkColor() const
{
ATLASSERT(::IsWindow(m_hWnd));
return (COLORREF)::SendMessage(m_hWnd, TTM_GETTIPBKCOLOR, 0, 0L);
}
void SetTipBkColor(COLORREF clr)
{
ATLASSERT(::IsWindow(m_hWnd));
::SendMessage(m_hWnd, TTM_SETTIPBKCOLOR, (WPARAM)clr, 0L);
}
COLORREF GetTipTextColor() const
{
ATLASSERT(::IsWindow(m_hWnd));
return (COLORREF)::SendMessage(m_hWnd, TTM_GETTIPTEXTCOLOR, 0, 0L);
}
void SetTipTextColor(COLORREF clr)
{
ATLASSERT(::IsWindow(m_hWnd));
::SendMessage(m_hWnd, TTM_SETTIPTEXTCOLOR, (WPARAM)clr, 0L);
}
BOOL GetCurrentTool(LPTOOLINFO lpToolInfo) const
{
ATLASSERT(::IsWindow(m_hWnd));
return (BOOL)::SendMessage(m_hWnd, TTM_GETCURRENTTOOL, 0, (LPARAM)lpToolInfo);
}
#if (_WIN32_IE >= 0x0500)
SIZE GetBubbleSize(LPTOOLINFO lpToolInfo) const
{
ATLASSERT(::IsWindow(m_hWnd));
DWORD dwRet = (DWORD)::SendMessage(m_hWnd, TTM_GETBUBBLESIZE, 0, (LPARAM)lpToolInfo);
SIZE size = { GET_X_LPARAM(dwRet), GET_Y_LPARAM(dwRet) };
return size;
}
BOOL SetTitle(UINT uIcon, LPCTSTR lpstrTitle)
{
ATLASSERT(::IsWindow(m_hWnd));
return (BOOL)::SendMessage(m_hWnd, TTM_SETTITLE, uIcon, (LPARAM)lpstrTitle);
}
#endif // (_WIN32_IE >= 0x0500)
#if (_WIN32_WINNT >= 0x0501)
void GetTitle(PTTGETTITLE pTTGetTitle) const
{
ATLASSERT(::IsWindow(m_hWnd));
::SendMessage(m_hWnd, TTM_GETTITLE, 0, (LPARAM)pTTGetTitle);
}
void SetWindowTheme(LPCWSTR lpstrTheme)
{
ATLASSERT(::IsWindow(m_hWnd));
::SendMessage(m_hWnd, TTM_SETWINDOWTHEME, 0, (LPARAM)lpstrTheme);
}
#endif // (_WIN32_WINNT >= 0x0501)
// Operations
void Activate(BOOL bActivate)
{
ATLASSERT(::IsWindow(m_hWnd));
::SendMessage(m_hWnd, TTM_ACTIVATE, bActivate, 0L);
}
BOOL AddTool(LPTOOLINFO lpToolInfo)
{
ATLASSERT(::IsWindow(m_hWnd));
return (BOOL)::SendMessage(m_hWnd, TTM_ADDTOOL, 0, (LPARAM)lpToolInfo);
}
BOOL AddTool(HWND hWnd, ATL::_U_STRINGorID text = LPSTR_TEXTCALLBACK, LPCRECT lpRectTool = NULL, UINT nIDTool = 0)
{
ATLASSERT(::IsWindow(m_hWnd));
ATLASSERT(hWnd != NULL);
// the toolrect and toolid must both be zero or both valid
ATLASSERT((lpRectTool != NULL && nIDTool != 0) || (lpRectTool == NULL && nIDTool == 0));
CToolInfo ti(0, hWnd, nIDTool, (LPRECT)lpRectTool, (LPTSTR)text.m_lpstr);
return (BOOL)::SendMessage(m_hWnd, TTM_ADDTOOL, 0, ti);
}
void DelTool(LPTOOLINFO lpToolInfo)
{
ATLASSERT(::IsWindow(m_hWnd));
::SendMessage(m_hWnd, TTM_DELTOOL, 0, (LPARAM)lpToolInfo);
}
void DelTool(HWND hWnd, UINT nIDTool = 0)
{
ATLASSERT(::IsWindow(m_hWnd));
ATLASSERT(hWnd != NULL);
CToolInfo ti(0, hWnd, nIDTool, NULL, NULL);
::SendMessage(m_hWnd, TTM_DELTOOL, 0, ti);
}
BOOL HitTest(LPTTHITTESTINFO lpHitTestInfo) const
{
ATLASSERT(::IsWindow(m_hWnd));
return (BOOL)::SendMessage(m_hWnd, TTM_HITTEST, 0, (LPARAM)lpHitTestInfo);
}
BOOL HitTest(HWND hWnd, POINT pt, LPTOOLINFO lpToolInfo) const
{
ATLASSERT(::IsWindow(m_hWnd));
ATLASSERT(hWnd != NULL);
ATLASSERT(lpToolInfo != NULL);
TTHITTESTINFO hti = { 0 };
hti.ti.cbSize = sizeof(TOOLINFO);
hti.hwnd = hWnd;
hti.pt.x = pt.x;
hti.pt.y = pt.y;
if((BOOL)::SendMessage(m_hWnd, TTM_HITTEST, 0, (LPARAM)&hti) != FALSE)
{
*lpToolInfo = hti.ti;
return TRUE;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -