?? atlctrls.h
字號:
// Windows Template Library - WTL version 7.0
// Copyright (C) 1997-2002 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 __ATLCTRLS_H__
#define __ATLCTRLS_H__
#pragma once
#ifndef __cplusplus
#error ATL requires C++ compilation (use a .cpp suffix)
#endif
#ifndef __ATLAPP_H__
#error atlctrls.h requires atlapp.h to be included first
#endif
#ifndef __ATLWIN_H__
#error atlctrls.h requires atlwin.h to be included first
#endif
#if (_WIN32_IE < 0x0300)
#error atlctrls.h requires IE Version 3.0 or higher
#endif
#include <richedit.h>
#include <richole.h>
// protect template members from windowsx.h macros
#ifdef _INC_WINDOWSX
#undef GetNextSibling
#undef GetPrevSibling
#endif //_INC_WINDOWSX
/////////////////////////////////////////////////////////////////////////////
// Classes in this file
//
// CStaticT<TBase>
// CButtonT<TBase>
// CListBoxT<TBase>
// CComboBoxT<TBase>
// CEditT<TBase>
// CEditCommands<T>
// CScrollBarT<TBase>
//
// CImageList
// CListViewCtrlT<TBase>
// CTreeViewCtrlT<TBase>
// CTreeItem
// CTreeViewCtrlExT<TBase>
// CHeaderCtrlT<TBase>
// CToolBarCtrlT<TBase>
// CStatusBarCtrlT<TBase>
// CTabCtrlT<TBase>
// CToolInfo
// CToolTipCtrlT<TBase>
// CTrackBarCtrlT<TBase>
// CUpDownCtrlT<TBase>
// CProgressBarCtrlT<TBase>
// CHotKeyCtrlT<TBase>
// CAnimateCtrlT<TBase>
// CRichEditCtrlT<TBase>
// CRichEditCommands<T>
// CDragListBoxT<TBase>
// CDragListNotifyImpl<T>
// CReBarCtrlT<TBase>
// CComboBoxExT<TBase>
// CDateTimePickerCtrlT<TBase>
// CMonthCalendarCtrlT<TBase>
// CFlatScrollBarImpl<T>
// CFlatScrollBarT<TBase>
// CIPAddressCtrlT<TBase>
// CPagerCtrlT<TBase>
// CLinkCtrlT<TBase>
//
// CCustomDraw<T>
namespace WTL
{
// These are wrapper classes for Windows standard and common controls.
// To implement a window based on a control, use following:
// Example: Implementing a window based on a list box
//
// class CMyListBox : CWindowImpl<CMyListBox, CListBox>
// {
// public:
// BEGIN_MSG_MAP(CMyListBox)
// // put your message handler entries here
// END_MSG_MAP()
// };
// --- Standard Windows controls ---
/////////////////////////////////////////////////////////////////////////////
// CStatic - client side for a Windows STATIC control
template <class TBase>
class CStaticT : public TBase
{
public:
// Constructors
CStaticT(HWND hWnd = NULL) : TBase(hWnd) { }
CStaticT< TBase >& operator=(HWND hWnd)
{
m_hWnd = hWnd;
return *this;
}
HWND Create(HWND hWndParent, _U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
DWORD dwStyle = 0, DWORD dwExStyle = 0,
_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
{
return CWindow::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
}
// Attributes
static LPCTSTR GetWndClassName()
{
return _T("STATIC");
}
HICON GetIcon() const
{
ATLASSERT(::IsWindow(m_hWnd));
return (HICON)::SendMessage(m_hWnd, STM_GETICON, 0, 0L);
}
HICON SetIcon(HICON hIcon)
{
ATLASSERT(::IsWindow(m_hWnd));
return (HICON)::SendMessage(m_hWnd, STM_SETICON, (WPARAM)hIcon, 0L);
}
HENHMETAFILE GetEnhMetaFile() const
{
ATLASSERT(::IsWindow(m_hWnd));
return (HENHMETAFILE)::SendMessage(m_hWnd, STM_GETIMAGE, IMAGE_ENHMETAFILE, 0L);
}
HENHMETAFILE SetEnhMetaFile(HENHMETAFILE hMetaFile)
{
ATLASSERT(::IsWindow(m_hWnd));
return (HENHMETAFILE)::SendMessage(m_hWnd, STM_SETIMAGE, IMAGE_ENHMETAFILE, (LPARAM)hMetaFile);
}
CBitmapHandle GetBitmap() const
{
ATLASSERT(::IsWindow(m_hWnd));
return CBitmapHandle((HBITMAP)::SendMessage(m_hWnd, STM_GETIMAGE, IMAGE_BITMAP, 0L));
}
CBitmapHandle SetBitmap(HBITMAP hBitmap)
{
ATLASSERT(::IsWindow(m_hWnd));
return CBitmapHandle((HBITMAP)::SendMessage(m_hWnd, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBitmap));
}
HCURSOR GetCursor() const
{
ATLASSERT(::IsWindow(m_hWnd));
return (HCURSOR)::SendMessage(m_hWnd, STM_GETIMAGE, IMAGE_CURSOR, 0L);
}
HCURSOR SetCursor(HCURSOR hCursor)
{
ATLASSERT(::IsWindow(m_hWnd));
return (HCURSOR)::SendMessage(m_hWnd, STM_SETIMAGE, IMAGE_CURSOR, (LPARAM)hCursor);
}
};
typedef CStaticT<CWindow> CStatic;
/////////////////////////////////////////////////////////////////////////////
// CButton - client side for a Windows BUTTON control
template <class TBase>
class CButtonT : public TBase
{
public:
// Constructors
CButtonT(HWND hWnd = NULL) : TBase(hWnd) { }
CButtonT< TBase >& operator=(HWND hWnd)
{
m_hWnd = hWnd;
return *this;
}
HWND Create(HWND hWndParent, _U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
DWORD dwStyle = 0, DWORD dwExStyle = 0,
_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
{
return CWindow::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
}
// Attributes
static LPCTSTR GetWndClassName()
{
return _T("BUTTON");
}
UINT GetState() const
{
ATLASSERT(::IsWindow(m_hWnd));
return (UINT)::SendMessage(m_hWnd, BM_GETSTATE, 0, 0L);
}
void SetState(BOOL bHighlight)
{
ATLASSERT(::IsWindow(m_hWnd));
::SendMessage(m_hWnd, BM_SETSTATE, bHighlight, 0L);
}
int GetCheck() const
{
ATLASSERT(::IsWindow(m_hWnd));
return (int)::SendMessage(m_hWnd, BM_GETCHECK, 0, 0L);
}
void SetCheck(int nCheck)
{
ATLASSERT(::IsWindow(m_hWnd));
::SendMessage(m_hWnd, BM_SETCHECK, nCheck, 0L);
}
UINT GetButtonStyle() const
{
ATLASSERT(::IsWindow(m_hWnd));
return (UINT)::GetWindowLong(m_hWnd, GWL_STYLE) & 0xff;
}
void SetButtonStyle(UINT nStyle, BOOL bRedraw = TRUE)
{
ATLASSERT(::IsWindow(m_hWnd));
::SendMessage(m_hWnd, BM_SETSTYLE, nStyle, (LPARAM)bRedraw);
}
HICON GetIcon() const
{
ATLASSERT(::IsWindow(m_hWnd));
return (HICON)::SendMessage(m_hWnd, BM_GETIMAGE, IMAGE_ICON, 0L);
}
HICON SetIcon(HICON hIcon)
{
ATLASSERT(::IsWindow(m_hWnd));
return (HICON)::SendMessage(m_hWnd, BM_SETIMAGE, IMAGE_ICON, (LPARAM)hIcon);
}
CBitmapHandle GetBitmap() const
{
ATLASSERT(::IsWindow(m_hWnd));
return CBitmapHandle((HBITMAP)::SendMessage(m_hWnd, BM_GETIMAGE, IMAGE_BITMAP, 0L));
}
CBitmapHandle SetBitmap(HBITMAP hBitmap)
{
ATLASSERT(::IsWindow(m_hWnd));
return CBitmapHandle((HBITMAP)::SendMessage(m_hWnd, BM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBitmap));
}
#if (_WIN32_WINNT >= 0x0501)
BOOL GetIdealSize(LPSIZE lpSize) const
{
ATLASSERT(::IsWindow(m_hWnd));
return (BOOL)::SendMessage(m_hWnd, BCM_GETIDEALSIZE, 0, (LPARAM)lpSize);
}
BOOL GetImageList(PBUTTON_IMAGELIST pButtonImagelist) const
{
ATLASSERT(::IsWindow(m_hWnd));
return (BOOL)::SendMessage(m_hWnd, BCM_GETIMAGELIST, 0, (LPARAM)pButtonImagelist);
}
BOOL SetImageList(PBUTTON_IMAGELIST pButtonImagelist)
{
ATLASSERT(::IsWindow(m_hWnd));
return (BOOL)::SendMessage(m_hWnd, BCM_SETIMAGELIST, 0, (LPARAM)pButtonImagelist);
}
BOOL GetTextMargin(LPRECT lpRect) const
{
ATLASSERT(::IsWindow(m_hWnd));
return (BOOL)::SendMessage(m_hWnd, BCM_GETTEXTMARGIN, 0, (LPARAM)lpRect);
}
BOOL SetTextMargin(LPRECT lpRect)
{
ATLASSERT(::IsWindow(m_hWnd));
return (BOOL)::SendMessage(m_hWnd, BCM_SETTEXTMARGIN, 0, (LPARAM)lpRect);
}
#endif //(_WIN32_WINNT >= 0x0501)
// Operations
void Click()
{
ATLASSERT(::IsWindow(m_hWnd));
::SendMessage(m_hWnd, BM_CLICK, 0, 0L);
}
};
typedef CButtonT<CWindow> CButton;
/////////////////////////////////////////////////////////////////////////////
// CListBox - client side for a Windows LISTBOX control
template <class TBase>
class CListBoxT : public TBase
{
public:
// Constructors
CListBoxT(HWND hWnd = NULL) : TBase(hWnd) { }
CListBoxT< TBase >& operator=(HWND hWnd)
{
m_hWnd = hWnd;
return *this;
}
HWND Create(HWND hWndParent, _U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
DWORD dwStyle = 0, DWORD dwExStyle = 0,
_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
{
return CWindow::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
}
// Attributes
static LPCTSTR GetWndClassName()
{
return _T("LISTBOX");
}
// for entire listbox
int GetCount() const
{
ATLASSERT(::IsWindow(m_hWnd));
return (int)::SendMessage(m_hWnd, LB_GETCOUNT, 0, 0L);
}
int SetCount(int cItems)
{
ATLASSERT(::IsWindow(m_hWnd));
ATLASSERT(((GetStyle() & LBS_NODATA) != 0) && ((GetStyle() & LBS_HASSTRINGS) == 0));
return (int)::SendMessage(m_hWnd, LB_SETCOUNT, cItems, 0L);
}
int GetHorizontalExtent() const
{
ATLASSERT(::IsWindow(m_hWnd));
return (int)::SendMessage(m_hWnd, LB_GETHORIZONTALEXTENT, 0, 0L);
}
void SetHorizontalExtent(int cxExtent)
{
ATLASSERT(::IsWindow(m_hWnd));
::SendMessage(m_hWnd, LB_SETHORIZONTALEXTENT, cxExtent, 0L);
}
int GetTopIndex() const
{
ATLASSERT(::IsWindow(m_hWnd));
return (int)::SendMessage(m_hWnd, LB_GETTOPINDEX, 0, 0L);
}
int SetTopIndex(int nIndex)
{
ATLASSERT(::IsWindow(m_hWnd));
return (int)::SendMessage(m_hWnd, LB_SETTOPINDEX, nIndex, 0L);
}
LCID GetLocale() const
{
ATLASSERT(::IsWindow(m_hWnd));
return (LCID)::SendMessage(m_hWnd, LB_GETLOCALE, 0, 0L);
}
LCID SetLocale(LCID nNewLocale)
{
ATLASSERT(::IsWindow(m_hWnd));
return (LCID)::SendMessage(m_hWnd, LB_SETLOCALE, (WPARAM)nNewLocale, 0L);
}
#if (WINVER >= 0x0500)
DWORD GetListBoxInfo() const
{
ATLASSERT(::IsWindow(m_hWnd));
#if (_WIN32_WINNT >= 0x0501)
return (DWORD)::SendMessage(m_hWnd, LB_GETLISTBOXINFO, 0, 0L);
#else //!(_WIN32_WINNT >= 0x0501)
return ::GetListBoxInfo(m_hWnd);
#endif //!(_WIN32_WINNT >= 0x0501)
}
#endif //(WINVER >= 0x0500)
// for single-selection listboxes
int GetCurSel() const
{
ATLASSERT(::IsWindow(m_hWnd));
ATLASSERT((GetStyle() & (LBS_MULTIPLESEL | LBS_EXTENDEDSEL)) == 0);
return (int)::SendMessage(m_hWnd, LB_GETCURSEL, 0, 0L);
}
int SetCurSel(int nSelect)
{
ATLASSERT(::IsWindow(m_hWnd));
ATLASSERT((GetStyle() & (LBS_MULTIPLESEL | LBS_EXTENDEDSEL)) == 0);
return (int)::SendMessage(m_hWnd, LB_SETCURSEL, nSelect, 0L);
}
// for multiple-selection listboxes
int GetSel(int nIndex) const // also works for single-selection
{
ATLASSERT(::IsWindow(m_hWnd));
return (int)::SendMessage(m_hWnd, LB_GETSEL, nIndex, 0L);
}
int SetSel(int nIndex, BOOL bSelect = TRUE)
{
ATLASSERT(::IsWindow(m_hWnd));
ATLASSERT((GetStyle() & (LBS_MULTIPLESEL | LBS_EXTENDEDSEL)) != 0);
return (int)::SendMessage(m_hWnd, LB_SETSEL, bSelect, nIndex);
}
int GetSelCount() const
{
ATLASSERT(::IsWindow(m_hWnd));
ATLASSERT((GetStyle() & (LBS_MULTIPLESEL | LBS_EXTENDEDSEL)) != 0);
return (int)::SendMessage(m_hWnd, LB_GETSELCOUNT, 0, 0L);
}
int GetSelItems(int nMaxItems, LPINT rgIndex) const
{
ATLASSERT(::IsWindow(m_hWnd));
ATLASSERT((GetStyle() & (LBS_MULTIPLESEL | LBS_EXTENDEDSEL)) != 0);
return (int)::SendMessage(m_hWnd, LB_GETSELITEMS, nMaxItems, (LPARAM)rgIndex);
}
int GetAnchorIndex() const
{
ATLASSERT(::IsWindow(m_hWnd));
ATLASSERT((GetStyle() & (LBS_MULTIPLESEL | LBS_EXTENDEDSEL)) != 0);
return (int)::SendMessage(m_hWnd, LB_GETANCHORINDEX, 0, 0L);
}
void SetAnchorIndex(int nIndex)
{
ATLASSERT(::IsWindow(m_hWnd));
ATLASSERT((GetStyle() & (LBS_MULTIPLESEL | LBS_EXTENDEDSEL)) != 0);
::SendMessage(m_hWnd, LB_SETANCHORINDEX, nIndex, 0L);
}
int GetCaretIndex() const
{
ATLASSERT(::IsWindow(m_hWnd));
return (int)::SendMessage(m_hWnd, LB_GETCARETINDEX, 0, 0);
}
int SetCaretIndex(int nIndex, BOOL bScroll = TRUE)
{
ATLASSERT(::IsWindow(m_hWnd));
return (int)::SendMessage(m_hWnd, LB_SETCARETINDEX, nIndex, MAKELONG(bScroll, 0));
}
// for listbox items
DWORD_PTR GetItemData(int nIndex) const
{
ATLASSERT(::IsWindow(m_hWnd));
return (DWORD_PTR)::SendMessage(m_hWnd, LB_GETITEMDATA, nIndex, 0L);
}
int SetItemData(int nIndex, DWORD_PTR dwItemData)
{
ATLASSERT(::IsWindow(m_hWnd));
return (int)::SendMessage(m_hWnd, LB_SETITEMDATA, nIndex, (LPARAM)dwItemData);
}
void* GetItemDataPtr(int nIndex) const
{
ATLASSERT(::IsWindow(m_hWnd));
return (void*)::SendMessage(m_hWnd, LB_GETITEMDATA, nIndex, 0L);
}
int SetItemDataPtr(int nIndex, void* pData)
{
ATLASSERT(::IsWindow(m_hWnd));
return SetItemData(nIndex, (DWORD_PTR)pData);
}
int GetItemRect(int nIndex, LPRECT lpRect) const
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -