📄 atlctrls.h
字号:
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
{
ATLASSERT(::IsWindow(m_hWnd));
return (int)::SendMessage(m_hWnd, LB_GETITEMRECT, nIndex, (LPARAM)lpRect);
}
int GetText(int nIndex, LPTSTR lpszBuffer) const
{
ATLASSERT(::IsWindow(m_hWnd));
return (int)::SendMessage(m_hWnd, LB_GETTEXT, nIndex, (LPARAM)lpszBuffer);
}
#ifndef _ATL_NO_COM
#ifdef _OLEAUTO_H_
BOOL GetTextBSTR(int nIndex, BSTR& bstrText) const
{
USES_CONVERSION;
ATLASSERT(::IsWindow(m_hWnd));
ATLASSERT(bstrText == NULL);
int nLen = GetTextLen(nIndex);
if(nLen == LB_ERR)
return FALSE;
CTempBuffer<TCHAR, _WTL_STACK_ALLOC_THRESHOLD> buff;
LPTSTR lpstrText = buff.Allocate(nLen + 1);
if(lpstrText == NULL)
return FALSE;
if(GetText(nIndex, lpstrText) == LB_ERR)
return FALSE;
bstrText = ::SysAllocString(T2OLE(lpstrText));
return (bstrText != NULL) ? TRUE : FALSE;
}
#endif // _OLEAUTO_H_
#endif // !_ATL_NO_COM
#if defined(_WTL_USE_CSTRING) || defined(__ATLSTR_H__)
int GetText(int nIndex, _CSTRING_NS::CString& strText) const
{
ATLASSERT(::IsWindow(m_hWnd));
int cchLen = GetTextLen(nIndex);
if(cchLen == LB_ERR)
return LB_ERR;
int nRet = LB_ERR;
LPTSTR lpstr = strText.GetBufferSetLength(cchLen);
if(lpstr != NULL)
{
nRet = GetText(nIndex, lpstr);
strText.ReleaseBuffer();
}
return nRet;
}
#endif // defined(_WTL_USE_CSTRING) || defined(__ATLSTR_H__)
int GetTextLen(int nIndex) const
{
ATLASSERT(::IsWindow(m_hWnd));
return (int)::SendMessage(m_hWnd, LB_GETTEXTLEN, nIndex, 0L);
}
int GetItemHeight(int nIndex) const
{
ATLASSERT(::IsWindow(m_hWnd));
return (int)::SendMessage(m_hWnd, LB_GETITEMHEIGHT, nIndex, 0L);
}
int SetItemHeight(int nIndex, UINT cyItemHeight)
{
ATLASSERT(::IsWindow(m_hWnd));
return (int)::SendMessage(m_hWnd, LB_SETITEMHEIGHT, nIndex, MAKELONG(cyItemHeight, 0));
}
// Settable only attributes
void SetColumnWidth(int cxWidth)
{
ATLASSERT(::IsWindow(m_hWnd));
::SendMessage(m_hWnd, LB_SETCOLUMNWIDTH, cxWidth, 0L);
}
BOOL SetTabStops(int nTabStops, LPINT rgTabStops)
{
ATLASSERT(::IsWindow(m_hWnd));
ATLASSERT((GetStyle() & LBS_USETABSTOPS) != 0);
return (BOOL)::SendMessage(m_hWnd, LB_SETTABSTOPS, nTabStops, (LPARAM)rgTabStops);
}
BOOL SetTabStops()
{
ATLASSERT(::IsWindow(m_hWnd));
ATLASSERT((GetStyle() & LBS_USETABSTOPS) != 0);
return (BOOL)::SendMessage(m_hWnd, LB_SETTABSTOPS, 0, 0L);
}
BOOL SetTabStops(const int& cxEachStop) // takes an 'int'
{
ATLASSERT(::IsWindow(m_hWnd));
ATLASSERT((GetStyle() & LBS_USETABSTOPS) != 0);
return (BOOL)::SendMessage(m_hWnd, LB_SETTABSTOPS, 1, (LPARAM)(LPINT)&cxEachStop);
}
// Operations
int InitStorage(int nItems, UINT nBytes)
{
ATLASSERT(::IsWindow(m_hWnd));
return (int)::SendMessage(m_hWnd, LB_INITSTORAGE, (WPARAM)nItems, nBytes);
}
void ResetContent()
{
ATLASSERT(::IsWindow(m_hWnd));
::SendMessage(m_hWnd, LB_RESETCONTENT, 0, 0L);
}
UINT ItemFromPoint(POINT pt, BOOL& bOutside) const
{
ATLASSERT(::IsWindow(m_hWnd));
DWORD dw = (DWORD)::SendMessage(m_hWnd, LB_ITEMFROMPOINT, 0, MAKELPARAM(pt.x, pt.y));
bOutside = (BOOL)HIWORD(dw);
return (UINT)LOWORD(dw);
}
// manipulating listbox items
int AddString(LPCTSTR lpszItem)
{
ATLASSERT(::IsWindow(m_hWnd));
return (int)::SendMessage(m_hWnd, LB_ADDSTRING, 0, (LPARAM)lpszItem);
}
int DeleteString(UINT nIndex)
{
ATLASSERT(::IsWindow(m_hWnd));
return (int)::SendMessage(m_hWnd, LB_DELETESTRING, nIndex, 0L);
}
int InsertString(int nIndex, LPCTSTR lpszItem)
{
ATLASSERT(::IsWindow(m_hWnd));
return (int)::SendMessage(m_hWnd, LB_INSERTSTRING, nIndex, (LPARAM)lpszItem);
}
#ifndef _WIN32_WCE
int Dir(UINT attr, LPCTSTR lpszWildCard)
{
ATLASSERT(::IsWindow(m_hWnd));
return (int)::SendMessage(m_hWnd, LB_DIR, attr, (LPARAM)lpszWildCard);
}
int AddFile(LPCTSTR lpstrFileName)
{
ATLASSERT(::IsWindow(m_hWnd));
return (int)::SendMessage(m_hWnd, LB_ADDFILE, 0, (LPARAM)lpstrFileName);
}
#endif // !_WIN32_WCE
// selection helpers
int FindString(int nStartAfter, LPCTSTR lpszItem) const
{
ATLASSERT(::IsWindow(m_hWnd));
return (int)::SendMessage(m_hWnd, LB_FINDSTRING, nStartAfter, (LPARAM)lpszItem);
}
int FindStringExact(int nIndexStart, LPCTSTR lpszFind) const
{
ATLASSERT(::IsWindow(m_hWnd));
return (int)::SendMessage(m_hWnd, LB_FINDSTRINGEXACT, nIndexStart, (LPARAM)lpszFind);
}
int SelectString(int nStartAfter, LPCTSTR lpszItem)
{
ATLASSERT(::IsWindow(m_hWnd));
return (int)::SendMessage(m_hWnd, LB_SELECTSTRING, nStartAfter, (LPARAM)lpszItem);
}
int SelItemRange(BOOL bSelect, int nFirstItem, int nLastItem)
{
ATLASSERT(::IsWindow(m_hWnd));
ATLASSERT((GetStyle() & (LBS_MULTIPLESEL | LBS_EXTENDEDSEL)) != 0);
ATLASSERT(nFirstItem <= nLastItem);
return bSelect ? (int)::SendMessage(m_hWnd, LB_SELITEMRANGEEX, nFirstItem, nLastItem) : (int)::SendMessage(m_hWnd, LB_SELITEMRANGEEX, nLastItem, nFirstItem);
}
#ifdef WIN32_PLATFORM_WFSP // SmartPhone only messages
DWORD GetInputMode(BOOL bCurrentMode = TRUE)
{
return SendMessage(LB_GETINPUTMODE, 0, (LPARAM)bCurrentMode);
}
BOOL SetInputMode(DWORD dwMode)
{
return SendMessage(LB_SETINPUTMODE, 0, (LPARAM)dwMode);
}
#endif // WIN32_PLATFORM_WFSP
};
typedef CListBoxT<ATL::CWindow> CListBox;
///////////////////////////////////////////////////////////////////////////////
// CComboBox - client side for a Windows COMBOBOX control
#ifndef WIN32_PLATFORM_WFSP // No COMBOBOX on SmartPhones
template <class TBase>
class CComboBoxT : public TBase
{
public:
// Constructors
CComboBoxT(HWND hWnd = NULL) : TBase(hWnd)
{ }
CComboBoxT< 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 _T("COMBOBOX");
}
// for entire combo box
int GetCount() const
{
ATLASSERT(::IsWindow(m_hWnd));
return (int)::SendMessage(m_hWnd, CB_GETCOUNT, 0, 0L);
}
int GetCurSel() const
{
ATLASSERT(::IsWindow(m_hWnd));
return (int)::SendMessage(m_hWnd, CB_GETCURSEL, 0, 0L);
}
int SetCurSel(int nSelect)
{
ATLASSERT(::IsWindow(m_hWnd));
return (int)::SendMessage(m_hWnd, CB_SETCURSEL, nSelect, 0L);
}
LCID GetLocale() const
{
ATLASSERT(::IsWindow(m_hWnd));
return (LCID)::SendMessage(m_hWnd, CB_GETLOCALE, 0, 0L);
}
LCID SetLocale(LCID nNewLocale)
{
ATLASSERT(::IsWindow(m_hWnd));
return (LCID)::SendMessage(m_hWnd, CB_SETLOCALE, (WPARAM)nNewLocale, 0L);
}
int GetTopIndex() const
{
ATLASSERT(::IsWindow(m_hWnd));
return (int)::SendMessage(m_hWnd, CB_GETTOPINDEX, 0, 0L);
}
int SetTopIndex(int nIndex)
{
ATLASSERT(::IsWindow(m_hWnd));
return (int)::SendMessage(m_hWnd, CB_SETTOPINDEX, nIndex, 0L);
}
UINT GetHorizontalExtent() const
{
ATLASSERT(::IsWindow(m_hWnd));
return (UINT)::SendMessage(m_hWnd, CB_GETHORIZONTALEXTENT, 0, 0L);
}
void SetHorizontalExtent(UINT nExtent)
{
ATLASSERT(::IsWindow(m_hWnd));
::SendMessage(m_hWnd, CB_SETHORIZONTALEXTENT, nExtent, 0L);
}
int GetDroppedWidth() const
{
ATLASSERT(::IsWindow(m_hWnd));
return (int)::SendMessage(m_hWnd, CB_GETDROPPEDWIDTH, 0, 0L);
}
int SetDroppedWidth(UINT nWidth)
{
ATLASSERT(::IsWindow(m_hWnd));
return (int)::SendMessage(m_hWnd, CB_SETDROPPEDWIDTH, nWidth, 0L);
}
#if ((WINVER >= 0x0500) && !defined(_WIN32_WCE)) || (defined(_WIN32_WCE) && (_WIN32_WCE >= 420))
BOOL GetComboBoxInfo(PCOMBOBOXINFO pComboBoxInfo) const
{
ATLASSERT(::IsWindow(m_hWnd));
#if ((_WIN32_WINNT >= 0x0501) && !defined(_WIN32_WCE)) || (defined(_WIN32_WCE) && (_WIN32_WCE >= 420))
return (BOOL)::SendMessage(m_hWnd, CB_GETCOMBOBOXINFO, 0, (LPARAM)pComboBoxInfo);
#else // !((_WIN32_WINNT >= 0x0501) && !defined(_WIN32_WCE)) || (defined(_WIN32_WCE) && (_WIN32_WCE >= 420))
return ::GetComboBoxInfo(m_hWnd, pComboBoxInfo);
#endif // !((_WIN32_WINNT >= 0x0501) && !defined(_WIN32_WCE)) || (defined(_WIN32_WCE) && (_WIN32_WCE >= 420))
}
#endif // ((WINVER >= 0x0500) && !defined(_WIN32_WCE)) || (defined(_WIN32_WCE) && (_WIN32_WCE >= 420))
// for edit control
DWORD GetEditSel() const
{
ATLASSERT(::IsWindow(m_hWnd));
return (DWORD)::SendMessage(m_hWnd, CB_GETEDITSEL, 0, 0L);
}
BOOL SetEditSel(int nStartChar, int nEndChar)
{
ATLASSERT(::IsWindow(m_hWnd));
return (BOOL)::SendMessage(m_hWnd, CB_SETEDITSEL, 0, MAKELONG(nStartChar, nEndChar));
}
// for combobox item
DWORD_PTR GetItemData(int nIndex) const
{
ATLASSERT(::IsWindow(m_hWnd));
return (DWORD_PTR)::SendMessage(m_hWnd, CB_GETITEMDATA, nIndex, 0L);
}
int SetItemData(int nIndex, DWORD_PTR dwItemData)
{
ATLASSERT(::IsWindow(m_hWnd));
return (int)::SendMessage(m_hWnd, CB_SETITEMDATA, nIndex, (LPARAM)dwItemData);
}
void* GetItemDataPtr(int nIndex) const
{
ATLASSERT(::IsWindow(m_hWnd));
return (void*)GetItemData(nIndex);
}
int SetItemDataPtr(int nIndex, void* pData)
{
ATLASSERT(::IsWindow(m_hWnd));
return SetItemData(nIndex, (DWORD_PTR)pData);
}
int GetLBText(int nIndex, LPTSTR lpszText) const
{
ATLASSERT(::IsWindow(m_hWnd));
return (int)::SendMessage(m_hWnd, CB_GETLBTEXT, nIndex, (LPARAM)lpszText);
}
#ifndef _ATL_NO_COM
BOOL GetLBTextBSTR(int nIndex, BSTR& bstrText) const
{
USES_CONVERSION;
ATLASSERT(::IsWindow(m_hWnd));
ATLASSERT(bstrText == NULL);
int nLen = GetLBTextLen(nIndex);
if(nLen == CB_ERR)
return FALSE;
CTempBuffer<TCHAR, _WTL_STACK_ALLOC_THRESHOLD> buff;
LPTSTR lpstrText = buff.Allocate(nLen + 1);
if(lpstrText == NULL)
return FALSE;
if(GetLBText(nIndex, lpstrText) == CB_ERR)
return FALSE;
bstrText = ::SysAllocString(T2OLE(lpstrText));
return (bstrText != NULL) ? TRUE : FALSE;
}
#endif // !_ATL_NO_COM
#if defined(_WTL_USE_CSTRING) || defined(__ATLSTR_H__)
int GetLBText(int nIndex, _CSTRING_NS::CString& strText) const
{
ATLASSERT(::IsWindow(m_hWnd));
int cchLen = GetLBTextLen(nIndex);
if(cchLen == CB_ERR)
return CB_ERR;
int nRet = CB_ERR;
LPTSTR lpstr = strText.GetBufferSetLength(cchLen);
if(lpstr != NULL)
{
nRet = GetLBText(nIndex, lpstr);
strText.ReleaseBuffer();
}
return nRet;
}
#endif // defined(_WTL_USE_CSTRING) || defined(__ATLSTR_H__)
int GetLBTextLen(int nIndex) const
{
ATLASSERT(::IsWindow(m_hWnd));
return (int)::SendMessage(m_hWnd, CB_GETLBTEXTLEN, nIndex, 0L);
}
int GetItemHeight(int nIndex) const
{
ATLASSERT(::IsWindow(m_hWnd));
return (int)::SendMessage(m_hWnd, CB_GETITEMHEIGHT, nIndex, 0L);
}
int SetItemHeight(int nIndex, UINT cyItemHeight)
{
ATLASSERT(::IsWindow(m_hWnd));
return (int)::SendMessage(m_hWnd, CB_SETITEMHEIGHT, nIndex, MAKELONG(cyItemHeight, 0));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -