Cleanup setting of 'sysroot' in common.gypi
[chromium-blink-merge.git] / third_party / wtl / include / atlctrls.h
blobcbafb29cf40f58f9fde1492e2311b9d96c248dbc
1 // Windows Template Library - WTL version 8.0
2 // Copyright (C) Microsoft Corporation. All rights reserved.
3 //
4 // This file is a part of the Windows Template Library.
5 // The use and distribution terms for this software are covered by the
6 // Microsoft Permissive License (Ms-PL) which can be found in the file
7 // Ms-PL.txt at the root of this distribution.
9 #ifndef __ATLCTRLS_H__
10 #define __ATLCTRLS_H__
12 #pragma once
14 #ifndef __cplusplus
15 #error ATL requires C++ compilation (use a .cpp suffix)
16 #endif
18 #ifndef __ATLAPP_H__
19 #error atlctrls.h requires atlapp.h to be included first
20 #endif
22 #ifndef __ATLWIN_H__
23 #error atlctrls.h requires atlwin.h to be included first
24 #endif
26 #if (_WIN32_IE < 0x0300)
27 #error atlctrls.h requires IE Version 3.0 or higher
28 #endif
30 #ifndef _WIN32_WCE
31 #include <richedit.h>
32 #include <richole.h>
33 #elif defined(WIN32_PLATFORM_WFSP) && !defined(_WINUSERM_H_)
34 #include <winuserm.h>
35 #endif // !_WIN32_WCE
37 // protect template members from windowsx.h macros
38 #ifdef _INC_WINDOWSX
39 #undef GetNextSibling
40 #undef GetPrevSibling
41 #endif // _INC_WINDOWSX
44 ///////////////////////////////////////////////////////////////////////////////
45 // Classes in this file:
47 // CStaticT<TBase> - CStatic
48 // CButtonT<TBase> - CButton
49 // CListBoxT<TBase> - CListBox
50 // CComboBoxT<TBase> - CComboBox
51 // CEditT<TBase> - CEdit
52 // CEditCommands<T>
53 // CScrollBarT<TBase> - CScrollBar
55 // CImageList
56 // CListViewCtrlT<TBase> - CListViewCtrl
57 // CTreeViewCtrlT<TBase> - CTreeViewCtrl
58 // CTreeItemT<TBase> - CTreeItem
59 // CTreeViewCtrlExT<TBase> - CTreeViewCtrlEx
60 // CHeaderCtrlT<TBase> - CHeaderCtrl
61 // CToolBarCtrlT<TBase> - CToolBarCtrl
62 // CStatusBarCtrlT<TBase> - CStatusBarCtrl
63 // CTabCtrlT<TBase> - CTabCtrl
64 // CToolInfo
65 // CToolTipCtrlT<TBase> - CToolTipCtrl
66 // CTrackBarCtrlT<TBase> - CTrackBarCtrl
67 // CUpDownCtrlT<TBase> - CUpDownCtrl
68 // CProgressBarCtrlT<TBase> - CProgressBarCtrl
69 // CHotKeyCtrlT<TBase> - CHotKeyCtrl
70 // CAnimateCtrlT<TBase> - CAnimateCtrl
71 // CRichEditCtrlT<TBase> - CRichEditCtrl
72 // CRichEditCommands<T>
73 // CDragListBoxT<TBase> - CDragListBox
74 // CDragListNotifyImpl<T>
75 // CReBarCtrlT<TBase> - CReBarCtrl
76 // CComboBoxExT<TBase> - CComboBoxEx
77 // CDateTimePickerCtrlT<TBase> - CDateTimePickerCtrl
78 // CMonthCalendarCtrlT<TBase> - CMonthCalendarCtrl
79 // CFlatScrollBarImpl<T>
80 // CFlatScrollBarT<TBase> - CFlatScrollBar
81 // CIPAddressCtrlT<TBase> - CIPAddressCtrl
82 // CPagerCtrlT<TBase> - CPagerCtrl
83 // CLinkCtrlT<TBase> - CLinkCtrl
85 // CCustomDraw<T>
87 // CCECommandBarCtrlT<TBase> - CCECommandBarCtrl
88 // CCECommandBandsCtrlT<TBase> - CCECommandBandsCtrl
91 namespace WTL
94 // These are wrapper classes for Windows standard and common controls.
95 // To implement a window based on a control, use following:
96 // Example: Implementing a window based on a list box
98 // class CMyListBox : CWindowImpl<CMyListBox, CListBox>
99 // {
100 // public:
101 // BEGIN_MSG_MAP(CMyListBox)
102 // // put your message handler entries here
103 // END_MSG_MAP()
104 // };
108 // --- Standard Windows controls ---
110 ///////////////////////////////////////////////////////////////////////////////
111 // CStatic - client side for a Windows STATIC control
113 template <class TBase>
114 class CStaticT : public TBase
116 public:
117 // Constructors
118 CStaticT(HWND hWnd = NULL) : TBase(hWnd)
121 CStaticT< TBase >& operator =(HWND hWnd)
123 m_hWnd = hWnd;
124 return *this;
127 HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
128 DWORD dwStyle = 0, DWORD dwExStyle = 0,
129 ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
131 return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
134 // Attributes
135 static LPCTSTR GetWndClassName()
137 return _T("STATIC");
140 #ifndef _WIN32_WCE
141 HICON GetIcon() const
143 ATLASSERT(::IsWindow(m_hWnd));
144 return (HICON)::SendMessage(m_hWnd, STM_GETICON, 0, 0L);
147 HICON SetIcon(HICON hIcon)
149 ATLASSERT(::IsWindow(m_hWnd));
150 return (HICON)::SendMessage(m_hWnd, STM_SETICON, (WPARAM)hIcon, 0L);
153 HENHMETAFILE GetEnhMetaFile() const
155 ATLASSERT(::IsWindow(m_hWnd));
156 return (HENHMETAFILE)::SendMessage(m_hWnd, STM_GETIMAGE, IMAGE_ENHMETAFILE, 0L);
159 HENHMETAFILE SetEnhMetaFile(HENHMETAFILE hMetaFile)
161 ATLASSERT(::IsWindow(m_hWnd));
162 return (HENHMETAFILE)::SendMessage(m_hWnd, STM_SETIMAGE, IMAGE_ENHMETAFILE, (LPARAM)hMetaFile);
164 #else // CE specific
165 HICON GetIcon() const
167 ATLASSERT(::IsWindow(m_hWnd));
168 return (HICON)::SendMessage(m_hWnd, STM_GETIMAGE, IMAGE_ICON, 0L);
171 HICON SetIcon(HICON hIcon)
173 ATLASSERT(::IsWindow(m_hWnd));
174 return (HICON)::SendMessage(m_hWnd, STM_SETIMAGE, IMAGE_ICON, (LPARAM)hIcon);
176 #endif // _WIN32_WCE
178 CBitmapHandle GetBitmap() const
180 ATLASSERT(::IsWindow(m_hWnd));
181 return CBitmapHandle((HBITMAP)::SendMessage(m_hWnd, STM_GETIMAGE, IMAGE_BITMAP, 0L));
184 CBitmapHandle SetBitmap(HBITMAP hBitmap)
186 ATLASSERT(::IsWindow(m_hWnd));
187 return CBitmapHandle((HBITMAP)::SendMessage(m_hWnd, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBitmap));
190 HCURSOR GetCursor() const
192 ATLASSERT(::IsWindow(m_hWnd));
193 return (HCURSOR)::SendMessage(m_hWnd, STM_GETIMAGE, IMAGE_CURSOR, 0L);
196 HCURSOR SetCursor(HCURSOR hCursor)
198 ATLASSERT(::IsWindow(m_hWnd));
199 return (HCURSOR)::SendMessage(m_hWnd, STM_SETIMAGE, IMAGE_CURSOR, (LPARAM)hCursor);
203 typedef CStaticT<ATL::CWindow> CStatic;
206 ///////////////////////////////////////////////////////////////////////////////
207 // CButton - client side for a Windows BUTTON control
209 template <class TBase>
210 class CButtonT : public TBase
212 public:
213 // Constructors
214 CButtonT(HWND hWnd = NULL) : TBase(hWnd)
217 CButtonT< TBase >& operator =(HWND hWnd)
219 m_hWnd = hWnd;
220 return *this;
223 HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
224 DWORD dwStyle = 0, DWORD dwExStyle = 0,
225 ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
227 return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
230 // Attributes
231 static LPCTSTR GetWndClassName()
233 return _T("BUTTON");
236 UINT GetState() const
238 ATLASSERT(::IsWindow(m_hWnd));
239 return (UINT)::SendMessage(m_hWnd, BM_GETSTATE, 0, 0L);
242 void SetState(BOOL bHighlight)
244 ATLASSERT(::IsWindow(m_hWnd));
245 ::SendMessage(m_hWnd, BM_SETSTATE, bHighlight, 0L);
248 int GetCheck() const
250 ATLASSERT(::IsWindow(m_hWnd));
251 return (int)::SendMessage(m_hWnd, BM_GETCHECK, 0, 0L);
254 void SetCheck(int nCheck)
256 ATLASSERT(::IsWindow(m_hWnd));
257 ::SendMessage(m_hWnd, BM_SETCHECK, nCheck, 0L);
260 UINT GetButtonStyle() const
262 ATLASSERT(::IsWindow(m_hWnd));
263 return (UINT)::GetWindowLong(m_hWnd, GWL_STYLE) & 0xFFFF;
266 void SetButtonStyle(UINT nStyle, BOOL bRedraw = TRUE)
268 ATLASSERT(::IsWindow(m_hWnd));
269 ::SendMessage(m_hWnd, BM_SETSTYLE, nStyle, (LPARAM)bRedraw);
272 #ifndef _WIN32_WCE
273 HICON GetIcon() const
275 ATLASSERT(::IsWindow(m_hWnd));
276 return (HICON)::SendMessage(m_hWnd, BM_GETIMAGE, IMAGE_ICON, 0L);
279 HICON SetIcon(HICON hIcon)
281 ATLASSERT(::IsWindow(m_hWnd));
282 return (HICON)::SendMessage(m_hWnd, BM_SETIMAGE, IMAGE_ICON, (LPARAM)hIcon);
285 CBitmapHandle GetBitmap() const
287 ATLASSERT(::IsWindow(m_hWnd));
288 return CBitmapHandle((HBITMAP)::SendMessage(m_hWnd, BM_GETIMAGE, IMAGE_BITMAP, 0L));
291 CBitmapHandle SetBitmap(HBITMAP hBitmap)
293 ATLASSERT(::IsWindow(m_hWnd));
294 return CBitmapHandle((HBITMAP)::SendMessage(m_hWnd, BM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBitmap));
296 #endif // !_WIN32_WCE
298 #if (_WIN32_WINNT >= 0x0501)
299 BOOL GetIdealSize(LPSIZE lpSize) const
301 ATLASSERT(::IsWindow(m_hWnd));
302 return (BOOL)::SendMessage(m_hWnd, BCM_GETIDEALSIZE, 0, (LPARAM)lpSize);
305 BOOL GetImageList(PBUTTON_IMAGELIST pButtonImagelist) const
307 ATLASSERT(::IsWindow(m_hWnd));
308 return (BOOL)::SendMessage(m_hWnd, BCM_GETIMAGELIST, 0, (LPARAM)pButtonImagelist);
311 BOOL SetImageList(PBUTTON_IMAGELIST pButtonImagelist)
313 ATLASSERT(::IsWindow(m_hWnd));
314 return (BOOL)::SendMessage(m_hWnd, BCM_SETIMAGELIST, 0, (LPARAM)pButtonImagelist);
317 BOOL GetTextMargin(LPRECT lpRect) const
319 ATLASSERT(::IsWindow(m_hWnd));
320 return (BOOL)::SendMessage(m_hWnd, BCM_GETTEXTMARGIN, 0, (LPARAM)lpRect);
323 BOOL SetTextMargin(LPRECT lpRect)
325 ATLASSERT(::IsWindow(m_hWnd));
326 return (BOOL)::SendMessage(m_hWnd, BCM_SETTEXTMARGIN, 0, (LPARAM)lpRect);
328 #endif // (_WIN32_WINNT >= 0x0501)
330 #if (WINVER >= 0x0600)
331 void SetDontClick(BOOL bDontClick)
333 ATLASSERT(::IsWindow(m_hWnd));
334 ::SendMessage(m_hWnd, BM_SETDONTCLICK, (WPARAM)bDontClick, 0L);
336 #endif // (WINVER >= 0x0600)
338 #if (_WIN32_WINNT >= 0x0600)
339 BOOL SetDropDownState(BOOL bDropDown)
341 ATLASSERT(::IsWindow(m_hWnd));
342 ATLASSERT((GetStyle() & (BS_SPLITBUTTON | BS_DEFSPLITBUTTON)) != 0);
343 return (BOOL)::SendMessage(m_hWnd, BCM_SETDROPDOWNSTATE, (WPARAM)bDropDown, 0L);
346 BOOL GetSplitInfo(PBUTTON_SPLITINFO pSplitInfo) const
348 ATLASSERT(::IsWindow(m_hWnd));
349 ATLASSERT((GetStyle() & (BS_SPLITBUTTON | BS_DEFSPLITBUTTON)) != 0);
350 return (BOOL)::SendMessage(m_hWnd, BCM_GETSPLITINFO, 0, (LPARAM)pSplitInfo);
353 BOOL SetSplitInfo(PBUTTON_SPLITINFO pSplitInfo)
355 ATLASSERT(::IsWindow(m_hWnd));
356 ATLASSERT((GetStyle() & (BS_SPLITBUTTON | BS_DEFSPLITBUTTON)) != 0);
357 return (BOOL)::SendMessage(m_hWnd, BCM_SETSPLITINFO, 0, (LPARAM)pSplitInfo);
360 int GetNoteLength() const
362 ATLASSERT(::IsWindow(m_hWnd));
363 ATLASSERT((GetStyle() & (BS_COMMANDLINK | BS_DEFCOMMANDLINK)) != 0);
364 return (int)::SendMessage(m_hWnd, BCM_GETNOTELENGTH, 0, 0L);
367 BOOL GetNote(LPWSTR lpstrNoteText, int cchNoteText) const
369 ATLASSERT(::IsWindow(m_hWnd));
370 ATLASSERT((GetStyle() & (BS_COMMANDLINK | BS_DEFCOMMANDLINK)) != 0);
371 return (BOOL)::SendMessage(m_hWnd, BCM_GETNOTE, cchNoteText, (LPARAM)lpstrNoteText);
374 BOOL SetNote(LPCWSTR lpstrNoteText)
376 ATLASSERT(::IsWindow(m_hWnd));
377 ATLASSERT((GetStyle() & (BS_COMMANDLINK | BS_DEFCOMMANDLINK)) != 0);
378 return (BOOL)::SendMessage(m_hWnd, BCM_SETNOTE, 0, (LPARAM)lpstrNoteText);
381 LRESULT SetElevationRequiredState(BOOL bSet)
383 ATLASSERT(::IsWindow(m_hWnd));
384 return ::SendMessage(m_hWnd, BCM_SETSHIELD, 0, (LPARAM)bSet);
386 #endif // (_WIN32_WINNT >= 0x0600)
388 // Operations
389 void Click()
391 ATLASSERT(::IsWindow(m_hWnd));
392 ::SendMessage(m_hWnd, BM_CLICK, 0, 0L);
396 typedef CButtonT<ATL::CWindow> CButton;
399 ///////////////////////////////////////////////////////////////////////////////
400 // CListBox - client side for a Windows LISTBOX control
402 template <class TBase>
403 class CListBoxT : public TBase
405 public:
406 // Constructors
407 CListBoxT(HWND hWnd = NULL) : TBase(hWnd)
410 CListBoxT< TBase >& operator =(HWND hWnd)
412 m_hWnd = hWnd;
413 return *this;
416 HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
417 DWORD dwStyle = 0, DWORD dwExStyle = 0,
418 ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
420 return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
423 // Attributes
424 static LPCTSTR GetWndClassName()
426 return _T("LISTBOX");
429 // for entire listbox
430 int GetCount() const
432 ATLASSERT(::IsWindow(m_hWnd));
433 return (int)::SendMessage(m_hWnd, LB_GETCOUNT, 0, 0L);
436 #ifndef _WIN32_WCE
437 int SetCount(int cItems)
439 ATLASSERT(::IsWindow(m_hWnd));
440 ATLASSERT(((GetStyle() & LBS_NODATA) != 0) && ((GetStyle() & LBS_HASSTRINGS) == 0));
441 return (int)::SendMessage(m_hWnd, LB_SETCOUNT, cItems, 0L);
443 #endif // !_WIN32_WCE
445 int GetHorizontalExtent() const
447 ATLASSERT(::IsWindow(m_hWnd));
448 return (int)::SendMessage(m_hWnd, LB_GETHORIZONTALEXTENT, 0, 0L);
451 void SetHorizontalExtent(int cxExtent)
453 ATLASSERT(::IsWindow(m_hWnd));
454 ::SendMessage(m_hWnd, LB_SETHORIZONTALEXTENT, cxExtent, 0L);
457 int GetTopIndex() const
459 ATLASSERT(::IsWindow(m_hWnd));
460 return (int)::SendMessage(m_hWnd, LB_GETTOPINDEX, 0, 0L);
463 int SetTopIndex(int nIndex)
465 ATLASSERT(::IsWindow(m_hWnd));
466 return (int)::SendMessage(m_hWnd, LB_SETTOPINDEX, nIndex, 0L);
469 LCID GetLocale() const
471 ATLASSERT(::IsWindow(m_hWnd));
472 return (LCID)::SendMessage(m_hWnd, LB_GETLOCALE, 0, 0L);
475 LCID SetLocale(LCID nNewLocale)
477 ATLASSERT(::IsWindow(m_hWnd));
478 return (LCID)::SendMessage(m_hWnd, LB_SETLOCALE, (WPARAM)nNewLocale, 0L);
481 #if (WINVER >= 0x0500) && !defined(_WIN32_WCE)
482 DWORD GetListBoxInfo() const
484 ATLASSERT(::IsWindow(m_hWnd));
485 #if (_WIN32_WINNT >= 0x0501)
486 return (DWORD)::SendMessage(m_hWnd, LB_GETLISTBOXINFO, 0, 0L);
487 #else // !(_WIN32_WINNT >= 0x0501)
488 return ::GetListBoxInfo(m_hWnd);
489 #endif // !(_WIN32_WINNT >= 0x0501)
491 #endif // (WINVER >= 0x0500) && !defined(_WIN32_WCE)
493 // for single-selection listboxes
494 int GetCurSel() const
496 ATLASSERT(::IsWindow(m_hWnd));
497 ATLASSERT((GetStyle() & (LBS_MULTIPLESEL | LBS_EXTENDEDSEL)) == 0);
498 return (int)::SendMessage(m_hWnd, LB_GETCURSEL, 0, 0L);
501 int SetCurSel(int nSelect)
503 ATLASSERT(::IsWindow(m_hWnd));
504 ATLASSERT((GetStyle() & (LBS_MULTIPLESEL | LBS_EXTENDEDSEL)) == 0);
505 return (int)::SendMessage(m_hWnd, LB_SETCURSEL, nSelect, 0L);
508 // for multiple-selection listboxes
509 int GetSel(int nIndex) const // also works for single-selection
511 ATLASSERT(::IsWindow(m_hWnd));
512 return (int)::SendMessage(m_hWnd, LB_GETSEL, nIndex, 0L);
515 int SetSel(int nIndex, BOOL bSelect = TRUE)
517 ATLASSERT(::IsWindow(m_hWnd));
518 ATLASSERT((GetStyle() & (LBS_MULTIPLESEL | LBS_EXTENDEDSEL)) != 0);
519 return (int)::SendMessage(m_hWnd, LB_SETSEL, bSelect, nIndex);
522 int GetSelCount() const
524 ATLASSERT(::IsWindow(m_hWnd));
525 ATLASSERT((GetStyle() & (LBS_MULTIPLESEL | LBS_EXTENDEDSEL)) != 0);
526 return (int)::SendMessage(m_hWnd, LB_GETSELCOUNT, 0, 0L);
529 int GetSelItems(int nMaxItems, LPINT rgIndex) const
531 ATLASSERT(::IsWindow(m_hWnd));
532 ATLASSERT((GetStyle() & (LBS_MULTIPLESEL | LBS_EXTENDEDSEL)) != 0);
533 return (int)::SendMessage(m_hWnd, LB_GETSELITEMS, nMaxItems, (LPARAM)rgIndex);
536 int GetAnchorIndex() const
538 ATLASSERT(::IsWindow(m_hWnd));
539 ATLASSERT((GetStyle() & (LBS_MULTIPLESEL | LBS_EXTENDEDSEL)) != 0);
540 return (int)::SendMessage(m_hWnd, LB_GETANCHORINDEX, 0, 0L);
543 void SetAnchorIndex(int nIndex)
545 ATLASSERT(::IsWindow(m_hWnd));
546 ATLASSERT((GetStyle() & (LBS_MULTIPLESEL | LBS_EXTENDEDSEL)) != 0);
547 ::SendMessage(m_hWnd, LB_SETANCHORINDEX, nIndex, 0L);
550 int GetCaretIndex() const
552 ATLASSERT(::IsWindow(m_hWnd));
553 return (int)::SendMessage(m_hWnd, LB_GETCARETINDEX, 0, 0);
556 int SetCaretIndex(int nIndex, BOOL bScroll = TRUE)
558 ATLASSERT(::IsWindow(m_hWnd));
559 return (int)::SendMessage(m_hWnd, LB_SETCARETINDEX, nIndex, MAKELONG(bScroll, 0));
562 // for listbox items
563 DWORD_PTR GetItemData(int nIndex) const
565 ATLASSERT(::IsWindow(m_hWnd));
566 return (DWORD_PTR)::SendMessage(m_hWnd, LB_GETITEMDATA, nIndex, 0L);
569 int SetItemData(int nIndex, DWORD_PTR dwItemData)
571 ATLASSERT(::IsWindow(m_hWnd));
572 return (int)::SendMessage(m_hWnd, LB_SETITEMDATA, nIndex, (LPARAM)dwItemData);
575 void* GetItemDataPtr(int nIndex) const
577 ATLASSERT(::IsWindow(m_hWnd));
578 return (void*)::SendMessage(m_hWnd, LB_GETITEMDATA, nIndex, 0L);
581 int SetItemDataPtr(int nIndex, void* pData)
583 ATLASSERT(::IsWindow(m_hWnd));
584 return SetItemData(nIndex, (DWORD_PTR)pData);
587 int GetItemRect(int nIndex, LPRECT lpRect) const
589 ATLASSERT(::IsWindow(m_hWnd));
590 return (int)::SendMessage(m_hWnd, LB_GETITEMRECT, nIndex, (LPARAM)lpRect);
593 int GetText(int nIndex, LPTSTR lpszBuffer) const
595 ATLASSERT(::IsWindow(m_hWnd));
596 return (int)::SendMessage(m_hWnd, LB_GETTEXT, nIndex, (LPARAM)lpszBuffer);
599 #ifndef _ATL_NO_COM
600 #ifdef _OLEAUTO_H_
601 BOOL GetTextBSTR(int nIndex, BSTR& bstrText) const
603 USES_CONVERSION;
604 ATLASSERT(::IsWindow(m_hWnd));
605 ATLASSERT(bstrText == NULL);
607 int nLen = GetTextLen(nIndex);
608 if(nLen == LB_ERR)
609 return FALSE;
611 CTempBuffer<TCHAR, _WTL_STACK_ALLOC_THRESHOLD> buff;
612 LPTSTR lpstrText = buff.Allocate(nLen + 1);
613 if(lpstrText == NULL)
614 return FALSE;
616 if(GetText(nIndex, lpstrText) == LB_ERR)
617 return FALSE;
619 bstrText = ::SysAllocString(T2OLE(lpstrText));
620 return (bstrText != NULL) ? TRUE : FALSE;
622 #endif // _OLEAUTO_H_
623 #endif // !_ATL_NO_COM
625 #if defined(_WTL_USE_CSTRING) || defined(__ATLSTR_H__)
626 int GetText(int nIndex, _CSTRING_NS::CString& strText) const
628 ATLASSERT(::IsWindow(m_hWnd));
629 int cchLen = GetTextLen(nIndex);
630 if(cchLen == LB_ERR)
631 return LB_ERR;
632 int nRet = LB_ERR;
633 LPTSTR lpstr = strText.GetBufferSetLength(cchLen);
634 if(lpstr != NULL)
636 nRet = GetText(nIndex, lpstr);
637 strText.ReleaseBuffer();
639 return nRet;
641 #endif // defined(_WTL_USE_CSTRING) || defined(__ATLSTR_H__)
643 int GetTextLen(int nIndex) const
645 ATLASSERT(::IsWindow(m_hWnd));
646 return (int)::SendMessage(m_hWnd, LB_GETTEXTLEN, nIndex, 0L);
649 int GetItemHeight(int nIndex) const
651 ATLASSERT(::IsWindow(m_hWnd));
652 return (int)::SendMessage(m_hWnd, LB_GETITEMHEIGHT, nIndex, 0L);
655 int SetItemHeight(int nIndex, UINT cyItemHeight)
657 ATLASSERT(::IsWindow(m_hWnd));
658 return (int)::SendMessage(m_hWnd, LB_SETITEMHEIGHT, nIndex, MAKELONG(cyItemHeight, 0));
661 // Settable only attributes
662 void SetColumnWidth(int cxWidth)
664 ATLASSERT(::IsWindow(m_hWnd));
665 ::SendMessage(m_hWnd, LB_SETCOLUMNWIDTH, cxWidth, 0L);
668 BOOL SetTabStops(int nTabStops, LPINT rgTabStops)
670 ATLASSERT(::IsWindow(m_hWnd));
671 ATLASSERT((GetStyle() & LBS_USETABSTOPS) != 0);
672 return (BOOL)::SendMessage(m_hWnd, LB_SETTABSTOPS, nTabStops, (LPARAM)rgTabStops);
675 BOOL SetTabStops()
677 ATLASSERT(::IsWindow(m_hWnd));
678 ATLASSERT((GetStyle() & LBS_USETABSTOPS) != 0);
679 return (BOOL)::SendMessage(m_hWnd, LB_SETTABSTOPS, 0, 0L);
682 BOOL SetTabStops(const int& cxEachStop) // takes an 'int'
684 ATLASSERT(::IsWindow(m_hWnd));
685 ATLASSERT((GetStyle() & LBS_USETABSTOPS) != 0);
686 return (BOOL)::SendMessage(m_hWnd, LB_SETTABSTOPS, 1, (LPARAM)(LPINT)&cxEachStop);
689 // Operations
690 int InitStorage(int nItems, UINT nBytes)
692 ATLASSERT(::IsWindow(m_hWnd));
693 return (int)::SendMessage(m_hWnd, LB_INITSTORAGE, (WPARAM)nItems, nBytes);
696 void ResetContent()
698 ATLASSERT(::IsWindow(m_hWnd));
699 ::SendMessage(m_hWnd, LB_RESETCONTENT, 0, 0L);
702 UINT ItemFromPoint(POINT pt, BOOL& bOutside) const
704 ATLASSERT(::IsWindow(m_hWnd));
705 DWORD dw = (DWORD)::SendMessage(m_hWnd, LB_ITEMFROMPOINT, 0, MAKELPARAM(pt.x, pt.y));
706 bOutside = (BOOL)HIWORD(dw);
707 return (UINT)LOWORD(dw);
710 // manipulating listbox items
711 int AddString(LPCTSTR lpszItem)
713 ATLASSERT(::IsWindow(m_hWnd));
714 return (int)::SendMessage(m_hWnd, LB_ADDSTRING, 0, (LPARAM)lpszItem);
717 int DeleteString(UINT nIndex)
719 ATLASSERT(::IsWindow(m_hWnd));
720 return (int)::SendMessage(m_hWnd, LB_DELETESTRING, nIndex, 0L);
723 int InsertString(int nIndex, LPCTSTR lpszItem)
725 ATLASSERT(::IsWindow(m_hWnd));
726 return (int)::SendMessage(m_hWnd, LB_INSERTSTRING, nIndex, (LPARAM)lpszItem);
729 #ifndef _WIN32_WCE
730 int Dir(UINT attr, LPCTSTR lpszWildCard)
732 ATLASSERT(::IsWindow(m_hWnd));
733 return (int)::SendMessage(m_hWnd, LB_DIR, attr, (LPARAM)lpszWildCard);
736 int AddFile(LPCTSTR lpstrFileName)
738 ATLASSERT(::IsWindow(m_hWnd));
739 return (int)::SendMessage(m_hWnd, LB_ADDFILE, 0, (LPARAM)lpstrFileName);
741 #endif // !_WIN32_WCE
743 // selection helpers
744 int FindString(int nStartAfter, LPCTSTR lpszItem) const
746 ATLASSERT(::IsWindow(m_hWnd));
747 return (int)::SendMessage(m_hWnd, LB_FINDSTRING, nStartAfter, (LPARAM)lpszItem);
750 int FindStringExact(int nIndexStart, LPCTSTR lpszFind) const
752 ATLASSERT(::IsWindow(m_hWnd));
753 return (int)::SendMessage(m_hWnd, LB_FINDSTRINGEXACT, nIndexStart, (LPARAM)lpszFind);
756 int SelectString(int nStartAfter, LPCTSTR lpszItem)
758 ATLASSERT(::IsWindow(m_hWnd));
759 return (int)::SendMessage(m_hWnd, LB_SELECTSTRING, nStartAfter, (LPARAM)lpszItem);
762 int SelItemRange(BOOL bSelect, int nFirstItem, int nLastItem)
764 ATLASSERT(::IsWindow(m_hWnd));
765 ATLASSERT((GetStyle() & (LBS_MULTIPLESEL | LBS_EXTENDEDSEL)) != 0);
766 ATLASSERT(nFirstItem <= nLastItem);
767 return bSelect ? (int)::SendMessage(m_hWnd, LB_SELITEMRANGEEX, nFirstItem, nLastItem) : (int)::SendMessage(m_hWnd, LB_SELITEMRANGEEX, nLastItem, nFirstItem);
770 #ifdef WIN32_PLATFORM_WFSP // SmartPhone only messages
771 DWORD GetInputMode(BOOL bCurrentMode = TRUE)
773 return SendMessage(LB_GETINPUTMODE, 0, (LPARAM)bCurrentMode);
776 BOOL SetInputMode(DWORD dwMode)
778 return SendMessage(LB_SETINPUTMODE, 0, (LPARAM)dwMode);
780 #endif // WIN32_PLATFORM_WFSP
783 typedef CListBoxT<ATL::CWindow> CListBox;
786 ///////////////////////////////////////////////////////////////////////////////
787 // CComboBox - client side for a Windows COMBOBOX control
789 #ifndef WIN32_PLATFORM_WFSP // No COMBOBOX on SmartPhones
791 template <class TBase>
792 class CComboBoxT : public TBase
794 public:
795 // Constructors
796 CComboBoxT(HWND hWnd = NULL) : TBase(hWnd)
799 CComboBoxT< TBase >& operator =(HWND hWnd)
801 m_hWnd = hWnd;
802 return *this;
805 HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
806 DWORD dwStyle = 0, DWORD dwExStyle = 0,
807 ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
809 return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
812 // Attributes
813 static LPCTSTR GetWndClassName()
815 return _T("COMBOBOX");
818 // for entire combo box
819 int GetCount() const
821 ATLASSERT(::IsWindow(m_hWnd));
822 return (int)::SendMessage(m_hWnd, CB_GETCOUNT, 0, 0L);
825 int GetCurSel() const
827 ATLASSERT(::IsWindow(m_hWnd));
828 return (int)::SendMessage(m_hWnd, CB_GETCURSEL, 0, 0L);
831 int SetCurSel(int nSelect)
833 ATLASSERT(::IsWindow(m_hWnd));
834 return (int)::SendMessage(m_hWnd, CB_SETCURSEL, nSelect, 0L);
837 LCID GetLocale() const
839 ATLASSERT(::IsWindow(m_hWnd));
840 return (LCID)::SendMessage(m_hWnd, CB_GETLOCALE, 0, 0L);
843 LCID SetLocale(LCID nNewLocale)
845 ATLASSERT(::IsWindow(m_hWnd));
846 return (LCID)::SendMessage(m_hWnd, CB_SETLOCALE, (WPARAM)nNewLocale, 0L);
849 int GetTopIndex() const
851 ATLASSERT(::IsWindow(m_hWnd));
852 return (int)::SendMessage(m_hWnd, CB_GETTOPINDEX, 0, 0L);
855 int SetTopIndex(int nIndex)
857 ATLASSERT(::IsWindow(m_hWnd));
858 return (int)::SendMessage(m_hWnd, CB_SETTOPINDEX, nIndex, 0L);
861 UINT GetHorizontalExtent() const
863 ATLASSERT(::IsWindow(m_hWnd));
864 return (UINT)::SendMessage(m_hWnd, CB_GETHORIZONTALEXTENT, 0, 0L);
867 void SetHorizontalExtent(UINT nExtent)
869 ATLASSERT(::IsWindow(m_hWnd));
870 ::SendMessage(m_hWnd, CB_SETHORIZONTALEXTENT, nExtent, 0L);
873 int GetDroppedWidth() const
875 ATLASSERT(::IsWindow(m_hWnd));
876 return (int)::SendMessage(m_hWnd, CB_GETDROPPEDWIDTH, 0, 0L);
879 int SetDroppedWidth(UINT nWidth)
881 ATLASSERT(::IsWindow(m_hWnd));
882 return (int)::SendMessage(m_hWnd, CB_SETDROPPEDWIDTH, nWidth, 0L);
885 #if ((WINVER >= 0x0500) && !defined(_WIN32_WCE)) || (defined(_WIN32_WCE) && (_WIN32_WCE >= 420))
886 BOOL GetComboBoxInfo(PCOMBOBOXINFO pComboBoxInfo) const
888 ATLASSERT(::IsWindow(m_hWnd));
889 #if ((_WIN32_WINNT >= 0x0501) && !defined(_WIN32_WCE)) || (defined(_WIN32_WCE) && (_WIN32_WCE >= 420))
890 return (BOOL)::SendMessage(m_hWnd, CB_GETCOMBOBOXINFO, 0, (LPARAM)pComboBoxInfo);
891 #else // !((_WIN32_WINNT >= 0x0501) && !defined(_WIN32_WCE)) || (defined(_WIN32_WCE) && (_WIN32_WCE >= 420))
892 return ::GetComboBoxInfo(m_hWnd, pComboBoxInfo);
893 #endif // !((_WIN32_WINNT >= 0x0501) && !defined(_WIN32_WCE)) || (defined(_WIN32_WCE) && (_WIN32_WCE >= 420))
895 #endif // ((WINVER >= 0x0500) && !defined(_WIN32_WCE)) || (defined(_WIN32_WCE) && (_WIN32_WCE >= 420))
897 // for edit control
898 DWORD GetEditSel() const
900 ATLASSERT(::IsWindow(m_hWnd));
901 return (DWORD)::SendMessage(m_hWnd, CB_GETEDITSEL, 0, 0L);
904 BOOL SetEditSel(int nStartChar, int nEndChar)
906 ATLASSERT(::IsWindow(m_hWnd));
907 return (BOOL)::SendMessage(m_hWnd, CB_SETEDITSEL, 0, MAKELONG(nStartChar, nEndChar));
910 // for combobox item
911 DWORD_PTR GetItemData(int nIndex) const
913 ATLASSERT(::IsWindow(m_hWnd));
914 return (DWORD_PTR)::SendMessage(m_hWnd, CB_GETITEMDATA, nIndex, 0L);
917 int SetItemData(int nIndex, DWORD_PTR dwItemData)
919 ATLASSERT(::IsWindow(m_hWnd));
920 return (int)::SendMessage(m_hWnd, CB_SETITEMDATA, nIndex, (LPARAM)dwItemData);
923 void* GetItemDataPtr(int nIndex) const
925 ATLASSERT(::IsWindow(m_hWnd));
926 return (void*)GetItemData(nIndex);
929 int SetItemDataPtr(int nIndex, void* pData)
931 ATLASSERT(::IsWindow(m_hWnd));
932 return SetItemData(nIndex, (DWORD_PTR)pData);
935 int GetLBText(int nIndex, LPTSTR lpszText) const
937 ATLASSERT(::IsWindow(m_hWnd));
938 return (int)::SendMessage(m_hWnd, CB_GETLBTEXT, nIndex, (LPARAM)lpszText);
941 #ifndef _ATL_NO_COM
942 BOOL GetLBTextBSTR(int nIndex, BSTR& bstrText) const
944 USES_CONVERSION;
945 ATLASSERT(::IsWindow(m_hWnd));
946 ATLASSERT(bstrText == NULL);
948 int nLen = GetLBTextLen(nIndex);
949 if(nLen == CB_ERR)
950 return FALSE;
952 CTempBuffer<TCHAR, _WTL_STACK_ALLOC_THRESHOLD> buff;
953 LPTSTR lpstrText = buff.Allocate(nLen + 1);
954 if(lpstrText == NULL)
955 return FALSE;
957 if(GetLBText(nIndex, lpstrText) == CB_ERR)
958 return FALSE;
960 bstrText = ::SysAllocString(T2OLE(lpstrText));
961 return (bstrText != NULL) ? TRUE : FALSE;
963 #endif // !_ATL_NO_COM
965 #if defined(_WTL_USE_CSTRING) || defined(__ATLSTR_H__)
966 int GetLBText(int nIndex, _CSTRING_NS::CString& strText) const
968 ATLASSERT(::IsWindow(m_hWnd));
969 int cchLen = GetLBTextLen(nIndex);
970 if(cchLen == CB_ERR)
971 return CB_ERR;
972 int nRet = CB_ERR;
973 LPTSTR lpstr = strText.GetBufferSetLength(cchLen);
974 if(lpstr != NULL)
976 nRet = GetLBText(nIndex, lpstr);
977 strText.ReleaseBuffer();
979 return nRet;
981 #endif // defined(_WTL_USE_CSTRING) || defined(__ATLSTR_H__)
983 int GetLBTextLen(int nIndex) const
985 ATLASSERT(::IsWindow(m_hWnd));
986 return (int)::SendMessage(m_hWnd, CB_GETLBTEXTLEN, nIndex, 0L);
989 int GetItemHeight(int nIndex) const
991 ATLASSERT(::IsWindow(m_hWnd));
992 return (int)::SendMessage(m_hWnd, CB_GETITEMHEIGHT, nIndex, 0L);
995 int SetItemHeight(int nIndex, UINT cyItemHeight)
997 ATLASSERT(::IsWindow(m_hWnd));
998 return (int)::SendMessage(m_hWnd, CB_SETITEMHEIGHT, nIndex, MAKELONG(cyItemHeight, 0));
1001 BOOL GetExtendedUI() const
1003 ATLASSERT(::IsWindow(m_hWnd));
1004 return (BOOL)::SendMessage(m_hWnd, CB_GETEXTENDEDUI, 0, 0L);
1007 int SetExtendedUI(BOOL bExtended = TRUE)
1009 ATLASSERT(::IsWindow(m_hWnd));
1010 return (int)::SendMessage(m_hWnd, CB_SETEXTENDEDUI, bExtended, 0L);
1013 void GetDroppedControlRect(LPRECT lprect) const
1015 ATLASSERT(::IsWindow(m_hWnd));
1016 ::SendMessage(m_hWnd, CB_GETDROPPEDCONTROLRECT, 0, (LPARAM)lprect);
1019 BOOL GetDroppedState() const
1021 ATLASSERT(::IsWindow(m_hWnd));
1022 return (BOOL)::SendMessage(m_hWnd, CB_GETDROPPEDSTATE, 0, 0L);
1025 #if (_WIN32_WINNT >= 0x0501)
1026 int GetMinVisible() const
1028 ATLASSERT(::IsWindow(m_hWnd));
1029 return (int)::SendMessage(m_hWnd, CB_GETMINVISIBLE, 0, 0L);
1032 BOOL SetMinVisible(int nMinVisible)
1034 ATLASSERT(::IsWindow(m_hWnd));
1035 return (BOOL)::SendMessage(m_hWnd, CB_SETMINVISIBLE, nMinVisible, 0L);
1038 // Vista only
1039 BOOL GetCueBannerText(LPWSTR lpwText, int cchText) const
1041 #ifndef CB_GETCUEBANNER
1042 const UINT CB_GETCUEBANNER = (CBM_FIRST + 4);
1043 #endif
1044 ATLASSERT(::IsWindow(m_hWnd));
1045 return (BOOL)::SendMessage(m_hWnd, CB_GETCUEBANNER, (WPARAM)lpwText, cchText);
1048 // Vista only
1049 BOOL SetCueBannerText(LPCWSTR lpcwText)
1051 #ifndef CB_SETCUEBANNER
1052 const UINT CB_SETCUEBANNER = (CBM_FIRST + 3);
1053 #endif
1054 ATLASSERT(::IsWindow(m_hWnd));
1055 return (BOOL)::SendMessage(m_hWnd, CB_SETCUEBANNER, 0, (LPARAM)lpcwText);
1057 #endif // (_WIN32_WINNT >= 0x0501)
1059 // Operations
1060 int InitStorage(int nItems, UINT nBytes)
1062 ATLASSERT(::IsWindow(m_hWnd));
1063 return (int)::SendMessage(m_hWnd, CB_INITSTORAGE, (WPARAM)nItems, nBytes);
1066 void ResetContent()
1068 ATLASSERT(::IsWindow(m_hWnd));
1069 ::SendMessage(m_hWnd, CB_RESETCONTENT, 0, 0L);
1072 // for edit control
1073 BOOL LimitText(int nMaxChars)
1075 ATLASSERT(::IsWindow(m_hWnd));
1076 return (BOOL)::SendMessage(m_hWnd, CB_LIMITTEXT, nMaxChars, 0L);
1079 // for drop-down combo boxes
1080 void ShowDropDown(BOOL bShowIt = TRUE)
1082 ATLASSERT(::IsWindow(m_hWnd));
1083 ::SendMessage(m_hWnd, CB_SHOWDROPDOWN, bShowIt, 0L);
1086 // manipulating listbox items
1087 int AddString(LPCTSTR lpszString)
1089 ATLASSERT(::IsWindow(m_hWnd));
1090 return (int)::SendMessage(m_hWnd, CB_ADDSTRING, 0, (LPARAM)lpszString);
1093 int DeleteString(UINT nIndex)
1095 ATLASSERT(::IsWindow(m_hWnd));
1096 return (int)::SendMessage(m_hWnd, CB_DELETESTRING, nIndex, 0L);
1099 int InsertString(int nIndex, LPCTSTR lpszString)
1101 ATLASSERT(::IsWindow(m_hWnd));
1102 return (int)::SendMessage(m_hWnd, CB_INSERTSTRING, nIndex, (LPARAM)lpszString);
1105 #ifndef _WIN32_WCE
1106 int Dir(UINT attr, LPCTSTR lpszWildCard)
1108 ATLASSERT(::IsWindow(m_hWnd));
1109 return (int)::SendMessage(m_hWnd, CB_DIR, attr, (LPARAM)lpszWildCard);
1111 #endif // !_WIN32_WCE
1113 // selection helpers
1114 int FindString(int nStartAfter, LPCTSTR lpszString) const
1116 ATLASSERT(::IsWindow(m_hWnd));
1117 return (int)::SendMessage(m_hWnd, CB_FINDSTRING, nStartAfter, (LPARAM)lpszString);
1120 int FindStringExact(int nIndexStart, LPCTSTR lpszFind) const
1122 ATLASSERT(::IsWindow(m_hWnd));
1123 return (int)::SendMessage(m_hWnd, CB_FINDSTRINGEXACT, nIndexStart, (LPARAM)lpszFind);
1126 int SelectString(int nStartAfter, LPCTSTR lpszString)
1128 ATLASSERT(::IsWindow(m_hWnd));
1129 return (int)::SendMessage(m_hWnd, CB_SELECTSTRING, nStartAfter, (LPARAM)lpszString);
1132 // Clipboard operations
1133 void Clear()
1135 ATLASSERT(::IsWindow(m_hWnd));
1136 ::SendMessage(m_hWnd, WM_CLEAR, 0, 0L);
1139 void Copy()
1141 ATLASSERT(::IsWindow(m_hWnd));
1142 ::SendMessage(m_hWnd, WM_COPY, 0, 0L);
1145 void Cut()
1147 ATLASSERT(::IsWindow(m_hWnd));
1148 ::SendMessage(m_hWnd, WM_CUT, 0, 0L);
1151 void Paste()
1153 ATLASSERT(::IsWindow(m_hWnd));
1154 ::SendMessage(m_hWnd, WM_PASTE, 0, 0L);
1158 typedef CComboBoxT<ATL::CWindow> CComboBox;
1160 #endif // !WIN32_PLATFORM_WFSP
1162 ///////////////////////////////////////////////////////////////////////////////
1163 // CEdit - client side for a Windows EDIT control
1165 template <class TBase>
1166 class CEditT : public TBase
1168 public:
1169 // Constructors
1170 CEditT(HWND hWnd = NULL) : TBase(hWnd)
1173 CEditT< TBase >& operator =(HWND hWnd)
1175 m_hWnd = hWnd;
1176 return *this;
1179 HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
1180 DWORD dwStyle = 0, DWORD dwExStyle = 0,
1181 ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
1183 return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
1186 // Attributes
1187 static LPCTSTR GetWndClassName()
1189 return _T("EDIT");
1192 BOOL CanUndo() const
1194 ATLASSERT(::IsWindow(m_hWnd));
1195 return (BOOL)::SendMessage(m_hWnd, EM_CANUNDO, 0, 0L);
1198 int GetLineCount() const
1200 ATLASSERT(::IsWindow(m_hWnd));
1201 return (int)::SendMessage(m_hWnd, EM_GETLINECOUNT, 0, 0L);
1204 BOOL GetModify() const
1206 ATLASSERT(::IsWindow(m_hWnd));
1207 return (BOOL)::SendMessage(m_hWnd, EM_GETMODIFY, 0, 0L);
1210 void SetModify(BOOL bModified = TRUE)
1212 ATLASSERT(::IsWindow(m_hWnd));
1213 ::SendMessage(m_hWnd, EM_SETMODIFY, bModified, 0L);
1216 void GetRect(LPRECT lpRect) const
1218 ATLASSERT(::IsWindow(m_hWnd));
1219 ::SendMessage(m_hWnd, EM_GETRECT, 0, (LPARAM)lpRect);
1222 DWORD GetSel() const
1224 ATLASSERT(::IsWindow(m_hWnd));
1225 return (DWORD)::SendMessage(m_hWnd, EM_GETSEL, 0, 0L);
1228 void GetSel(int& nStartChar, int& nEndChar) const
1230 ATLASSERT(::IsWindow(m_hWnd));
1231 ::SendMessage(m_hWnd, EM_GETSEL, (WPARAM)&nStartChar, (LPARAM)&nEndChar);
1234 #ifndef _WIN32_WCE
1235 HLOCAL GetHandle() const
1237 ATLASSERT(::IsWindow(m_hWnd));
1238 return (HLOCAL)::SendMessage(m_hWnd, EM_GETHANDLE, 0, 0L);
1241 void SetHandle(HLOCAL hBuffer)
1243 ATLASSERT(::IsWindow(m_hWnd));
1244 ::SendMessage(m_hWnd, EM_SETHANDLE, (WPARAM)hBuffer, 0L);
1246 #endif // !_WIN32_WCE
1248 DWORD GetMargins() const
1250 ATLASSERT(::IsWindow(m_hWnd));
1251 return (DWORD)::SendMessage(m_hWnd, EM_GETMARGINS, 0, 0L);
1254 void SetMargins(UINT nLeft, UINT nRight)
1256 ATLASSERT(::IsWindow(m_hWnd));
1257 ::SendMessage(m_hWnd, EM_SETMARGINS, EC_LEFTMARGIN|EC_RIGHTMARGIN, MAKELONG(nLeft, nRight));
1260 UINT GetLimitText() const
1262 ATLASSERT(::IsWindow(m_hWnd));
1263 return (UINT)::SendMessage(m_hWnd, EM_GETLIMITTEXT, 0, 0L);
1266 void SetLimitText(UINT nMax)
1268 ATLASSERT(::IsWindow(m_hWnd));
1269 ::SendMessage(m_hWnd, EM_SETLIMITTEXT, nMax, 0L);
1272 POINT PosFromChar(UINT nChar) const
1274 ATLASSERT(::IsWindow(m_hWnd));
1275 DWORD dwRet = (DWORD)::SendMessage(m_hWnd, EM_POSFROMCHAR, nChar, 0);
1276 POINT point = { GET_X_LPARAM(dwRet), GET_Y_LPARAM(dwRet) };
1277 return point;
1280 int CharFromPos(POINT pt, int* pLine = NULL) const
1282 ATLASSERT(::IsWindow(m_hWnd));
1283 DWORD dwRet = (DWORD)::SendMessage(m_hWnd, EM_CHARFROMPOS, 0, MAKELPARAM(pt.x, pt.y));
1284 if(pLine != NULL)
1285 *pLine = (int)(short)HIWORD(dwRet);
1286 return (int)(short)LOWORD(dwRet);
1289 // NOTE: first word in lpszBuffer must contain the size of the buffer!
1290 int GetLine(int nIndex, LPTSTR lpszBuffer) const
1292 ATLASSERT(::IsWindow(m_hWnd));
1293 return (int)::SendMessage(m_hWnd, EM_GETLINE, nIndex, (LPARAM)lpszBuffer);
1296 int GetLine(int nIndex, LPTSTR lpszBuffer, int nMaxLength) const
1298 ATLASSERT(::IsWindow(m_hWnd));
1299 *(LPWORD)lpszBuffer = (WORD)nMaxLength;
1300 return (int)::SendMessage(m_hWnd, EM_GETLINE, nIndex, (LPARAM)lpszBuffer);
1303 TCHAR GetPasswordChar() const
1305 ATLASSERT(::IsWindow(m_hWnd));
1306 return (TCHAR)::SendMessage(m_hWnd, EM_GETPASSWORDCHAR, 0, 0L);
1309 void SetPasswordChar(TCHAR ch)
1311 ATLASSERT(::IsWindow(m_hWnd));
1312 ::SendMessage(m_hWnd, EM_SETPASSWORDCHAR, ch, 0L);
1315 #ifndef _WIN32_WCE
1316 EDITWORDBREAKPROC GetWordBreakProc() const
1318 ATLASSERT(::IsWindow(m_hWnd));
1319 return (EDITWORDBREAKPROC)::SendMessage(m_hWnd, EM_GETWORDBREAKPROC, 0, 0L);
1322 void SetWordBreakProc(EDITWORDBREAKPROC ewbprc)
1324 ATLASSERT(::IsWindow(m_hWnd));
1325 ::SendMessage(m_hWnd, EM_SETWORDBREAKPROC, 0, (LPARAM)ewbprc);
1327 #endif // !_WIN32_WCE
1329 int GetFirstVisibleLine() const
1331 ATLASSERT(::IsWindow(m_hWnd));
1332 return (int)::SendMessage(m_hWnd, EM_GETFIRSTVISIBLELINE, 0, 0L);
1335 #ifndef _WIN32_WCE
1336 int GetThumb() const
1338 ATLASSERT(::IsWindow(m_hWnd));
1339 ATLASSERT((GetStyle() & ES_MULTILINE) != 0);
1340 return (int)::SendMessage(m_hWnd, EM_GETTHUMB, 0, 0L);
1342 #endif // !_WIN32_WCE
1344 BOOL SetReadOnly(BOOL bReadOnly = TRUE)
1346 ATLASSERT(::IsWindow(m_hWnd));
1347 return (BOOL)::SendMessage(m_hWnd, EM_SETREADONLY, bReadOnly, 0L);
1350 #if (WINVER >= 0x0500) && !defined(_WIN32_WCE)
1351 UINT GetImeStatus(UINT uStatus) const
1353 ATLASSERT(::IsWindow(m_hWnd));
1354 return (UINT)::SendMessage(m_hWnd, EM_GETIMESTATUS, uStatus, 0L);
1357 UINT SetImeStatus(UINT uStatus, UINT uData)
1359 ATLASSERT(::IsWindow(m_hWnd));
1360 return (UINT)::SendMessage(m_hWnd, EM_SETIMESTATUS, uStatus, uData);
1362 #endif // (WINVER >= 0x0500) && !defined(_WIN32_WCE)
1364 #if (_WIN32_WINNT >= 0x0501)
1365 BOOL GetCueBannerText(LPCWSTR lpstrText, int cchText) const
1367 ATLASSERT(::IsWindow(m_hWnd));
1368 return (BOOL)::SendMessage(m_hWnd, EM_GETCUEBANNER, (WPARAM)lpstrText, cchText);
1371 // bKeepWithFocus - Vista only
1372 BOOL SetCueBannerText(LPCWSTR lpstrText, BOOL bKeepWithFocus = FALSE)
1374 ATLASSERT(::IsWindow(m_hWnd));
1375 return (BOOL)::SendMessage(m_hWnd, EM_SETCUEBANNER, (WPARAM)bKeepWithFocus, (LPARAM)(lpstrText));
1377 #endif // (_WIN32_WINNT >= 0x0501)
1379 // Operations
1380 void EmptyUndoBuffer()
1382 ATLASSERT(::IsWindow(m_hWnd));
1383 ::SendMessage(m_hWnd, EM_EMPTYUNDOBUFFER, 0, 0L);
1386 BOOL FmtLines(BOOL bAddEOL)
1388 ATLASSERT(::IsWindow(m_hWnd));
1389 return (BOOL)::SendMessage(m_hWnd, EM_FMTLINES, bAddEOL, 0L);
1392 void LimitText(int nChars = 0)
1394 ATLASSERT(::IsWindow(m_hWnd));
1395 ::SendMessage(m_hWnd, EM_LIMITTEXT, nChars, 0L);
1398 int LineFromChar(int nIndex = -1) const
1400 ATLASSERT(::IsWindow(m_hWnd));
1401 return (int)::SendMessage(m_hWnd, EM_LINEFROMCHAR, nIndex, 0L);
1404 int LineIndex(int nLine = -1) const
1406 ATLASSERT(::IsWindow(m_hWnd));
1407 return (int)::SendMessage(m_hWnd, EM_LINEINDEX, nLine, 0L);
1410 int LineLength(int nLine = -1) const
1412 ATLASSERT(::IsWindow(m_hWnd));
1413 return (int)::SendMessage(m_hWnd, EM_LINELENGTH, nLine, 0L);
1416 void LineScroll(int nLines, int nChars = 0)
1418 ATLASSERT(::IsWindow(m_hWnd));
1419 ::SendMessage(m_hWnd, EM_LINESCROLL, nChars, nLines);
1422 void ReplaceSel(LPCTSTR lpszNewText, BOOL bCanUndo = FALSE)
1424 ATLASSERT(::IsWindow(m_hWnd));
1425 ::SendMessage(m_hWnd, EM_REPLACESEL, (WPARAM) bCanUndo, (LPARAM)lpszNewText);
1428 void SetRect(LPCRECT lpRect)
1430 ATLASSERT(::IsWindow(m_hWnd));
1431 ::SendMessage(m_hWnd, EM_SETRECT, 0, (LPARAM)lpRect);
1434 void SetRectNP(LPCRECT lpRect)
1436 ATLASSERT(::IsWindow(m_hWnd));
1437 ::SendMessage(m_hWnd, EM_SETRECTNP, 0, (LPARAM)lpRect);
1440 void SetSel(DWORD dwSelection, BOOL bNoScroll = FALSE)
1442 ATLASSERT(::IsWindow(m_hWnd));
1443 ::SendMessage(m_hWnd, EM_SETSEL, LOWORD(dwSelection), HIWORD(dwSelection));
1444 if(!bNoScroll)
1445 ::SendMessage(m_hWnd, EM_SCROLLCARET, 0, 0L);
1448 void SetSel(int nStartChar, int nEndChar, BOOL bNoScroll = FALSE)
1450 ATLASSERT(::IsWindow(m_hWnd));
1451 ::SendMessage(m_hWnd, EM_SETSEL, nStartChar, nEndChar);
1452 if(!bNoScroll)
1453 ::SendMessage(m_hWnd, EM_SCROLLCARET, 0, 0L);
1456 void SetSelAll(BOOL bNoScroll = FALSE)
1458 SetSel(0, -1, bNoScroll);
1461 void SetSelNone(BOOL bNoScroll = FALSE)
1463 SetSel(-1, 0, bNoScroll);
1466 BOOL SetTabStops(int nTabStops, LPINT rgTabStops)
1468 ATLASSERT(::IsWindow(m_hWnd));
1469 return (BOOL)::SendMessage(m_hWnd, EM_SETTABSTOPS, nTabStops, (LPARAM)rgTabStops);
1472 BOOL SetTabStops()
1474 ATLASSERT(::IsWindow(m_hWnd));
1475 return (BOOL)::SendMessage(m_hWnd, EM_SETTABSTOPS, 0, 0L);
1478 BOOL SetTabStops(const int& cxEachStop) // takes an 'int'
1480 ATLASSERT(::IsWindow(m_hWnd));
1481 return (BOOL)::SendMessage(m_hWnd, EM_SETTABSTOPS, 1, (LPARAM)(LPINT)&cxEachStop);
1484 void ScrollCaret()
1486 ATLASSERT(::IsWindow(m_hWnd));
1487 ::SendMessage(m_hWnd, EM_SCROLLCARET, 0, 0L);
1490 int Scroll(int nScrollAction)
1492 ATLASSERT(::IsWindow(m_hWnd));
1493 ATLASSERT((GetStyle() & ES_MULTILINE) != 0);
1494 LRESULT lRet = ::SendMessage(m_hWnd, EM_SCROLL, nScrollAction, 0L);
1495 if(!(BOOL)HIWORD(lRet))
1496 return -1; // failed
1497 return (int)(short)LOWORD(lRet);
1501 void InsertText(int nInsertAfterChar, LPCTSTR lpstrText, BOOL bNoScroll = FALSE, BOOL bCanUndo = FALSE)
1503 SetSel(nInsertAfterChar, nInsertAfterChar, bNoScroll);
1504 ReplaceSel(lpstrText, bCanUndo);
1507 void AppendText(LPCTSTR lpstrText, BOOL bNoScroll = FALSE, BOOL bCanUndo = FALSE)
1509 InsertText(GetWindowTextLength(), lpstrText, bNoScroll, bCanUndo);
1512 #if (_WIN32_WINNT >= 0x0501)
1513 BOOL ShowBalloonTip(PEDITBALLOONTIP pEditBaloonTip)
1515 ATLASSERT(::IsWindow(m_hWnd));
1516 return (BOOL)::SendMessage(m_hWnd, EM_SHOWBALLOONTIP, 0, (LPARAM)pEditBaloonTip);
1519 BOOL HideBalloonTip()
1521 ATLASSERT(::IsWindow(m_hWnd));
1522 return (BOOL)::SendMessage(m_hWnd, EM_HIDEBALLOONTIP, 0, 0L);
1524 #endif // (_WIN32_WINNT >= 0x0501)
1526 #if (_WIN32_WINNT >= 0x0600)
1527 DWORD GetHilite() const
1529 ATLASSERT(::IsWindow(m_hWnd));
1530 return (DWORD)::SendMessage(m_hWnd, EM_GETHILITE, 0, 0L);
1533 void GetHilite(int& nStartChar, int& nEndChar) const
1535 ATLASSERT(::IsWindow(m_hWnd));
1536 DWORD dwRet = (DWORD)::SendMessage(m_hWnd, EM_GETHILITE, 0, 0L);
1537 nStartChar = (int)(short)LOWORD(dwRet);
1538 nEndChar = (int)(short)HIWORD(dwRet);
1541 void SetHilite(int nStartChar, int nEndChar)
1543 ATLASSERT(::IsWindow(m_hWnd));
1544 ::SendMessage(m_hWnd, EM_SETHILITE, nStartChar, nEndChar);
1546 #endif // (_WIN32_WINNT >= 0x0600)
1548 // Clipboard operations
1549 BOOL Undo()
1551 ATLASSERT(::IsWindow(m_hWnd));
1552 return (BOOL)::SendMessage(m_hWnd, EM_UNDO, 0, 0L);
1555 void Clear()
1557 ATLASSERT(::IsWindow(m_hWnd));
1558 ::SendMessage(m_hWnd, WM_CLEAR, 0, 0L);
1561 void Copy()
1563 ATLASSERT(::IsWindow(m_hWnd));
1564 ::SendMessage(m_hWnd, WM_COPY, 0, 0L);
1567 void Cut()
1569 ATLASSERT(::IsWindow(m_hWnd));
1570 ::SendMessage(m_hWnd, WM_CUT, 0, 0L);
1573 void Paste()
1575 ATLASSERT(::IsWindow(m_hWnd));
1576 ::SendMessage(m_hWnd, WM_PASTE, 0, 0L);
1579 #ifdef WIN32_PLATFORM_WFSP // SmartPhone only messages
1580 DWORD GetExtendedStyle()
1582 return SendMessage(EM_GETEXTENDEDSTYLE);
1585 DWORD SetExtendedStyle(DWORD dwMask, DWORD dwExStyle)
1587 return SendMessage(EM_SETEXTENDEDSTYLE, (WPARAM)dwMask, (LPARAM)dwExStyle);
1590 DWORD GetInputMode(BOOL bCurrentMode = TRUE)
1592 return SendMessage(EM_GETINPUTMODE, 0, (LPARAM)bCurrentMode);
1595 BOOL SetInputMode(DWORD dwMode)
1597 return SendMessage(EM_SETINPUTMODE, 0, (LPARAM)dwMode);
1600 BOOL SetSymbols(LPCTSTR szSymbols)
1602 return SendMessage(EM_SETSYMBOLS, 0, (LPARAM)szSymbols);
1605 BOOL ResetSymbols()
1607 return SendMessage(EM_SETSYMBOLS);
1609 #endif // WIN32_PLATFORM_WFSP
1612 typedef CEditT<ATL::CWindow> CEdit;
1615 ///////////////////////////////////////////////////////////////////////////////
1616 // CEditCommands - message handlers for standard EDIT commands
1618 // Chain to CEditCommands message map. Your class must also derive from CEdit.
1619 // Example:
1620 // class CMyEdit : public CWindowImpl<CMyEdit, CEdit>,
1621 // public CEditCommands<CMyEdit>
1622 // {
1623 // public:
1624 // BEGIN_MSG_MAP(CMyEdit)
1625 // // your handlers...
1626 // CHAIN_MSG_MAP_ALT(CEditCommands<CMyEdit>, 1)
1627 // END_MSG_MAP()
1628 // // other stuff...
1629 // };
1631 template <class T>
1632 class CEditCommands
1634 public:
1635 BEGIN_MSG_MAP(CEditCommands< T >)
1636 ALT_MSG_MAP(1)
1637 COMMAND_ID_HANDLER(ID_EDIT_CLEAR, OnEditClear)
1638 COMMAND_ID_HANDLER(ID_EDIT_CLEAR_ALL, OnEditClearAll)
1639 COMMAND_ID_HANDLER(ID_EDIT_COPY, OnEditCopy)
1640 COMMAND_ID_HANDLER(ID_EDIT_CUT, OnEditCut)
1641 COMMAND_ID_HANDLER(ID_EDIT_PASTE, OnEditPaste)
1642 COMMAND_ID_HANDLER(ID_EDIT_SELECT_ALL, OnEditSelectAll)
1643 COMMAND_ID_HANDLER(ID_EDIT_UNDO, OnEditUndo)
1644 END_MSG_MAP()
1646 LRESULT OnEditClear(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
1648 T* pT = static_cast<T*>(this);
1649 pT->Clear();
1650 return 0;
1653 LRESULT OnEditClearAll(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
1655 T* pT = static_cast<T*>(this);
1656 pT->SetSel(0, -1);
1657 pT->Clear();
1658 return 0;
1661 LRESULT OnEditCopy(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
1663 T* pT = static_cast<T*>(this);
1664 pT->Copy();
1665 return 0;
1668 LRESULT OnEditCut(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
1670 T* pT = static_cast<T*>(this);
1671 pT->Cut();
1672 return 0;
1675 LRESULT OnEditPaste(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
1677 T* pT = static_cast<T*>(this);
1678 pT->Paste();
1679 return 0;
1682 LRESULT OnEditSelectAll(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
1684 T* pT = static_cast<T*>(this);
1685 pT->SetSel(0, -1);
1686 return 0;
1689 LRESULT OnEditUndo(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
1691 T* pT = static_cast<T*>(this);
1692 pT->Undo();
1693 return 0;
1696 // State (update UI) helpers
1697 BOOL CanCut() const
1698 { return HasSelection(); }
1700 BOOL CanCopy() const
1701 { return HasSelection(); }
1703 BOOL CanClear() const
1704 { return HasSelection(); }
1706 BOOL CanSelectAll() const
1707 { return HasText(); }
1709 BOOL CanFind() const
1710 { return HasText(); }
1712 BOOL CanRepeat() const
1713 { return HasText(); }
1715 BOOL CanReplace() const
1716 { return HasText(); }
1718 BOOL CanClearAll() const
1719 { return HasText(); }
1721 // Implementation
1722 BOOL HasSelection() const
1724 const T* pT = static_cast<const T*>(this);
1725 int nMin, nMax;
1726 ::SendMessage(pT->m_hWnd, EM_GETSEL, (WPARAM)&nMin, (LPARAM)&nMax);
1727 return (nMin != nMax);
1730 BOOL HasText() const
1732 const T* pT = static_cast<const T*>(this);
1733 return (pT->GetWindowTextLength() > 0);
1738 ///////////////////////////////////////////////////////////////////////////////
1739 // CScrollBar - client side for a Windows SCROLLBAR control
1741 template <class TBase>
1742 class CScrollBarT : public TBase
1744 public:
1745 // Constructors
1746 CScrollBarT(HWND hWnd = NULL) : TBase(hWnd)
1749 CScrollBarT< TBase >& operator =(HWND hWnd)
1751 m_hWnd = hWnd;
1752 return *this;
1755 HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
1756 DWORD dwStyle = 0, DWORD dwExStyle = 0,
1757 ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
1759 return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
1762 // Attributes
1763 static LPCTSTR GetWndClassName()
1765 return _T("SCROLLBAR");
1768 #ifndef _WIN32_WCE
1769 int GetScrollPos() const
1771 ATLASSERT(::IsWindow(m_hWnd));
1772 return ::GetScrollPos(m_hWnd, SB_CTL);
1774 #endif // !_WIN32_WCE
1776 int SetScrollPos(int nPos, BOOL bRedraw = TRUE)
1778 ATLASSERT(::IsWindow(m_hWnd));
1779 return ::SetScrollPos(m_hWnd, SB_CTL, nPos, bRedraw);
1782 #ifndef _WIN32_WCE
1783 void GetScrollRange(LPINT lpMinPos, LPINT lpMaxPos) const
1785 ATLASSERT(::IsWindow(m_hWnd));
1786 ::GetScrollRange(m_hWnd, SB_CTL, lpMinPos, lpMaxPos);
1788 #endif // !_WIN32_WCE
1790 void SetScrollRange(int nMinPos, int nMaxPos, BOOL bRedraw = TRUE)
1792 ATLASSERT(::IsWindow(m_hWnd));
1793 ::SetScrollRange(m_hWnd, SB_CTL, nMinPos, nMaxPos, bRedraw);
1796 BOOL GetScrollInfo(LPSCROLLINFO lpScrollInfo) const
1798 ATLASSERT(::IsWindow(m_hWnd));
1799 return ::GetScrollInfo(m_hWnd, SB_CTL, lpScrollInfo);
1802 int SetScrollInfo(LPSCROLLINFO lpScrollInfo, BOOL bRedraw = TRUE)
1804 ATLASSERT(::IsWindow(m_hWnd));
1805 return ::SetScrollInfo(m_hWnd, SB_CTL, lpScrollInfo, bRedraw);
1808 #ifndef _WIN32_WCE
1809 int GetScrollLimit() const
1811 int nMin = 0, nMax = 0;
1812 ::GetScrollRange(m_hWnd, SB_CTL, &nMin, &nMax);
1813 SCROLLINFO info = { 0 };
1814 info.cbSize = sizeof(SCROLLINFO);
1815 info.fMask = SIF_PAGE;
1816 if(::GetScrollInfo(m_hWnd, SB_CTL, &info))
1817 nMax -= ((info.nPage - 1) > 0) ? (info.nPage - 1) : 0;
1819 return nMax;
1822 #if (WINVER >= 0x0500)
1823 BOOL GetScrollBarInfo(PSCROLLBARINFO pScrollBarInfo) const
1825 ATLASSERT(::IsWindow(m_hWnd));
1826 #if (_WIN32_WINNT >= 0x0501)
1827 return (BOOL)::SendMessage(m_hWnd, SBM_GETSCROLLBARINFO, 0, (LPARAM)pScrollBarInfo);
1828 #else // !(_WIN32_WINNT >= 0x0501)
1829 return ::GetScrollBarInfo(m_hWnd, OBJID_CLIENT, pScrollBarInfo);
1830 #endif // !(_WIN32_WINNT >= 0x0501)
1832 #endif // (WINVER >= 0x0500)
1834 // Operations
1835 void ShowScrollBar(BOOL bShow = TRUE)
1837 ATLASSERT(::IsWindow(m_hWnd));
1838 ::ShowScrollBar(m_hWnd, SB_CTL, bShow);
1841 BOOL EnableScrollBar(UINT nArrowFlags = ESB_ENABLE_BOTH)
1843 ATLASSERT(::IsWindow(m_hWnd));
1844 return ::EnableScrollBar(m_hWnd, SB_CTL, nArrowFlags);
1846 #endif // !_WIN32_WCE
1849 typedef CScrollBarT<ATL::CWindow> CScrollBar;
1852 // --- Windows Common Controls ---
1854 ///////////////////////////////////////////////////////////////////////////////
1855 // CImageList
1857 class CImageList
1859 public:
1860 HIMAGELIST m_hImageList;
1862 // Constructor
1863 CImageList(HIMAGELIST hImageList = NULL) : m_hImageList(hImageList)
1866 // Operators, etc.
1867 CImageList& operator =(HIMAGELIST hImageList)
1869 m_hImageList = hImageList;
1870 return *this;
1873 operator HIMAGELIST() const { return m_hImageList; }
1875 void Attach(HIMAGELIST hImageList)
1877 ATLASSERT(m_hImageList == NULL);
1878 ATLASSERT(hImageList != NULL);
1879 m_hImageList = hImageList;
1882 HIMAGELIST Detach()
1884 HIMAGELIST hImageList = m_hImageList;
1885 m_hImageList = NULL;
1886 return hImageList;
1889 bool IsNull() const { return (m_hImageList == NULL); }
1891 // Attributes
1892 int GetImageCount() const
1894 ATLASSERT(m_hImageList != NULL);
1895 return ImageList_GetImageCount(m_hImageList);
1898 COLORREF GetBkColor() const
1900 ATLASSERT(m_hImageList != NULL);
1901 return ImageList_GetBkColor(m_hImageList);
1904 COLORREF SetBkColor(COLORREF cr)
1906 ATLASSERT(m_hImageList != NULL);
1907 return ImageList_SetBkColor(m_hImageList, cr);
1910 BOOL GetImageInfo(int nImage, IMAGEINFO* pImageInfo) const
1912 ATLASSERT(m_hImageList != NULL);
1913 return ImageList_GetImageInfo(m_hImageList, nImage, pImageInfo);
1916 HICON GetIcon(int nIndex, UINT uFlags = ILD_NORMAL) const
1918 ATLASSERT(m_hImageList != NULL);
1919 return ImageList_GetIcon(m_hImageList, nIndex, uFlags);
1922 BOOL GetIconSize(int& cx, int& cy) const
1924 ATLASSERT(m_hImageList != NULL);
1925 return ImageList_GetIconSize(m_hImageList, &cx, &cy);
1928 BOOL GetIconSize(SIZE& size) const
1930 ATLASSERT(m_hImageList != NULL);
1931 return ImageList_GetIconSize(m_hImageList, (int*)&size.cx, (int*)&size.cy);
1934 BOOL SetIconSize(int cx, int cy)
1936 ATLASSERT(m_hImageList != NULL);
1937 return ImageList_SetIconSize(m_hImageList, cx, cy);
1940 BOOL SetIconSize(SIZE size)
1942 ATLASSERT(m_hImageList != NULL);
1943 return ImageList_SetIconSize(m_hImageList, size.cx, size.cy);
1946 BOOL SetImageCount(UINT uNewCount)
1948 ATLASSERT(m_hImageList != NULL);
1949 return ImageList_SetImageCount(m_hImageList, uNewCount);
1952 BOOL SetOverlayImage(int nImage, int nOverlay)
1954 ATLASSERT(m_hImageList != NULL);
1955 return ImageList_SetOverlayImage(m_hImageList, nImage, nOverlay);
1958 // Operations
1959 BOOL Create(int cx, int cy, UINT nFlags, int nInitial, int nGrow)
1961 ATLASSERT(m_hImageList == NULL);
1962 m_hImageList = ImageList_Create(cx, cy, nFlags, nInitial, nGrow);
1963 return (m_hImageList != NULL) ? TRUE : FALSE;
1966 BOOL Create(ATL::_U_STRINGorID bitmap, int cx, int nGrow, COLORREF crMask)
1968 ATLASSERT(m_hImageList == NULL);
1969 m_hImageList = ImageList_LoadBitmap(ModuleHelper::GetResourceInstance(), bitmap.m_lpstr, cx, nGrow, crMask);
1970 return (m_hImageList != NULL) ? TRUE : FALSE;
1973 BOOL CreateFromImage(ATL::_U_STRINGorID image, int cx, int nGrow, COLORREF crMask, UINT uType, UINT uFlags = LR_DEFAULTCOLOR | LR_DEFAULTSIZE)
1975 ATLASSERT(m_hImageList == NULL);
1976 m_hImageList = ImageList_LoadImage(ModuleHelper::GetResourceInstance(), image.m_lpstr, cx, nGrow, crMask, uType, uFlags);
1977 return (m_hImageList != NULL) ? TRUE : FALSE;
1980 BOOL Merge(HIMAGELIST hImageList1, int nImage1, HIMAGELIST hImageList2, int nImage2, int dx, int dy)
1982 ATLASSERT(m_hImageList == NULL);
1983 m_hImageList = ImageList_Merge(hImageList1, nImage1, hImageList2, nImage2, dx, dy);
1984 return (m_hImageList != NULL) ? TRUE : FALSE;
1987 #ifndef _WIN32_WCE
1988 #ifdef __IStream_INTERFACE_DEFINED__
1989 BOOL CreateFromStream(LPSTREAM lpStream)
1991 ATLASSERT(m_hImageList == NULL);
1992 m_hImageList = ImageList_Read(lpStream);
1993 return (m_hImageList != NULL) ? TRUE : FALSE;
1995 #endif // __IStream_INTERFACE_DEFINED__
1996 #endif // !_WIN32_WCE
1998 BOOL Destroy()
2000 if (m_hImageList == NULL)
2001 return FALSE;
2002 BOOL bRet = ImageList_Destroy(m_hImageList);
2003 if(bRet)
2004 m_hImageList = NULL;
2005 return bRet;
2008 int Add(HBITMAP hBitmap, HBITMAP hBitmapMask = NULL)
2010 ATLASSERT(m_hImageList != NULL);
2011 return ImageList_Add(m_hImageList, hBitmap, hBitmapMask);
2014 int Add(HBITMAP hBitmap, COLORREF crMask)
2016 ATLASSERT(m_hImageList != NULL);
2017 return ImageList_AddMasked(m_hImageList, hBitmap, crMask);
2020 BOOL Remove(int nImage)
2022 ATLASSERT(m_hImageList != NULL);
2023 return ImageList_Remove(m_hImageList, nImage);
2026 BOOL RemoveAll()
2028 ATLASSERT(m_hImageList != NULL);
2029 return ImageList_RemoveAll(m_hImageList);
2032 BOOL Replace(int nImage, HBITMAP hBitmap, HBITMAP hBitmapMask)
2034 ATLASSERT(m_hImageList != NULL);
2035 return ImageList_Replace(m_hImageList, nImage, hBitmap, hBitmapMask);
2038 int AddIcon(HICON hIcon)
2040 ATLASSERT(m_hImageList != NULL);
2041 return ImageList_AddIcon(m_hImageList, hIcon);
2044 int ReplaceIcon(int nImage, HICON hIcon)
2046 ATLASSERT(m_hImageList != NULL);
2047 return ImageList_ReplaceIcon(m_hImageList, nImage, hIcon);
2050 HICON ExtractIcon(int nImage)
2052 ATLASSERT(m_hImageList != NULL);
2053 return ImageList_ExtractIcon(NULL, m_hImageList, nImage);
2056 BOOL Draw(HDC hDC, int nImage, int x, int y, UINT nStyle)
2058 ATLASSERT(m_hImageList != NULL);
2059 ATLASSERT(hDC != NULL);
2060 return ImageList_Draw(m_hImageList, nImage, hDC, x, y, nStyle);
2063 BOOL Draw(HDC hDC, int nImage, POINT pt, UINT nStyle)
2065 ATLASSERT(m_hImageList != NULL);
2066 ATLASSERT(hDC != NULL);
2067 return ImageList_Draw(m_hImageList, nImage, hDC, pt.x, pt.y, nStyle);
2070 BOOL DrawEx(int nImage, HDC hDC, int x, int y, int dx, int dy, COLORREF rgbBk, COLORREF rgbFg, UINT fStyle)
2072 ATLASSERT(m_hImageList != NULL);
2073 ATLASSERT(hDC != NULL);
2074 return ImageList_DrawEx(m_hImageList, nImage, hDC, x, y, dx, dy, rgbBk, rgbFg, fStyle);
2077 BOOL DrawEx(int nImage, HDC hDC, RECT& rect, COLORREF rgbBk, COLORREF rgbFg, UINT fStyle)
2079 ATLASSERT(m_hImageList != NULL);
2080 ATLASSERT(hDC != NULL);
2081 return ImageList_DrawEx(m_hImageList, nImage, hDC, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, rgbBk, rgbFg, fStyle);
2084 static BOOL DrawIndirect(IMAGELISTDRAWPARAMS* pimldp)
2086 return ImageList_DrawIndirect(pimldp);
2089 BOOL Copy(int nSrc, int nDst, UINT uFlags = ILCF_MOVE)
2091 ATLASSERT(m_hImageList != NULL);
2092 return ImageList_Copy(m_hImageList, nDst, m_hImageList, nSrc, uFlags);
2095 #ifdef __IStream_INTERFACE_DEFINED__
2096 #ifndef _WIN32_WCE
2097 static HIMAGELIST Read(LPSTREAM lpStream)
2099 return ImageList_Read(lpStream);
2102 BOOL Write(LPSTREAM lpStream)
2104 ATLASSERT(m_hImageList != NULL);
2105 return ImageList_Write(m_hImageList, lpStream);
2107 #endif // !_WIN32_WCE
2109 #if (_WIN32_WINNT >= 0x0501)
2110 static HRESULT ReadEx(DWORD dwFlags, LPSTREAM lpStream, REFIID riid, PVOID* ppv)
2112 return ImageList_ReadEx(dwFlags, lpStream, riid, ppv);
2115 HRESULT WriteEx(DWORD dwFlags, LPSTREAM lpStream)
2117 ATLASSERT(m_hImageList != NULL);
2118 return ImageList_WriteEx(m_hImageList, dwFlags, lpStream);
2120 #endif // (_WIN32_WINNT >= 0x0501)
2121 #endif // __IStream_INTERFACE_DEFINED__
2123 // Drag operations
2124 BOOL BeginDrag(int nImage, POINT ptHotSpot)
2126 ATLASSERT(m_hImageList != NULL);
2127 return ImageList_BeginDrag(m_hImageList, nImage, ptHotSpot.x, ptHotSpot.y);
2130 BOOL BeginDrag(int nImage, int xHotSpot, int yHotSpot)
2132 ATLASSERT(m_hImageList != NULL);
2133 return ImageList_BeginDrag(m_hImageList, nImage, xHotSpot, yHotSpot);
2136 static void EndDrag()
2138 ImageList_EndDrag();
2141 static BOOL DragMove(POINT pt)
2143 return ImageList_DragMove(pt.x, pt.y);
2146 static BOOL DragMove(int x, int y)
2148 return ImageList_DragMove(x, y);
2151 BOOL SetDragCursorImage(int nDrag, POINT ptHotSpot)
2153 ATLASSERT(m_hImageList != NULL);
2154 return ImageList_SetDragCursorImage(m_hImageList, nDrag, ptHotSpot.x, ptHotSpot.y);
2157 BOOL SetDragCursorImage(int nDrag, int xHotSpot, int yHotSpot)
2159 ATLASSERT(m_hImageList != NULL);
2160 return ImageList_SetDragCursorImage(m_hImageList, nDrag, xHotSpot, yHotSpot);
2163 static BOOL DragShowNolock(BOOL bShow = TRUE)
2165 return ImageList_DragShowNolock(bShow);
2168 static CImageList GetDragImage(LPPOINT lpPoint, LPPOINT lpPointHotSpot)
2170 return CImageList(ImageList_GetDragImage(lpPoint, lpPointHotSpot));
2173 static BOOL DragEnter(HWND hWnd, POINT point)
2175 return ImageList_DragEnter(hWnd, point.x, point.y);
2178 static BOOL DragEnter(HWND hWnd, int x, int y)
2180 return ImageList_DragEnter(hWnd, x, y);
2183 static BOOL DragLeave(HWND hWnd)
2185 return ImageList_DragLeave(hWnd);
2188 #if (_WIN32_IE >= 0x0400)
2189 CImageList Duplicate() const
2191 ATLASSERT(m_hImageList != NULL);
2192 return CImageList(ImageList_Duplicate(m_hImageList));
2195 static CImageList Duplicate(HIMAGELIST hImageList)
2197 ATLASSERT(hImageList != NULL);
2198 return CImageList(ImageList_Duplicate(hImageList));
2200 #endif // (_WIN32_IE >= 0x0400)
2204 ///////////////////////////////////////////////////////////////////////////////
2205 // CToolTipCtrl
2207 #ifndef _WIN32_WCE
2209 class CToolInfo : public TOOLINFO
2211 public:
2212 CToolInfo(UINT nFlags, HWND hWnd, UINT nIDTool = 0, LPRECT lpRect = NULL, LPTSTR lpstrText = LPSTR_TEXTCALLBACK, LPARAM lUserParam = NULL)
2214 Init(nFlags, hWnd, nIDTool, lpRect, lpstrText, lUserParam);
2217 operator LPTOOLINFO() { return this; }
2219 operator LPARAM() { return (LPARAM)this; }
2221 void Init(UINT nFlags, HWND hWnd, UINT nIDTool = 0, LPRECT lpRect = NULL, LPTSTR lpstrText = LPSTR_TEXTCALLBACK, LPARAM lUserParam = NULL)
2223 ATLASSERT(::IsWindow(hWnd));
2224 memset(this, 0, sizeof(TOOLINFO));
2225 cbSize = sizeof(TOOLINFO);
2226 uFlags = nFlags;
2227 if(nIDTool == 0)
2229 hwnd = ::GetParent(hWnd);
2230 uFlags |= TTF_IDISHWND;
2231 uId = (UINT_PTR)hWnd;
2233 else
2235 hwnd = hWnd;
2236 uId = nIDTool;
2238 if(lpRect != NULL)
2239 rect = *lpRect;
2240 hinst = ModuleHelper::GetResourceInstance();
2241 lpszText = lpstrText;
2242 lParam = lUserParam;
2246 template <class TBase>
2247 class CToolTipCtrlT : public TBase
2249 public:
2250 // Constructors
2251 CToolTipCtrlT(HWND hWnd = NULL) : TBase(hWnd)
2254 CToolTipCtrlT< TBase >& operator =(HWND hWnd)
2256 m_hWnd = hWnd;
2257 return *this;
2260 HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
2261 DWORD dwStyle = 0, DWORD dwExStyle = 0,
2262 ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
2264 return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
2267 // Attributes
2268 static LPCTSTR GetWndClassName()
2270 return TOOLTIPS_CLASS;
2273 void GetText(LPTOOLINFO lpToolInfo) const
2275 ATLASSERT(::IsWindow(m_hWnd));
2276 ::SendMessage(m_hWnd, TTM_GETTEXT, 0, (LPARAM)&lpToolInfo);
2279 void GetText(LPTSTR lpstrText, HWND hWnd, UINT nIDTool = 0) const
2281 ATLASSERT(::IsWindow(m_hWnd));
2282 ATLASSERT(hWnd != NULL);
2283 CToolInfo ti(0, hWnd, nIDTool, NULL, lpstrText);
2284 ::SendMessage(m_hWnd, TTM_GETTEXT, 0, ti);
2287 BOOL GetToolInfo(LPTOOLINFO lpToolInfo) const
2289 ATLASSERT(::IsWindow(m_hWnd));
2290 return (BOOL)::SendMessage(m_hWnd, TTM_GETTOOLINFO, 0, (LPARAM)lpToolInfo);
2293 BOOL GetToolInfo(HWND hWnd, UINT nIDTool, UINT* puFlags, LPRECT lpRect, LPTSTR lpstrText) const
2295 ATLASSERT(::IsWindow(m_hWnd));
2296 ATLASSERT(hWnd != NULL);
2297 ATLASSERT(puFlags != NULL);
2298 ATLASSERT(lpRect != NULL);
2299 CToolInfo ti(0, hWnd, nIDTool, NULL, lpstrText);
2300 BOOL bRet = (BOOL)::SendMessage(m_hWnd, TTM_GETTOOLINFO, 0, ti);
2301 if(bRet != FALSE)
2303 *puFlags = ti.uFlags;
2304 *lpRect = ti.rect;
2306 return bRet;
2309 void SetToolInfo(LPTOOLINFO lpToolInfo)
2311 ATLASSERT(::IsWindow(m_hWnd));
2312 ::SendMessage(m_hWnd, TTM_SETTOOLINFO, 0, (LPARAM)lpToolInfo);
2315 void SetToolRect(LPTOOLINFO lpToolInfo)
2317 ATLASSERT(::IsWindow(m_hWnd));
2318 ::SendMessage(m_hWnd, TTM_NEWTOOLRECT, 0, (LPARAM)lpToolInfo);
2321 void SetToolRect(HWND hWnd, UINT nIDTool, LPCRECT lpRect)
2323 ATLASSERT(::IsWindow(m_hWnd));
2324 ATLASSERT(hWnd != NULL);
2325 ATLASSERT(nIDTool != 0);
2327 CToolInfo ti(0, hWnd, nIDTool, (LPRECT)lpRect, NULL);
2328 ::SendMessage(m_hWnd, TTM_NEWTOOLRECT, 0, ti);
2331 int GetToolCount() const
2333 ATLASSERT(::IsWindow(m_hWnd));
2334 return (int)::SendMessage(m_hWnd, TTM_GETTOOLCOUNT, 0, 0L);
2337 int GetDelayTime(DWORD dwType) const
2339 ATLASSERT(::IsWindow(m_hWnd));
2340 return (int)::SendMessage(m_hWnd, TTM_GETDELAYTIME, dwType, 0L);
2343 void SetDelayTime(DWORD dwType, int nTime)
2345 ATLASSERT(::IsWindow(m_hWnd));
2346 ::SendMessage(m_hWnd, TTM_SETDELAYTIME, dwType, MAKELPARAM(nTime, 0));
2349 void GetMargin(LPRECT lpRect) const
2351 ATLASSERT(::IsWindow(m_hWnd));
2352 ::SendMessage(m_hWnd, TTM_GETMARGIN, 0, (LPARAM)lpRect);
2355 void SetMargin(LPRECT lpRect)
2357 ATLASSERT(::IsWindow(m_hWnd));
2358 ::SendMessage(m_hWnd, TTM_SETMARGIN, 0, (LPARAM)lpRect);
2361 int GetMaxTipWidth() const
2363 ATLASSERT(::IsWindow(m_hWnd));
2364 return (int)::SendMessage(m_hWnd, TTM_GETMAXTIPWIDTH, 0, 0L);
2367 int SetMaxTipWidth(int nWidth)
2369 ATLASSERT(::IsWindow(m_hWnd));
2370 return (int)::SendMessage(m_hWnd, TTM_SETMAXTIPWIDTH, 0, nWidth);
2373 COLORREF GetTipBkColor() const
2375 ATLASSERT(::IsWindow(m_hWnd));
2376 return (COLORREF)::SendMessage(m_hWnd, TTM_GETTIPBKCOLOR, 0, 0L);
2379 void SetTipBkColor(COLORREF clr)
2381 ATLASSERT(::IsWindow(m_hWnd));
2382 ::SendMessage(m_hWnd, TTM_SETTIPBKCOLOR, (WPARAM)clr, 0L);
2385 COLORREF GetTipTextColor() const
2387 ATLASSERT(::IsWindow(m_hWnd));
2388 return (COLORREF)::SendMessage(m_hWnd, TTM_GETTIPTEXTCOLOR, 0, 0L);
2391 void SetTipTextColor(COLORREF clr)
2393 ATLASSERT(::IsWindow(m_hWnd));
2394 ::SendMessage(m_hWnd, TTM_SETTIPTEXTCOLOR, (WPARAM)clr, 0L);
2397 BOOL GetCurrentTool(LPTOOLINFO lpToolInfo) const
2399 ATLASSERT(::IsWindow(m_hWnd));
2400 return (BOOL)::SendMessage(m_hWnd, TTM_GETCURRENTTOOL, 0, (LPARAM)lpToolInfo);
2403 #if (_WIN32_IE >= 0x0500)
2404 SIZE GetBubbleSize(LPTOOLINFO lpToolInfo) const
2406 ATLASSERT(::IsWindow(m_hWnd));
2407 DWORD dwRet = (DWORD)::SendMessage(m_hWnd, TTM_GETBUBBLESIZE, 0, (LPARAM)lpToolInfo);
2408 SIZE size = { GET_X_LPARAM(dwRet), GET_Y_LPARAM(dwRet) };
2409 return size;
2412 BOOL SetTitle(UINT uIcon, LPCTSTR lpstrTitle)
2414 ATLASSERT(::IsWindow(m_hWnd));
2415 return (BOOL)::SendMessage(m_hWnd, TTM_SETTITLE, uIcon, (LPARAM)lpstrTitle);
2417 #endif // (_WIN32_IE >= 0x0500)
2419 #if (_WIN32_WINNT >= 0x0501)
2420 void GetTitle(PTTGETTITLE pTTGetTitle) const
2422 ATLASSERT(::IsWindow(m_hWnd));
2423 ::SendMessage(m_hWnd, TTM_GETTITLE, 0, (LPARAM)pTTGetTitle);
2426 void SetWindowTheme(LPCWSTR lpstrTheme)
2428 ATLASSERT(::IsWindow(m_hWnd));
2429 ::SendMessage(m_hWnd, TTM_SETWINDOWTHEME, 0, (LPARAM)lpstrTheme);
2431 #endif // (_WIN32_WINNT >= 0x0501)
2433 // Operations
2434 void Activate(BOOL bActivate)
2436 ATLASSERT(::IsWindow(m_hWnd));
2437 ::SendMessage(m_hWnd, TTM_ACTIVATE, bActivate, 0L);
2440 BOOL AddTool(LPTOOLINFO lpToolInfo)
2442 ATLASSERT(::IsWindow(m_hWnd));
2443 return (BOOL)::SendMessage(m_hWnd, TTM_ADDTOOL, 0, (LPARAM)lpToolInfo);
2446 BOOL AddTool(HWND hWnd, ATL::_U_STRINGorID text = LPSTR_TEXTCALLBACK, LPCRECT lpRectTool = NULL, UINT nIDTool = 0)
2448 ATLASSERT(::IsWindow(m_hWnd));
2449 ATLASSERT(hWnd != NULL);
2450 // the toolrect and toolid must both be zero or both valid
2451 ATLASSERT((lpRectTool != NULL && nIDTool != 0) || (lpRectTool == NULL && nIDTool == 0));
2453 CToolInfo ti(0, hWnd, nIDTool, (LPRECT)lpRectTool, (LPTSTR)text.m_lpstr);
2454 return (BOOL)::SendMessage(m_hWnd, TTM_ADDTOOL, 0, ti);
2457 void DelTool(LPTOOLINFO lpToolInfo)
2459 ATLASSERT(::IsWindow(m_hWnd));
2460 ::SendMessage(m_hWnd, TTM_DELTOOL, 0, (LPARAM)lpToolInfo);
2463 void DelTool(HWND hWnd, UINT nIDTool = 0)
2465 ATLASSERT(::IsWindow(m_hWnd));
2466 ATLASSERT(hWnd != NULL);
2468 CToolInfo ti(0, hWnd, nIDTool, NULL, NULL);
2469 ::SendMessage(m_hWnd, TTM_DELTOOL, 0, ti);
2472 BOOL HitTest(LPTTHITTESTINFO lpHitTestInfo) const
2474 ATLASSERT(::IsWindow(m_hWnd));
2475 return (BOOL)::SendMessage(m_hWnd, TTM_HITTEST, 0, (LPARAM)lpHitTestInfo);
2478 BOOL HitTest(HWND hWnd, POINT pt, LPTOOLINFO lpToolInfo) const
2480 ATLASSERT(::IsWindow(m_hWnd));
2481 ATLASSERT(hWnd != NULL);
2482 ATLASSERT(lpToolInfo != NULL);
2484 TTHITTESTINFO hti = { 0 };
2485 hti.ti.cbSize = sizeof(TOOLINFO);
2486 hti.hwnd = hWnd;
2487 hti.pt.x = pt.x;
2488 hti.pt.y = pt.y;
2489 if((BOOL)::SendMessage(m_hWnd, TTM_HITTEST, 0, (LPARAM)&hti) != FALSE)
2491 *lpToolInfo = hti.ti;
2492 return TRUE;
2494 return FALSE;
2497 void RelayEvent(LPMSG lpMsg)
2499 ATLASSERT(::IsWindow(m_hWnd));
2500 ::SendMessage(m_hWnd, TTM_RELAYEVENT, 0, (LPARAM)lpMsg);
2503 void UpdateTipText(LPTOOLINFO lpToolInfo)
2505 ATLASSERT(::IsWindow(m_hWnd));
2506 ::SendMessage(m_hWnd, TTM_UPDATETIPTEXT, 0, (LPARAM)lpToolInfo);
2509 void UpdateTipText(ATL::_U_STRINGorID text, HWND hWnd, UINT nIDTool = 0)
2511 ATLASSERT(::IsWindow(m_hWnd));
2512 ATLASSERT(hWnd != NULL);
2514 CToolInfo ti(0, hWnd, nIDTool, NULL, (LPTSTR)text.m_lpstr);
2515 ::SendMessage(m_hWnd, TTM_UPDATETIPTEXT, 0, ti);
2518 BOOL EnumTools(UINT nTool, LPTOOLINFO lpToolInfo) const
2520 ATLASSERT(::IsWindow(m_hWnd));
2521 return (BOOL)::SendMessage(m_hWnd, TTM_ENUMTOOLS, nTool, (LPARAM)lpToolInfo);
2524 void Pop()
2526 ATLASSERT(::IsWindow(m_hWnd));
2527 ::SendMessage(m_hWnd, TTM_POP, 0, 0L);
2530 void TrackActivate(LPTOOLINFO lpToolInfo, BOOL bActivate)
2532 ATLASSERT(::IsWindow(m_hWnd));
2533 ::SendMessage(m_hWnd, TTM_TRACKACTIVATE, bActivate, (LPARAM)lpToolInfo);
2536 void TrackPosition(int xPos, int yPos)
2538 ATLASSERT(::IsWindow(m_hWnd));
2539 ::SendMessage(m_hWnd, TTM_TRACKPOSITION, 0, MAKELPARAM(xPos, yPos));
2542 #if (_WIN32_IE >= 0x0400)
2543 void Update()
2545 ATLASSERT(::IsWindow(m_hWnd));
2546 ::SendMessage(m_hWnd, TTM_UPDATE, 0, 0L);
2548 #endif // (_WIN32_IE >= 0x0400)
2550 #if (_WIN32_IE >= 0x0500)
2551 BOOL AdjustRect(LPRECT lpRect, BOOL bLarger /*= TRUE*/)
2553 ATLASSERT(::IsWindow(m_hWnd));
2554 return (BOOL)::SendMessage(m_hWnd, TTM_ADJUSTRECT, bLarger, (LPARAM)lpRect);
2556 #endif // (_WIN32_IE >= 0x0500)
2558 #if (_WIN32_WINNT >= 0x0501)
2559 void Popup()
2561 ATLASSERT(::IsWindow(m_hWnd));
2562 ::SendMessage(m_hWnd, TTM_POPUP, 0, 0L);
2564 #endif // (_WIN32_WINNT >= 0x0501)
2567 typedef CToolTipCtrlT<ATL::CWindow> CToolTipCtrl;
2569 #endif // !_WIN32_WCE
2572 ///////////////////////////////////////////////////////////////////////////////
2573 // CHeaderCtrl
2575 template <class TBase>
2576 class CHeaderCtrlT : public TBase
2578 public:
2579 // Constructors
2580 CHeaderCtrlT(HWND hWnd = NULL) : TBase(hWnd)
2583 CHeaderCtrlT< TBase >& operator =(HWND hWnd)
2585 m_hWnd = hWnd;
2586 return *this;
2589 HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
2590 DWORD dwStyle = 0, DWORD dwExStyle = 0,
2591 ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
2593 return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
2596 // Attributes
2597 static LPCTSTR GetWndClassName()
2599 return WC_HEADER;
2602 int GetItemCount() const
2604 ATLASSERT(::IsWindow(m_hWnd));
2605 return (int)::SendMessage(m_hWnd, HDM_GETITEMCOUNT, 0, 0L);
2608 BOOL GetItem(int nIndex, LPHDITEM pHeaderItem) const
2610 ATLASSERT(::IsWindow(m_hWnd));
2611 return (BOOL)::SendMessage(m_hWnd, HDM_GETITEM, nIndex, (LPARAM)pHeaderItem);
2614 BOOL SetItem(int nIndex, LPHDITEM pHeaderItem)
2616 ATLASSERT(::IsWindow(m_hWnd));
2617 return (BOOL)::SendMessage(m_hWnd, HDM_SETITEM, nIndex, (LPARAM)pHeaderItem);
2620 CImageList GetImageList() const
2622 ATLASSERT(::IsWindow(m_hWnd));
2623 return CImageList((HIMAGELIST)::SendMessage(m_hWnd, HDM_GETIMAGELIST, 0, 0L));
2626 CImageList SetImageList(HIMAGELIST hImageList)
2628 ATLASSERT(::IsWindow(m_hWnd));
2629 return CImageList((HIMAGELIST)::SendMessage(m_hWnd, HDM_SETIMAGELIST, 0, (LPARAM)hImageList));
2632 BOOL GetOrderArray(int nSize, int* lpnArray) const
2634 ATLASSERT(::IsWindow(m_hWnd));
2635 return (BOOL)::SendMessage(m_hWnd, HDM_GETORDERARRAY, nSize, (LPARAM)lpnArray);
2638 BOOL SetOrderArray(int nSize, int* lpnArray)
2640 ATLASSERT(::IsWindow(m_hWnd));
2641 return (BOOL)::SendMessage(m_hWnd, HDM_SETORDERARRAY, nSize, (LPARAM)lpnArray);
2644 BOOL GetItemRect(int nIndex, LPRECT lpItemRect) const
2646 ATLASSERT(::IsWindow(m_hWnd));
2647 return (BOOL)::SendMessage(m_hWnd, HDM_GETITEMRECT, nIndex, (LPARAM)lpItemRect);
2650 int SetHotDivider(BOOL bPos, DWORD dwInputValue)
2652 ATLASSERT(::IsWindow(m_hWnd));
2653 return (int)::SendMessage(m_hWnd, HDM_SETHOTDIVIDER, bPos, dwInputValue);
2656 #if (_WIN32_IE >= 0x0400) && !defined(_WIN32_WCE)
2657 BOOL GetUnicodeFormat() const
2659 ATLASSERT(::IsWindow(m_hWnd));
2660 return (BOOL)::SendMessage(m_hWnd, HDM_GETUNICODEFORMAT, 0, 0L);
2663 BOOL SetUnicodeFormat(BOOL bUnicode = TRUE)
2665 ATLASSERT(::IsWindow(m_hWnd));
2666 return (BOOL)::SendMessage(m_hWnd, HDM_SETUNICODEFORMAT, bUnicode, 0L);
2668 #endif // (_WIN32_IE >= 0x0400) && !defined(_WIN32_WCE)
2670 #if (_WIN32_IE >= 0x0500) && !defined(_WIN32_WCE)
2671 int GetBitmapMargin() const
2673 ATLASSERT(::IsWindow(m_hWnd));
2674 return (int)::SendMessage(m_hWnd, HDM_GETBITMAPMARGIN, 0, 0L);
2677 int SetBitmapMargin(int nWidth)
2679 ATLASSERT(::IsWindow(m_hWnd));
2680 return (int)::SendMessage(m_hWnd, HDM_SETBITMAPMARGIN, nWidth, 0L);
2683 int SetFilterChangeTimeout(DWORD dwTimeOut)
2685 ATLASSERT(::IsWindow(m_hWnd));
2686 return (int)::SendMessage(m_hWnd, HDM_SETFILTERCHANGETIMEOUT, 0, dwTimeOut);
2688 #endif // (_WIN32_IE >= 0x0500) && !defined(_WIN32_WCE)
2690 #if (_WIN32_WINNT >= 0x0600)
2691 BOOL GetItemDropDownRect(int nIndex, LPRECT lpRect) const
2693 ATLASSERT(::IsWindow(m_hWnd));
2694 return (BOOL)::SendMessage(m_hWnd, HDM_GETITEMDROPDOWNRECT, nIndex, (LPARAM)lpRect);
2697 BOOL GetOverflowRect(LPRECT lpRect) const
2699 ATLASSERT(::IsWindow(m_hWnd));
2700 return (BOOL)::SendMessage(m_hWnd, HDM_GETOVERFLOWRECT, 0, (LPARAM)lpRect);
2703 int GetFocusedItem() const
2705 ATLASSERT(::IsWindow(m_hWnd));
2706 return (int)::SendMessage(m_hWnd, HDM_GETFOCUSEDITEM, 0, 0L);
2709 BOOL SetFocusedItem(int nIndex)
2711 ATLASSERT(::IsWindow(m_hWnd));
2712 return (BOOL)::SendMessage(m_hWnd, HDM_SETFOCUSEDITEM, 0, nIndex);
2714 #endif // (_WIN32_WINNT >= 0x0600)
2716 // Operations
2717 int InsertItem(int nIndex, LPHDITEM phdi)
2719 ATLASSERT(::IsWindow(m_hWnd));
2720 return (int)::SendMessage(m_hWnd, HDM_INSERTITEM, nIndex, (LPARAM)phdi);
2723 int AddItem(LPHDITEM phdi)
2725 return InsertItem(GetItemCount(), phdi);
2728 BOOL DeleteItem(int nIndex)
2730 ATLASSERT(::IsWindow(m_hWnd));
2731 return (BOOL)::SendMessage(m_hWnd, HDM_DELETEITEM, nIndex, 0L);
2734 BOOL Layout(HD_LAYOUT* pHeaderLayout)
2736 ATLASSERT(::IsWindow(m_hWnd));
2737 return (BOOL)::SendMessage(m_hWnd, HDM_LAYOUT, 0, (LPARAM)pHeaderLayout);
2740 int HitTest(LPHDHITTESTINFO lpHitTestInfo) const
2742 ATLASSERT(::IsWindow(m_hWnd));
2743 return (int)::SendMessage(m_hWnd, HDM_HITTEST, 0, (LPARAM)lpHitTestInfo);
2746 int OrderToIndex(int nOrder)
2748 ATLASSERT(::IsWindow(m_hWnd));
2749 return (int)::SendMessage(m_hWnd, HDM_ORDERTOINDEX, nOrder, 0L);
2752 CImageList CreateDragImage(int nIndex)
2754 ATLASSERT(::IsWindow(m_hWnd));
2755 return CImageList((HIMAGELIST)::SendMessage(m_hWnd, HDM_CREATEDRAGIMAGE, nIndex, 0L));
2758 #if (_WIN32_IE >= 0x0500) && !defined(_WIN32_WCE)
2759 int EditFilter(int nColumn, BOOL bDiscardChanges)
2761 ATLASSERT(::IsWindow(m_hWnd));
2762 return (int)::SendMessage(m_hWnd, HDM_EDITFILTER, nColumn, MAKELPARAM(bDiscardChanges, 0));
2765 int ClearFilter(int nColumn)
2767 ATLASSERT(::IsWindow(m_hWnd));
2768 return (int)::SendMessage(m_hWnd, HDM_CLEARFILTER, nColumn, 0L);
2771 int ClearAllFilters()
2773 ATLASSERT(::IsWindow(m_hWnd));
2774 return (int)::SendMessage(m_hWnd, HDM_CLEARFILTER, (WPARAM)-1, 0L);
2776 #endif // (_WIN32_IE >= 0x0500) && !defined(_WIN32_WCE)
2779 typedef CHeaderCtrlT<ATL::CWindow> CHeaderCtrl;
2782 ///////////////////////////////////////////////////////////////////////////////
2783 // CListViewCtrl
2785 template <class TBase>
2786 class CListViewCtrlT : public TBase
2788 public:
2789 // Constructors
2790 CListViewCtrlT(HWND hWnd = NULL) : TBase(hWnd)
2793 CListViewCtrlT< TBase >& operator =(HWND hWnd)
2795 m_hWnd = hWnd;
2796 return *this;
2799 HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
2800 DWORD dwStyle = 0, DWORD dwExStyle = 0,
2801 ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
2803 return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
2806 // Attributes
2807 static LPCTSTR GetWndClassName()
2809 return WC_LISTVIEW;
2812 COLORREF GetBkColor() const
2814 ATLASSERT(::IsWindow(m_hWnd));
2815 return (COLORREF)::SendMessage(m_hWnd, LVM_GETBKCOLOR, 0, 0L);
2818 BOOL SetBkColor(COLORREF cr)
2820 ATLASSERT(::IsWindow(m_hWnd));
2821 return (BOOL)::SendMessage(m_hWnd, LVM_SETBKCOLOR, 0, cr);
2824 CImageList GetImageList(int nImageListType) const
2826 ATLASSERT(::IsWindow(m_hWnd));
2827 return CImageList((HIMAGELIST)::SendMessage(m_hWnd, LVM_GETIMAGELIST, nImageListType, 0L));
2830 CImageList SetImageList(HIMAGELIST hImageList, int nImageList)
2832 ATLASSERT(::IsWindow(m_hWnd));
2833 return CImageList((HIMAGELIST)::SendMessage(m_hWnd, LVM_SETIMAGELIST, nImageList, (LPARAM)hImageList));
2836 int GetItemCount() const
2838 ATLASSERT(::IsWindow(m_hWnd));
2839 return (int)::SendMessage(m_hWnd, LVM_GETITEMCOUNT, 0, 0L);
2842 BOOL SetItemCount(int nItems)
2844 ATLASSERT(::IsWindow(m_hWnd));
2845 return (BOOL)::SendMessage(m_hWnd, LVM_SETITEMCOUNT, nItems, 0L);
2848 BOOL GetItem(LPLVITEM pItem) const
2850 ATLASSERT(::IsWindow(m_hWnd));
2851 return (BOOL)::SendMessage(m_hWnd, LVM_GETITEM, 0, (LPARAM)pItem);
2854 BOOL SetItem(const LVITEM* pItem)
2856 ATLASSERT(::IsWindow(m_hWnd));
2857 return (BOOL)::SendMessage(m_hWnd, LVM_SETITEM, 0, (LPARAM)pItem);
2860 BOOL SetItem(int nItem, int nSubItem, UINT nMask, LPCTSTR lpszItem,
2861 int nImage, UINT nState, UINT nStateMask, LPARAM lParam)
2863 ATLASSERT(::IsWindow(m_hWnd));
2864 LVITEM lvi = { 0 };
2865 lvi.mask = nMask;
2866 lvi.iItem = nItem;
2867 lvi.iSubItem = nSubItem;
2868 lvi.stateMask = nStateMask;
2869 lvi.state = nState;
2870 lvi.pszText = (LPTSTR) lpszItem;
2871 lvi.iImage = nImage;
2872 lvi.lParam = lParam;
2873 return (BOOL)::SendMessage(m_hWnd, LVM_SETITEM, 0, (LPARAM)&lvi);
2876 UINT GetItemState(int nItem, UINT nMask) const
2878 ATLASSERT(::IsWindow(m_hWnd));
2879 return (UINT)::SendMessage(m_hWnd, LVM_GETITEMSTATE, nItem, nMask);
2882 BOOL SetItemState(int nItem, UINT nState, UINT nStateMask)
2884 ATLASSERT(::IsWindow(m_hWnd));
2885 LVITEM lvi = { 0 };
2886 lvi.state = nState;
2887 lvi.stateMask = nStateMask;
2888 return (BOOL)::SendMessage(m_hWnd, LVM_SETITEMSTATE, nItem, (LPARAM)&lvi);
2891 BOOL SetItemState(int nItem, LPLVITEM pItem)
2893 ATLASSERT(::IsWindow(m_hWnd));
2894 return (BOOL)::SendMessage(m_hWnd, LVM_SETITEMSTATE, nItem, (LPARAM)pItem);
2897 #ifndef _ATL_NO_COM
2898 BOOL GetItemText(int nItem, int nSubItem, BSTR& bstrText) const
2900 USES_CONVERSION;
2901 ATLASSERT(::IsWindow(m_hWnd));
2902 ATLASSERT(bstrText == NULL);
2903 LVITEM lvi = { 0 };
2904 lvi.iSubItem = nSubItem;
2906 LPTSTR lpstrText = NULL;
2907 int nRes = 0;
2908 for(int nLen = 256; ; nLen *= 2)
2910 ATLTRY(lpstrText = new TCHAR[nLen]);
2911 if(lpstrText == NULL)
2912 break;
2913 lpstrText[0] = NULL;
2914 lvi.cchTextMax = nLen;
2915 lvi.pszText = lpstrText;
2916 nRes = (int)::SendMessage(m_hWnd, LVM_GETITEMTEXT, (WPARAM)nItem, (LPARAM)&lvi);
2917 if(nRes < nLen - 1)
2918 break;
2919 delete [] lpstrText;
2920 lpstrText = NULL;
2923 if(lpstrText != NULL)
2925 if(nRes != 0)
2926 bstrText = ::SysAllocString(T2OLE(lpstrText));
2927 delete [] lpstrText;
2930 return (bstrText != NULL) ? TRUE : FALSE;
2932 #endif // !_ATL_NO_COM
2934 #if defined(_WTL_USE_CSTRING) || defined(__ATLSTR_H__)
2935 int GetItemText(int nItem, int nSubItem, _CSTRING_NS::CString& strText) const
2937 ATLASSERT(::IsWindow(m_hWnd));
2938 LVITEM lvi = { 0 };
2939 lvi.iSubItem = nSubItem;
2941 strText.Empty();
2942 int nRes = 0;
2943 for(int nLen = 256; ; nLen *= 2)
2945 lvi.cchTextMax = nLen;
2946 lvi.pszText = strText.GetBufferSetLength(nLen);
2947 if(lvi.pszText == NULL)
2949 nRes = 0;
2950 break;
2952 nRes = (int)::SendMessage(m_hWnd, LVM_GETITEMTEXT, (WPARAM)nItem, (LPARAM)&lvi);
2953 if(nRes < nLen - 1)
2954 break;
2956 strText.ReleaseBuffer();
2957 return nRes;
2959 #endif // defined(_WTL_USE_CSTRING) || defined(__ATLSTR_H__)
2961 int GetItemText(int nItem, int nSubItem, LPTSTR lpszText, int nLen) const
2963 ATLASSERT(::IsWindow(m_hWnd));
2964 LVITEM lvi = { 0 };
2965 lvi.iSubItem = nSubItem;
2966 lvi.cchTextMax = nLen;
2967 lvi.pszText = lpszText;
2968 return (int)::SendMessage(m_hWnd, LVM_GETITEMTEXT, (WPARAM)nItem, (LPARAM)&lvi);
2971 BOOL SetItemText(int nItem, int nSubItem, LPCTSTR lpszText)
2973 ATLASSERT(::IsWindow(m_hWnd));
2974 return SetItem(nItem, nSubItem, LVIF_TEXT, lpszText, 0, 0, 0, 0);
2977 DWORD_PTR GetItemData(int nItem) const
2979 ATLASSERT(::IsWindow(m_hWnd));
2980 LVITEM lvi = { 0 };
2981 lvi.iItem = nItem;
2982 lvi.mask = LVIF_PARAM;
2983 BOOL bRet = (BOOL)::SendMessage(m_hWnd, LVM_GETITEM, 0, (LPARAM)&lvi);
2984 return (DWORD_PTR)(bRet ? lvi.lParam : NULL);
2987 BOOL SetItemData(int nItem, DWORD_PTR dwData)
2989 ATLASSERT(::IsWindow(m_hWnd));
2990 return SetItem(nItem, 0, LVIF_PARAM, NULL, 0, 0, 0, (LPARAM)dwData);
2993 UINT GetCallbackMask() const
2995 ATLASSERT(::IsWindow(m_hWnd));
2996 return (UINT)::SendMessage(m_hWnd, LVM_GETCALLBACKMASK, 0, 0L);
2999 BOOL SetCallbackMask(UINT nMask)
3001 ATLASSERT(::IsWindow(m_hWnd));
3002 return (BOOL)::SendMessage(m_hWnd, LVM_SETCALLBACKMASK, nMask, 0L);
3005 BOOL GetItemPosition(int nItem, LPPOINT lpPoint) const
3007 ATLASSERT(::IsWindow(m_hWnd));
3008 return (BOOL)::SendMessage(m_hWnd, LVM_GETITEMPOSITION, nItem, (LPARAM)lpPoint);
3011 BOOL SetItemPosition(int nItem, POINT pt)
3013 ATLASSERT(::IsWindow(m_hWnd));
3014 ATLASSERT(((GetStyle() & LVS_TYPEMASK) == LVS_ICON) || ((GetStyle() & LVS_TYPEMASK) == LVS_SMALLICON));
3015 return (BOOL)::SendMessage(m_hWnd, LVM_SETITEMPOSITION32, nItem, (LPARAM)&pt);
3018 BOOL SetItemPosition(int nItem, int x, int y)
3020 ATLASSERT(::IsWindow(m_hWnd));
3021 ATLASSERT(((GetStyle() & LVS_TYPEMASK) == LVS_ICON) || ((GetStyle() & LVS_TYPEMASK) == LVS_SMALLICON));
3022 POINT pt = { x, y };
3023 return (BOOL)::SendMessage(m_hWnd, LVM_SETITEMPOSITION32, nItem, (LPARAM)&pt);
3026 int GetStringWidth(LPCTSTR lpsz) const
3028 ATLASSERT(::IsWindow(m_hWnd));
3029 return (int)::SendMessage(m_hWnd, LVM_GETSTRINGWIDTH, 0, (LPARAM)lpsz);
3032 CEdit GetEditControl() const
3034 ATLASSERT(::IsWindow(m_hWnd));
3035 return CEdit((HWND)::SendMessage(m_hWnd, LVM_GETEDITCONTROL, 0, 0L));
3038 BOOL GetColumn(int nCol, LVCOLUMN* pColumn) const
3040 ATLASSERT(::IsWindow(m_hWnd));
3041 return (BOOL)::SendMessage(m_hWnd, LVM_GETCOLUMN, nCol, (LPARAM)pColumn);
3044 BOOL SetColumn(int nCol, const LVCOLUMN* pColumn)
3046 ATLASSERT(::IsWindow(m_hWnd));
3047 return (BOOL)::SendMessage(m_hWnd, LVM_SETCOLUMN, nCol, (LPARAM)pColumn);
3050 int GetColumnWidth(int nCol) const
3052 ATLASSERT(::IsWindow(m_hWnd));
3053 return (int)::SendMessage(m_hWnd, LVM_GETCOLUMNWIDTH, nCol, 0L);
3056 BOOL SetColumnWidth(int nCol, int cx)
3058 ATLASSERT(::IsWindow(m_hWnd));
3059 return (BOOL)::SendMessage(m_hWnd, LVM_SETCOLUMNWIDTH, nCol, MAKELPARAM(cx, 0));
3062 BOOL GetViewRect(LPRECT lpRect) const
3064 ATLASSERT(::IsWindow(m_hWnd));
3065 return (BOOL)::SendMessage(m_hWnd, LVM_GETVIEWRECT, 0, (LPARAM)lpRect);
3068 COLORREF GetTextColor() const
3070 ATLASSERT(::IsWindow(m_hWnd));
3071 return (COLORREF)::SendMessage(m_hWnd, LVM_GETTEXTCOLOR, 0, 0L);
3074 BOOL SetTextColor(COLORREF cr)
3076 ATLASSERT(::IsWindow(m_hWnd));
3077 return (BOOL)::SendMessage(m_hWnd, LVM_SETTEXTCOLOR, 0, cr);
3080 COLORREF GetTextBkColor() const
3082 ATLASSERT(::IsWindow(m_hWnd));
3083 return (COLORREF)::SendMessage(m_hWnd, LVM_GETTEXTBKCOLOR, 0, 0L);
3086 BOOL SetTextBkColor(COLORREF cr)
3088 ATLASSERT(::IsWindow(m_hWnd));
3089 return (BOOL)::SendMessage(m_hWnd, LVM_SETTEXTBKCOLOR, 0, cr);
3092 int GetTopIndex() const
3094 ATLASSERT(::IsWindow(m_hWnd));
3095 return (int)::SendMessage(m_hWnd, LVM_GETTOPINDEX, 0, 0L);
3098 int GetCountPerPage() const
3100 ATLASSERT(::IsWindow(m_hWnd));
3101 return (int)::SendMessage(m_hWnd, LVM_GETCOUNTPERPAGE, 0, 0L);
3104 BOOL GetOrigin(LPPOINT lpPoint) const
3106 ATLASSERT(::IsWindow(m_hWnd));
3107 return (BOOL)::SendMessage(m_hWnd, LVM_GETORIGIN, 0, (LPARAM)lpPoint);
3110 UINT GetSelectedCount() const
3112 ATLASSERT(::IsWindow(m_hWnd));
3113 return (UINT)::SendMessage(m_hWnd, LVM_GETSELECTEDCOUNT, 0, 0L);
3116 BOOL GetItemRect(int nItem, LPRECT lpRect, UINT nCode) const
3118 ATLASSERT(::IsWindow(m_hWnd));
3119 lpRect->left = nCode;
3120 return (BOOL)::SendMessage(m_hWnd, LVM_GETITEMRECT, (WPARAM)nItem, (LPARAM)lpRect);
3123 #ifndef _WIN32_WCE
3124 HCURSOR GetHotCursor() const
3126 ATLASSERT(::IsWindow(m_hWnd));
3127 return (HCURSOR)::SendMessage(m_hWnd, LVM_GETHOTCURSOR, 0, 0L);
3130 HCURSOR SetHotCursor(HCURSOR hHotCursor)
3132 ATLASSERT(::IsWindow(m_hWnd));
3133 return (HCURSOR)::SendMessage(m_hWnd, LVM_SETHOTCURSOR, 0, (LPARAM)hHotCursor);
3136 int GetHotItem() const
3138 ATLASSERT(::IsWindow(m_hWnd));
3139 return (int)::SendMessage(m_hWnd, LVM_GETHOTITEM, 0, 0L);
3142 int SetHotItem(int nIndex)
3144 ATLASSERT(::IsWindow(m_hWnd));
3145 return (int)::SendMessage(m_hWnd, LVM_SETHOTITEM, nIndex, 0L);
3147 #endif // !_WIN32_WCE
3149 BOOL GetColumnOrderArray(int nCount, int* lpnArray) const
3151 ATLASSERT(::IsWindow(m_hWnd));
3152 return (BOOL)::SendMessage(m_hWnd, LVM_GETCOLUMNORDERARRAY, nCount, (LPARAM)lpnArray);
3155 BOOL SetColumnOrderArray(int nCount, int* lpnArray)
3157 ATLASSERT(::IsWindow(m_hWnd));
3158 return (BOOL)::SendMessage(m_hWnd, LVM_SETCOLUMNORDERARRAY, nCount, (LPARAM)lpnArray);
3161 CHeaderCtrl GetHeader() const
3163 ATLASSERT(::IsWindow(m_hWnd));
3164 return CHeaderCtrl((HWND)::SendMessage(m_hWnd, LVM_GETHEADER, 0, 0L));
3167 BOOL GetSubItemRect(int nItem, int nSubItem, int nFlag, LPRECT lpRect) const
3169 ATLASSERT(::IsWindow(m_hWnd));
3170 ATLASSERT((GetStyle() & LVS_TYPEMASK) == LVS_REPORT);
3171 ATLASSERT(lpRect != NULL);
3172 lpRect->top = nSubItem;
3173 lpRect->left = nFlag;
3174 return (BOOL)::SendMessage(m_hWnd, LVM_GETSUBITEMRECT, nItem, (LPARAM)lpRect);
3177 DWORD SetIconSpacing(int cx, int cy)
3179 ATLASSERT(::IsWindow(m_hWnd));
3180 ATLASSERT((GetStyle() & LVS_TYPEMASK) == LVS_ICON);
3181 return (DWORD)::SendMessage(m_hWnd, LVM_SETICONSPACING, 0, MAKELPARAM(cx, cy));
3184 int GetISearchString(LPTSTR lpstr) const
3186 ATLASSERT(::IsWindow(m_hWnd));
3187 return (int)::SendMessage(m_hWnd, LVM_GETISEARCHSTRING, 0, (LPARAM)lpstr);
3190 void GetItemSpacing(SIZE& sizeSpacing, BOOL bSmallIconView = FALSE) const
3192 ATLASSERT(::IsWindow(m_hWnd));
3193 DWORD dwRet = (DWORD)::SendMessage(m_hWnd, LVM_GETITEMSPACING, bSmallIconView, 0L);
3194 sizeSpacing.cx = GET_X_LPARAM(dwRet);
3195 sizeSpacing.cy = GET_Y_LPARAM(dwRet);
3198 #if (_WIN32_WCE >= 410)
3199 void SetItemSpacing(INT cySpacing)
3201 ATLASSERT(::IsWindow(m_hWnd));
3202 ListView_SetItemSpacing(m_hWnd, cySpacing);
3204 #endif // (_WIN32_WCE >= 410)
3206 // single-selection only
3207 int GetSelectedIndex() const
3209 ATLASSERT(::IsWindow(m_hWnd));
3210 ATLASSERT((GetStyle() & LVS_SINGLESEL) != 0);
3211 return (int)::SendMessage(m_hWnd, LVM_GETNEXTITEM, (WPARAM)-1, MAKELPARAM(LVNI_ALL | LVNI_SELECTED, 0));
3214 BOOL GetSelectedItem(LPLVITEM pItem) const
3216 ATLASSERT(::IsWindow(m_hWnd));
3217 ATLASSERT((GetStyle() & LVS_SINGLESEL) != 0);
3218 ATLASSERT(pItem != NULL);
3219 pItem->iItem = (int)::SendMessage(m_hWnd, LVM_GETNEXTITEM, (WPARAM)-1, MAKELPARAM(LVNI_ALL | LVNI_SELECTED, 0));
3220 if(pItem->iItem == -1)
3221 return FALSE;
3222 return (BOOL)::SendMessage(m_hWnd, LVM_GETITEM, 0, (LPARAM)pItem);
3225 // extended list view styles
3226 DWORD GetExtendedListViewStyle() const
3228 ATLASSERT(::IsWindow(m_hWnd));
3229 return (DWORD)::SendMessage(m_hWnd, LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0L);
3232 // dwExMask = 0 means all styles
3233 DWORD SetExtendedListViewStyle(DWORD dwExStyle, DWORD dwExMask = 0)
3235 ATLASSERT(::IsWindow(m_hWnd));
3236 return (DWORD)::SendMessage(m_hWnd, LVM_SETEXTENDEDLISTVIEWSTYLE, dwExMask, dwExStyle);
3239 // checkboxes only
3240 BOOL GetCheckState(int nIndex) const
3242 ATLASSERT(::IsWindow(m_hWnd));
3243 ATLASSERT((GetExtendedListViewStyle() & LVS_EX_CHECKBOXES) != 0);
3244 UINT uRet = GetItemState(nIndex, LVIS_STATEIMAGEMASK);
3245 return (uRet >> 12) - 1;
3248 BOOL SetCheckState(int nItem, BOOL bCheck)
3250 int nCheck = bCheck ? 2 : 1; // one based index
3251 return SetItemState(nItem, INDEXTOSTATEIMAGEMASK(nCheck), LVIS_STATEIMAGEMASK);
3254 // view type
3255 DWORD GetViewType() const
3257 ATLASSERT(::IsWindow(m_hWnd));
3258 return (GetStyle() & LVS_TYPEMASK);
3261 DWORD SetViewType(DWORD dwType)
3263 ATLASSERT(::IsWindow(m_hWnd));
3264 ATLASSERT(dwType == LVS_ICON || dwType == LVS_SMALLICON || dwType == LVS_LIST || dwType == LVS_REPORT);
3265 DWORD dwOldType = GetViewType();
3266 if(dwType != dwOldType)
3267 ModifyStyle(LVS_TYPEMASK, (dwType & LVS_TYPEMASK));
3268 return dwOldType;
3271 #if (_WIN32_IE >= 0x0400)
3272 #ifndef _WIN32_WCE
3273 BOOL GetBkImage(LPLVBKIMAGE plvbki) const
3275 ATLASSERT(::IsWindow(m_hWnd));
3276 return (BOOL)::SendMessage(m_hWnd, LVM_GETBKIMAGE, 0, (LPARAM)plvbki);
3279 BOOL SetBkImage(LPLVBKIMAGE plvbki)
3281 ATLASSERT(::IsWindow(m_hWnd));
3282 return (BOOL)::SendMessage(m_hWnd, LVM_SETBKIMAGE, 0, (LPARAM)plvbki);
3284 #endif // !_WIN32_WCE
3286 int GetSelectionMark() const
3288 ATLASSERT(::IsWindow(m_hWnd));
3289 return (int)::SendMessage(m_hWnd, LVM_GETSELECTIONMARK, 0, 0L);
3292 int SetSelectionMark(int nIndex)
3294 ATLASSERT(::IsWindow(m_hWnd));
3295 return (int)::SendMessage(m_hWnd, LVM_SETSELECTIONMARK, 0, nIndex);
3298 #ifndef _WIN32_WCE
3299 BOOL GetWorkAreas(int nWorkAreas, LPRECT lpRect) const
3301 ATLASSERT(::IsWindow(m_hWnd));
3302 return (BOOL)::SendMessage(m_hWnd, LVM_GETWORKAREAS, nWorkAreas, (LPARAM)lpRect);
3305 BOOL SetWorkAreas(int nWorkAreas, LPRECT lpRect)
3307 ATLASSERT(::IsWindow(m_hWnd));
3308 return (BOOL)::SendMessage(m_hWnd, LVM_SETWORKAREAS, nWorkAreas, (LPARAM)lpRect);
3311 DWORD GetHoverTime() const
3313 ATLASSERT(::IsWindow(m_hWnd));
3314 ATLASSERT((GetExtendedListViewStyle() & (LVS_EX_TRACKSELECT | LVS_EX_ONECLICKACTIVATE | LVS_EX_TWOCLICKACTIVATE)) != 0);
3315 return (DWORD)::SendMessage(m_hWnd, LVM_GETHOVERTIME, 0, 0L);
3318 DWORD SetHoverTime(DWORD dwHoverTime)
3320 ATLASSERT(::IsWindow(m_hWnd));
3321 ATLASSERT((GetExtendedListViewStyle() & (LVS_EX_TRACKSELECT | LVS_EX_ONECLICKACTIVATE | LVS_EX_TWOCLICKACTIVATE)) != 0);
3322 return (DWORD)::SendMessage(m_hWnd, LVM_SETHOVERTIME, 0, dwHoverTime);
3325 BOOL GetNumberOfWorkAreas(int* pnWorkAreas) const
3327 ATLASSERT(::IsWindow(m_hWnd));
3328 return (BOOL)::SendMessage(m_hWnd, LVM_GETNUMBEROFWORKAREAS, 0, (LPARAM)pnWorkAreas);
3330 #endif // !_WIN32_WCE
3332 BOOL SetItemCountEx(int nItems, DWORD dwFlags)
3334 ATLASSERT(::IsWindow(m_hWnd));
3335 ATLASSERT(((GetStyle() & LVS_OWNERDATA) != 0) && (((GetStyle() & LVS_TYPEMASK) == LVS_REPORT) || ((GetStyle() & LVS_TYPEMASK) == LVS_LIST)));
3336 return (BOOL)::SendMessage(m_hWnd, LVM_SETITEMCOUNT, nItems, dwFlags);
3339 #ifndef _WIN32_WCE
3340 CToolTipCtrl GetToolTips() const
3342 ATLASSERT(::IsWindow(m_hWnd));
3343 return CToolTipCtrl((HWND)::SendMessage(m_hWnd, LVM_GETTOOLTIPS, 0, 0L));
3346 CToolTipCtrl SetToolTips(HWND hWndTT)
3348 ATLASSERT(::IsWindow(m_hWnd));
3349 return CToolTipCtrl((HWND)::SendMessage(m_hWnd, LVM_SETTOOLTIPS, (WPARAM)hWndTT, 0L));
3352 BOOL GetUnicodeFormat() const
3354 ATLASSERT(::IsWindow(m_hWnd));
3355 return (BOOL)::SendMessage(m_hWnd, LVM_GETUNICODEFORMAT, 0, 0L);
3358 BOOL SetUnicodeFormat(BOOL bUnicode = TRUE)
3360 ATLASSERT(::IsWindow(m_hWnd));
3361 return (BOOL)::SendMessage(m_hWnd, LVM_SETUNICODEFORMAT, bUnicode, 0L);
3363 #endif // !_WIN32_WCE
3364 #endif // (_WIN32_IE >= 0x0400)
3366 #if (_WIN32_WINNT >= 0x0501)
3367 int GetSelectedColumn() const
3369 ATLASSERT(::IsWindow(m_hWnd));
3370 return (int)::SendMessage(m_hWnd, LVM_GETSELECTEDCOLUMN, 0, 0L);
3373 void SetSelectedColumn(int nColumn)
3375 ATLASSERT(::IsWindow(m_hWnd));
3376 ::SendMessage(m_hWnd, LVM_SETSELECTEDCOLUMN, nColumn, 0L);
3379 DWORD GetView() const
3381 ATLASSERT(::IsWindow(m_hWnd));
3382 return (DWORD)::SendMessage(m_hWnd, LVM_GETVIEW, 0, 0L);
3385 int SetView(DWORD dwView)
3387 ATLASSERT(::IsWindow(m_hWnd));
3388 return (int)::SendMessage(m_hWnd, LVM_SETVIEW, dwView, 0L);
3391 BOOL IsGroupViewEnabled() const
3393 ATLASSERT(::IsWindow(m_hWnd));
3394 return (BOOL)::SendMessage(m_hWnd, LVM_ISGROUPVIEWENABLED, 0, 0L);
3397 int GetGroupInfo(int nGroupID, PLVGROUP pGroup) const
3399 ATLASSERT(::IsWindow(m_hWnd));
3400 return (int)::SendMessage(m_hWnd, LVM_GETGROUPINFO, nGroupID, (LPARAM)pGroup);
3403 int SetGroupInfo(int nGroupID, PLVGROUP pGroup)
3405 ATLASSERT(::IsWindow(m_hWnd));
3406 return (int)::SendMessage(m_hWnd, LVM_SETGROUPINFO, nGroupID, (LPARAM)pGroup);
3409 void GetGroupMetrics(PLVGROUPMETRICS pGroupMetrics) const
3411 ATLASSERT(::IsWindow(m_hWnd));
3412 ::SendMessage(m_hWnd, LVM_GETGROUPMETRICS, 0, (LPARAM)pGroupMetrics);
3415 void SetGroupMetrics(PLVGROUPMETRICS pGroupMetrics)
3417 ATLASSERT(::IsWindow(m_hWnd));
3418 ::SendMessage(m_hWnd, LVM_SETGROUPMETRICS, 0, (LPARAM)pGroupMetrics);
3421 void GetTileViewInfo(PLVTILEVIEWINFO pTileViewInfo) const
3423 ATLASSERT(::IsWindow(m_hWnd));
3424 ::SendMessage(m_hWnd, LVM_GETTILEVIEWINFO, 0, (LPARAM)pTileViewInfo);
3427 BOOL SetTileViewInfo(PLVTILEVIEWINFO pTileViewInfo)
3429 ATLASSERT(::IsWindow(m_hWnd));
3430 return (BOOL)::SendMessage(m_hWnd, LVM_SETTILEVIEWINFO, 0, (LPARAM)pTileViewInfo);
3433 void GetTileInfo(PLVTILEINFO pTileInfo) const
3435 ATLASSERT(::IsWindow(m_hWnd));
3436 ::SendMessage(m_hWnd, LVM_GETTILEINFO, 0, (LPARAM)pTileInfo);
3439 BOOL SetTileInfo(PLVTILEINFO pTileInfo)
3441 ATLASSERT(::IsWindow(m_hWnd));
3442 return (BOOL)::SendMessage(m_hWnd, LVM_SETTILEINFO, 0, (LPARAM)pTileInfo);
3445 BOOL GetInsertMark(LPLVINSERTMARK pInsertMark) const
3447 ATLASSERT(::IsWindow(m_hWnd));
3448 return (BOOL)::SendMessage(m_hWnd, LVM_GETINSERTMARK, 0, (LPARAM)pInsertMark);
3451 BOOL SetInsertMark(LPLVINSERTMARK pInsertMark)
3453 ATLASSERT(::IsWindow(m_hWnd));
3454 return (BOOL)::SendMessage(m_hWnd, LVM_SETINSERTMARK, 0, (LPARAM)pInsertMark);
3457 int GetInsertMarkRect(LPRECT lpRect) const
3459 ATLASSERT(::IsWindow(m_hWnd));
3460 return (int)::SendMessage(m_hWnd, LVM_GETINSERTMARKRECT, 0, (LPARAM)lpRect);
3463 COLORREF GetInsertMarkColor() const
3465 ATLASSERT(::IsWindow(m_hWnd));
3466 return (COLORREF)::SendMessage(m_hWnd, LVM_GETINSERTMARKCOLOR, 0, 0L);
3469 COLORREF SetInsertMarkColor(COLORREF clr)
3471 ATLASSERT(::IsWindow(m_hWnd));
3472 return (COLORREF)::SendMessage(m_hWnd, LVM_SETINSERTMARKCOLOR, 0, clr);
3475 COLORREF GetOutlineColor() const
3477 ATLASSERT(::IsWindow(m_hWnd));
3478 return (COLORREF)::SendMessage(m_hWnd, LVM_GETOUTLINECOLOR, 0, 0L);
3481 COLORREF SetOutlineColor(COLORREF clr)
3483 ATLASSERT(::IsWindow(m_hWnd));
3484 return (COLORREF)::SendMessage(m_hWnd, LVM_SETOUTLINECOLOR, 0, clr);
3486 #endif // (_WIN32_WINNT >= 0x0501)
3488 #if (_WIN32_WINNT >= 0x0600)
3489 int GetGroupCount() const
3491 ATLASSERT(::IsWindow(m_hWnd));
3492 return (int)::SendMessage(m_hWnd, LVM_GETGROUPCOUNT, 0, 0L);
3495 BOOL GetGroupInfoByIndex(int nIndex, PLVGROUP pGroup) const
3497 ATLASSERT(::IsWindow(m_hWnd));
3498 return (BOOL)::SendMessage(m_hWnd, LVM_GETGROUPINFOBYINDEX, nIndex, (LPARAM)pGroup);
3501 BOOL GetGroupRect(int nGroupID, int nType, LPRECT lpRect) const
3503 ATLASSERT(::IsWindow(m_hWnd));
3504 ATLASSERT(lpRect != NULL);
3505 if(lpRect != NULL)
3506 lpRect->top = nType;
3507 return (BOOL)::SendMessage(m_hWnd, LVM_GETGROUPRECT, nGroupID, (LPARAM)lpRect);
3510 UINT GetGroupState(int nGroupID, UINT uMask) const
3512 ATLASSERT(::IsWindow(m_hWnd));
3513 return (UINT)::SendMessage(m_hWnd, LVM_GETGROUPSTATE, nGroupID, (LPARAM)uMask);
3516 int GetFocusedGroup() const
3518 ATLASSERT(::IsWindow(m_hWnd));
3519 return (int)::SendMessage(m_hWnd, LVM_GETFOCUSEDGROUP, 0, 0L);
3522 BOOL GetEmptyText(LPWSTR lpstrText, int cchText) const
3524 ATLASSERT(::IsWindow(m_hWnd));
3525 return (BOOL)::SendMessage(m_hWnd, LVM_GETEMPTYTEXT, cchText, (LPARAM)lpstrText);
3528 BOOL GetFooterRect(LPRECT lpRect) const
3530 ATLASSERT(::IsWindow(m_hWnd));
3531 return (BOOL)::SendMessage(m_hWnd, LVM_GETFOOTERRECT, 0, (LPARAM)lpRect);
3534 BOOL GetFooterInfo(LPLVFOOTERINFO lpFooterInfo) const
3536 ATLASSERT(::IsWindow(m_hWnd));
3537 return (BOOL)::SendMessage(m_hWnd, LVM_GETFOOTERINFO, 0, (LPARAM)lpFooterInfo);
3540 BOOL GetFooterItemRect(int nItem, LPRECT lpRect) const
3542 ATLASSERT(::IsWindow(m_hWnd));
3543 return (BOOL)::SendMessage(m_hWnd, LVM_GETFOOTERITEMRECT, nItem, (LPARAM)lpRect);
3546 BOOL GetFooterItem(int nItem, LPLVFOOTERITEM lpFooterItem) const
3548 ATLASSERT(::IsWindow(m_hWnd));
3549 return (BOOL)::SendMessage(m_hWnd, LVM_GETFOOTERITEM, nItem, (LPARAM)lpFooterItem);
3552 BOOL GetItemIndexRect(PLVITEMINDEX pItemIndex, int nSubItem, int nType, LPRECT lpRect) const
3554 ATLASSERT(::IsWindow(m_hWnd));
3555 ATLASSERT(pItemIndex != NULL);
3556 ATLASSERT(lpRect != NULL);
3557 if(lpRect != NULL)
3559 lpRect->top = nSubItem;
3560 lpRect->left = nType;
3562 return (BOOL)::SendMessage(m_hWnd, LVM_GETITEMINDEXRECT, (WPARAM)pItemIndex, (LPARAM)lpRect);
3565 BOOL SetItemIndexState(PLVITEMINDEX pItemIndex, UINT uState, UINT dwMask)
3567 ATLASSERT(::IsWindow(m_hWnd));
3568 LVITEM lvi = { 0 };
3569 lvi.state = uState;
3570 lvi.stateMask = dwMask;
3571 return (BOOL)::SendMessage(m_hWnd, LVM_SETITEMINDEXSTATE, (WPARAM)pItemIndex, (LPARAM)&lvi);
3574 BOOL GetNextItemIndex(PLVITEMINDEX pItemIndex, WORD wFlags) const
3576 ATLASSERT(::IsWindow(m_hWnd));
3577 return (BOOL)::SendMessage(m_hWnd, LVM_GETNEXTITEMINDEX, (WPARAM)pItemIndex, MAKELPARAM(wFlags, 0));
3579 #endif // (_WIN32_WINNT >= 0x0600)
3581 // Operations
3582 int InsertColumn(int nCol, const LVCOLUMN* pColumn)
3584 ATLASSERT(::IsWindow(m_hWnd));
3585 return (int)::SendMessage(m_hWnd, LVM_INSERTCOLUMN, nCol, (LPARAM)pColumn);
3588 int InsertColumn(int nCol, LPCTSTR lpszColumnHeading, int nFormat = LVCFMT_LEFT,
3589 int nWidth = -1, int nSubItem = -1, int iImage = -1, int iOrder = -1)
3591 LVCOLUMN column = { 0 };
3592 column.mask = LVCF_TEXT|LVCF_FMT;
3593 column.pszText = (LPTSTR)lpszColumnHeading;
3594 column.fmt = nFormat;
3595 if (nWidth != -1)
3597 column.mask |= LVCF_WIDTH;
3598 column.cx = nWidth;
3600 if (nSubItem != -1)
3602 column.mask |= LVCF_SUBITEM;
3603 column.iSubItem = nSubItem;
3605 if (iImage != -1)
3607 column.mask |= LVCF_IMAGE;
3608 column.iImage = iImage;
3610 if (iOrder != -1)
3612 column.mask |= LVCF_ORDER;
3613 column.iOrder = iOrder;
3615 return InsertColumn(nCol, &column);
3618 BOOL DeleteColumn(int nCol)
3620 ATLASSERT(::IsWindow(m_hWnd));
3621 return (BOOL)::SendMessage(m_hWnd, LVM_DELETECOLUMN, nCol, 0L);
3624 int InsertItem(UINT nMask, int nItem, LPCTSTR lpszItem, UINT nState, UINT nStateMask, int nImage, LPARAM lParam)
3626 ATLASSERT(::IsWindow(m_hWnd));
3627 LVITEM item = { 0 };
3628 item.mask = nMask;
3629 item.iItem = nItem;
3630 item.iSubItem = 0;
3631 item.pszText = (LPTSTR)lpszItem;
3632 item.state = nState;
3633 item.stateMask = nStateMask;
3634 item.iImage = nImage;
3635 item.lParam = lParam;
3636 return InsertItem(&item);
3639 int InsertItem(const LVITEM* pItem)
3641 ATLASSERT(::IsWindow(m_hWnd));
3642 return (int)::SendMessage(m_hWnd, LVM_INSERTITEM, 0, (LPARAM)pItem);
3645 int InsertItem(int nItem, LPCTSTR lpszItem)
3647 ATLASSERT(::IsWindow(m_hWnd));
3648 return InsertItem(LVIF_TEXT, nItem, lpszItem, 0, 0, 0, 0);
3651 int InsertItem(int nItem, LPCTSTR lpszItem, int nImage)
3653 ATLASSERT(::IsWindow(m_hWnd));
3654 return InsertItem(LVIF_TEXT|LVIF_IMAGE, nItem, lpszItem, 0, 0, nImage, 0);
3657 int GetNextItem(int nItem, int nFlags) const
3659 ATLASSERT(::IsWindow(m_hWnd));
3660 return (int)::SendMessage(m_hWnd, LVM_GETNEXTITEM, nItem, MAKELPARAM(nFlags, 0));
3663 BOOL DeleteItem(int nItem)
3665 ATLASSERT(::IsWindow(m_hWnd));
3666 return (BOOL)::SendMessage(m_hWnd, LVM_DELETEITEM, nItem, 0L);
3669 BOOL DeleteAllItems()
3671 ATLASSERT(::IsWindow(m_hWnd));
3672 return (BOOL)::SendMessage(m_hWnd, LVM_DELETEALLITEMS, 0, 0L);
3675 int FindItem(LVFINDINFO* pFindInfo, int nStart) const
3677 ATLASSERT(::IsWindow(m_hWnd));
3678 return (int)::SendMessage(m_hWnd, LVM_FINDITEM, nStart, (LPARAM)pFindInfo);
3681 int HitTest(LVHITTESTINFO* pHitTestInfo) const
3683 ATLASSERT(::IsWindow(m_hWnd));
3684 return (int)::SendMessage(m_hWnd, LVM_HITTEST, 0, (LPARAM)pHitTestInfo);
3687 int HitTest(POINT pt, UINT* pFlags) const
3689 ATLASSERT(::IsWindow(m_hWnd));
3690 LVHITTESTINFO hti = { 0 };
3691 hti.pt = pt;
3692 int nRes = (int)::SendMessage(m_hWnd, LVM_HITTEST, 0, (LPARAM)&hti);
3693 if (pFlags != NULL)
3694 *pFlags = hti.flags;
3695 return nRes;
3698 BOOL EnsureVisible(int nItem, BOOL bPartialOK)
3700 ATLASSERT(::IsWindow(m_hWnd));
3701 return (BOOL)::SendMessage(m_hWnd, LVM_ENSUREVISIBLE, nItem, MAKELPARAM(bPartialOK, 0));
3704 BOOL Scroll(SIZE size)
3706 ATLASSERT(::IsWindow(m_hWnd));
3707 return (BOOL)::SendMessage(m_hWnd, LVM_SCROLL, size.cx, size.cy);
3710 BOOL RedrawItems(int nFirst, int nLast)
3712 ATLASSERT(::IsWindow(m_hWnd));
3713 return (BOOL)::SendMessage(m_hWnd, LVM_REDRAWITEMS, nFirst, nLast);
3716 BOOL Arrange(UINT nCode)
3718 ATLASSERT(::IsWindow(m_hWnd));
3719 return (BOOL)::SendMessage(m_hWnd, LVM_ARRANGE, nCode, 0L);
3722 CEdit EditLabel(int nItem)
3724 ATLASSERT(::IsWindow(m_hWnd));
3725 return CEdit((HWND)::SendMessage(m_hWnd, LVM_EDITLABEL, nItem, 0L));
3728 BOOL Update(int nItem)
3730 ATLASSERT(::IsWindow(m_hWnd));
3731 return (BOOL)::SendMessage(m_hWnd, LVM_UPDATE, nItem, 0L);
3734 BOOL SortItems(PFNLVCOMPARE pfnCompare, LPARAM lParamSort)
3736 ATLASSERT(::IsWindow(m_hWnd));
3737 return (BOOL)::SendMessage(m_hWnd, LVM_SORTITEMS, (WPARAM)lParamSort, (LPARAM)pfnCompare);
3740 CImageList RemoveImageList(int nImageList)
3742 ATLASSERT(::IsWindow(m_hWnd));
3743 return CImageList((HIMAGELIST)::SendMessage(m_hWnd, LVM_SETIMAGELIST, (WPARAM)nImageList, NULL));
3746 CImageList CreateDragImage(int nItem, LPPOINT lpPoint)
3748 ATLASSERT(::IsWindow(m_hWnd));
3749 return CImageList((HIMAGELIST)::SendMessage(m_hWnd, LVM_CREATEDRAGIMAGE, nItem, (LPARAM)lpPoint));
3752 DWORD ApproximateViewRect(int cx = -1, int cy = -1, int nCount = -1)
3754 ATLASSERT(::IsWindow(m_hWnd));
3755 return (DWORD)::SendMessage(m_hWnd, LVM_APPROXIMATEVIEWRECT, nCount, MAKELPARAM(cx, cy));
3758 int SubItemHitTest(LPLVHITTESTINFO lpInfo) const
3760 ATLASSERT(::IsWindow(m_hWnd));
3761 return (int)::SendMessage(m_hWnd, LVM_SUBITEMHITTEST, 0, (LPARAM)lpInfo);
3764 int AddColumn(LPCTSTR strItem, int nItem, int nSubItem = -1,
3765 int nMask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM,
3766 int nFmt = LVCFMT_LEFT)
3768 const int cxOffset = 15;
3769 ATLASSERT(::IsWindow(m_hWnd));
3770 LVCOLUMN lvc = { 0 };
3771 lvc.mask = nMask;
3772 lvc.fmt = nFmt;
3773 lvc.pszText = (LPTSTR)strItem;
3774 lvc.cx = GetStringWidth(lvc.pszText) + cxOffset;
3775 if(nMask & LVCF_SUBITEM)
3776 lvc.iSubItem = (nSubItem != -1) ? nSubItem : nItem;
3777 return InsertColumn(nItem, &lvc);
3780 int AddItem(int nItem, int nSubItem, LPCTSTR strItem, int nImageIndex = -1)
3782 ATLASSERT(::IsWindow(m_hWnd));
3783 LVITEM lvItem = { 0 };
3784 lvItem.mask = LVIF_TEXT;
3785 lvItem.iItem = nItem;
3786 lvItem.iSubItem = nSubItem;
3787 lvItem.pszText = (LPTSTR)strItem;
3788 if(nImageIndex != -1)
3790 lvItem.mask |= LVIF_IMAGE;
3791 lvItem.iImage = nImageIndex;
3793 if(nSubItem == 0)
3794 return InsertItem(&lvItem);
3795 return SetItem(&lvItem) ? nItem : -1;
3798 #if (_WIN32_IE >= 0x0500) && !defined(_WIN32_WCE)
3799 BOOL SortItemsEx(PFNLVCOMPARE pfnCompare, LPARAM lParamSort)
3801 ATLASSERT(::IsWindow(m_hWnd));
3802 return (BOOL)::SendMessage(m_hWnd, LVM_SORTITEMSEX, (WPARAM)lParamSort, (LPARAM)pfnCompare);
3804 #endif // (_WIN32_IE >= 0x0500) && !defined(_WIN32_WCE)
3806 #if (_WIN32_WINNT >= 0x0501)
3807 int InsertGroup(int nItem, PLVGROUP pGroup)
3809 ATLASSERT(::IsWindow(m_hWnd));
3810 return (int)::SendMessage(m_hWnd, LVM_INSERTGROUP, nItem, (LPARAM)pGroup);
3813 int AddGroup(PLVGROUP pGroup)
3815 return InsertGroup(-1, pGroup);
3818 int RemoveGroup(int nGroupID)
3820 ATLASSERT(::IsWindow(m_hWnd));
3821 return (int)::SendMessage(m_hWnd, LVM_REMOVEGROUP, nGroupID, 0L);
3824 void MoveGroup(int nGroupID, int nItem)
3826 ATLASSERT(::IsWindow(m_hWnd));
3827 ::SendMessage(m_hWnd, LVM_MOVEGROUP, nGroupID, nItem);
3830 void MoveItemToGroup(int nItem, int nGroupID)
3832 ATLASSERT(::IsWindow(m_hWnd));
3833 ::SendMessage(m_hWnd, LVM_MOVEITEMTOGROUP, nItem, nGroupID);
3836 int EnableGroupView(BOOL bEnable)
3838 ATLASSERT(::IsWindow(m_hWnd));
3839 return (int)::SendMessage(m_hWnd, LVM_ENABLEGROUPVIEW, bEnable, 0L);
3842 int SortGroups(PFNLVGROUPCOMPARE pCompareFunc, LPVOID lpVoid = NULL)
3844 ATLASSERT(::IsWindow(m_hWnd));
3845 return (int)::SendMessage(m_hWnd, LVM_SORTGROUPS, (WPARAM)pCompareFunc, (LPARAM)lpVoid);
3848 void InsertGroupSorted(PLVINSERTGROUPSORTED pInsertGroupSorted)
3850 ATLASSERT(::IsWindow(m_hWnd));
3851 ::SendMessage(m_hWnd, LVM_INSERTGROUPSORTED, (WPARAM)pInsertGroupSorted, 0L);
3854 void RemoveAllGroups()
3856 ATLASSERT(::IsWindow(m_hWnd));
3857 ::SendMessage(m_hWnd, LVM_REMOVEALLGROUPS, 0, 0L);
3860 BOOL HasGroup(int nGroupID)
3862 ATLASSERT(::IsWindow(m_hWnd));
3863 return (BOOL)::SendMessage(m_hWnd, LVM_HASGROUP, nGroupID, 0L);
3866 BOOL InsertMarkHitTest(LPPOINT lpPoint, LPLVINSERTMARK pInsertMark) const
3868 ATLASSERT(::IsWindow(m_hWnd));
3869 return (BOOL)::SendMessage(m_hWnd, LVM_INSERTMARKHITTEST, (WPARAM)lpPoint, (LPARAM)pInsertMark);
3872 BOOL SetInfoTip(PLVSETINFOTIP pSetInfoTip)
3874 ATLASSERT(::IsWindow(m_hWnd));
3875 return (BOOL)::SendMessage(m_hWnd, LVM_SETINFOTIP, 0, (LPARAM)pSetInfoTip);
3878 void CancelEditLabel()
3880 ATLASSERT(::IsWindow(m_hWnd));
3881 ::SendMessage(m_hWnd, LVM_CANCELEDITLABEL, 0, 0L);
3884 UINT MapIndexToID(int nIndex) const
3886 ATLASSERT(::IsWindow(m_hWnd));
3887 return (UINT)::SendMessage(m_hWnd, LVM_MAPINDEXTOID, nIndex, 0L);
3890 int MapIDToIndex(UINT uID) const
3892 ATLASSERT(::IsWindow(m_hWnd));
3893 return (int)::SendMessage(m_hWnd, LVM_MAPIDTOINDEX, uID, 0L);
3895 #endif // (_WIN32_WINNT >= 0x0501)
3897 #if (_WIN32_WINNT >= 0x0600)
3898 int HitTestEx(LPLVHITTESTINFO lpHitTestInfo) const
3900 ATLASSERT(::IsWindow(m_hWnd));
3901 return (int)::SendMessage(m_hWnd, LVM_HITTEST, (WPARAM)-1, (LPARAM)lpHitTestInfo);
3904 int HitTestEx(POINT pt, UINT* pFlags) const
3906 ATLASSERT(::IsWindow(m_hWnd));
3907 LVHITTESTINFO hti = { 0 };
3908 hti.pt = pt;
3909 int nRes = (int)::SendMessage(m_hWnd, LVM_HITTEST, (WPARAM)-1, (LPARAM)&hti);
3910 if (pFlags != NULL)
3911 *pFlags = hti.flags;
3912 return nRes;
3915 int SubItemHitTestEx(LPLVHITTESTINFO lpHitTestInfo) const
3917 ATLASSERT(::IsWindow(m_hWnd));
3918 return (int)::SendMessage(m_hWnd, LVM_SUBITEMHITTEST, (WPARAM)-1, (LPARAM)lpHitTestInfo);
3920 #endif // (_WIN32_WINNT >= 0x0600)
3922 // single-selection only
3923 BOOL SelectItem(int nIndex)
3925 ATLASSERT(::IsWindow(m_hWnd));
3926 ATLASSERT((GetStyle() & LVS_SINGLESEL) != 0);
3928 BOOL bRet = SetItemState(nIndex, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
3929 if(bRet)
3930 bRet = EnsureVisible(nIndex, FALSE);
3931 return bRet;
3935 typedef CListViewCtrlT<ATL::CWindow> CListViewCtrl;
3938 ///////////////////////////////////////////////////////////////////////////////
3939 // CTreeViewCtrl
3941 template <class TBase>
3942 class CTreeViewCtrlT : public TBase
3944 public:
3945 // Constructors
3946 CTreeViewCtrlT(HWND hWnd = NULL) : TBase(hWnd)
3949 CTreeViewCtrlT< TBase >& operator =(HWND hWnd)
3951 m_hWnd = hWnd;
3952 return *this;
3955 HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
3956 DWORD dwStyle = 0, DWORD dwExStyle = 0,
3957 ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
3959 return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
3962 // Attributes
3963 static LPCTSTR GetWndClassName()
3965 return WC_TREEVIEW;
3968 UINT GetCount() const
3970 ATLASSERT(::IsWindow(m_hWnd));
3971 return (UINT)::SendMessage(m_hWnd, TVM_GETCOUNT, 0, 0L);
3974 UINT GetIndent() const
3976 ATLASSERT(::IsWindow(m_hWnd));
3977 return (UINT)::SendMessage(m_hWnd, TVM_GETINDENT, 0, 0L);
3980 void SetIndent(UINT nIndent)
3982 ATLASSERT(::IsWindow(m_hWnd));
3983 ::SendMessage(m_hWnd, TVM_SETINDENT, nIndent, 0L);
3986 CImageList GetImageList(int nImageListType = TVSIL_NORMAL) const
3988 ATLASSERT(::IsWindow(m_hWnd));
3989 return CImageList((HIMAGELIST)::SendMessage(m_hWnd, TVM_GETIMAGELIST, (WPARAM)nImageListType, 0L));
3992 CImageList SetImageList(HIMAGELIST hImageList, int nImageListType = TVSIL_NORMAL)
3994 ATLASSERT(::IsWindow(m_hWnd));
3995 return CImageList((HIMAGELIST)::SendMessage(m_hWnd, TVM_SETIMAGELIST, (WPARAM)nImageListType, (LPARAM)hImageList));
3998 BOOL GetItem(LPTVITEM pItem) const
4000 ATLASSERT(::IsWindow(m_hWnd));
4001 return (BOOL)::SendMessage(m_hWnd, TVM_GETITEM, 0, (LPARAM)pItem);
4004 BOOL SetItem(LPTVITEM pItem)
4006 ATLASSERT(::IsWindow(m_hWnd));
4007 return (BOOL)::SendMessage(m_hWnd, TVM_SETITEM, 0, (LPARAM)pItem);
4010 BOOL SetItem(HTREEITEM hItem, UINT nMask, LPCTSTR lpszItem, int nImage,
4011 int nSelectedImage, UINT nState, UINT nStateMask, LPARAM lParam)
4013 ATLASSERT(::IsWindow(m_hWnd));
4014 TVITEM item = { 0 };
4015 item.hItem = hItem;
4016 item.mask = nMask;
4017 item.pszText = (LPTSTR) lpszItem;
4018 item.iImage = nImage;
4019 item.iSelectedImage = nSelectedImage;
4020 item.state = nState;
4021 item.stateMask = nStateMask;
4022 item.lParam = lParam;
4023 return (BOOL)::SendMessage(m_hWnd, TVM_SETITEM, 0, (LPARAM)&item);
4026 BOOL GetItemText(HTREEITEM hItem, LPTSTR lpstrText, int nLen) const
4028 ATLASSERT(::IsWindow(m_hWnd));
4029 ATLASSERT(lpstrText != NULL);
4031 TVITEM item = { 0 };
4032 item.hItem = hItem;
4033 item.mask = TVIF_TEXT;
4034 item.pszText = lpstrText;
4035 item.cchTextMax = nLen;
4037 return (BOOL)::SendMessage(m_hWnd, TVM_GETITEM, 0, (LPARAM)&item);
4040 #ifndef _ATL_NO_COM
4041 BOOL GetItemText(HTREEITEM hItem, BSTR& bstrText) const
4043 USES_CONVERSION;
4044 ATLASSERT(::IsWindow(m_hWnd));
4045 ATLASSERT(bstrText == NULL);
4046 TVITEM item = { 0 };
4047 item.hItem = hItem;
4048 item.mask = TVIF_TEXT;
4050 LPTSTR lpstrText = NULL;
4051 BOOL bRet = FALSE;
4052 for(int nLen = 256; ; nLen *= 2)
4054 ATLTRY(lpstrText = new TCHAR[nLen]);
4055 if(lpstrText == NULL)
4056 break;
4057 lpstrText[0] = NULL;
4058 item.pszText = lpstrText;
4059 item.cchTextMax = nLen;
4060 bRet = (BOOL)::SendMessage(m_hWnd, TVM_GETITEM, 0, (LPARAM)&item);
4061 if(!bRet || (lstrlen(item.pszText) < nLen - 1))
4062 break;
4063 delete [] lpstrText;
4064 lpstrText = NULL;
4067 if(lpstrText != NULL)
4069 if(bRet)
4070 bstrText = ::SysAllocString(T2OLE(lpstrText));
4071 delete [] lpstrText;
4074 return (bstrText != NULL) ? TRUE : FALSE;
4076 #endif // !_ATL_NO_COM
4078 #if defined(_WTL_USE_CSTRING) || defined(__ATLSTR_H__)
4079 BOOL GetItemText(HTREEITEM hItem, _CSTRING_NS::CString& strText) const
4081 ATLASSERT(::IsWindow(m_hWnd));
4082 TVITEM item = { 0 };
4083 item.hItem = hItem;
4084 item.mask = TVIF_TEXT;
4086 strText.Empty();
4087 BOOL bRet = FALSE;
4088 for(int nLen = 256; ; nLen *= 2)
4090 item.pszText = strText.GetBufferSetLength(nLen);
4091 if(item.pszText == NULL)
4093 bRet = FALSE;
4094 break;
4096 item.cchTextMax = nLen;
4097 bRet = (BOOL)::SendMessage(m_hWnd, TVM_GETITEM, 0, (LPARAM)&item);
4098 if(!bRet || (lstrlen(item.pszText) < nLen - 1))
4099 break;
4101 strText.ReleaseBuffer();
4102 return bRet;
4104 #endif // defined(_WTL_USE_CSTRING) || defined(__ATLSTR_H__)
4106 BOOL SetItemText(HTREEITEM hItem, LPCTSTR lpszItem)
4108 ATLASSERT(::IsWindow(m_hWnd));
4109 return SetItem(hItem, TVIF_TEXT, lpszItem, 0, 0, 0, 0, NULL);
4112 BOOL GetItemImage(HTREEITEM hItem, int& nImage, int& nSelectedImage) const
4114 ATLASSERT(::IsWindow(m_hWnd));
4115 TVITEM item = { 0 };
4116 item.hItem = hItem;
4117 item.mask = TVIF_IMAGE|TVIF_SELECTEDIMAGE;
4118 BOOL bRes = (BOOL)::SendMessage(m_hWnd, TVM_GETITEM, 0, (LPARAM)&item);
4119 if (bRes)
4121 nImage = item.iImage;
4122 nSelectedImage = item.iSelectedImage;
4124 return bRes;
4127 BOOL SetItemImage(HTREEITEM hItem, int nImage, int nSelectedImage)
4129 ATLASSERT(::IsWindow(m_hWnd));
4130 return SetItem(hItem, TVIF_IMAGE|TVIF_SELECTEDIMAGE, NULL, nImage, nSelectedImage, 0, 0, NULL);
4133 UINT GetItemState(HTREEITEM hItem, UINT nStateMask) const
4135 ATLASSERT(::IsWindow(m_hWnd));
4136 #if (_WIN32_IE >= 0x0500) && !defined(_WIN32_WCE)
4137 return (((UINT)::SendMessage(m_hWnd, TVM_GETITEMSTATE, (WPARAM)hItem, (LPARAM)nStateMask)) & nStateMask);
4138 #else // !((_WIN32_IE >= 0x0500) && !defined(_WIN32_WCE))
4139 TVITEM item = { 0 };
4140 item.hItem = hItem;
4141 item.mask = TVIF_STATE;
4142 item.state = 0;
4143 item.stateMask = nStateMask;
4144 ::SendMessage(m_hWnd, TVM_GETITEM, 0, (LPARAM)&item);
4145 return (item.state & nStateMask);
4146 #endif // !((_WIN32_IE >= 0x0500) && !defined(_WIN32_WCE))
4149 BOOL SetItemState(HTREEITEM hItem, UINT nState, UINT nStateMask)
4151 ATLASSERT(::IsWindow(m_hWnd));
4152 return SetItem(hItem, TVIF_STATE, NULL, 0, 0, nState, nStateMask, NULL);
4155 DWORD_PTR GetItemData(HTREEITEM hItem) const
4157 ATLASSERT(::IsWindow(m_hWnd));
4158 TVITEM item = { 0 };
4159 item.hItem = hItem;
4160 item.mask = TVIF_PARAM;
4161 BOOL bRet = (BOOL)::SendMessage(m_hWnd, TVM_GETITEM, 0, (LPARAM)&item);
4162 return (DWORD_PTR)(bRet ? item.lParam : NULL);
4165 BOOL SetItemData(HTREEITEM hItem, DWORD_PTR dwData)
4167 ATLASSERT(::IsWindow(m_hWnd));
4168 return SetItem(hItem, TVIF_PARAM, NULL, 0, 0, 0, 0, (LPARAM)dwData);
4171 CEdit GetEditControl() const
4173 ATLASSERT(::IsWindow(m_hWnd));
4174 return CEdit((HWND)::SendMessage(m_hWnd, TVM_GETEDITCONTROL, 0, 0L));
4177 UINT GetVisibleCount() const
4179 ATLASSERT(::IsWindow(m_hWnd));
4180 return (UINT)::SendMessage(m_hWnd, TVM_GETVISIBLECOUNT, 0, 0L);
4183 BOOL GetItemRect(HTREEITEM hItem, LPRECT lpRect, BOOL bTextOnly) const
4185 ATLASSERT(::IsWindow(m_hWnd));
4186 *(HTREEITEM*)lpRect = hItem;
4187 return (BOOL)::SendMessage(m_hWnd, TVM_GETITEMRECT, (WPARAM)bTextOnly, (LPARAM)lpRect);
4190 BOOL ItemHasChildren(HTREEITEM hItem) const
4192 ATLASSERT(::IsWindow(m_hWnd));
4193 TVITEM item = { 0 };
4194 item.hItem = hItem;
4195 item.mask = TVIF_CHILDREN;
4196 ::SendMessage(m_hWnd, TVM_GETITEM, 0, (LPARAM)&item);
4197 return item.cChildren;
4200 #ifndef _WIN32_WCE
4201 CToolTipCtrl GetToolTips() const
4203 ATLASSERT(::IsWindow(m_hWnd));
4204 return CToolTipCtrl((HWND)::SendMessage(m_hWnd, TVM_GETTOOLTIPS, 0, 0L));
4207 CToolTipCtrl SetToolTips(HWND hWndTT)
4209 ATLASSERT(::IsWindow(m_hWnd));
4210 return CToolTipCtrl((HWND)::SendMessage(m_hWnd, TVM_SETTOOLTIPS, (WPARAM)hWndTT, 0L));
4212 #endif // !_WIN32_WCE
4214 int GetISearchString(LPTSTR lpstr) const
4216 ATLASSERT(::IsWindow(m_hWnd));
4217 return (int)::SendMessage(m_hWnd, TVM_GETISEARCHSTRING, 0, (LPARAM)lpstr);
4220 // checkboxes only
4221 BOOL GetCheckState(HTREEITEM hItem) const
4223 ATLASSERT(::IsWindow(m_hWnd));
4224 ATLASSERT((GetStyle() & TVS_CHECKBOXES) != 0);
4225 UINT uRet = GetItemState(hItem, TVIS_STATEIMAGEMASK);
4226 return (uRet >> 12) - 1;
4229 BOOL SetCheckState(HTREEITEM hItem, BOOL bCheck)
4231 int nCheck = bCheck ? 2 : 1; // one based index
4232 return SetItemState(hItem, INDEXTOSTATEIMAGEMASK(nCheck), TVIS_STATEIMAGEMASK);
4235 #if (_WIN32_IE >= 0x0400) && !defined(_WIN32_WCE)
4236 COLORREF GetBkColor() const
4238 ATLASSERT(::IsWindow(m_hWnd));
4239 return (COLORREF)::SendMessage(m_hWnd, TVM_GETBKCOLOR, 0, 0L);
4242 COLORREF SetBkColor(COLORREF clr)
4244 ATLASSERT(::IsWindow(m_hWnd));
4245 return (COLORREF)::SendMessage(m_hWnd, TVM_SETBKCOLOR, 0, (LPARAM)clr);
4248 COLORREF GetInsertMarkColor() const
4250 ATLASSERT(::IsWindow(m_hWnd));
4251 return (COLORREF)::SendMessage(m_hWnd, TVM_GETINSERTMARKCOLOR, 0, 0L);
4254 COLORREF SetInsertMarkColor(COLORREF clr)
4256 ATLASSERT(::IsWindow(m_hWnd));
4257 return (COLORREF)::SendMessage(m_hWnd, TVM_SETINSERTMARKCOLOR, 0, (LPARAM)clr);
4260 int GetItemHeight() const
4262 ATLASSERT(::IsWindow(m_hWnd));
4263 return (int)::SendMessage(m_hWnd, TVM_GETITEMHEIGHT, 0, 0L);
4266 int SetItemHeight(int cyHeight)
4268 ATLASSERT(::IsWindow(m_hWnd));
4269 return (int)::SendMessage(m_hWnd, TVM_SETITEMHEIGHT, cyHeight, 0L);
4272 int GetScrollTime() const
4274 ATLASSERT(::IsWindow(m_hWnd));
4275 return (int)::SendMessage(m_hWnd, TVM_GETSCROLLTIME, 0, 0L);
4278 int SetScrollTime(int nScrollTime)
4280 ATLASSERT(::IsWindow(m_hWnd));
4281 return (int)::SendMessage(m_hWnd, TVM_SETSCROLLTIME, nScrollTime, 0L);
4284 COLORREF GetTextColor() const
4286 ATLASSERT(::IsWindow(m_hWnd));
4287 return (COLORREF)::SendMessage(m_hWnd, TVM_GETTEXTCOLOR, 0, 0L);
4290 COLORREF SetTextColor(COLORREF clr)
4292 ATLASSERT(::IsWindow(m_hWnd));
4293 return (COLORREF)::SendMessage(m_hWnd, TVM_SETTEXTCOLOR, 0, (LPARAM)clr);
4296 BOOL GetUnicodeFormat() const
4298 ATLASSERT(::IsWindow(m_hWnd));
4299 return (BOOL)::SendMessage(m_hWnd, TVM_GETUNICODEFORMAT, 0, 0L);
4302 BOOL SetUnicodeFormat(BOOL bUnicode = TRUE)
4304 ATLASSERT(::IsWindow(m_hWnd));
4305 return (BOOL)::SendMessage(m_hWnd, TVM_SETUNICODEFORMAT, bUnicode, 0L);
4307 #endif // (_WIN32_IE >= 0x0400) && !defined(_WIN32_WCE)
4309 #if (_WIN32_IE >= 0x0500) && !defined(_WIN32_WCE)
4310 COLORREF GetLineColor() const
4312 ATLASSERT(::IsWindow(m_hWnd));
4313 return (COLORREF)::SendMessage(m_hWnd, TVM_GETLINECOLOR, 0, 0L);
4316 COLORREF SetLineColor(COLORREF clrNew /*= CLR_DEFAULT*/)
4318 ATLASSERT(::IsWindow(m_hWnd));
4319 return (COLORREF)::SendMessage(m_hWnd, TVM_SETLINECOLOR, 0, (LPARAM)clrNew);
4321 #endif // (_WIN32_IE >= 0x0500) && !defined(_WIN32_WCE)
4323 #if (_WIN32_IE >= 0x0400) && !defined(_WIN32_WCE)
4324 BOOL GetItem(LPTVITEMEX pItem) const
4326 ATLASSERT(::IsWindow(m_hWnd));
4327 return (BOOL)::SendMessage(m_hWnd, TVM_GETITEM, 0, (LPARAM)pItem);
4330 BOOL SetItem(LPTVITEMEX pItem)
4332 ATLASSERT(::IsWindow(m_hWnd));
4333 return (BOOL)::SendMessage(m_hWnd, TVM_SETITEM, 0, (LPARAM)pItem);
4335 #endif // (_WIN32_IE >= 0x0400) && !defined(_WIN32_WCE)
4337 DWORD GetExtendedStyle() const
4339 #ifndef TVM_GETEXTENDEDSTYLE
4340 const UINT TVM_GETEXTENDEDSTYLE = (TV_FIRST + 45);
4341 #endif
4342 ATLASSERT(::IsWindow(m_hWnd));
4343 return (DWORD)::SendMessage(m_hWnd, TVM_GETEXTENDEDSTYLE, 0, 0L);
4346 DWORD SetExtendedStyle(DWORD dwStyle, DWORD dwMask)
4348 #ifndef TVM_SETEXTENDEDSTYLE
4349 const UINT TVM_SETEXTENDEDSTYLE = (TV_FIRST + 44);
4350 #endif
4351 ATLASSERT(::IsWindow(m_hWnd));
4352 return (DWORD)::SendMessage(m_hWnd, TVM_SETEXTENDEDSTYLE, dwMask, dwStyle);
4355 #if (_WIN32_WINNT >= 0x0600)
4356 BOOL SetAutoScrollInfo(UINT uPixPerSec, UINT uUpdateTime)
4358 ATLASSERT(::IsWindow(m_hWnd));
4359 return (BOOL)::SendMessage(m_hWnd, TVM_SETAUTOSCROLLINFO, (WPARAM)uPixPerSec, (LPARAM)uUpdateTime);
4362 DWORD GetSelectedCount() const
4364 ATLASSERT(::IsWindow(m_hWnd));
4365 return (DWORD)::SendMessage(m_hWnd, TVM_GETSELECTEDCOUNT, 0, 0L);
4368 BOOL GetItemPartRect(HTREEITEM hItem, TVITEMPART partID, LPRECT lpRect) const
4370 ATLASSERT(::IsWindow(m_hWnd));
4371 TVGETITEMPARTRECTINFO gipri = { hItem, lpRect, partID };
4372 return (BOOL)::SendMessage(m_hWnd, TVM_GETITEMPARTRECT, 0, (LPARAM)&gipri);
4374 #endif // (_WIN32_WINNT >= 0x0600)
4376 // Operations
4377 HTREEITEM InsertItem(LPTVINSERTSTRUCT lpInsertStruct)
4379 ATLASSERT(::IsWindow(m_hWnd));
4380 return (HTREEITEM)::SendMessage(m_hWnd, TVM_INSERTITEM, 0, (LPARAM)lpInsertStruct);
4383 HTREEITEM InsertItem(LPCTSTR lpszItem, int nImage,
4384 int nSelectedImage, HTREEITEM hParent, HTREEITEM hInsertAfter)
4386 ATLASSERT(::IsWindow(m_hWnd));
4387 return InsertItem(TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE, lpszItem, nImage, nSelectedImage, 0, 0, 0, hParent, hInsertAfter);
4390 HTREEITEM InsertItem(LPCTSTR lpszItem, HTREEITEM hParent, HTREEITEM hInsertAfter)
4392 ATLASSERT(::IsWindow(m_hWnd));
4393 return InsertItem(TVIF_TEXT, lpszItem, 0, 0, 0, 0, 0, hParent, hInsertAfter);
4396 HTREEITEM InsertItem(UINT nMask, LPCTSTR lpszItem, int nImage,
4397 int nSelectedImage, UINT nState, UINT nStateMask, LPARAM lParam,
4398 HTREEITEM hParent, HTREEITEM hInsertAfter)
4400 ATLASSERT(::IsWindow(m_hWnd));
4401 TVINSERTSTRUCT tvis = { 0 };
4402 tvis.hParent = hParent;
4403 tvis.hInsertAfter = hInsertAfter;
4404 tvis.item.mask = nMask;
4405 tvis.item.pszText = (LPTSTR) lpszItem;
4406 tvis.item.iImage = nImage;
4407 tvis.item.iSelectedImage = nSelectedImage;
4408 tvis.item.state = nState;
4409 tvis.item.stateMask = nStateMask;
4410 tvis.item.lParam = lParam;
4411 return (HTREEITEM)::SendMessage(m_hWnd, TVM_INSERTITEM, 0, (LPARAM)&tvis);
4414 BOOL DeleteItem(HTREEITEM hItem)
4416 ATLASSERT(::IsWindow(m_hWnd));
4417 return (BOOL)::SendMessage(m_hWnd, TVM_DELETEITEM, 0, (LPARAM)hItem);
4420 BOOL DeleteAllItems()
4422 ATLASSERT(::IsWindow(m_hWnd));
4423 return (BOOL)::SendMessage(m_hWnd, TVM_DELETEITEM, 0, (LPARAM)TVI_ROOT);
4426 BOOL Expand(HTREEITEM hItem, UINT nCode = TVE_EXPAND)
4428 ATLASSERT(::IsWindow(m_hWnd));
4429 return (BOOL)::SendMessage(m_hWnd, TVM_EXPAND, nCode, (LPARAM)hItem);
4432 HTREEITEM GetNextItem(HTREEITEM hItem, UINT nCode) const
4434 ATLASSERT(::IsWindow(m_hWnd));
4435 return (HTREEITEM)::SendMessage(m_hWnd, TVM_GETNEXTITEM, nCode, (LPARAM)hItem);
4438 HTREEITEM GetChildItem(HTREEITEM hItem) const
4440 ATLASSERT(::IsWindow(m_hWnd));
4441 return (HTREEITEM)::SendMessage(m_hWnd, TVM_GETNEXTITEM, TVGN_CHILD, (LPARAM)hItem);
4444 HTREEITEM GetNextSiblingItem(HTREEITEM hItem) const
4446 ATLASSERT(::IsWindow(m_hWnd));
4447 return (HTREEITEM)::SendMessage(m_hWnd, TVM_GETNEXTITEM, TVGN_NEXT, (LPARAM)hItem);
4450 HTREEITEM GetPrevSiblingItem(HTREEITEM hItem) const
4452 ATLASSERT(::IsWindow(m_hWnd));
4453 return (HTREEITEM)::SendMessage(m_hWnd, TVM_GETNEXTITEM, TVGN_PREVIOUS, (LPARAM)hItem);
4456 HTREEITEM GetParentItem(HTREEITEM hItem) const
4458 ATLASSERT(::IsWindow(m_hWnd));
4459 return (HTREEITEM)::SendMessage(m_hWnd, TVM_GETNEXTITEM, TVGN_PARENT, (LPARAM)hItem);
4462 HTREEITEM GetFirstVisibleItem() const
4464 ATLASSERT(::IsWindow(m_hWnd));
4465 return (HTREEITEM)::SendMessage(m_hWnd, TVM_GETNEXTITEM, TVGN_FIRSTVISIBLE, 0L);
4468 HTREEITEM GetNextVisibleItem(HTREEITEM hItem) const
4470 ATLASSERT(::IsWindow(m_hWnd));
4471 return (HTREEITEM)::SendMessage(m_hWnd, TVM_GETNEXTITEM, TVGN_NEXTVISIBLE, (LPARAM)hItem);
4474 HTREEITEM GetPrevVisibleItem(HTREEITEM hItem) const
4476 ATLASSERT(::IsWindow(m_hWnd));
4477 return (HTREEITEM)::SendMessage(m_hWnd, TVM_GETNEXTITEM, TVGN_PREVIOUSVISIBLE, (LPARAM)hItem);
4480 HTREEITEM GetSelectedItem() const
4482 ATLASSERT(::IsWindow(m_hWnd));
4483 return (HTREEITEM)::SendMessage(m_hWnd, TVM_GETNEXTITEM, TVGN_CARET, 0L);
4486 HTREEITEM GetDropHilightItem() const
4488 ATLASSERT(::IsWindow(m_hWnd));
4489 return (HTREEITEM)::SendMessage(m_hWnd, TVM_GETNEXTITEM, TVGN_DROPHILITE, 0L);
4492 HTREEITEM GetRootItem() const
4494 ATLASSERT(::IsWindow(m_hWnd));
4495 return (HTREEITEM)::SendMessage(m_hWnd, TVM_GETNEXTITEM, TVGN_ROOT, 0L);
4498 #if !defined(_WIN32_WCE) && (_WIN32_IE >= 0x0400)
4499 HTREEITEM GetLastVisibleItem() const
4501 ATLASSERT(::IsWindow(m_hWnd));
4502 return (HTREEITEM)::SendMessage(m_hWnd, TVM_GETNEXTITEM, TVGN_LASTVISIBLE, 0L);
4504 #endif // !defined(_WIN32_WCE) && (_WIN32_IE >= 0x0400)
4506 #if (_WIN32_IE >= 0x0600)
4507 HTREEITEM GetNextSelectedItem() const
4509 ATLASSERT(::IsWindow(m_hWnd));
4510 return (HTREEITEM)::SendMessage(m_hWnd, TVM_GETNEXTITEM, TVGN_NEXTSELECTED, 0L);
4512 #endif // (_WIN32_IE >= 0x0600)
4514 BOOL Select(HTREEITEM hItem, UINT nCode)
4516 ATLASSERT(::IsWindow(m_hWnd));
4517 return (BOOL)::SendMessage(m_hWnd, TVM_SELECTITEM, nCode, (LPARAM)hItem);
4520 BOOL SelectItem(HTREEITEM hItem)
4522 ATLASSERT(::IsWindow(m_hWnd));
4523 return (BOOL)::SendMessage(m_hWnd, TVM_SELECTITEM, TVGN_CARET, (LPARAM)hItem);
4526 BOOL SelectDropTarget(HTREEITEM hItem)
4528 ATLASSERT(::IsWindow(m_hWnd));
4529 return (BOOL)::SendMessage(m_hWnd, TVM_SELECTITEM, TVGN_DROPHILITE, (LPARAM)hItem);
4532 BOOL SelectSetFirstVisible(HTREEITEM hItem)
4534 ATLASSERT(::IsWindow(m_hWnd));
4535 return (BOOL)::SendMessage(m_hWnd, TVM_SELECTITEM, TVGN_FIRSTVISIBLE, (LPARAM)hItem);
4538 CEdit EditLabel(HTREEITEM hItem)
4540 ATLASSERT(::IsWindow(m_hWnd));
4541 return CEdit((HWND)::SendMessage(m_hWnd, TVM_EDITLABEL, 0, (LPARAM)hItem));
4544 BOOL EndEditLabelNow(BOOL bCancel)
4546 ATLASSERT(::IsWindow(m_hWnd));
4547 return (BOOL)::SendMessage(m_hWnd, TVM_ENDEDITLABELNOW, bCancel, 0L);
4550 HTREEITEM HitTest(TVHITTESTINFO* pHitTestInfo) const
4552 ATLASSERT(::IsWindow(m_hWnd));
4553 return (HTREEITEM)::SendMessage(m_hWnd, TVM_HITTEST, 0, (LPARAM)pHitTestInfo);
4556 HTREEITEM HitTest(POINT pt, UINT* pFlags) const
4558 ATLASSERT(::IsWindow(m_hWnd));
4559 TVHITTESTINFO hti = { 0 };
4560 hti.pt = pt;
4561 HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(m_hWnd, TVM_HITTEST, 0, (LPARAM)&hti);
4562 if (pFlags != NULL)
4563 *pFlags = hti.flags;
4564 return hTreeItem;
4567 BOOL SortChildren(HTREEITEM hItem, BOOL bRecurse = FALSE)
4569 ATLASSERT(::IsWindow(m_hWnd));
4570 return (BOOL)::SendMessage(m_hWnd, TVM_SORTCHILDREN, (WPARAM)bRecurse, (LPARAM)hItem);
4573 BOOL EnsureVisible(HTREEITEM hItem)
4575 ATLASSERT(::IsWindow(m_hWnd));
4576 return (BOOL)::SendMessage(m_hWnd, TVM_ENSUREVISIBLE, 0, (LPARAM)hItem);
4579 BOOL SortChildrenCB(LPTVSORTCB pSort, BOOL bRecurse = FALSE)
4581 ATLASSERT(::IsWindow(m_hWnd));
4582 return (BOOL)::SendMessage(m_hWnd, TVM_SORTCHILDRENCB, (WPARAM)bRecurse, (LPARAM)pSort);
4585 CImageList RemoveImageList(int nImageList)
4587 ATLASSERT(::IsWindow(m_hWnd));
4588 return CImageList((HIMAGELIST)::SendMessage(m_hWnd, TVM_SETIMAGELIST, (WPARAM)nImageList, NULL));
4591 CImageList CreateDragImage(HTREEITEM hItem)
4593 ATLASSERT(::IsWindow(m_hWnd));
4594 return CImageList((HIMAGELIST)::SendMessage(m_hWnd, TVM_CREATEDRAGIMAGE, 0, (LPARAM)hItem));
4597 #if (_WIN32_IE >= 0x0400) && !defined(_WIN32_WCE)
4598 BOOL SetInsertMark(HTREEITEM hTreeItem, BOOL bAfter)
4600 ATLASSERT(::IsWindow(m_hWnd));
4601 return (BOOL)::SendMessage(m_hWnd, TVM_SETINSERTMARK, bAfter, (LPARAM)hTreeItem);
4604 BOOL RemoveInsertMark()
4606 ATLASSERT(::IsWindow(m_hWnd));
4607 return (BOOL)::SendMessage(m_hWnd, TVM_SETINSERTMARK, 0, 0L);
4609 #endif // (_WIN32_IE >= 0x0400) && !defined(_WIN32_WCE)
4611 #if (_WIN32_WINNT >= 0x0501)
4612 HTREEITEM MapAccIDToHTREEITEM(UINT uID) const
4614 ATLASSERT(::IsWindow(m_hWnd));
4615 return (HTREEITEM)::SendMessage(m_hWnd, TVM_MAPACCIDTOHTREEITEM, uID, 0L);
4618 UINT MapHTREEITEMToAccID(HTREEITEM hTreeItem) const
4620 ATLASSERT(::IsWindow(m_hWnd));
4621 return (UINT)::SendMessage(m_hWnd, TVM_MAPHTREEITEMTOACCID, (WPARAM)hTreeItem, 0L);
4623 #endif // (_WIN32_WINNT >= 0x0501)
4625 #if (_WIN32_WINNT >= 0x0600)
4626 void ShowInfoTip(HTREEITEM hItem)
4628 ATLASSERT(::IsWindow(m_hWnd));
4629 ::SendMessage(m_hWnd, TVM_SHOWINFOTIP, 0, (LPARAM)hItem);
4631 #endif // (_WIN32_WINNT >= 0x0600)
4634 typedef CTreeViewCtrlT<ATL::CWindow> CTreeViewCtrl;
4637 ///////////////////////////////////////////////////////////////////////////////
4638 // CTreeViewCtrlEx
4640 // forward declaration
4641 template <class TBase> class CTreeViewCtrlExT;
4643 // Note: TBase here is for CTreeViewCtrlExT, and not for CTreeItemT itself
4644 template <class TBase>
4645 class CTreeItemT
4647 public:
4648 HTREEITEM m_hTreeItem;
4649 CTreeViewCtrlExT<TBase>* m_pTreeView;
4651 // Construction
4652 CTreeItemT(HTREEITEM hTreeItem = NULL, CTreeViewCtrlExT<TBase>* pTreeView = NULL) : m_hTreeItem(hTreeItem), m_pTreeView(pTreeView)
4655 CTreeItemT(const CTreeItemT<TBase>& posSrc)
4657 *this = posSrc;
4660 operator HTREEITEM() { return m_hTreeItem; }
4662 CTreeItemT<TBase>& operator =(const CTreeItemT<TBase>& itemSrc)
4664 m_hTreeItem = itemSrc.m_hTreeItem;
4665 m_pTreeView = itemSrc.m_pTreeView;
4666 return *this;
4669 // Attributes
4670 CTreeViewCtrlExT<TBase>* GetTreeView() const { return m_pTreeView; }
4672 BOOL operator !() const { return m_hTreeItem == NULL; }
4674 BOOL IsNull() const { return m_hTreeItem == NULL; }
4676 BOOL GetRect(LPRECT lpRect, BOOL bTextOnly) const;
4677 BOOL GetText(LPTSTR lpstrText, int nLen) const;
4678 #ifndef _ATL_NO_COM
4679 BOOL GetText(BSTR& bstrText) const;
4680 #endif // !_ATL_NO_COM
4681 #if defined(_WTL_USE_CSTRING) || defined(__ATLSTR_H__)
4682 BOOL GetText(_CSTRING_NS::CString& strText) const;
4683 #endif // defined(_WTL_USE_CSTRING) || defined(__ATLSTR_H__)
4684 BOOL SetText(LPCTSTR lpszItem);
4685 BOOL GetImage(int& nImage, int& nSelectedImage) const;
4686 BOOL SetImage(int nImage, int nSelectedImage);
4687 UINT GetState(UINT nStateMask) const;
4688 BOOL SetState(UINT nState, UINT nStateMask);
4689 DWORD_PTR GetData() const;
4690 BOOL SetData(DWORD_PTR dwData);
4691 BOOL SetItem(UINT nMask, LPCTSTR lpszItem, int nImage, int nSelectedImage, UINT nState, UINT nStateMask, LPARAM lParam);
4693 // Operations
4694 CTreeItemT<TBase> InsertAfter(LPCTSTR lpstrItem, HTREEITEM hItemAfter, int nImageIndex)
4696 return _Insert(lpstrItem, nImageIndex, hItemAfter);
4699 CTreeItemT<TBase> AddHead(LPCTSTR lpstrItem, int nImageIndex)
4701 return _Insert(lpstrItem, nImageIndex, TVI_FIRST);
4704 CTreeItemT<TBase> AddTail(LPCTSTR lpstrItem, int nImageIndex)
4706 return _Insert(lpstrItem, nImageIndex, TVI_LAST);
4709 CTreeItemT<TBase> GetChild() const;
4710 CTreeItemT<TBase> GetNext(UINT nCode) const;
4711 CTreeItemT<TBase> GetNextSibling() const;
4712 CTreeItemT<TBase> GetPrevSibling() const;
4713 CTreeItemT<TBase> GetParent() const;
4714 CTreeItemT<TBase> GetFirstVisible() const;
4715 CTreeItemT<TBase> GetNextVisible() const;
4716 CTreeItemT<TBase> GetPrevVisible() const;
4717 CTreeItemT<TBase> GetSelected() const;
4718 CTreeItemT<TBase> GetDropHilight() const;
4719 CTreeItemT<TBase> GetRoot() const;
4720 #if !defined(_WIN32_WCE) && (_WIN32_IE >= 0x0400)
4721 CTreeItemT<TBase> GetLastVisible() const;
4722 #endif // !defined(_WIN32_WCE) && (_WIN32_IE >= 0x0400)
4723 #if (_WIN32_IE >= 0x0600)
4724 CTreeItemT<TBase> GetNextSelected() const;
4725 #endif // (_WIN32_IE >= 0x0600)
4726 BOOL HasChildren() const;
4727 BOOL Delete();
4728 BOOL Expand(UINT nCode = TVE_EXPAND);
4729 BOOL Select(UINT nCode);
4730 BOOL Select();
4731 BOOL SelectDropTarget();
4732 BOOL SelectSetFirstVisible();
4733 HWND EditLabel();
4734 HIMAGELIST CreateDragImage();
4735 BOOL SortChildren(BOOL bRecurse = FALSE);
4736 BOOL EnsureVisible();
4737 CTreeItemT<TBase> _Insert(LPCTSTR lpstrItem, int nImageIndex, HTREEITEM hItemAfter);
4738 int GetImageIndex() const;
4739 #if (_WIN32_IE >= 0x0400) && !defined(_WIN32_WCE)
4740 BOOL SetInsertMark(BOOL bAfter);
4741 #endif // (_WIN32_IE >= 0x0400) && !defined(_WIN32_WCE)
4742 #if (_WIN32_WINNT >= 0x0501)
4743 UINT MapHTREEITEMToAccID() const;
4744 #endif // (_WIN32_WINNT >= 0x0501)
4745 #if (_WIN32_WINNT >= 0x0600)
4746 void ShowInfoTip();
4747 BOOL GetPartRect(TVITEMPART partID, LPRECT lpRect) const;
4748 #endif // (_WIN32_WINNT >= 0x0600)
4751 typedef CTreeItemT<ATL::CWindow> CTreeItem;
4754 template <class TBase>
4755 class CTreeViewCtrlExT : public CTreeViewCtrlT< TBase >
4757 public:
4758 // Constructors
4759 CTreeViewCtrlExT(HWND hWnd = NULL) : CTreeViewCtrlT< TBase >(hWnd)
4762 CTreeViewCtrlExT< TBase >& operator =(HWND hWnd)
4764 m_hWnd = hWnd;
4765 return *this;
4768 // Operations (overides that return CTreeItem)
4769 CTreeItemT<TBase> InsertItem(LPTVINSERTSTRUCT lpInsertStruct)
4771 ATLASSERT(::IsWindow(m_hWnd));
4772 HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(m_hWnd, TVM_INSERTITEM, 0, (LPARAM)lpInsertStruct);
4773 return CTreeItemT<TBase>(hTreeItem, this);
4776 CTreeItemT<TBase> InsertItem(LPCTSTR lpszItem, int nImage,
4777 int nSelectedImage, HTREEITEM hParent, HTREEITEM hInsertAfter)
4779 ATLASSERT(::IsWindow(m_hWnd));
4780 return InsertItem(TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE, lpszItem, nImage, nSelectedImage, 0, 0, 0, hParent, hInsertAfter);
4783 CTreeItemT<TBase> InsertItem(LPCTSTR lpszItem, HTREEITEM hParent, HTREEITEM hInsertAfter)
4785 ATLASSERT(::IsWindow(m_hWnd));
4786 return InsertItem(TVIF_TEXT, lpszItem, 0, 0, 0, 0, 0, hParent, hInsertAfter);
4789 CTreeItemT<TBase> GetNextItem(HTREEITEM hItem, UINT nCode) const
4791 ATLASSERT(::IsWindow(m_hWnd));
4792 HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(m_hWnd, TVM_GETNEXTITEM, nCode, (LPARAM)hItem);
4793 return CTreeItemT<TBase>(hTreeItem, (CTreeViewCtrlExT<TBase>*)this);
4796 CTreeItemT<TBase> GetChildItem(HTREEITEM hItem) const
4798 ATLASSERT(::IsWindow(m_hWnd));
4799 HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(m_hWnd, TVM_GETNEXTITEM, TVGN_CHILD, (LPARAM)hItem);
4800 return CTreeItemT<TBase>(hTreeItem, (CTreeViewCtrlExT<TBase>*)this);
4803 CTreeItemT<TBase> GetNextSiblingItem(HTREEITEM hItem) const
4805 ATLASSERT(::IsWindow(m_hWnd));
4806 HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(m_hWnd, TVM_GETNEXTITEM, TVGN_NEXT, (LPARAM)hItem);
4807 return CTreeItemT<TBase>(hTreeItem, (CTreeViewCtrlExT<TBase>*)this);
4810 CTreeItemT<TBase> GetPrevSiblingItem(HTREEITEM hItem) const
4812 ATLASSERT(::IsWindow(m_hWnd));
4813 HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(m_hWnd, TVM_GETNEXTITEM, TVGN_PREVIOUS, (LPARAM)hItem);
4814 return CTreeItemT<TBase>(hTreeItem, (CTreeViewCtrlExT<TBase>*)this);
4817 CTreeItemT<TBase> GetParentItem(HTREEITEM hItem) const
4819 ATLASSERT(::IsWindow(m_hWnd));
4820 HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(m_hWnd, TVM_GETNEXTITEM, TVGN_PARENT, (LPARAM)hItem);
4821 return CTreeItemT<TBase>(hTreeItem, (CTreeViewCtrlExT<TBase>*)this);
4824 CTreeItemT<TBase> GetFirstVisibleItem() const
4826 ATLASSERT(::IsWindow(m_hWnd));
4827 HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(m_hWnd, TVM_GETNEXTITEM, TVGN_FIRSTVISIBLE, 0L);
4828 return CTreeItemT<TBase>(hTreeItem, (CTreeViewCtrlExT<TBase>*)this);
4831 CTreeItemT<TBase> GetNextVisibleItem(HTREEITEM hItem) const
4833 ATLASSERT(::IsWindow(m_hWnd));
4834 HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(m_hWnd, TVM_GETNEXTITEM, TVGN_NEXTVISIBLE, (LPARAM)hItem);
4835 return CTreeItemT<TBase>(hTreeItem, (CTreeViewCtrlExT<TBase>*)this);
4838 CTreeItemT<TBase> GetPrevVisibleItem(HTREEITEM hItem) const
4840 ATLASSERT(::IsWindow(m_hWnd));
4841 HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(m_hWnd, TVM_GETNEXTITEM, TVGN_PREVIOUSVISIBLE, (LPARAM)hItem);
4842 return CTreeItemT<TBase>(hTreeItem, (CTreeViewCtrlExT<TBase>*)this);
4845 CTreeItemT<TBase> GetSelectedItem() const
4847 ATLASSERT(::IsWindow(m_hWnd));
4848 HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(m_hWnd, TVM_GETNEXTITEM, TVGN_CARET, 0L);
4849 return CTreeItemT<TBase>(hTreeItem, (CTreeViewCtrlExT<TBase>*)this);
4852 CTreeItemT<TBase> GetDropHilightItem() const
4854 ATLASSERT(::IsWindow(m_hWnd));
4855 HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(m_hWnd, TVM_GETNEXTITEM, TVGN_DROPHILITE, 0L);
4856 return CTreeItemT<TBase>(hTreeItem, (CTreeViewCtrlExT<TBase>*)this);
4859 CTreeItemT<TBase> GetRootItem() const
4861 ATLASSERT(::IsWindow(m_hWnd));
4862 HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(m_hWnd, TVM_GETNEXTITEM, TVGN_ROOT, 0L);
4863 return CTreeItemT<TBase>(hTreeItem, (CTreeViewCtrlExT<TBase>*)this);
4866 #if !defined(_WIN32_WCE) && (_WIN32_IE >= 0x0400)
4867 CTreeItemT<TBase> GetLastVisibleItem() const
4869 ATLASSERT(::IsWindow(m_hWnd));
4870 HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(m_hWnd, TVM_GETNEXTITEM, TVGN_LASTVISIBLE, 0L);
4871 return CTreeItemT<TBase>(hTreeItem, (CTreeViewCtrlExT<TBase>*)this);
4873 #endif // !defined(_WIN32_WCE) && (_WIN32_IE >= 0x0400)
4875 #if (_WIN32_IE >= 0x0600)
4876 CTreeItemT<TBase> GetNextSelectedItem() const
4878 ATLASSERT(::IsWindow(m_hWnd));
4879 HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(m_hWnd, TVM_GETNEXTITEM, TVGN_NEXTSELECTED, 0L);
4880 return CTreeItemT<TBase>(hTreeItem, (CTreeViewCtrlExT<TBase>*)this);
4882 #endif // (_WIN32_IE >= 0x0600)
4884 CTreeItemT<TBase> HitTest(TVHITTESTINFO* pHitTestInfo) const
4886 ATLASSERT(::IsWindow(m_hWnd));
4887 HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(m_hWnd, TVM_HITTEST, 0, (LPARAM)pHitTestInfo);
4888 return CTreeItemT<TBase>(hTreeItem, (CTreeViewCtrlExT<TBase>*)this);
4891 CTreeItemT<TBase> InsertItem(UINT nMask, LPCTSTR lpszItem, int nImage,
4892 int nSelectedImage, UINT nState, UINT nStateMask, LPARAM lParam,
4893 HTREEITEM hParent, HTREEITEM hInsertAfter)
4895 ATLASSERT(::IsWindow(m_hWnd));
4896 TVINSERTSTRUCT tvis = { 0 };
4897 tvis.hParent = hParent;
4898 tvis.hInsertAfter = hInsertAfter;
4899 tvis.item.mask = nMask;
4900 tvis.item.pszText = (LPTSTR) lpszItem;
4901 tvis.item.iImage = nImage;
4902 tvis.item.iSelectedImage = nSelectedImage;
4903 tvis.item.state = nState;
4904 tvis.item.stateMask = nStateMask;
4905 tvis.item.lParam = lParam;
4906 HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(m_hWnd, TVM_INSERTITEM, 0, (LPARAM)&tvis);
4907 return CTreeItemT<TBase>(hTreeItem, this);
4910 CTreeItemT<TBase> HitTest(POINT pt, UINT* pFlags) const
4912 ATLASSERT(::IsWindow(m_hWnd));
4913 TVHITTESTINFO hti = { 0 };
4914 hti.pt = pt;
4915 HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(m_hWnd, TVM_HITTEST, 0, (LPARAM)&hti);
4916 if (pFlags != NULL)
4917 *pFlags = hti.flags;
4918 return CTreeItemT<TBase>(hTreeItem, (CTreeViewCtrlExT<TBase>*)this);
4921 #if (_WIN32_WINNT >= 0x0501)
4922 CTreeItemT<TBase> MapAccIDToHTREEITEM(UINT uID) const
4924 ATLASSERT(::IsWindow(m_hWnd));
4925 HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(m_hWnd, TVM_MAPACCIDTOHTREEITEM, uID, 0L);
4926 return CTreeItemT<TBase>(hTreeItem, (CTreeViewCtrlExT<TBase>*)this);
4928 #endif // (_WIN32_WINNT >= 0x0501)
4931 typedef CTreeViewCtrlExT<ATL::CWindow> CTreeViewCtrlEx;
4934 // CTreeItem inline methods
4935 template <class TBase>
4936 inline BOOL CTreeItemT<TBase>::GetRect(LPRECT lpRect, BOOL bTextOnly) const
4938 ATLASSERT(m_pTreeView != NULL);
4939 return m_pTreeView->GetItemRect(m_hTreeItem,lpRect,bTextOnly);
4942 template <class TBase>
4943 inline CTreeItemT<TBase> CTreeItemT<TBase>::GetNext(UINT nCode) const
4945 ATLASSERT(m_pTreeView != NULL);
4946 return m_pTreeView->GetNextItem(m_hTreeItem,nCode);
4949 template <class TBase>
4950 inline CTreeItemT<TBase> CTreeItemT<TBase>::GetChild() const
4952 ATLASSERT(m_pTreeView != NULL);
4953 return m_pTreeView->GetChildItem(m_hTreeItem);
4956 template <class TBase>
4957 inline CTreeItemT<TBase> CTreeItemT<TBase>::GetNextSibling() const
4959 ATLASSERT(m_pTreeView != NULL);
4960 return m_pTreeView->GetNextSiblingItem(m_hTreeItem);
4963 template <class TBase>
4964 inline CTreeItemT<TBase> CTreeItemT<TBase>::GetPrevSibling() const
4966 ATLASSERT(m_pTreeView != NULL);
4967 return m_pTreeView->GetPrevSiblingItem(m_hTreeItem);
4970 template <class TBase>
4971 inline CTreeItemT<TBase> CTreeItemT<TBase>::GetParent() const
4973 ATLASSERT(m_pTreeView != NULL);
4974 return m_pTreeView->GetParentItem(m_hTreeItem);
4977 template <class TBase>
4978 inline CTreeItemT<TBase> CTreeItemT<TBase>::GetFirstVisible() const
4980 ATLASSERT(m_pTreeView != NULL);
4981 return m_pTreeView->GetFirstVisibleItem();
4984 template <class TBase>
4985 inline CTreeItemT<TBase> CTreeItemT<TBase>::GetNextVisible() const
4987 ATLASSERT(m_pTreeView != NULL);
4988 return m_pTreeView->GetNextVisibleItem(m_hTreeItem);
4991 template <class TBase>
4992 inline CTreeItemT<TBase> CTreeItemT<TBase>::GetPrevVisible() const
4994 ATLASSERT(m_pTreeView != NULL);
4995 return m_pTreeView->GetPrevVisibleItem(m_hTreeItem);
4998 template <class TBase>
4999 inline CTreeItemT<TBase> CTreeItemT<TBase>::GetSelected() const
5001 ATLASSERT(m_pTreeView != NULL);
5002 return m_pTreeView->GetSelectedItem();
5005 template <class TBase>
5006 inline CTreeItemT<TBase> CTreeItemT<TBase>::GetDropHilight() const
5008 ATLASSERT(m_pTreeView != NULL);
5009 return m_pTreeView->GetDropHilightItem();
5012 template <class TBase>
5013 inline CTreeItemT<TBase> CTreeItemT<TBase>::GetRoot() const
5015 ATLASSERT(m_pTreeView != NULL);
5016 return m_pTreeView->GetRootItem();
5019 #if !defined(_WIN32_WCE) && (_WIN32_IE >= 0x0400)
5020 template <class TBase>
5021 inline CTreeItemT<TBase> CTreeItemT<TBase>::GetLastVisible() const
5023 ATLASSERT(m_pTreeView != NULL);
5024 return m_pTreeView->GetLastVisibleItem();
5026 #endif // !defined(_WIN32_WCE) && (_WIN32_IE >= 0x0400)
5028 #if (_WIN32_IE >= 0x0600)
5029 template <class TBase>
5030 inline CTreeItemT<TBase> CTreeItemT<TBase>::GetNextSelected() const
5032 ATLASSERT(m_pTreeView != NULL);
5033 return m_pTreeView->GetNextSelectedItem();
5035 #endif // (_WIN32_IE >= 0x0600)
5037 template <class TBase>
5038 inline BOOL CTreeItemT<TBase>::GetText(LPTSTR lpstrText, int nLen) const
5040 ATLASSERT(m_pTreeView != NULL);
5041 return m_pTreeView->GetItemText(m_hTreeItem, lpstrText, nLen);
5044 #ifndef _ATL_NO_COM
5045 #ifdef _OLEAUTO_H_
5046 template <class TBase>
5047 inline BOOL CTreeItemT<TBase>::GetText(BSTR& bstrText) const
5049 ATLASSERT(m_pTreeView != NULL);
5050 return m_pTreeView->GetItemText(m_hTreeItem, bstrText);
5052 #endif // _OLEAUTO_H_
5053 #endif // !_ATL_NO_COM
5055 #if defined(_WTL_USE_CSTRING) || defined(__ATLSTR_H__)
5056 template <class TBase>
5057 inline BOOL CTreeItemT<TBase>::GetText(_CSTRING_NS::CString& strText) const
5059 ATLASSERT(m_pTreeView != NULL);
5060 return m_pTreeView->GetItemText(m_hTreeItem, strText);
5062 #endif // defined(_WTL_USE_CSTRING) || defined(__ATLSTR_H__)
5064 template <class TBase>
5065 inline BOOL CTreeItemT<TBase>::GetImage(int& nImage, int& nSelectedImage) const
5067 ATLASSERT(m_pTreeView != NULL);
5068 return m_pTreeView->GetItemImage(m_hTreeItem,nImage,nSelectedImage);
5071 template <class TBase>
5072 inline UINT CTreeItemT<TBase>::GetState(UINT nStateMask) const
5074 ATLASSERT(m_pTreeView != NULL);
5075 return m_pTreeView->GetItemState(m_hTreeItem,nStateMask);
5078 template <class TBase>
5079 inline DWORD_PTR CTreeItemT<TBase>::GetData() const
5081 ATLASSERT(m_pTreeView != NULL);
5082 return m_pTreeView->GetItemData(m_hTreeItem);
5085 template <class TBase>
5086 inline BOOL CTreeItemT<TBase>::SetItem(UINT nMask, LPCTSTR lpszItem, int nImage,
5087 int nSelectedImage, UINT nState, UINT nStateMask, LPARAM lParam)
5089 ATLASSERT(m_pTreeView != NULL);
5090 return m_pTreeView->SetItem(m_hTreeItem, nMask, lpszItem, nImage, nSelectedImage, nState, nStateMask, lParam);
5093 template <class TBase>
5094 inline BOOL CTreeItemT<TBase>::SetText(LPCTSTR lpszItem)
5096 ATLASSERT(m_pTreeView != NULL);
5097 return m_pTreeView->SetItemText(m_hTreeItem,lpszItem);
5100 template <class TBase>
5101 inline BOOL CTreeItemT<TBase>::SetImage(int nImage, int nSelectedImage)
5103 ATLASSERT(m_pTreeView != NULL);
5104 return m_pTreeView->SetItemImage(m_hTreeItem,nImage,nSelectedImage);
5107 template <class TBase>
5108 inline BOOL CTreeItemT<TBase>::SetState(UINT nState, UINT nStateMask)
5110 ATLASSERT(m_pTreeView != NULL);
5111 return m_pTreeView->SetItemState(m_hTreeItem,nState,nStateMask);
5114 template <class TBase>
5115 inline BOOL CTreeItemT<TBase>::SetData(DWORD_PTR dwData)
5117 ATLASSERT(m_pTreeView != NULL);
5118 return m_pTreeView->SetItemData(m_hTreeItem,dwData);
5121 template <class TBase>
5122 inline BOOL CTreeItemT<TBase>::HasChildren() const
5124 ATLASSERT(m_pTreeView != NULL);
5125 return m_pTreeView->ItemHasChildren(m_hTreeItem);
5128 template <class TBase>
5129 inline BOOL CTreeItemT<TBase>::Delete()
5131 ATLASSERT(m_pTreeView != NULL);
5132 return m_pTreeView->DeleteItem(m_hTreeItem);
5135 template <class TBase>
5136 inline BOOL CTreeItemT<TBase>::Expand(UINT nCode /*= TVE_EXPAND*/)
5138 ATLASSERT(m_pTreeView != NULL);
5139 return m_pTreeView->Expand(m_hTreeItem,nCode);
5142 template <class TBase>
5143 inline BOOL CTreeItemT<TBase>::Select(UINT nCode)
5145 ATLASSERT(m_pTreeView != NULL);
5146 return m_pTreeView->Select(m_hTreeItem,nCode);
5149 template <class TBase>
5150 inline BOOL CTreeItemT<TBase>::Select()
5152 ATLASSERT(m_pTreeView != NULL);
5153 return m_pTreeView->SelectItem(m_hTreeItem);
5156 template <class TBase>
5157 inline BOOL CTreeItemT<TBase>::SelectDropTarget()
5159 ATLASSERT(m_pTreeView != NULL);
5160 return m_pTreeView->SelectDropTarget(m_hTreeItem);
5163 template <class TBase>
5164 inline BOOL CTreeItemT<TBase>::SelectSetFirstVisible()
5166 ATLASSERT(m_pTreeView != NULL);
5167 return m_pTreeView->SelectSetFirstVisible(m_hTreeItem);
5170 template <class TBase>
5171 inline HWND CTreeItemT<TBase>::EditLabel()
5173 ATLASSERT(m_pTreeView != NULL);
5174 return m_pTreeView->EditLabel(m_hTreeItem);
5177 template <class TBase>
5178 inline HIMAGELIST CTreeItemT<TBase>::CreateDragImage()
5180 ATLASSERT(m_pTreeView != NULL);
5181 return m_pTreeView->CreateDragImage(m_hTreeItem);
5184 template <class TBase>
5185 inline BOOL CTreeItemT<TBase>::SortChildren(BOOL bRecurse /*= FALSE*/)
5187 ATLASSERT(m_pTreeView != NULL);
5188 return m_pTreeView->SortChildren(m_hTreeItem, bRecurse);
5191 template <class TBase>
5192 inline BOOL CTreeItemT<TBase>::EnsureVisible()
5194 ATLASSERT(m_pTreeView != NULL);
5195 return m_pTreeView->EnsureVisible(m_hTreeItem);
5198 template <class TBase>
5199 inline CTreeItemT<TBase> CTreeItemT<TBase>::_Insert(LPCTSTR lpstrItem, int nImageIndex, HTREEITEM hItemAfter)
5201 ATLASSERT(m_pTreeView != NULL);
5202 TVINSERTSTRUCT ins = { 0 };
5203 ins.hParent = m_hTreeItem;
5204 ins.hInsertAfter = hItemAfter;
5205 ins.item.mask = TVIF_TEXT;
5206 ins.item.pszText = (LPTSTR)lpstrItem;
5207 if(nImageIndex != -1)
5209 ins.item.mask |= TVIF_IMAGE | TVIF_SELECTEDIMAGE;
5210 ins.item.iImage = nImageIndex;
5211 ins.item.iSelectedImage = nImageIndex;
5213 return CTreeItemT<TBase>(m_pTreeView->InsertItem(&ins), m_pTreeView);
5216 template <class TBase>
5217 inline int CTreeItemT<TBase>::GetImageIndex() const
5219 ATLASSERT(m_pTreeView != NULL);
5220 TVITEM item = { 0 };
5221 item.mask = TVIF_HANDLE | TVIF_IMAGE;
5222 item.hItem = m_hTreeItem;
5223 m_pTreeView->GetItem(&item);
5224 return item.iImage;
5227 #if (_WIN32_IE >= 0x0400) && !defined(_WIN32_WCE)
5228 template <class TBase>
5229 inline BOOL CTreeItemT<TBase>::SetInsertMark(BOOL bAfter)
5231 ATLASSERT(m_pTreeView != NULL);
5232 return m_pTreeView->SetInsertMark(m_hTreeItem, bAfter);
5234 #endif // (_WIN32_IE >= 0x0400) && !defined(_WIN32_WCE)
5236 #if (_WIN32_WINNT >= 0x0501)
5237 template <class TBase>
5238 inline UINT CTreeItemT<TBase>::MapHTREEITEMToAccID() const
5240 ATLASSERT(m_pTreeView != NULL);
5241 return m_pTreeView->MapHTREEITEMToAccID(m_hTreeItem);
5243 #endif // (_WIN32_WINNT >= 0x0501)
5245 #if (_WIN32_WINNT >= 0x0600)
5246 template <class TBase>
5247 inline void CTreeItemT<TBase>::ShowInfoTip()
5249 ATLASSERT(m_pTreeView != NULL);
5250 m_pTreeView->ShowInfoTip(m_hTreeItem);
5253 template <class TBase>
5254 inline BOOL CTreeItemT<TBase>::GetPartRect(TVITEMPART partID, LPRECT lpRect) const
5256 ATLASSERT(m_pTreeView != NULL);
5257 return m_pTreeView->GetItemPartRect(m_hTreeItem, partID, lpRect);
5259 #endif // (_WIN32_WINNT >= 0x0600)
5262 ///////////////////////////////////////////////////////////////////////////////
5263 // CToolBarCtrl
5265 template <class TBase>
5266 class CToolBarCtrlT : public TBase
5268 public:
5269 // Construction
5270 CToolBarCtrlT(HWND hWnd = NULL) : TBase(hWnd)
5273 CToolBarCtrlT< TBase >& operator =(HWND hWnd)
5275 m_hWnd = hWnd;
5276 return *this;
5279 HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
5280 DWORD dwStyle = 0, DWORD dwExStyle = 0,
5281 ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
5283 return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
5286 // Attributes
5287 static LPCTSTR GetWndClassName()
5289 return TOOLBARCLASSNAME;
5292 BOOL IsButtonEnabled(int nID) const
5294 ATLASSERT(::IsWindow(m_hWnd));
5295 return (BOOL)::SendMessage(m_hWnd, TB_ISBUTTONENABLED, nID, 0L);
5298 BOOL IsButtonChecked(int nID) const
5300 ATLASSERT(::IsWindow(m_hWnd));
5301 return (BOOL)::SendMessage(m_hWnd, TB_ISBUTTONCHECKED, nID, 0L);
5304 BOOL IsButtonPressed(int nID) const
5306 ATLASSERT(::IsWindow(m_hWnd));
5307 return (BOOL)::SendMessage(m_hWnd, TB_ISBUTTONPRESSED, nID, 0L);
5310 BOOL IsButtonHidden(int nID) const
5312 ATLASSERT(::IsWindow(m_hWnd));
5313 return(BOOL) ::SendMessage(m_hWnd, TB_ISBUTTONHIDDEN, nID, 0L);
5316 BOOL IsButtonIndeterminate(int nID) const
5318 ATLASSERT(::IsWindow(m_hWnd));
5319 return (BOOL)::SendMessage(m_hWnd, TB_ISBUTTONINDETERMINATE, nID, 0L);
5322 int GetState(int nID) const
5324 ATLASSERT(::IsWindow(m_hWnd));
5325 return (int)::SendMessage(m_hWnd, TB_GETSTATE, nID, 0L);
5328 BOOL SetState(int nID, UINT nState)
5330 ATLASSERT(::IsWindow(m_hWnd));
5331 return (BOOL)::SendMessage(m_hWnd, TB_SETSTATE, nID, MAKELPARAM(nState, 0));
5334 BOOL GetButton(int nIndex, LPTBBUTTON lpButton) const
5336 ATLASSERT(::IsWindow(m_hWnd));
5337 return (BOOL)::SendMessage(m_hWnd, TB_GETBUTTON, nIndex, (LPARAM)lpButton);
5340 int GetButtonCount() const
5342 ATLASSERT(::IsWindow(m_hWnd));
5343 return (int)::SendMessage(m_hWnd, TB_BUTTONCOUNT, 0, 0L);
5346 BOOL GetItemRect(int nIndex, LPRECT lpRect) const
5348 ATLASSERT(::IsWindow(m_hWnd));
5349 return (BOOL)::SendMessage(m_hWnd, TB_GETITEMRECT, nIndex, (LPARAM)lpRect);
5352 void SetButtonStructSize(int nSize = sizeof(TBBUTTON))
5354 ATLASSERT(::IsWindow(m_hWnd));
5355 ::SendMessage(m_hWnd, TB_BUTTONSTRUCTSIZE, nSize, 0L);
5358 BOOL SetButtonSize(SIZE size)
5360 ATLASSERT(::IsWindow(m_hWnd));
5361 return (BOOL)::SendMessage(m_hWnd, TB_SETBUTTONSIZE, 0, MAKELPARAM(size.cx, size.cy));
5364 BOOL SetButtonSize(int cx, int cy)
5366 ATLASSERT(::IsWindow(m_hWnd));
5367 return (BOOL)::SendMessage(m_hWnd, TB_SETBUTTONSIZE, 0, MAKELPARAM(cx, cy));
5370 BOOL SetBitmapSize(SIZE size)
5372 ATLASSERT(::IsWindow(m_hWnd));
5373 return (BOOL)::SendMessage(m_hWnd, TB_SETBITMAPSIZE, 0, MAKELPARAM(size.cx, size.cy));
5376 BOOL SetBitmapSize(int cx, int cy)
5378 ATLASSERT(::IsWindow(m_hWnd));
5379 return (BOOL)::SendMessage(m_hWnd, TB_SETBITMAPSIZE, 0, MAKELPARAM(cx, cy));
5382 #ifndef _WIN32_WCE
5383 CToolTipCtrl GetToolTips() const
5385 ATLASSERT(::IsWindow(m_hWnd));
5386 return CToolTipCtrl((HWND)::SendMessage(m_hWnd, TB_GETTOOLTIPS, 0, 0L));
5389 void SetToolTips(HWND hWndToolTip)
5391 ATLASSERT(::IsWindow(m_hWnd));
5392 ::SendMessage(m_hWnd, TB_SETTOOLTIPS, (WPARAM)hWndToolTip, 0L);
5394 #endif // !_WIN32_WCE
5396 void SetNotifyWnd(HWND hWnd)
5398 ATLASSERT(::IsWindow(m_hWnd));
5399 ::SendMessage(m_hWnd, TB_SETPARENT, (WPARAM)hWnd, 0L);
5402 int GetRows() const
5404 ATLASSERT(::IsWindow(m_hWnd));
5405 return (int)::SendMessage(m_hWnd, TB_GETROWS, 0, 0L);
5408 void SetRows(int nRows, BOOL bLarger, LPRECT lpRect)
5410 ATLASSERT(::IsWindow(m_hWnd));
5411 ::SendMessage(m_hWnd, TB_SETROWS, MAKELPARAM(nRows, bLarger), (LPARAM)lpRect);
5414 BOOL SetCmdID(int nIndex, UINT nID)
5416 ATLASSERT(::IsWindow(m_hWnd));
5417 return (BOOL)::SendMessage(m_hWnd, TB_SETCMDID, nIndex, nID);
5420 DWORD GetBitmapFlags() const
5422 ATLASSERT(::IsWindow(m_hWnd));
5423 return (DWORD)::SendMessage(m_hWnd, TB_GETBITMAPFLAGS, 0, 0L);
5426 int GetBitmap(int nID) const
5428 ATLASSERT(::IsWindow(m_hWnd));
5429 return (int)::SendMessage(m_hWnd, TB_GETBITMAP, nID, 0L);
5432 int GetButtonText(int nID, LPTSTR lpstrText) const
5434 ATLASSERT(::IsWindow(m_hWnd));
5435 return (int)::SendMessage(m_hWnd, TB_GETBUTTONTEXT, nID, (LPARAM)lpstrText);
5438 // nIndex - IE5 or higher only
5439 CImageList GetImageList(int nIndex = 0) const
5441 ATLASSERT(::IsWindow(m_hWnd));
5442 return CImageList((HIMAGELIST)::SendMessage(m_hWnd, TB_GETIMAGELIST, nIndex, 0L));
5445 // nIndex - IE5 or higher only
5446 CImageList SetImageList(HIMAGELIST hImageList, int nIndex = 0)
5448 ATLASSERT(::IsWindow(m_hWnd));
5449 return CImageList((HIMAGELIST)::SendMessage(m_hWnd, TB_SETIMAGELIST, nIndex, (LPARAM)hImageList));
5452 // nIndex - IE5 or higher only
5453 CImageList GetDisabledImageList(int nIndex = 0) const
5455 ATLASSERT(::IsWindow(m_hWnd));
5456 return CImageList((HIMAGELIST)::SendMessage(m_hWnd, TB_GETDISABLEDIMAGELIST, nIndex, 0L));
5459 // nIndex - IE5 or higher only
5460 CImageList SetDisabledImageList(HIMAGELIST hImageList, int nIndex = 0)
5462 ATLASSERT(::IsWindow(m_hWnd));
5463 return CImageList((HIMAGELIST)::SendMessage(m_hWnd, TB_SETDISABLEDIMAGELIST, nIndex, (LPARAM)hImageList));
5466 #ifndef _WIN32_WCE
5467 // nIndex - IE5 or higher only
5468 CImageList GetHotImageList(int nIndex = 0) const
5470 ATLASSERT(::IsWindow(m_hWnd));
5471 return CImageList((HIMAGELIST)::SendMessage(m_hWnd, TB_GETHOTIMAGELIST, nIndex, 0L));
5474 // nIndex - IE5 or higher only
5475 CImageList SetHotImageList(HIMAGELIST hImageList, int nIndex = 0)
5477 ATLASSERT(::IsWindow(m_hWnd));
5478 return CImageList((HIMAGELIST)::SendMessage(m_hWnd, TB_SETHOTIMAGELIST, nIndex, (LPARAM)hImageList));
5480 #endif // !_WIN32_WCE
5482 DWORD GetStyle() const
5484 ATLASSERT(::IsWindow(m_hWnd));
5485 return (DWORD)::SendMessage(m_hWnd, TB_GETSTYLE, 0, 0L);
5488 void SetStyle(DWORD dwStyle)
5490 ATLASSERT(::IsWindow(m_hWnd));
5491 ::SendMessage(m_hWnd, TB_SETSTYLE, 0, dwStyle);
5494 DWORD GetButtonSize() const
5496 ATLASSERT(::IsWindow(m_hWnd));
5497 return (DWORD)::SendMessage(m_hWnd, TB_GETBUTTONSIZE, 0, 0L);
5500 void GetButtonSize(SIZE& size) const
5502 ATLASSERT(::IsWindow(m_hWnd));
5503 DWORD dwRet = (DWORD)::SendMessage(m_hWnd, TB_GETBUTTONSIZE, 0, 0L);
5504 size.cx = LOWORD(dwRet);
5505 size.cy = HIWORD(dwRet);
5508 BOOL GetRect(int nID, LPRECT lpRect) const
5510 ATLASSERT(::IsWindow(m_hWnd));
5511 return (BOOL)::SendMessage(m_hWnd, TB_GETRECT, nID, (LPARAM)lpRect);
5514 int GetTextRows() const
5516 ATLASSERT(::IsWindow(m_hWnd));
5517 return (int)::SendMessage(m_hWnd, TB_GETTEXTROWS, 0, 0L);
5520 BOOL SetButtonWidth(int cxMin, int cxMax)
5522 ATLASSERT(::IsWindow(m_hWnd));
5523 return (BOOL)::SendMessage(m_hWnd, TB_SETBUTTONWIDTH, 0, MAKELPARAM(cxMin, cxMax));
5526 BOOL SetIndent(int nIndent)
5528 ATLASSERT(::IsWindow(m_hWnd));
5529 return (BOOL)::SendMessage(m_hWnd, TB_SETINDENT, nIndent, 0L);
5532 BOOL SetMaxTextRows(int nMaxTextRows)
5534 ATLASSERT(::IsWindow(m_hWnd));
5535 return (BOOL)::SendMessage(m_hWnd, TB_SETMAXTEXTROWS, nMaxTextRows, 0L);
5538 #if (_WIN32_IE >= 0x0400)
5539 #ifndef _WIN32_WCE
5540 BOOL GetAnchorHighlight() const
5542 ATLASSERT(::IsWindow(m_hWnd));
5543 return (BOOL)::SendMessage(m_hWnd, TB_GETANCHORHIGHLIGHT, 0, 0L);
5546 BOOL SetAnchorHighlight(BOOL bEnable = TRUE)
5548 ATLASSERT(::IsWindow(m_hWnd));
5549 return (BOOL)::SendMessage(m_hWnd, TB_SETANCHORHIGHLIGHT, bEnable, 0L);
5551 #endif // !_WIN32_WCE
5553 int GetButtonInfo(int nID, LPTBBUTTONINFO lptbbi) const
5555 ATLASSERT(::IsWindow(m_hWnd));
5556 return (int)::SendMessage(m_hWnd, TB_GETBUTTONINFO, nID, (LPARAM)lptbbi);
5559 BOOL SetButtonInfo(int nID, LPTBBUTTONINFO lptbbi)
5561 ATLASSERT(::IsWindow(m_hWnd));
5562 return (BOOL)::SendMessage(m_hWnd, TB_SETBUTTONINFO, nID, (LPARAM)lptbbi);
5565 BOOL SetButtonInfo(int nID, DWORD dwMask, BYTE Style, BYTE State, LPCTSTR lpszItem,
5566 int iImage, WORD cx, int iCommand, DWORD_PTR lParam)
5568 ATLASSERT(::IsWindow(m_hWnd));
5569 TBBUTTONINFO tbbi = { 0 };
5570 tbbi.cbSize = sizeof(TBBUTTONINFO);
5571 tbbi.dwMask = dwMask;
5572 tbbi.idCommand = iCommand;
5573 tbbi.iImage = iImage;
5574 tbbi.fsState = State;
5575 tbbi.fsStyle = Style;
5576 tbbi.cx = cx;
5577 tbbi.pszText = (LPTSTR) lpszItem;
5578 tbbi.lParam = lParam;
5579 return (BOOL)::SendMessage(m_hWnd, TB_SETBUTTONINFO, nID, (LPARAM)&tbbi);
5582 #ifndef _WIN32_WCE
5583 int GetHotItem() const
5585 ATLASSERT(::IsWindow(m_hWnd));
5586 return (int)::SendMessage(m_hWnd, TB_GETHOTITEM, 0, 0L);
5589 int SetHotItem(int nItem)
5591 ATLASSERT(::IsWindow(m_hWnd));
5592 return (int)::SendMessage(m_hWnd, TB_SETHOTITEM, nItem, 0L);
5594 #endif // !_WIN32_WCE
5596 BOOL IsButtonHighlighted(int nButtonID) const
5598 ATLASSERT(::IsWindow(m_hWnd));
5599 return (BOOL)::SendMessage(m_hWnd, TB_ISBUTTONHIGHLIGHTED, nButtonID, 0L);
5602 DWORD SetDrawTextFlags(DWORD dwMask, DWORD dwFlags)
5604 ATLASSERT(::IsWindow(m_hWnd));
5605 return (DWORD)::SendMessage(m_hWnd, TB_SETDRAWTEXTFLAGS, dwMask, dwFlags);
5608 #ifndef _WIN32_WCE
5609 BOOL GetColorScheme(LPCOLORSCHEME lpcs) const
5611 ATLASSERT(::IsWindow(m_hWnd));
5612 return (BOOL)::SendMessage(m_hWnd, TB_GETCOLORSCHEME, 0, (LPARAM)lpcs);
5615 void SetColorScheme(LPCOLORSCHEME lpcs)
5617 ATLASSERT(::IsWindow(m_hWnd));
5618 ::SendMessage(m_hWnd, TB_SETCOLORSCHEME, 0, (LPARAM)lpcs);
5621 DWORD GetExtendedStyle() const
5623 ATLASSERT(::IsWindow(m_hWnd));
5624 return (DWORD)::SendMessage(m_hWnd, TB_GETEXTENDEDSTYLE, 0, 0L);
5627 DWORD SetExtendedStyle(DWORD dwStyle)
5629 ATLASSERT(::IsWindow(m_hWnd));
5630 return (DWORD)::SendMessage(m_hWnd, TB_SETEXTENDEDSTYLE, 0, dwStyle);
5633 void GetInsertMark(LPTBINSERTMARK lptbim) const
5635 ATLASSERT(::IsWindow(m_hWnd));
5636 ::SendMessage(m_hWnd, TB_GETINSERTMARK, 0, (LPARAM)lptbim);
5639 void SetInsertMark(LPTBINSERTMARK lptbim)
5641 ATLASSERT(::IsWindow(m_hWnd));
5642 ::SendMessage(m_hWnd, TB_SETINSERTMARK, 0, (LPARAM)lptbim);
5645 COLORREF GetInsertMarkColor() const
5647 ATLASSERT(::IsWindow(m_hWnd));
5648 return (COLORREF)::SendMessage(m_hWnd, TB_GETINSERTMARKCOLOR, 0, 0L);
5651 COLORREF SetInsertMarkColor(COLORREF clr)
5653 ATLASSERT(::IsWindow(m_hWnd));
5654 return (COLORREF)::SendMessage(m_hWnd, TB_SETINSERTMARKCOLOR, 0, (LPARAM)clr);
5657 BOOL GetMaxSize(LPSIZE lpSize) const
5659 ATLASSERT(::IsWindow(m_hWnd));
5660 return (BOOL)::SendMessage(m_hWnd, TB_GETMAXSIZE, 0, (LPARAM)lpSize);
5663 void GetPadding(LPSIZE lpSizePadding) const
5665 ATLASSERT(::IsWindow(m_hWnd));
5666 ATLASSERT(lpSizePadding != NULL);
5667 DWORD dwRet = (DWORD)::SendMessage(m_hWnd, TB_GETPADDING, 0, 0L);
5668 lpSizePadding->cx = GET_X_LPARAM(dwRet);
5669 lpSizePadding->cy = GET_Y_LPARAM(dwRet);
5672 void SetPadding(int cx, int cy, LPSIZE lpSizePadding = NULL)
5674 ATLASSERT(::IsWindow(m_hWnd));
5675 DWORD dwRet = (DWORD)::SendMessage(m_hWnd, TB_SETPADDING, 0, MAKELPARAM(cx, cy));
5676 if(lpSizePadding != NULL)
5678 lpSizePadding->cx = GET_X_LPARAM(dwRet);
5679 lpSizePadding->cy = GET_Y_LPARAM(dwRet);
5683 BOOL GetUnicodeFormat() const
5685 ATLASSERT(::IsWindow(m_hWnd));
5686 return (BOOL)::SendMessage(m_hWnd, TB_GETUNICODEFORMAT, 0, 0L);
5689 BOOL SetUnicodeFormat(BOOL bUnicode = TRUE)
5691 ATLASSERT(::IsWindow(m_hWnd));
5692 return (BOOL)::SendMessage(m_hWnd, TB_SETUNICODEFORMAT, bUnicode, 0L);
5694 #endif // !_WIN32_WCE
5695 #endif // (_WIN32_IE >= 0x0400)
5697 #if (_WIN32_IE >= 0x0500) && !defined(_WIN32_WCE)
5698 int GetString(int nString, LPTSTR lpstrString, int cchMaxLen) const
5700 ATLASSERT(::IsWindow(m_hWnd));
5701 return (int)::SendMessage(m_hWnd, TB_GETSTRING, MAKEWPARAM(cchMaxLen, nString), (LPARAM)lpstrString);
5704 int GetStringBSTR(int nString, BSTR& bstrString) const
5706 USES_CONVERSION;
5707 ATLASSERT(::IsWindow(m_hWnd));
5708 ATLASSERT(bstrString == NULL);
5709 int nLength = (int)(short)LOWORD(::SendMessage(m_hWnd, TB_GETSTRING, MAKEWPARAM(0, nString), NULL));
5710 if(nLength != -1)
5712 CTempBuffer<TCHAR, _WTL_STACK_ALLOC_THRESHOLD> buff;
5713 LPTSTR lpstrText = buff.Allocate(nLength + 1);
5714 if(lpstrText != NULL)
5716 nLength = (int)::SendMessage(m_hWnd, TB_GETSTRING, MAKEWPARAM(nLength + 1, nString), (LPARAM)lpstrText);
5717 if(nLength != -1)
5718 bstrString = ::SysAllocString(T2OLE(lpstrText));
5720 else
5722 nLength = -1;
5726 return nLength;
5729 #if defined(_WTL_USE_CSTRING) || defined(__ATLSTR_H__)
5730 int GetString(int nString, _CSTRING_NS::CString& str) const
5732 ATLASSERT(::IsWindow(m_hWnd));
5733 int nLength = (int)(short)LOWORD(::SendMessage(m_hWnd, TB_GETSTRING, MAKEWPARAM(0, nString), NULL));
5734 if(nLength != -1)
5736 LPTSTR lpstr = str.GetBufferSetLength(nLength + 1);
5737 if(lpstr != NULL)
5738 nLength = (int)::SendMessage(m_hWnd, TB_GETSTRING, MAKEWPARAM(nLength + 1, nString), (LPARAM)lpstr);
5739 else
5740 nLength = -1;
5741 str.ReleaseBuffer();
5743 return nLength;
5745 #endif // defined(_WTL_USE_CSTRING) || defined(__ATLSTR_H__)
5746 #endif // (_WIN32_IE >= 0x0500) && !defined(_WIN32_WCE)
5748 #if (_WIN32_WINNT >= 0x0501)
5749 void GetMetrics(LPTBMETRICS lptbm) const
5751 ATLASSERT(::IsWindow(m_hWnd));
5752 ::SendMessage(m_hWnd, TB_GETMETRICS, 0, (LPARAM)lptbm);
5755 void SetMetrics(LPTBMETRICS lptbm)
5757 ATLASSERT(::IsWindow(m_hWnd));
5758 ::SendMessage(m_hWnd, TB_SETMETRICS, 0, (LPARAM)lptbm);
5761 void SetWindowTheme(LPCWSTR lpstrTheme)
5763 ATLASSERT(::IsWindow(m_hWnd));
5764 ::SendMessage(m_hWnd, TB_SETWINDOWTHEME, 0, (LPARAM)lpstrTheme);
5766 #endif // (_WIN32_WINNT >= 0x0501)
5768 #if (_WIN32_WINNT >= 0x0600)
5769 CImageList GetPressedImageList(int nIndex = 0) const
5771 ATLASSERT(::IsWindow(m_hWnd));
5772 return CImageList((HIMAGELIST)::SendMessage(m_hWnd, TB_GETPRESSEDIMAGELIST, nIndex, 0L));
5775 CImageList SetPressedImageList(HIMAGELIST hImageList, int nIndex = 0)
5777 ATLASSERT(::IsWindow(m_hWnd));
5778 return CImageList((HIMAGELIST)::SendMessage(m_hWnd, TB_SETPRESSEDIMAGELIST, nIndex, (LPARAM)hImageList));
5780 #endif // (_WIN32_WINNT >= 0x0600)
5782 // Operations
5783 BOOL EnableButton(int nID, BOOL bEnable = TRUE)
5785 ATLASSERT(::IsWindow(m_hWnd));
5786 return (BOOL)::SendMessage(m_hWnd, TB_ENABLEBUTTON, nID, MAKELPARAM(bEnable, 0));
5789 BOOL CheckButton(int nID, BOOL bCheck = TRUE)
5791 ATLASSERT(::IsWindow(m_hWnd));
5792 return (BOOL)::SendMessage(m_hWnd, TB_CHECKBUTTON, nID, MAKELPARAM(bCheck, 0));
5795 BOOL PressButton(int nID, BOOL bPress = TRUE)
5797 ATLASSERT(::IsWindow(m_hWnd));
5798 return (BOOL)::SendMessage(m_hWnd, TB_PRESSBUTTON, nID, MAKELPARAM(bPress, 0));
5801 BOOL HideButton(int nID, BOOL bHide = TRUE)
5803 ATLASSERT(::IsWindow(m_hWnd));
5804 return (BOOL)::SendMessage(m_hWnd, TB_HIDEBUTTON, nID, MAKELPARAM(bHide, 0));
5807 BOOL Indeterminate(int nID, BOOL bIndeterminate = TRUE)
5809 ATLASSERT(::IsWindow(m_hWnd));
5810 return (BOOL)::SendMessage(m_hWnd, TB_INDETERMINATE, nID, MAKELPARAM(bIndeterminate, 0));
5813 int AddBitmap(int nNumButtons, UINT nBitmapID)
5815 ATLASSERT(::IsWindow(m_hWnd));
5816 TBADDBITMAP tbab = { 0 };
5817 tbab.hInst = ModuleHelper::GetResourceInstance();
5818 ATLASSERT(tbab.hInst != NULL);
5819 tbab.nID = nBitmapID;
5820 return (int)::SendMessage(m_hWnd, TB_ADDBITMAP, (WPARAM)nNumButtons, (LPARAM)&tbab);
5823 int AddBitmap(int nNumButtons, HBITMAP hBitmap)
5825 ATLASSERT(::IsWindow(m_hWnd));
5826 TBADDBITMAP tbab = { 0 };
5827 tbab.hInst = NULL;
5828 tbab.nID = (UINT_PTR)hBitmap;
5829 return (int)::SendMessage(m_hWnd, TB_ADDBITMAP, (WPARAM)nNumButtons, (LPARAM)&tbab);
5832 BOOL AddButtons(int nNumButtons, LPTBBUTTON lpButtons)
5834 ATLASSERT(::IsWindow(m_hWnd));
5835 return (BOOL)::SendMessage(m_hWnd, TB_ADDBUTTONS, nNumButtons, (LPARAM)lpButtons);
5838 BOOL InsertButton(int nIndex, LPTBBUTTON lpButton)
5840 ATLASSERT(::IsWindow(m_hWnd));
5841 return (BOOL)::SendMessage(m_hWnd, TB_INSERTBUTTON, nIndex, (LPARAM)lpButton);
5844 BOOL InsertButton(int nIndex, int iCommand, BYTE Style, BYTE State, int iBitmap,
5845 INT_PTR iString, DWORD_PTR lParam)
5847 ATLASSERT(::IsWindow(m_hWnd));
5848 TBBUTTON tbb = { 0 };
5849 tbb.fsStyle = Style;
5850 tbb.fsState = State;
5851 tbb.idCommand = iCommand;
5852 tbb.iBitmap = iBitmap;
5853 tbb.iString = iString;
5854 tbb.dwData = lParam;
5855 return (BOOL)::SendMessage(m_hWnd, TB_INSERTBUTTON, nIndex, (LPARAM)&tbb);
5858 BOOL InsertButton(int nIndex, int iCommand, BYTE Style, BYTE State, int iBitmap,
5859 LPCTSTR lpszItem, DWORD_PTR lParam)
5861 return InsertButton(nIndex, iCommand, Style, State, iBitmap, (INT_PTR)lpszItem, lParam);
5864 BOOL AddButton(LPTBBUTTON lpButton)
5866 return InsertButton(-1, lpButton);
5869 BOOL AddButton(int iCommand, BYTE Style, BYTE State, int iBitmap, INT_PTR iString, DWORD_PTR lParam)
5871 return InsertButton(-1, iCommand, Style, State, iBitmap, iString, lParam);
5874 BOOL AddButton(int iCommand, BYTE Style, BYTE State, int iBitmap, LPCTSTR lpszItem, DWORD_PTR lParam)
5876 return InsertButton(-1, iCommand, Style, State, iBitmap, lpszItem, lParam);
5879 BOOL DeleteButton(int nIndex)
5881 ATLASSERT(::IsWindow(m_hWnd));
5882 return (BOOL)::SendMessage(m_hWnd, TB_DELETEBUTTON, nIndex, 0L);
5885 UINT CommandToIndex(UINT nID) const
5887 ATLASSERT(::IsWindow(m_hWnd));
5888 return (UINT)::SendMessage(m_hWnd, TB_COMMANDTOINDEX, nID, 0L);
5891 #ifndef _WIN32_WCE
5892 void SaveState(HKEY hKeyRoot, LPCTSTR lpszSubKey, LPCTSTR lpszValueName)
5894 ATLASSERT(::IsWindow(m_hWnd));
5895 TBSAVEPARAMS tbs = { 0 };
5896 tbs.hkr = hKeyRoot;
5897 tbs.pszSubKey = lpszSubKey;
5898 tbs.pszValueName = lpszValueName;
5899 ::SendMessage(m_hWnd, TB_SAVERESTORE, (WPARAM)TRUE, (LPARAM)&tbs);
5902 void RestoreState(HKEY hKeyRoot, LPCTSTR lpszSubKey, LPCTSTR lpszValueName)
5904 ATLASSERT(::IsWindow(m_hWnd));
5905 TBSAVEPARAMS tbs = { 0 };
5906 tbs.hkr = hKeyRoot;
5907 tbs.pszSubKey = lpszSubKey;
5908 tbs.pszValueName = lpszValueName;
5909 ::SendMessage(m_hWnd, TB_SAVERESTORE, (WPARAM)FALSE, (LPARAM)&tbs);
5912 void Customize()
5914 ATLASSERT(::IsWindow(m_hWnd));
5915 ::SendMessage(m_hWnd, TB_CUSTOMIZE, 0, 0L);
5917 #endif // !_WIN32_WCE
5919 int AddString(UINT nStringID)
5921 ATLASSERT(::IsWindow(m_hWnd));
5922 return (int)::SendMessage(m_hWnd, TB_ADDSTRING, (WPARAM)ModuleHelper::GetResourceInstance(), (LPARAM)nStringID);
5925 int AddStrings(LPCTSTR lpszStrings)
5927 ATLASSERT(::IsWindow(m_hWnd));
5928 return (int)::SendMessage(m_hWnd, TB_ADDSTRING, 0, (LPARAM)lpszStrings);
5931 void AutoSize()
5933 ATLASSERT(::IsWindow(m_hWnd));
5934 ::SendMessage(m_hWnd, TB_AUTOSIZE, 0, 0L);
5937 BOOL ChangeBitmap(int nID, int nBitmap)
5939 ATLASSERT(::IsWindow(m_hWnd));
5940 return (BOOL)::SendMessage(m_hWnd, TB_CHANGEBITMAP, nID, MAKELPARAM(nBitmap, 0));
5943 int LoadImages(int nBitmapID)
5945 ATLASSERT(::IsWindow(m_hWnd));
5946 return (int)::SendMessage(m_hWnd, TB_LOADIMAGES, nBitmapID, (LPARAM)ModuleHelper::GetResourceInstance());
5949 int LoadStdImages(int nBitmapID)
5951 ATLASSERT(::IsWindow(m_hWnd));
5952 return (int)::SendMessage(m_hWnd, TB_LOADIMAGES, nBitmapID, (LPARAM)HINST_COMMCTRL);
5955 BOOL ReplaceBitmap(LPTBREPLACEBITMAP ptbrb)
5957 ATLASSERT(::IsWindow(m_hWnd));
5958 return (BOOL)::SendMessage(m_hWnd, TB_REPLACEBITMAP, 0, (LPARAM)ptbrb);
5961 #if (_WIN32_IE >= 0x0400)
5962 int HitTest(LPPOINT lpPoint) const
5964 ATLASSERT(::IsWindow(m_hWnd));
5965 return (int)::SendMessage(m_hWnd, TB_HITTEST, 0, (LPARAM)lpPoint);
5968 #ifndef _WIN32_WCE
5969 BOOL InsertMarkHitTest(LPPOINT lpPoint, LPTBINSERTMARK lptbim) const
5971 ATLASSERT(::IsWindow(m_hWnd));
5972 return (BOOL)::SendMessage(m_hWnd, TB_INSERTMARKHITTEST, (WPARAM)lpPoint, (LPARAM)lptbim);
5975 BOOL InsertMarkHitTest(int x, int y, LPTBINSERTMARK lptbim) const
5977 ATLASSERT(::IsWindow(m_hWnd));
5978 POINT pt = { x, y };
5979 return (BOOL)::SendMessage(m_hWnd, TB_INSERTMARKHITTEST, (WPARAM)&pt, (LPARAM)lptbim);
5982 BOOL MapAccelerator(TCHAR chAccel, int& nID) const
5984 ATLASSERT(::IsWindow(m_hWnd));
5985 return (BOOL)::SendMessage(m_hWnd, TB_MAPACCELERATOR, (WPARAM)chAccel, (LPARAM)&nID);
5988 BOOL MarkButton(int nID, BOOL bHighlight = TRUE)
5990 ATLASSERT(::IsWindow(m_hWnd));
5991 return (BOOL)::SendMessage(m_hWnd, TB_MARKBUTTON, nID, MAKELPARAM(bHighlight, 0));
5994 BOOL MoveButton(int nOldPos, int nNewPos)
5996 ATLASSERT(::IsWindow(m_hWnd));
5997 return (BOOL)::SendMessage(m_hWnd, TB_MOVEBUTTON, nOldPos, nNewPos);
6000 HRESULT GetObject(REFIID iid, LPVOID* ppvObject)
6002 ATLASSERT(::IsWindow(m_hWnd));
6003 return (HRESULT)::SendMessage(m_hWnd, TB_GETOBJECT, (WPARAM)&iid, (LPARAM)ppvObject);
6005 #endif // !_WIN32_WCE
6006 #endif // (_WIN32_IE >= 0x0400)
6009 typedef CToolBarCtrlT<ATL::CWindow> CToolBarCtrl;
6012 ///////////////////////////////////////////////////////////////////////////////
6013 // CStatusBarCtrl
6015 template <class TBase>
6016 class CStatusBarCtrlT : public TBase
6018 public:
6019 // Constructors
6020 CStatusBarCtrlT(HWND hWnd = NULL) : TBase(hWnd)
6023 CStatusBarCtrlT< TBase >& operator =(HWND hWnd)
6025 m_hWnd = hWnd;
6026 return *this;
6029 HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
6030 DWORD dwStyle = 0, DWORD dwExStyle = 0,
6031 ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
6033 return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
6036 // Methods
6037 static LPCTSTR GetWndClassName()
6039 return STATUSCLASSNAME;
6042 int GetParts(int nParts, int* pParts) const
6044 ATLASSERT(::IsWindow(m_hWnd));
6045 return (int)::SendMessage(m_hWnd, SB_GETPARTS, nParts, (LPARAM)pParts);
6048 BOOL SetParts(int nParts, int* pWidths)
6050 ATLASSERT(::IsWindow(m_hWnd));
6051 return (BOOL)::SendMessage(m_hWnd, SB_SETPARTS, nParts, (LPARAM)pWidths);
6054 int GetTextLength(int nPane, int* pType = NULL) const
6056 ATLASSERT(::IsWindow(m_hWnd));
6057 ATLASSERT(nPane < 256);
6058 DWORD dwRet = (DWORD)::SendMessage(m_hWnd, SB_GETTEXTLENGTH, (WPARAM)nPane, 0L);
6059 if (pType != NULL)
6060 *pType = (int)(short)HIWORD(dwRet);
6061 return (int)(short)LOWORD(dwRet);
6064 int GetText(int nPane, LPTSTR lpszText, int* pType = NULL) const
6066 ATLASSERT(::IsWindow(m_hWnd));
6067 ATLASSERT(nPane < 256);
6068 DWORD dwRet = (DWORD)::SendMessage(m_hWnd, SB_GETTEXT, (WPARAM)nPane, (LPARAM)lpszText);
6069 if(pType != NULL)
6070 *pType = (int)(short)HIWORD(dwRet);
6071 return (int)(short)LOWORD(dwRet);
6074 #ifndef _ATL_NO_COM
6075 BOOL GetTextBSTR(int nPane, BSTR& bstrText, int* pType = NULL) const
6077 USES_CONVERSION;
6078 ATLASSERT(::IsWindow(m_hWnd));
6079 ATLASSERT(nPane < 256);
6080 ATLASSERT(bstrText == NULL);
6081 int nLength = (int)(short)LOWORD(::SendMessage(m_hWnd, SB_GETTEXTLENGTH, (WPARAM)nPane, 0L));
6082 if(nLength == 0)
6083 return FALSE;
6085 CTempBuffer<TCHAR, _WTL_STACK_ALLOC_THRESHOLD> buff;
6086 LPTSTR lpstrText = buff.Allocate(nLength + 1);
6087 if(lpstrText == NULL)
6088 return FALSE;
6090 if(!GetText(nPane, lpstrText, pType))
6091 return FALSE;
6093 bstrText = ::SysAllocString(T2OLE(lpstrText));
6094 return (bstrText != NULL) ? TRUE : FALSE;
6096 #endif // !_ATL_NO_COM
6098 #if defined(_WTL_USE_CSTRING) || defined(__ATLSTR_H__)
6099 int GetText(int nPane, _CSTRING_NS::CString& strText, int* pType = NULL) const
6101 ATLASSERT(::IsWindow(m_hWnd));
6102 ATLASSERT(nPane < 256);
6103 int nLength = (int)(short)LOWORD(::SendMessage(m_hWnd, SB_GETTEXTLENGTH, (WPARAM)nPane, 0L));
6104 if(nLength == 0)
6105 return 0;
6107 LPTSTR lpstr = strText.GetBufferSetLength(nLength);
6108 if(lpstr == NULL)
6109 return 0;
6110 return GetText(nPane, lpstr, pType);
6112 #endif // defined(_WTL_USE_CSTRING) || defined(__ATLSTR_H__)
6114 BOOL SetText(int nPane, LPCTSTR lpszText, int nType = 0)
6116 ATLASSERT(::IsWindow(m_hWnd));
6117 ATLASSERT(nPane < 256);
6118 return (BOOL)::SendMessage(m_hWnd, SB_SETTEXT, (nPane | nType), (LPARAM)lpszText);
6121 BOOL GetRect(int nPane, LPRECT lpRect) const
6123 ATLASSERT(::IsWindow(m_hWnd));
6124 ATLASSERT(nPane < 256);
6125 return (BOOL)::SendMessage(m_hWnd, SB_GETRECT, nPane, (LPARAM)lpRect);
6128 BOOL GetBorders(int* pBorders) const
6130 ATLASSERT(::IsWindow(m_hWnd));
6131 return (BOOL)::SendMessage(m_hWnd, SB_GETBORDERS, 0, (LPARAM)pBorders);
6134 BOOL GetBorders(int& nHorz, int& nVert, int& nSpacing) const
6136 ATLASSERT(::IsWindow(m_hWnd));
6137 int borders[3] = { 0, 0, 0 };
6138 BOOL bResult = (BOOL)::SendMessage(m_hWnd, SB_GETBORDERS, 0, (LPARAM)&borders);
6139 if(bResult)
6141 nHorz = borders[0];
6142 nVert = borders[1];
6143 nSpacing = borders[2];
6145 return bResult;
6148 void SetMinHeight(int nMin)
6150 ATLASSERT(::IsWindow(m_hWnd));
6151 ::SendMessage(m_hWnd, SB_SETMINHEIGHT, nMin, 0L);
6154 BOOL SetSimple(BOOL bSimple = TRUE)
6156 ATLASSERT(::IsWindow(m_hWnd));
6157 return (BOOL)::SendMessage(m_hWnd, SB_SIMPLE, bSimple, 0L);
6160 BOOL IsSimple() const
6162 ATLASSERT(::IsWindow(m_hWnd));
6163 return (BOOL)::SendMessage(m_hWnd, SB_ISSIMPLE, 0, 0L);
6166 #if (_WIN32_IE >= 0x0400) && !defined(_WIN32_WCE)
6167 BOOL GetUnicodeFormat() const
6169 ATLASSERT(::IsWindow(m_hWnd));
6170 return (BOOL)::SendMessage(m_hWnd, SB_GETUNICODEFORMAT, 0, 0L);
6173 BOOL SetUnicodeFormat(BOOL bUnicode = TRUE)
6175 ATLASSERT(::IsWindow(m_hWnd));
6176 return (BOOL)::SendMessage(m_hWnd, SB_SETUNICODEFORMAT, bUnicode, 0L);
6179 void GetTipText(int nPane, LPTSTR lpstrText, int nSize) const
6181 ATLASSERT(::IsWindow(m_hWnd));
6182 ATLASSERT(nPane < 256);
6183 ::SendMessage(m_hWnd, SB_GETTIPTEXT, MAKEWPARAM(nPane, nSize), (LPARAM)lpstrText);
6186 void SetTipText(int nPane, LPCTSTR lpstrText)
6188 ATLASSERT(::IsWindow(m_hWnd));
6189 ATLASSERT(nPane < 256);
6190 ::SendMessage(m_hWnd, SB_SETTIPTEXT, nPane, (LPARAM)lpstrText);
6192 #endif // (_WIN32_IE >= 0x0400) && !defined(_WIN32_WCE)
6194 #if ((_WIN32_IE >= 0x0400) && !defined(_WIN32_WCE)) || (defined(_WIN32_WCE) && (_WIN32_WCE >= 0x0500))
6195 COLORREF SetBkColor(COLORREF clrBk)
6197 ATLASSERT(::IsWindow(m_hWnd));
6198 return (COLORREF)::SendMessage(m_hWnd, SB_SETBKCOLOR, 0, (LPARAM)clrBk);
6201 HICON GetIcon(int nPane) const
6203 ATLASSERT(::IsWindow(m_hWnd));
6204 ATLASSERT(nPane < 256);
6205 return (HICON)::SendMessage(m_hWnd, SB_GETICON, nPane, 0L);
6208 BOOL SetIcon(int nPane, HICON hIcon)
6210 ATLASSERT(::IsWindow(m_hWnd));
6211 ATLASSERT(nPane < 256);
6212 return (BOOL)::SendMessage(m_hWnd, SB_SETICON, nPane, (LPARAM)hIcon);
6214 #endif // ((_WIN32_IE >= 0x0400) && !defined(_WIN32_WCE)) || (defined(_WIN32_WCE) && (_WIN32_WCE >= 0x0500))
6217 typedef CStatusBarCtrlT<ATL::CWindow> CStatusBarCtrl;
6220 ///////////////////////////////////////////////////////////////////////////////
6221 // CTabCtrl
6223 template <class TBase>
6224 class CTabCtrlT : public TBase
6226 public:
6227 // Constructors
6228 CTabCtrlT(HWND hWnd = NULL) : TBase(hWnd)
6231 CTabCtrlT< TBase >& operator =(HWND hWnd)
6233 m_hWnd = hWnd;
6234 return *this;
6237 HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
6238 DWORD dwStyle = 0, DWORD dwExStyle = 0,
6239 ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
6241 return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
6244 // Attributes
6245 static LPCTSTR GetWndClassName()
6247 return WC_TABCONTROL;
6250 CImageList GetImageList() const
6252 ATLASSERT(::IsWindow(m_hWnd));
6253 return CImageList((HIMAGELIST)::SendMessage(m_hWnd, TCM_GETIMAGELIST, 0, 0L));
6256 CImageList SetImageList(HIMAGELIST hImageList)
6258 ATLASSERT(::IsWindow(m_hWnd));
6259 return CImageList((HIMAGELIST)::SendMessage(m_hWnd, TCM_SETIMAGELIST, 0, (LPARAM)hImageList));
6262 int GetItemCount() const
6264 ATLASSERT(::IsWindow(m_hWnd));
6265 return (int)::SendMessage(m_hWnd, TCM_GETITEMCOUNT, 0, 0L);
6268 BOOL GetItem(int nItem, LPTCITEM pTabCtrlItem) const
6270 ATLASSERT(::IsWindow(m_hWnd));
6271 return (BOOL)::SendMessage(m_hWnd, TCM_GETITEM, nItem, (LPARAM)pTabCtrlItem);
6274 BOOL SetItem(int nItem, LPTCITEM pTabCtrlItem)
6276 ATLASSERT(::IsWindow(m_hWnd));
6277 return (BOOL)::SendMessage(m_hWnd, TCM_SETITEM, nItem, (LPARAM)pTabCtrlItem);
6280 int SetItem(int nItem, UINT mask, LPCTSTR lpszItem, DWORD dwState, DWORD dwStateMask, int iImage, LPARAM lParam)
6282 ATLASSERT(::IsWindow(m_hWnd));
6283 TCITEM tci = { 0 };
6284 tci.mask = mask;
6285 tci.pszText = (LPTSTR) lpszItem;
6286 tci.dwState = dwState;
6287 tci.dwStateMask = dwStateMask;
6288 tci.iImage = iImage;
6289 tci.lParam = lParam;
6290 return (int)::SendMessage(m_hWnd, TCM_SETITEM, nItem, (LPARAM)&tci);
6293 BOOL GetItemRect(int nItem, LPRECT lpRect) const
6295 ATLASSERT(::IsWindow(m_hWnd));
6296 return (BOOL)::SendMessage(m_hWnd, TCM_GETITEMRECT, nItem, (LPARAM)lpRect);
6299 int GetCurSel() const
6301 ATLASSERT(::IsWindow(m_hWnd));
6302 return (int)::SendMessage(m_hWnd, TCM_GETCURSEL, 0, 0L);
6305 int SetCurSel(int nItem)
6307 ATLASSERT(::IsWindow(m_hWnd));
6308 return (int)::SendMessage(m_hWnd, TCM_SETCURSEL, nItem, 0L);
6311 SIZE SetItemSize(SIZE size)
6313 ATLASSERT(::IsWindow(m_hWnd));
6314 DWORD dwSize = (DWORD)::SendMessage(m_hWnd, TCM_SETITEMSIZE, 0, MAKELPARAM(size.cx, size.cy));
6315 SIZE sizeRet = { GET_X_LPARAM(dwSize), GET_Y_LPARAM(dwSize) };
6316 return sizeRet;
6319 void SetItemSize(int cx, int cy)
6321 ATLASSERT(::IsWindow(m_hWnd));
6322 ::SendMessage(m_hWnd, TCM_SETITEMSIZE, 0, MAKELPARAM(cx, cy));
6325 void SetPadding(SIZE size)
6327 ATLASSERT(::IsWindow(m_hWnd));
6328 ::SendMessage(m_hWnd, TCM_SETPADDING, 0, MAKELPARAM(size.cx, size.cy));
6331 int GetRowCount() const
6333 ATLASSERT(::IsWindow(m_hWnd));
6334 return (int)::SendMessage(m_hWnd, TCM_GETROWCOUNT, 0, 0L);
6337 #ifndef _WIN32_WCE
6338 CToolTipCtrl GetTooltips() const
6340 ATLASSERT(::IsWindow(m_hWnd));
6341 return CToolTipCtrl((HWND)::SendMessage(m_hWnd, TCM_GETTOOLTIPS, 0, 0L));
6344 void SetTooltips(HWND hWndToolTip)
6346 ATLASSERT(::IsWindow(m_hWnd));
6347 ::SendMessage(m_hWnd, TCM_SETTOOLTIPS, (WPARAM)hWndToolTip, 0L);
6349 #endif // !_WIN32_WCE
6351 int GetCurFocus() const
6353 ATLASSERT(::IsWindow(m_hWnd));
6354 return (int)::SendMessage(m_hWnd, TCM_GETCURFOCUS, 0, 0L);
6357 void SetCurFocus(int nItem)
6359 ATLASSERT(::IsWindow(m_hWnd));
6360 ::SendMessage(m_hWnd, TCM_SETCURFOCUS, nItem, 0L);
6363 BOOL SetItemExtra(int cbExtra)
6365 ATLASSERT(::IsWindow(m_hWnd));
6366 ATLASSERT(GetItemCount() == 0); // must be empty
6367 return (BOOL)::SendMessage(m_hWnd, TCM_SETITEMEXTRA, cbExtra, 0L);
6370 int SetMinTabWidth(int nWidth = -1)
6372 ATLASSERT(::IsWindow(m_hWnd));
6373 return (int)::SendMessage(m_hWnd, TCM_SETMINTABWIDTH, 0, nWidth);
6376 #if (_WIN32_IE >= 0x0400)
6377 DWORD GetExtendedStyle() const
6379 ATLASSERT(::IsWindow(m_hWnd));
6380 return (DWORD)::SendMessage(m_hWnd, TCM_GETEXTENDEDSTYLE, 0, 0L);
6383 DWORD SetExtendedStyle(DWORD dwExMask, DWORD dwExStyle)
6385 ATLASSERT(::IsWindow(m_hWnd));
6386 return (DWORD)::SendMessage(m_hWnd, TCM_SETEXTENDEDSTYLE, dwExMask, dwExStyle);
6389 #ifndef _WIN32_WCE
6390 BOOL GetUnicodeFormat() const
6392 ATLASSERT(::IsWindow(m_hWnd));
6393 return (BOOL)::SendMessage(m_hWnd, TCM_GETUNICODEFORMAT, 0, 0L);
6396 BOOL SetUnicodeFormat(BOOL bUnicode = TRUE)
6398 ATLASSERT(::IsWindow(m_hWnd));
6399 return (BOOL)::SendMessage(m_hWnd, TCM_SETUNICODEFORMAT, bUnicode, 0L);
6401 #endif // !_WIN32_WCE
6402 #endif // (_WIN32_IE >= 0x0400)
6404 // Operations
6405 int InsertItem(int nItem, LPTCITEM pTabCtrlItem)
6407 ATLASSERT(::IsWindow(m_hWnd));
6408 return (int)::SendMessage(m_hWnd, TCM_INSERTITEM, nItem, (LPARAM)pTabCtrlItem);
6411 int InsertItem(int nItem, UINT mask, LPCTSTR lpszItem, int iImage, LPARAM lParam)
6413 ATLASSERT(::IsWindow(m_hWnd));
6414 TCITEM tci = { 0 };
6415 tci.mask = mask;
6416 tci.pszText = (LPTSTR) lpszItem;
6417 tci.iImage = iImage;
6418 tci.lParam = lParam;
6419 return (int)::SendMessage(m_hWnd, TCM_INSERTITEM, nItem, (LPARAM)&tci);
6422 int InsertItem(int nItem, LPCTSTR lpszItem)
6424 ATLASSERT(::IsWindow(m_hWnd));
6425 TCITEM tci = { 0 };
6426 tci.mask = TCIF_TEXT;
6427 tci.pszText = (LPTSTR) lpszItem;
6428 return (int)::SendMessage(m_hWnd, TCM_INSERTITEM, nItem, (LPARAM)&tci);
6431 int AddItem(LPTCITEM pTabCtrlItem)
6433 return InsertItem(GetItemCount(), pTabCtrlItem);
6436 int AddItem(UINT mask, LPCTSTR lpszItem, int iImage, LPARAM lParam)
6438 return InsertItem(GetItemCount(), mask, lpszItem, iImage, lParam);
6441 int AddItem(LPCTSTR lpszItem)
6443 return InsertItem(GetItemCount(), lpszItem);
6446 BOOL DeleteItem(int nItem)
6448 ATLASSERT(::IsWindow(m_hWnd));
6449 return (BOOL)::SendMessage(m_hWnd, TCM_DELETEITEM, nItem, 0L);
6452 BOOL DeleteAllItems()
6454 ATLASSERT(::IsWindow(m_hWnd));
6455 return (BOOL)::SendMessage(m_hWnd, TCM_DELETEALLITEMS, 0, 0L);
6458 void AdjustRect(BOOL bLarger, LPRECT lpRect)
6460 ATLASSERT(::IsWindow(m_hWnd));
6461 ::SendMessage(m_hWnd, TCM_ADJUSTRECT, bLarger, (LPARAM)lpRect);
6464 void RemoveImage(int nImage)
6466 ATLASSERT(::IsWindow(m_hWnd));
6467 ::SendMessage(m_hWnd, TCM_REMOVEIMAGE, nImage, 0L);
6470 int HitTest(TC_HITTESTINFO* pHitTestInfo) const
6472 ATLASSERT(::IsWindow(m_hWnd));
6473 return (int)::SendMessage(m_hWnd, TCM_HITTEST, 0, (LPARAM)pHitTestInfo);
6476 void DeselectAll(BOOL bExcludeFocus = TRUE)
6478 ATLASSERT(::IsWindow(m_hWnd));
6479 ::SendMessage(m_hWnd, TCM_DESELECTALL, bExcludeFocus, 0L);
6482 #if (_WIN32_IE >= 0x0400)
6483 BOOL HighlightItem(int nIndex, BOOL bHighlight = TRUE)
6485 ATLASSERT(::IsWindow(m_hWnd));
6486 return (BOOL)::SendMessage(m_hWnd, TCM_HIGHLIGHTITEM, nIndex, MAKELPARAM(bHighlight, 0));
6488 #endif // (_WIN32_IE >= 0x0400)
6491 typedef CTabCtrlT<ATL::CWindow> CTabCtrl;
6494 ///////////////////////////////////////////////////////////////////////////////
6495 // CTrackBarCtrl
6497 template <class TBase>
6498 class CTrackBarCtrlT : public TBase
6500 public:
6501 // Constructors
6502 CTrackBarCtrlT(HWND hWnd = NULL) : TBase(hWnd)
6505 CTrackBarCtrlT< TBase >& operator =(HWND hWnd)
6507 m_hWnd = hWnd;
6508 return *this;
6511 HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
6512 DWORD dwStyle = 0, DWORD dwExStyle = 0,
6513 ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
6515 return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
6518 // Attributes
6519 static LPCTSTR GetWndClassName()
6521 return TRACKBAR_CLASS;
6524 int GetLineSize() const
6526 ATLASSERT(::IsWindow(m_hWnd));
6527 return (int)::SendMessage(m_hWnd, TBM_GETLINESIZE, 0, 0L);
6530 int SetLineSize(int nSize)
6532 ATLASSERT(::IsWindow(m_hWnd));
6533 return (int)::SendMessage(m_hWnd, TBM_SETLINESIZE, 0, nSize);
6536 int GetPageSize() const
6538 ATLASSERT(::IsWindow(m_hWnd));
6539 return (int)::SendMessage(m_hWnd, TBM_GETPAGESIZE, 0, 0L);
6542 int SetPageSize(int nSize)
6544 ATLASSERT(::IsWindow(m_hWnd));
6545 return (int)::SendMessage(m_hWnd, TBM_SETPAGESIZE, 0, nSize);
6548 int GetRangeMin() const
6550 ATLASSERT(::IsWindow(m_hWnd));
6551 return (int)::SendMessage(m_hWnd, TBM_GETRANGEMIN, 0, 0L);
6554 void SetRangeMin(int nMin, BOOL bRedraw = FALSE)
6556 ATLASSERT(::IsWindow(m_hWnd));
6557 ::SendMessage(m_hWnd, TBM_SETRANGEMIN, bRedraw, nMin);
6560 int GetRangeMax() const
6562 ATLASSERT(::IsWindow(m_hWnd));
6563 return (int)::SendMessage(m_hWnd, TBM_GETRANGEMAX, 0, 0L);
6566 void SetRangeMax(int nMax, BOOL bRedraw = FALSE)
6568 ATLASSERT(::IsWindow(m_hWnd));
6569 ::SendMessage(m_hWnd, TBM_SETRANGEMAX, bRedraw, nMax);
6572 void GetRange(int& nMin, int& nMax) const
6574 nMin = GetRangeMin();
6575 nMax = GetRangeMax();
6578 void SetRange(int nMin, int nMax, BOOL bRedraw = TRUE)
6580 ATLASSERT(::IsWindow(m_hWnd));
6581 ::SendMessage(m_hWnd, TBM_SETRANGE, bRedraw, MAKELPARAM(nMin, nMax));
6584 int GetSelStart() const
6586 ATLASSERT(::IsWindow(m_hWnd));
6587 return (int)::SendMessage(m_hWnd, TBM_GETSELSTART, 0, 0L);
6590 void SetSelStart(int nMin)
6592 ATLASSERT(::IsWindow(m_hWnd));
6593 ::SendMessage(m_hWnd, TBM_SETSELSTART, 0, (LPARAM)nMin);
6596 int GetSelEnd() const
6598 ATLASSERT(::IsWindow(m_hWnd));
6599 return (int)::SendMessage(m_hWnd, TBM_GETSELEND, 0, 0L);
6602 void SetSelEnd(int nMax)
6604 ATLASSERT(::IsWindow(m_hWnd));
6605 ::SendMessage(m_hWnd, TBM_SETSELEND, 0, (LPARAM)nMax);
6608 void GetSelection(int& nMin, int& nMax) const
6610 nMin = GetSelStart();
6611 nMax = GetSelEnd();
6614 void SetSelection(int nMin, int nMax)
6616 SetSelStart(nMin);
6617 SetSelEnd(nMax);
6620 void GetChannelRect(LPRECT lprc) const
6622 ATLASSERT(::IsWindow(m_hWnd));
6623 ::SendMessage(m_hWnd, TBM_GETCHANNELRECT, 0, (LPARAM)lprc);
6626 void GetThumbRect(LPRECT lprc) const
6628 ATLASSERT(::IsWindow(m_hWnd));
6629 ::SendMessage(m_hWnd, TBM_GETTHUMBRECT, 0, (LPARAM)lprc);
6632 int GetPos() const
6634 ATLASSERT(::IsWindow(m_hWnd));
6635 return (int)::SendMessage(m_hWnd, TBM_GETPOS, 0, 0L);
6638 void SetPos(int nPos)
6640 ATLASSERT(::IsWindow(m_hWnd));
6641 ::SendMessage(m_hWnd, TBM_SETPOS, TRUE, nPos);
6644 UINT GetNumTics() const
6646 ATLASSERT(::IsWindow(m_hWnd));
6647 return (UINT)::SendMessage(m_hWnd, TBM_GETNUMTICS, 0, 0L);
6650 DWORD* GetTicArray() const
6652 ATLASSERT(::IsWindow(m_hWnd));
6653 return (DWORD*)::SendMessage(m_hWnd, TBM_GETPTICS, 0, 0L);
6656 int GetTic(int nTic) const
6658 ATLASSERT(::IsWindow(m_hWnd));
6659 return (int)::SendMessage(m_hWnd, TBM_GETTIC, nTic, 0L);
6662 BOOL SetTic(int nTic)
6664 ATLASSERT(::IsWindow(m_hWnd));
6665 return (BOOL)::SendMessage(m_hWnd, TBM_SETTIC, 0, nTic);
6668 int GetTicPos(int nTic) const
6670 ATLASSERT(::IsWindow(m_hWnd));
6671 return (int)::SendMessage(m_hWnd, TBM_GETTICPOS, nTic, 0L);
6674 void SetTicFreq(int nFreq)
6676 ATLASSERT(::IsWindow(m_hWnd));
6677 ::SendMessage(m_hWnd, TBM_SETTICFREQ, nFreq, 0L);
6680 int GetThumbLength() const
6682 ATLASSERT(::IsWindow(m_hWnd));
6683 return (int)::SendMessage(m_hWnd, TBM_GETTHUMBLENGTH, 0, 0L);
6686 void SetThumbLength(int nLength)
6688 ATLASSERT(::IsWindow(m_hWnd));
6689 ::SendMessage(m_hWnd, TBM_SETTHUMBLENGTH, nLength, 0L);
6692 void SetSel(int nStart, int nEnd, BOOL bRedraw = TRUE)
6694 ATLASSERT(::IsWindow(m_hWnd));
6695 ATLASSERT((GetStyle() & TBS_ENABLESELRANGE) != 0);
6696 ::SendMessage(m_hWnd, TBM_SETSEL, bRedraw, MAKELPARAM(nStart, nEnd));
6699 ATL::CWindow GetBuddy(BOOL bLeft = TRUE) const
6701 ATLASSERT(::IsWindow(m_hWnd));
6702 return ATL::CWindow((HWND)::SendMessage(m_hWnd, TBM_GETBUDDY, bLeft, 0L));
6705 ATL::CWindow SetBuddy(HWND hWndBuddy, BOOL bLeft = TRUE)
6707 ATLASSERT(::IsWindow(m_hWnd));
6708 return ATL::CWindow((HWND)::SendMessage(m_hWnd, TBM_SETBUDDY, bLeft, (LPARAM)hWndBuddy));
6711 #ifndef _WIN32_WCE
6712 CToolTipCtrl GetToolTips() const
6714 ATLASSERT(::IsWindow(m_hWnd));
6715 return CToolTipCtrl((HWND)::SendMessage(m_hWnd, TBM_GETTOOLTIPS, 0, 0L));
6718 void SetToolTips(HWND hWndTT)
6720 ATLASSERT(::IsWindow(m_hWnd));
6721 ::SendMessage(m_hWnd, TBM_SETTOOLTIPS, (WPARAM)hWndTT, 0L);
6724 int SetTipSide(int nSide)
6726 ATLASSERT(::IsWindow(m_hWnd));
6727 return (int)::SendMessage(m_hWnd, TBM_SETTIPSIDE, nSide, 0L);
6729 #endif // !_WIN32_WCE
6731 #if (_WIN32_IE >= 0x0400) && !defined(_WIN32_WCE)
6732 BOOL GetUnicodeFormat() const
6734 ATLASSERT(::IsWindow(m_hWnd));
6735 return (BOOL)::SendMessage(m_hWnd, TBM_GETUNICODEFORMAT, 0, 0L);
6738 BOOL SetUnicodeFormat(BOOL bUnicode = TRUE)
6740 ATLASSERT(::IsWindow(m_hWnd));
6741 return (BOOL)::SendMessage(m_hWnd, TBM_SETUNICODEFORMAT, bUnicode, 0L);
6743 #endif // (_WIN32_IE >= 0x0400) && !defined(_WIN32_WCE)
6745 // Operations
6746 void ClearSel(BOOL bRedraw = FALSE)
6748 ATLASSERT(::IsWindow(m_hWnd));
6749 ::SendMessage(m_hWnd, TBM_CLEARSEL, bRedraw, 0L);
6752 void VerifyPos()
6754 ATLASSERT(::IsWindow(m_hWnd));
6755 ::SendMessage(m_hWnd, TBM_SETPOS, FALSE, 0L);
6758 void ClearTics(BOOL bRedraw = FALSE)
6760 ATLASSERT(::IsWindow(m_hWnd));
6761 ::SendMessage(m_hWnd, TBM_CLEARTICS, bRedraw, 0L);
6765 typedef CTrackBarCtrlT<ATL::CWindow> CTrackBarCtrl;
6768 ///////////////////////////////////////////////////////////////////////////////
6769 // CUpDownCtrl
6771 template <class TBase>
6772 class CUpDownCtrlT : public TBase
6774 public:
6775 // Constructors
6776 CUpDownCtrlT(HWND hWnd = NULL) : TBase(hWnd)
6779 CUpDownCtrlT< TBase >& operator =(HWND hWnd)
6781 m_hWnd = hWnd;
6782 return *this;
6785 HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
6786 DWORD dwStyle = 0, DWORD dwExStyle = 0,
6787 ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
6789 return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
6792 // Attributes
6793 static LPCTSTR GetWndClassName()
6795 return UPDOWN_CLASS;
6798 UINT GetAccel(int nAccel, UDACCEL* pAccel) const
6800 ATLASSERT(::IsWindow(m_hWnd));
6801 return (UINT)LOWORD(::SendMessage(m_hWnd, UDM_GETACCEL, nAccel, (LPARAM)pAccel));
6804 BOOL SetAccel(int nAccel, UDACCEL* pAccel)
6806 ATLASSERT(::IsWindow(m_hWnd));
6807 return (BOOL)LOWORD(::SendMessage(m_hWnd, UDM_SETACCEL, nAccel, (LPARAM)pAccel));
6810 UINT GetBase() const
6812 ATLASSERT(::IsWindow(m_hWnd));
6813 return (UINT)LOWORD(::SendMessage(m_hWnd, UDM_GETBASE, 0, 0L));
6816 int SetBase(int nBase)
6818 ATLASSERT(::IsWindow(m_hWnd));
6819 return (int)::SendMessage(m_hWnd, UDM_SETBASE, nBase, 0L);
6822 ATL::CWindow GetBuddy() const
6824 ATLASSERT(::IsWindow(m_hWnd));
6825 return ATL::CWindow((HWND)::SendMessage(m_hWnd, UDM_GETBUDDY, 0, 0L));
6828 ATL::CWindow SetBuddy(HWND hWndBuddy)
6830 ATLASSERT(::IsWindow(m_hWnd));
6831 return ATL::CWindow((HWND)::SendMessage(m_hWnd, UDM_SETBUDDY, (WPARAM)hWndBuddy, 0L));
6834 int GetPos(LPBOOL lpbError = NULL) const
6836 ATLASSERT(::IsWindow(m_hWnd));
6837 DWORD dwRet = (DWORD)::SendMessage(m_hWnd, UDM_GETPOS, 0, 0L);
6838 // Note: Seems that Windows always sets error to TRUE if
6839 // UDS_SETBUDDYINT style is not used
6840 if(lpbError != NULL)
6841 *lpbError = (HIWORD(dwRet) != 0) ? TRUE : FALSE;
6842 return (int)(short)LOWORD(dwRet);
6845 int SetPos(int nPos)
6847 ATLASSERT(::IsWindow(m_hWnd));
6848 return (int)(short)LOWORD(::SendMessage(m_hWnd, UDM_SETPOS, 0, MAKELPARAM(nPos, 0)));
6851 DWORD GetRange() const
6853 ATLASSERT(::IsWindow(m_hWnd));
6854 return (DWORD)::SendMessage(m_hWnd, UDM_GETRANGE, 0, 0L);
6857 void GetRange(int& nLower, int& nUpper) const
6859 ATLASSERT(::IsWindow(m_hWnd));
6860 DWORD dwRet = (DWORD)::SendMessage(m_hWnd, UDM_GETRANGE, 0, 0L);
6861 nLower = (int)(short)HIWORD(dwRet);
6862 nUpper = (int)(short)LOWORD(dwRet);
6865 void SetRange(int nLower, int nUpper)
6867 ATLASSERT(::IsWindow(m_hWnd));
6868 ::SendMessage(m_hWnd, UDM_SETRANGE, 0, MAKELPARAM(nUpper, nLower));
6871 #if (_WIN32_IE >= 0x0400)
6872 void SetRange32(int nLower, int nUpper)
6874 ATLASSERT(::IsWindow(m_hWnd));
6875 ::SendMessage(m_hWnd, UDM_SETRANGE32, nLower, nUpper);
6878 void GetRange32(int& nLower, int& nUpper) const
6880 ATLASSERT(::IsWindow(m_hWnd));
6881 ::SendMessage(m_hWnd, UDM_GETRANGE32, (WPARAM)&nLower, (LPARAM)&nUpper);
6884 #ifndef _WIN32_WCE
6885 BOOL GetUnicodeFormat() const
6887 ATLASSERT(::IsWindow(m_hWnd));
6888 return (BOOL)::SendMessage(m_hWnd, UDM_GETUNICODEFORMAT, 0, 0L);
6891 BOOL SetUnicodeFormat(BOOL bUnicode = TRUE)
6893 ATLASSERT(::IsWindow(m_hWnd));
6894 return (BOOL)::SendMessage(m_hWnd, UDM_SETUNICODEFORMAT, bUnicode, 0L);
6896 #endif // !_WIN32_WCE
6897 #endif // (_WIN32_IE >= 0x0400)
6899 #if (_WIN32_IE >= 0x0500) && !defined(_WIN32_WCE)
6900 int GetPos32(LPBOOL lpbError = NULL) const
6902 ATLASSERT(::IsWindow(m_hWnd));
6903 // Note: Seems that Windows always sets error to TRUE if
6904 // UDS_SETBUDDYINT style is not used
6905 return (int)::SendMessage(m_hWnd, UDM_GETPOS32, 0, (LPARAM)lpbError);
6908 int SetPos32(int nPos)
6910 ATLASSERT(::IsWindow(m_hWnd));
6911 return (int)::SendMessage(m_hWnd, UDM_SETPOS32, 0, (LPARAM)nPos);
6913 #endif // (_WIN32_IE >= 0x0500) && !defined(_WIN32_WCE)
6916 typedef CUpDownCtrlT<ATL::CWindow> CUpDownCtrl;
6919 ///////////////////////////////////////////////////////////////////////////////
6920 // CProgressBarCtrl
6922 template <class TBase>
6923 class CProgressBarCtrlT : public TBase
6925 public:
6926 // Constructors
6927 CProgressBarCtrlT(HWND hWnd = NULL) : TBase(hWnd)
6930 CProgressBarCtrlT< TBase >& operator =(HWND hWnd)
6932 m_hWnd = hWnd;
6933 return *this;
6936 HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
6937 DWORD dwStyle = 0, DWORD dwExStyle = 0,
6938 ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
6940 return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
6943 // Attributes
6944 static LPCTSTR GetWndClassName()
6946 return PROGRESS_CLASS;
6949 DWORD SetRange(int nLower, int nUpper)
6951 ATLASSERT(::IsWindow(m_hWnd));
6952 return (DWORD)::SendMessage(m_hWnd, PBM_SETRANGE, 0, MAKELPARAM(nLower, nUpper));
6955 int SetPos(int nPos)
6957 ATLASSERT(::IsWindow(m_hWnd));
6958 return (int)(short)LOWORD(::SendMessage(m_hWnd, PBM_SETPOS, nPos, 0L));
6961 int OffsetPos(int nPos)
6963 ATLASSERT(::IsWindow(m_hWnd));
6964 return (int)(short)LOWORD(::SendMessage(m_hWnd, PBM_DELTAPOS, nPos, 0L));
6967 int SetStep(int nStep)
6969 ATLASSERT(::IsWindow(m_hWnd));
6970 return (int)(short)LOWORD(::SendMessage(m_hWnd, PBM_SETSTEP, nStep, 0L));
6973 UINT GetPos() const
6975 ATLASSERT(::IsWindow(m_hWnd));
6976 return (UINT)::SendMessage(m_hWnd, PBM_GETPOS, 0, 0L);
6979 void GetRange(PPBRANGE pPBRange) const
6981 ATLASSERT(::IsWindow(m_hWnd));
6982 ATLASSERT(pPBRange != NULL);
6983 ::SendMessage(m_hWnd, PBM_GETRANGE, TRUE, (LPARAM)pPBRange);
6986 void GetRange(int& nLower, int& nUpper) const
6988 ATLASSERT(::IsWindow(m_hWnd));
6989 PBRANGE range = { 0 };
6990 ::SendMessage(m_hWnd, PBM_GETRANGE, TRUE, (LPARAM)&range);
6991 nLower = range.iLow;
6992 nUpper = range.iHigh;
6995 int GetRangeLimit(BOOL bLowLimit) const
6997 ATLASSERT(::IsWindow(m_hWnd));
6998 return (int)::SendMessage(m_hWnd, PBM_GETRANGE, bLowLimit, (LPARAM)NULL);
7001 DWORD SetRange32(int nMin, int nMax)
7003 ATLASSERT(::IsWindow(m_hWnd));
7004 return (DWORD)::SendMessage(m_hWnd, PBM_SETRANGE32, nMin, nMax);
7007 #if (_WIN32_IE >= 0x0400) && !defined(_WIN32_WCE)
7008 COLORREF SetBarColor(COLORREF clr)
7010 ATLASSERT(::IsWindow(m_hWnd));
7011 return (COLORREF)::SendMessage(m_hWnd, PBM_SETBARCOLOR, 0, (LPARAM)clr);
7014 COLORREF SetBkColor(COLORREF clr)
7016 ATLASSERT(::IsWindow(m_hWnd));
7017 return (COLORREF)::SendMessage(m_hWnd, PBM_SETBKCOLOR, 0, (LPARAM)clr);
7019 #endif // (_WIN32_IE >= 0x0400) && !defined(_WIN32_WCE)
7021 #if (_WIN32_WINNT >= 0x0501) && defined(PBM_SETMARQUEE)
7022 BOOL SetMarquee(BOOL bMarquee, UINT uUpdateTime = 0U)
7024 ATLASSERT(::IsWindow(m_hWnd));
7025 return (BOOL)::SendMessage(m_hWnd, PBM_SETMARQUEE, (WPARAM)bMarquee, (LPARAM)uUpdateTime);
7027 #endif // (_WIN32_WINNT >= 0x0501) && defined(PBM_SETMARQUEE)
7029 #if (_WIN32_WINNT >= 0x0600)
7030 int GetStep() const
7032 ATLASSERT(::IsWindow(m_hWnd));
7033 return (int)::SendMessage(m_hWnd, PBM_GETSTEP, 0, 0L);
7036 COLORREF GetBkColor() const
7038 ATLASSERT(::IsWindow(m_hWnd));
7039 return (COLORREF)::SendMessage(m_hWnd, PBM_GETBKCOLOR, 0, 0L);
7042 COLORREF GetBarColor() const
7044 ATLASSERT(::IsWindow(m_hWnd));
7045 return (COLORREF)::SendMessage(m_hWnd, PBM_GETBARCOLOR, 0, 0L);
7048 int GetState() const
7050 ATLASSERT(::IsWindow(m_hWnd));
7051 return (int)::SendMessage(m_hWnd, PBM_GETSTATE, 0, 0L);
7054 int SetState(int nState)
7056 ATLASSERT(::IsWindow(m_hWnd));
7057 return (int)::SendMessage(m_hWnd, PBM_SETSTATE, nState, 0L);
7059 #endif // (_WIN32_WINNT >= 0x0600)
7061 // Operations
7062 int StepIt()
7064 ATLASSERT(::IsWindow(m_hWnd));
7065 return (int)(short)LOWORD(::SendMessage(m_hWnd, PBM_STEPIT, 0, 0L));
7069 typedef CProgressBarCtrlT<ATL::CWindow> CProgressBarCtrl;
7072 ///////////////////////////////////////////////////////////////////////////////
7073 // CHotKeyCtrl
7075 #ifndef _WIN32_WCE
7077 template <class TBase>
7078 class CHotKeyCtrlT : public TBase
7080 public:
7081 // Constructors
7082 CHotKeyCtrlT(HWND hWnd = NULL) : TBase(hWnd)
7085 CHotKeyCtrlT< TBase >& operator =(HWND hWnd)
7087 m_hWnd = hWnd;
7088 return *this;
7091 HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
7092 DWORD dwStyle = 0, DWORD dwExStyle = 0,
7093 ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
7095 return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
7098 // Attributes
7099 static LPCTSTR GetWndClassName()
7101 return HOTKEY_CLASS;
7104 DWORD GetHotKey() const
7106 ATLASSERT(::IsWindow(m_hWnd));
7107 return (DWORD)::SendMessage(m_hWnd, HKM_GETHOTKEY, 0, 0L);
7110 void GetHotKey(WORD &wVirtualKeyCode, WORD &wModifiers) const
7112 ATLASSERT(::IsWindow(m_hWnd));
7113 DWORD dw = (DWORD)::SendMessage(m_hWnd, HKM_GETHOTKEY, 0, 0L);
7114 wVirtualKeyCode = LOBYTE(LOWORD(dw));
7115 wModifiers = HIBYTE(LOWORD(dw));
7118 void SetHotKey(WORD wVirtualKeyCode, WORD wModifiers)
7120 ATLASSERT(::IsWindow(m_hWnd));
7121 ::SendMessage(m_hWnd, HKM_SETHOTKEY, MAKEWORD(wVirtualKeyCode, wModifiers), 0L);
7124 void SetRules(WORD wInvalidComb, WORD wModifiers)
7126 ATLASSERT(::IsWindow(m_hWnd));
7127 ::SendMessage(m_hWnd, HKM_SETRULES, wInvalidComb, MAKELPARAM(wModifiers, 0));
7131 typedef CHotKeyCtrlT<ATL::CWindow> CHotKeyCtrl;
7133 #endif // !_WIN32_WCE
7136 ///////////////////////////////////////////////////////////////////////////////
7137 // CAnimateCtrl
7139 #ifndef _WIN32_WCE
7141 template <class TBase>
7142 class CAnimateCtrlT : public TBase
7144 public:
7145 // Constructors
7146 CAnimateCtrlT(HWND hWnd = NULL) : TBase(hWnd)
7149 CAnimateCtrlT< TBase >& operator =(HWND hWnd)
7151 m_hWnd = hWnd;
7152 return *this;
7155 HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
7156 DWORD dwStyle = 0, DWORD dwExStyle = 0,
7157 ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
7159 return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
7162 // Attributes
7163 static LPCTSTR GetWndClassName()
7165 return ANIMATE_CLASS;
7168 // Operations
7169 BOOL Open(ATL::_U_STRINGorID FileName)
7171 ATLASSERT(::IsWindow(m_hWnd));
7172 return (BOOL)::SendMessage(m_hWnd, ACM_OPEN, 0, (LPARAM)FileName.m_lpstr);
7175 BOOL Play(UINT nFrom, UINT nTo, UINT nRep)
7177 ATLASSERT(::IsWindow(m_hWnd));
7178 return (BOOL)::SendMessage(m_hWnd, ACM_PLAY, nRep, MAKELPARAM(nFrom, nTo));
7181 BOOL Stop()
7183 ATLASSERT(::IsWindow(m_hWnd));
7184 return (BOOL)::SendMessage(m_hWnd, ACM_STOP, 0, 0L);
7187 BOOL Close()
7189 ATLASSERT(::IsWindow(m_hWnd));
7190 return (BOOL)::SendMessage(m_hWnd, ACM_OPEN, 0, 0L);
7193 BOOL Seek(UINT nTo)
7195 ATLASSERT(::IsWindow(m_hWnd));
7196 return (BOOL)::SendMessage(m_hWnd, ACM_PLAY, 0, MAKELPARAM(nTo, nTo));
7199 // Vista only
7200 BOOL IsPlaying() const
7202 #ifndef ACM_ISPLAYING
7203 const UINT ACM_ISPLAYING = (WM_USER+104);
7204 #endif
7205 ATLASSERT(::IsWindow(m_hWnd));
7206 return (BOOL)::SendMessage(m_hWnd, ACM_ISPLAYING, 0, 0L);
7210 typedef CAnimateCtrlT<ATL::CWindow> CAnimateCtrl;
7212 #endif // !_WIN32_WCE
7215 ///////////////////////////////////////////////////////////////////////////////
7216 // CRichEditCtrl
7218 #ifndef _WIN32_WCE
7220 #ifdef _UNICODE
7221 #if (_RICHEDIT_VER == 0x0100)
7222 #undef RICHEDIT_CLASS
7223 #define RICHEDIT_CLASS L"RICHEDIT"
7224 #endif // (_RICHEDIT_VER == 0x0100)
7225 #endif // _UNICODE
7227 template <class TBase>
7228 class CRichEditCtrlT : public TBase
7230 public:
7231 // Constructors
7232 CRichEditCtrlT(HWND hWnd = NULL) : TBase(hWnd)
7235 CRichEditCtrlT< TBase >& operator =(HWND hWnd)
7237 m_hWnd = hWnd;
7238 return *this;
7241 HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
7242 DWORD dwStyle = 0, DWORD dwExStyle = 0,
7243 ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
7245 return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
7248 // Attributes
7249 static LPCTSTR GetWndClassName()
7251 return RICHEDIT_CLASS;
7254 static LPCTSTR GetLibraryName()
7256 #if (_RICHEDIT_VER >= 0x0200)
7257 return _T("RICHED20.DLL");
7258 #else
7259 return _T("RICHED32.DLL");
7260 #endif
7263 int GetLineCount() const
7265 ATLASSERT(::IsWindow(m_hWnd));
7266 return (int)::SendMessage(m_hWnd, EM_GETLINECOUNT, 0, 0L);
7269 BOOL GetModify() const
7271 ATLASSERT(::IsWindow(m_hWnd));
7272 return (BOOL)::SendMessage(m_hWnd, EM_GETMODIFY, 0, 0L);
7275 void SetModify(BOOL bModified = TRUE)
7277 ATLASSERT(::IsWindow(m_hWnd));
7278 ::SendMessage(m_hWnd, EM_SETMODIFY, bModified, 0L);
7281 void GetRect(LPRECT lpRect) const
7283 ATLASSERT(::IsWindow(m_hWnd));
7284 ::SendMessage(m_hWnd, EM_GETRECT, 0, (LPARAM)lpRect);
7287 DWORD GetOptions() const
7289 ATLASSERT(::IsWindow(m_hWnd));
7290 return (DWORD)::SendMessage(m_hWnd, EM_GETOPTIONS, 0, 0L);
7293 DWORD SetOptions(WORD wOperation, DWORD dwOptions)
7295 ATLASSERT(::IsWindow(m_hWnd));
7296 return (DWORD)::SendMessage(m_hWnd, EM_SETOPTIONS, wOperation, dwOptions);
7299 // NOTE: first word in lpszBuffer must contain the size of the buffer!
7300 int GetLine(int nIndex, LPTSTR lpszBuffer) const
7302 ATLASSERT(::IsWindow(m_hWnd));
7303 return (int)::SendMessage(m_hWnd, EM_GETLINE, nIndex, (LPARAM)lpszBuffer);
7306 int GetLine(int nIndex, LPTSTR lpszBuffer, int nMaxLength) const
7308 ATLASSERT(::IsWindow(m_hWnd));
7309 *(LPWORD)lpszBuffer = (WORD)nMaxLength;
7310 return (int)::SendMessage(m_hWnd, EM_GETLINE, nIndex, (LPARAM)lpszBuffer);
7313 BOOL CanUndo() const
7315 ATLASSERT(::IsWindow(m_hWnd));
7316 return (BOOL)::SendMessage(m_hWnd, EM_CANUNDO, 0, 0L);
7319 BOOL CanPaste(UINT nFormat = 0) const
7321 ATLASSERT(::IsWindow(m_hWnd));
7322 return (BOOL)::SendMessage(m_hWnd, EM_CANPASTE, nFormat, 0L);
7325 void GetSel(LONG& nStartChar, LONG& nEndChar) const
7327 ATLASSERT(::IsWindow(m_hWnd));
7328 CHARRANGE cr = { 0, 0 };
7329 ::SendMessage(m_hWnd, EM_EXGETSEL, 0, (LPARAM)&cr);
7330 nStartChar = cr.cpMin;
7331 nEndChar = cr.cpMax;
7334 void GetSel(CHARRANGE &cr) const
7336 ATLASSERT(::IsWindow(m_hWnd));
7337 ::SendMessage(m_hWnd, EM_EXGETSEL, 0, (LPARAM)&cr);
7340 int SetSel(LONG nStartChar, LONG nEndChar)
7342 ATLASSERT(::IsWindow(m_hWnd));
7343 CHARRANGE cr = { nStartChar, nEndChar };
7344 return (int)::SendMessage(m_hWnd, EM_EXSETSEL, 0, (LPARAM)&cr);
7347 int SetSel(CHARRANGE &cr)
7349 ATLASSERT(::IsWindow(m_hWnd));
7350 return (int)::SendMessage(m_hWnd, EM_EXSETSEL, 0, (LPARAM)&cr);
7353 int SetSelAll()
7355 return SetSel(0, -1);
7358 int SetSelNone()
7360 return SetSel(-1, 0);
7363 DWORD GetDefaultCharFormat(CHARFORMAT& cf) const
7365 ATLASSERT(::IsWindow(m_hWnd));
7366 cf.cbSize = sizeof(CHARFORMAT);
7367 return (DWORD)::SendMessage(m_hWnd, EM_GETCHARFORMAT, 0, (LPARAM)&cf);
7370 DWORD GetSelectionCharFormat(CHARFORMAT& cf) const
7372 ATLASSERT(::IsWindow(m_hWnd));
7373 cf.cbSize = sizeof(CHARFORMAT);
7374 return (DWORD)::SendMessage(m_hWnd, EM_GETCHARFORMAT, 1, (LPARAM)&cf);
7377 DWORD GetEventMask() const
7379 ATLASSERT(::IsWindow(m_hWnd));
7380 return (DWORD)::SendMessage(m_hWnd, EM_GETEVENTMASK, 0, 0L);
7383 LONG GetLimitText() const
7385 ATLASSERT(::IsWindow(m_hWnd));
7386 return (LONG)::SendMessage(m_hWnd, EM_GETLIMITTEXT, 0, 0L);
7389 DWORD GetParaFormat(PARAFORMAT& pf) const
7391 ATLASSERT(::IsWindow(m_hWnd));
7392 pf.cbSize = sizeof(PARAFORMAT);
7393 return (DWORD)::SendMessage(m_hWnd, EM_GETPARAFORMAT, 0, (LPARAM)&pf);
7396 #if (_RICHEDIT_VER >= 0x0200)
7397 LONG GetSelText(LPTSTR lpstrBuff) const
7399 ATLASSERT(::IsWindow(m_hWnd));
7400 return (LONG)::SendMessage(m_hWnd, EM_GETSELTEXT, 0, (LPARAM)lpstrBuff);
7402 #else // !(_RICHEDIT_VER >= 0x0200)
7403 // RichEdit 1.0 EM_GETSELTEXT is ANSI only
7404 LONG GetSelText(LPSTR lpstrBuff) const
7406 ATLASSERT(::IsWindow(m_hWnd));
7407 return (LONG)::SendMessage(m_hWnd, EM_GETSELTEXT, 0, (LPARAM)lpstrBuff);
7409 #endif // !(_RICHEDIT_VER >= 0x0200)
7411 #ifndef _ATL_NO_COM
7412 BOOL GetSelTextBSTR(BSTR& bstrText) const
7414 USES_CONVERSION;
7415 ATLASSERT(::IsWindow(m_hWnd));
7416 ATLASSERT(bstrText == NULL);
7418 CHARRANGE cr = { 0, 0 };
7419 ::SendMessage(m_hWnd, EM_EXGETSEL, 0, (LPARAM)&cr);
7421 #if (_RICHEDIT_VER >= 0x0200)
7422 CTempBuffer<TCHAR, _WTL_STACK_ALLOC_THRESHOLD> buff;
7423 LPTSTR lpstrText = buff.Allocate(cr.cpMax - cr.cpMin + 1);
7424 if(lpstrText == NULL)
7425 return FALSE;
7426 if(::SendMessage(m_hWnd, EM_GETSELTEXT, 0, (LPARAM)lpstrText) == 0)
7427 return FALSE;
7429 bstrText = ::SysAllocString(T2W(lpstrText));
7430 #else // !(_RICHEDIT_VER >= 0x0200)
7431 CTempBuffer<char, _WTL_STACK_ALLOC_THRESHOLD> buff;
7432 LPSTR lpstrText = buff.Allocate(cr.cpMax - cr.cpMin + 1);
7433 if(lpstrText == NULL)
7434 return FALSE;
7435 if(::SendMessage(m_hWnd, EM_GETSELTEXT, 0, (LPARAM)lpstrText) == 0)
7436 return FALSE;
7438 bstrText = ::SysAllocString(A2W(lpstrText));
7439 #endif // !(_RICHEDIT_VER >= 0x0200)
7441 return (bstrText != NULL) ? TRUE : FALSE;
7443 #endif // !_ATL_NO_COM
7445 #if defined(_WTL_USE_CSTRING) || defined(__ATLSTR_H__)
7446 LONG GetSelText(_CSTRING_NS::CString& strText) const
7448 ATLASSERT(::IsWindow(m_hWnd));
7450 CHARRANGE cr = { 0, 0 };
7451 ::SendMessage(m_hWnd, EM_EXGETSEL, 0, (LPARAM)&cr);
7453 #if (_RICHEDIT_VER >= 0x0200)
7454 LONG lLen = 0;
7455 LPTSTR lpstrText = strText.GetBufferSetLength(cr.cpMax - cr.cpMin);
7456 if(lpstrText != NULL)
7458 lLen = (LONG)::SendMessage(m_hWnd, EM_GETSELTEXT, 0, (LPARAM)lpstrText);
7459 strText.ReleaseBuffer();
7461 #else // !(_RICHEDIT_VER >= 0x0200)
7462 CTempBuffer<char, _WTL_STACK_ALLOC_THRESHOLD> buff;
7463 LPSTR lpstrText = buff.Allocate(cr.cpMax - cr.cpMin + 1);
7464 if(lpstrText == NULL)
7465 return 0;
7466 LONG lLen = (LONG)::SendMessage(m_hWnd, EM_GETSELTEXT, 0, (LPARAM)lpstrText);
7467 if(lLen == 0)
7468 return 0;
7470 USES_CONVERSION;
7471 strText = A2T(lpstrText);
7472 #endif // !(_RICHEDIT_VER >= 0x0200)
7474 return lLen;
7476 #endif // defined(_WTL_USE_CSTRING) || defined(__ATLSTR_H__)
7478 WORD GetSelectionType() const
7480 ATLASSERT(::IsWindow(m_hWnd));
7481 return (WORD)::SendMessage(m_hWnd, EM_SELECTIONTYPE, 0, 0L);
7484 COLORREF SetBackgroundColor(COLORREF cr)
7486 ATLASSERT(::IsWindow(m_hWnd));
7487 return (COLORREF)::SendMessage(m_hWnd, EM_SETBKGNDCOLOR, 0, cr);
7490 COLORREF SetBackgroundColor() // sets to system background
7492 ATLASSERT(::IsWindow(m_hWnd));
7493 return (COLORREF)::SendMessage(m_hWnd, EM_SETBKGNDCOLOR, 1, 0);
7496 BOOL SetCharFormat(CHARFORMAT& cf, WORD wFlags)
7498 ATLASSERT(::IsWindow(m_hWnd));
7499 cf.cbSize = sizeof(CHARFORMAT);
7500 return (BOOL)::SendMessage(m_hWnd, EM_SETCHARFORMAT, (WPARAM)wFlags, (LPARAM)&cf);
7503 BOOL SetDefaultCharFormat(CHARFORMAT& cf)
7505 ATLASSERT(::IsWindow(m_hWnd));
7506 cf.cbSize = sizeof(CHARFORMAT);
7507 return (BOOL)::SendMessage(m_hWnd, EM_SETCHARFORMAT, 0, (LPARAM)&cf);
7510 BOOL SetSelectionCharFormat(CHARFORMAT& cf)
7512 ATLASSERT(::IsWindow(m_hWnd));
7513 cf.cbSize = sizeof(CHARFORMAT);
7514 return (BOOL)::SendMessage(m_hWnd, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf);
7517 BOOL SetWordCharFormat(CHARFORMAT& cf)
7519 ATLASSERT(::IsWindow(m_hWnd));
7520 cf.cbSize = sizeof(CHARFORMAT);
7521 return (BOOL)::SendMessage(m_hWnd, EM_SETCHARFORMAT, SCF_SELECTION | SCF_WORD, (LPARAM)&cf);
7524 DWORD SetEventMask(DWORD dwEventMask)
7526 ATLASSERT(::IsWindow(m_hWnd));
7527 return (DWORD)::SendMessage(m_hWnd, EM_SETEVENTMASK, 0, dwEventMask);
7530 BOOL SetParaFormat(PARAFORMAT& pf)
7532 ATLASSERT(::IsWindow(m_hWnd));
7533 pf.cbSize = sizeof(PARAFORMAT);
7534 return (BOOL)::SendMessage(m_hWnd, EM_SETPARAFORMAT, 0, (LPARAM)&pf);
7537 BOOL SetTargetDevice(HDC hDC, int cxLineWidth)
7539 ATLASSERT(::IsWindow(m_hWnd));
7540 return (BOOL)::SendMessage(m_hWnd, EM_SETTARGETDEVICE, (WPARAM)hDC, cxLineWidth);
7543 int GetTextLength() const
7545 ATLASSERT(::IsWindow(m_hWnd));
7546 return (int)::SendMessage(m_hWnd, WM_GETTEXTLENGTH, 0, 0L);
7549 BOOL SetReadOnly(BOOL bReadOnly = TRUE)
7551 ATLASSERT(::IsWindow(m_hWnd));
7552 return (BOOL)::SendMessage(m_hWnd, EM_SETREADONLY, bReadOnly, 0L);
7555 int GetFirstVisibleLine() const
7557 ATLASSERT(::IsWindow(m_hWnd));
7558 return (int)::SendMessage(m_hWnd, EM_GETFIRSTVISIBLELINE, 0, 0L);
7561 EDITWORDBREAKPROCEX GetWordBreakProcEx() const
7563 ATLASSERT(::IsWindow(m_hWnd));
7564 return (EDITWORDBREAKPROCEX)::SendMessage(m_hWnd, EM_GETWORDBREAKPROCEX, 0, 0L);
7567 EDITWORDBREAKPROCEX SetWordBreakProcEx(EDITWORDBREAKPROCEX pfnEditWordBreakProcEx)
7569 ATLASSERT(::IsWindow(m_hWnd));
7570 return (EDITWORDBREAKPROCEX)::SendMessage(m_hWnd, EM_SETWORDBREAKPROCEX, 0, (LPARAM)pfnEditWordBreakProcEx);
7573 int GetTextRange(TEXTRANGE* pTextRange) const
7575 ATLASSERT(::IsWindow(m_hWnd));
7576 return (int)::SendMessage(m_hWnd, EM_GETTEXTRANGE, 0, (LPARAM)pTextRange);
7579 #if (_RICHEDIT_VER >= 0x0200)
7580 int GetTextRange(LONG nStartChar, LONG nEndChar, LPTSTR lpstrText) const
7582 ATLASSERT(::IsWindow(m_hWnd));
7583 TEXTRANGE tr = { 0 };
7584 tr.chrg.cpMin = nStartChar;
7585 tr.chrg.cpMax = nEndChar;
7586 tr.lpstrText = lpstrText;
7587 return (int)::SendMessage(m_hWnd, EM_GETTEXTRANGE, 0, (LPARAM)&tr);
7589 #else // !(_RICHEDIT_VER >= 0x0200)
7591 int GetTextRange(LONG nStartChar, LONG nEndChar, LPSTR lpstrText) const
7593 ATLASSERT(::IsWindow(m_hWnd));
7594 TEXTRANGE tr = { 0 };
7595 tr.chrg.cpMin = nStartChar;
7596 tr.chrg.cpMax = nEndChar;
7597 tr.lpstrText = lpstrText;
7598 return (int)::SendMessage(m_hWnd, EM_GETTEXTRANGE, 0, (LPARAM)&tr);
7600 #endif // !(_RICHEDIT_VER >= 0x0200)
7602 #if (_RICHEDIT_VER >= 0x0200)
7603 DWORD GetDefaultCharFormat(CHARFORMAT2& cf) const
7605 ATLASSERT(::IsWindow(m_hWnd));
7606 cf.cbSize = sizeof(CHARFORMAT2);
7607 return (DWORD)::SendMessage(m_hWnd, EM_GETCHARFORMAT, 0, (LPARAM)&cf);
7610 BOOL SetCharFormat(CHARFORMAT2& cf, WORD wFlags)
7612 ATLASSERT(::IsWindow(m_hWnd));
7613 cf.cbSize = sizeof(CHARFORMAT2);
7614 return (BOOL)::SendMessage(m_hWnd, EM_SETCHARFORMAT, (WPARAM)wFlags, (LPARAM)&cf);
7617 BOOL SetDefaultCharFormat(CHARFORMAT2& cf)
7619 ATLASSERT(::IsWindow(m_hWnd));
7620 cf.cbSize = sizeof(CHARFORMAT2);
7621 return (BOOL)::SendMessage(m_hWnd, EM_SETCHARFORMAT, 0, (LPARAM)&cf);
7624 DWORD GetSelectionCharFormat(CHARFORMAT2& cf) const
7626 ATLASSERT(::IsWindow(m_hWnd));
7627 cf.cbSize = sizeof(CHARFORMAT2);
7628 return (DWORD)::SendMessage(m_hWnd, EM_GETCHARFORMAT, 1, (LPARAM)&cf);
7631 BOOL SetSelectionCharFormat(CHARFORMAT2& cf)
7633 ATLASSERT(::IsWindow(m_hWnd));
7634 cf.cbSize = sizeof(CHARFORMAT2);
7635 return (BOOL)::SendMessage(m_hWnd, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf);
7638 BOOL SetWordCharFormat(CHARFORMAT2& cf)
7640 ATLASSERT(::IsWindow(m_hWnd));
7641 cf.cbSize = sizeof(CHARFORMAT2);
7642 return (BOOL)::SendMessage(m_hWnd, EM_SETCHARFORMAT, SCF_SELECTION | SCF_WORD, (LPARAM)&cf);
7645 DWORD GetParaFormat(PARAFORMAT2& pf) const
7647 ATLASSERT(::IsWindow(m_hWnd));
7648 pf.cbSize = sizeof(PARAFORMAT2);
7649 return (DWORD)::SendMessage(m_hWnd, EM_GETPARAFORMAT, 0, (LPARAM)&pf);
7652 BOOL SetParaFormat(PARAFORMAT2& pf)
7654 ATLASSERT(::IsWindow(m_hWnd));
7655 pf.cbSize = sizeof(PARAFORMAT2);
7656 return (BOOL)::SendMessage(m_hWnd, EM_SETPARAFORMAT, 0, (LPARAM)&pf);
7659 TEXTMODE GetTextMode() const
7661 ATLASSERT(::IsWindow(m_hWnd));
7662 return (TEXTMODE)::SendMessage(m_hWnd, EM_GETTEXTMODE, 0, 0L);
7665 BOOL SetTextMode(TEXTMODE enumTextMode)
7667 ATLASSERT(::IsWindow(m_hWnd));
7668 return !(BOOL)::SendMessage(m_hWnd, EM_SETTEXTMODE, enumTextMode, 0L);
7671 UNDONAMEID GetUndoName() const
7673 ATLASSERT(::IsWindow(m_hWnd));
7674 return (UNDONAMEID)::SendMessage(m_hWnd, EM_GETUNDONAME, 0, 0L);
7677 UNDONAMEID GetRedoName() const
7679 ATLASSERT(::IsWindow(m_hWnd));
7680 return (UNDONAMEID)::SendMessage(m_hWnd, EM_GETREDONAME, 0, 0L);
7683 BOOL CanRedo() const
7685 ATLASSERT(::IsWindow(m_hWnd));
7686 return (BOOL)::SendMessage(m_hWnd, EM_CANREDO, 0, 0L);
7689 BOOL GetAutoURLDetect() const
7691 ATLASSERT(::IsWindow(m_hWnd));
7692 return (BOOL)::SendMessage(m_hWnd, EM_GETAUTOURLDETECT, 0, 0L);
7695 BOOL SetAutoURLDetect(BOOL bAutoDetect = TRUE)
7697 ATLASSERT(::IsWindow(m_hWnd));
7698 return !(BOOL)::SendMessage(m_hWnd, EM_AUTOURLDETECT, bAutoDetect, 0L);
7701 // this method is deprecated, please use SetAutoURLDetect
7702 BOOL EnableAutoURLDetect(BOOL bEnable = TRUE) { return SetAutoURLDetect(bEnable); }
7704 UINT SetUndoLimit(UINT uUndoLimit)
7706 ATLASSERT(::IsWindow(m_hWnd));
7707 return (UINT)::SendMessage(m_hWnd, EM_SETUNDOLIMIT, uUndoLimit, 0L);
7710 void SetPalette(HPALETTE hPalette)
7712 ATLASSERT(::IsWindow(m_hWnd));
7713 ::SendMessage(m_hWnd, EM_SETPALETTE, (WPARAM)hPalette, 0L);
7716 int GetTextEx(GETTEXTEX* pGetTextEx, LPTSTR lpstrText) const
7718 ATLASSERT(::IsWindow(m_hWnd));
7719 return (int)::SendMessage(m_hWnd, EM_GETTEXTEX, (WPARAM)pGetTextEx, (LPARAM)lpstrText);
7722 int GetTextEx(LPTSTR lpstrText, int nTextLen, DWORD dwFlags = GT_DEFAULT, UINT uCodePage = CP_ACP, LPCSTR lpDefaultChar = NULL, LPBOOL lpUsedDefChar = NULL) const
7724 ATLASSERT(::IsWindow(m_hWnd));
7725 GETTEXTEX gte = { 0 };
7726 gte.cb = nTextLen * sizeof(TCHAR);
7727 gte.codepage = uCodePage;
7728 gte.flags = dwFlags;
7729 gte.lpDefaultChar = lpDefaultChar;
7730 gte.lpUsedDefChar = lpUsedDefChar;
7731 return (int)::SendMessage(m_hWnd, EM_GETTEXTEX, (WPARAM)&gte, (LPARAM)lpstrText);
7734 int GetTextLengthEx(GETTEXTLENGTHEX* pGetTextLengthEx) const
7736 ATLASSERT(::IsWindow(m_hWnd));
7737 return (int)::SendMessage(m_hWnd, EM_GETTEXTLENGTHEX, (WPARAM)pGetTextLengthEx, 0L);
7740 int GetTextLengthEx(DWORD dwFlags = GTL_DEFAULT, UINT uCodePage = CP_ACP) const
7742 ATLASSERT(::IsWindow(m_hWnd));
7743 GETTEXTLENGTHEX gtle = { 0 };
7744 gtle.codepage = uCodePage;
7745 gtle.flags = dwFlags;
7746 return (int)::SendMessage(m_hWnd, EM_GETTEXTLENGTHEX, (WPARAM)&gtle, 0L);
7748 #endif // (_RICHEDIT_VER >= 0x0200)
7750 #if (_RICHEDIT_VER >= 0x0300)
7751 int SetTextEx(SETTEXTEX* pSetTextEx, LPCTSTR lpstrText)
7753 ATLASSERT(::IsWindow(m_hWnd));
7754 return (int)::SendMessage(m_hWnd, EM_SETTEXTEX, (WPARAM)pSetTextEx, (LPARAM)lpstrText);
7757 int SetTextEx(LPCTSTR lpstrText, DWORD dwFlags = ST_DEFAULT, UINT uCodePage = CP_ACP)
7759 ATLASSERT(::IsWindow(m_hWnd));
7760 SETTEXTEX ste = { 0 };
7761 ste.flags = dwFlags;
7762 ste.codepage = uCodePage;
7763 return (int)::SendMessage(m_hWnd, EM_SETTEXTEX, (WPARAM)&ste, (LPARAM)lpstrText);
7766 int GetEditStyle() const
7768 ATLASSERT(::IsWindow(m_hWnd));
7769 return (int)::SendMessage(m_hWnd, EM_GETEDITSTYLE, 0, 0L);
7772 int SetEditStyle(int nStyle, int nMask = -1)
7774 ATLASSERT(::IsWindow(m_hWnd));
7775 if(nMask == -1)
7776 nMask = nStyle; // set everything specified
7777 return (int)::SendMessage(m_hWnd, EM_SETEDITSTYLE, nStyle, nMask);
7780 BOOL SetFontSize(int nFontSizeDelta)
7782 ATLASSERT(::IsWindow(m_hWnd));
7783 ATLASSERT(nFontSizeDelta >= -1637 && nFontSizeDelta <= 1638);
7784 return (BOOL)::SendMessage(m_hWnd, EM_SETFONTSIZE, nFontSizeDelta, 0L);
7787 void GetScrollPos(LPPOINT lpPoint) const
7789 ATLASSERT(::IsWindow(m_hWnd));
7790 ATLASSERT(lpPoint != NULL);
7791 ::SendMessage(m_hWnd, EM_GETSCROLLPOS, 0, (LPARAM)lpPoint);
7794 void SetScrollPos(LPPOINT lpPoint)
7796 ATLASSERT(::IsWindow(m_hWnd));
7797 ATLASSERT(lpPoint != NULL);
7798 ::SendMessage(m_hWnd, EM_SETSCROLLPOS, 0, (LPARAM)lpPoint);
7801 BOOL GetZoom(int& nNum, int& nDen) const
7803 ATLASSERT(::IsWindow(m_hWnd));
7804 return (BOOL)::SendMessage(m_hWnd, EM_GETZOOM, (WPARAM)&nNum, (LPARAM)&nDen);
7807 BOOL SetZoom(int nNum, int nDen)
7809 ATLASSERT(::IsWindow(m_hWnd));
7810 ATLASSERT(nNum >= 0 && nNum <= 64);
7811 ATLASSERT(nDen >= 0 && nDen <= 64);
7812 return (BOOL)::SendMessage(m_hWnd, EM_SETZOOM, nNum, nDen);
7815 BOOL SetZoomOff()
7817 ATLASSERT(::IsWindow(m_hWnd));
7818 return (BOOL)::SendMessage(m_hWnd, EM_SETZOOM, 0, 0L);
7820 #endif // (_RICHEDIT_VER >= 0x0300)
7822 // Operations
7823 void LimitText(LONG nChars = 0)
7825 ATLASSERT(::IsWindow(m_hWnd));
7826 ::SendMessage(m_hWnd, EM_EXLIMITTEXT, 0, nChars);
7829 int LineFromChar(LONG nIndex) const
7831 ATLASSERT(::IsWindow(m_hWnd));
7832 return (int)::SendMessage(m_hWnd, EM_EXLINEFROMCHAR, 0, nIndex);
7835 POINT PosFromChar(LONG nChar) const
7837 ATLASSERT(::IsWindow(m_hWnd));
7838 POINT point = { 0, 0 };
7839 ::SendMessage(m_hWnd, EM_POSFROMCHAR, (WPARAM)&point, nChar);
7840 return point;
7843 int CharFromPos(POINT pt) const
7845 ATLASSERT(::IsWindow(m_hWnd));
7846 POINTL ptl = { pt.x, pt.y };
7847 return (int)::SendMessage(m_hWnd, EM_CHARFROMPOS, 0, (LPARAM)&ptl);
7850 void EmptyUndoBuffer()
7852 ATLASSERT(::IsWindow(m_hWnd));
7853 ::SendMessage(m_hWnd, EM_EMPTYUNDOBUFFER, 0, 0L);
7856 int LineIndex(int nLine = -1) const
7858 ATLASSERT(::IsWindow(m_hWnd));
7859 return (int)::SendMessage(m_hWnd, EM_LINEINDEX, nLine, 0L);
7862 int LineLength(int nLine = -1) const
7864 ATLASSERT(::IsWindow(m_hWnd));
7865 return (int)::SendMessage(m_hWnd, EM_LINELENGTH, nLine, 0L);
7868 BOOL LineScroll(int nLines, int nChars = 0)
7870 ATLASSERT(::IsWindow(m_hWnd));
7871 return (BOOL)::SendMessage(m_hWnd, EM_LINESCROLL, nChars, nLines);
7874 void ReplaceSel(LPCTSTR lpszNewText, BOOL bCanUndo = FALSE)
7876 ATLASSERT(::IsWindow(m_hWnd));
7877 ::SendMessage(m_hWnd, EM_REPLACESEL, (WPARAM) bCanUndo, (LPARAM)lpszNewText);
7880 void SetRect(LPCRECT lpRect)
7882 ATLASSERT(::IsWindow(m_hWnd));
7883 ::SendMessage(m_hWnd, EM_SETRECT, 0, (LPARAM)lpRect);
7886 BOOL DisplayBand(LPRECT pDisplayRect)
7888 ATLASSERT(::IsWindow(m_hWnd));
7889 return (BOOL)::SendMessage(m_hWnd, EM_DISPLAYBAND, 0, (LPARAM)pDisplayRect);
7892 LONG FindText(DWORD dwFlags, FINDTEXT& ft) const
7894 ATLASSERT(::IsWindow(m_hWnd));
7895 #if (_RICHEDIT_VER >= 0x0200) && defined(_UNICODE)
7896 return (LONG)::SendMessage(m_hWnd, EM_FINDTEXTW, dwFlags, (LPARAM)&ft);
7897 #else
7898 return (LONG)::SendMessage(m_hWnd, EM_FINDTEXT, dwFlags, (LPARAM)&ft);
7899 #endif
7902 LONG FindText(DWORD dwFlags, FINDTEXTEX& ft) const
7904 ATLASSERT(::IsWindow(m_hWnd));
7905 #if (_RICHEDIT_VER >= 0x0200) && defined(_UNICODE)
7906 return (LONG)::SendMessage(m_hWnd, EM_FINDTEXTEXW, dwFlags, (LPARAM)&ft);
7907 #else
7908 return (LONG)::SendMessage(m_hWnd, EM_FINDTEXTEX, dwFlags, (LPARAM)&ft);
7909 #endif
7912 LONG FormatRange(FORMATRANGE& fr, BOOL bDisplay = TRUE)
7914 ATLASSERT(::IsWindow(m_hWnd));
7915 return (LONG)::SendMessage(m_hWnd, EM_FORMATRANGE, bDisplay, (LPARAM)&fr);
7918 LONG FormatRange(FORMATRANGE* pFormatRange, BOOL bDisplay = TRUE)
7920 ATLASSERT(::IsWindow(m_hWnd));
7921 return (LONG)::SendMessage(m_hWnd, EM_FORMATRANGE, bDisplay, (LPARAM)pFormatRange);
7924 void HideSelection(BOOL bHide = TRUE, BOOL bChangeStyle = FALSE)
7926 ATLASSERT(::IsWindow(m_hWnd));
7927 ::SendMessage(m_hWnd, EM_HIDESELECTION, bHide, bChangeStyle);
7930 void PasteSpecial(UINT uClipFormat, DWORD dwAspect = 0, HMETAFILE hMF = 0)
7932 ATLASSERT(::IsWindow(m_hWnd));
7933 REPASTESPECIAL reps = { dwAspect, (DWORD_PTR)hMF };
7934 ::SendMessage(m_hWnd, EM_PASTESPECIAL, uClipFormat, (LPARAM)&reps);
7937 void RequestResize()
7939 ATLASSERT(::IsWindow(m_hWnd));
7940 ::SendMessage(m_hWnd, EM_REQUESTRESIZE, 0, 0L);
7943 LONG StreamIn(UINT uFormat, EDITSTREAM& es)
7945 ATLASSERT(::IsWindow(m_hWnd));
7946 return (LONG)::SendMessage(m_hWnd, EM_STREAMIN, uFormat, (LPARAM)&es);
7949 LONG StreamOut(UINT uFormat, EDITSTREAM& es)
7951 ATLASSERT(::IsWindow(m_hWnd));
7952 return (LONG)::SendMessage(m_hWnd, EM_STREAMOUT, uFormat, (LPARAM)&es);
7955 DWORD FindWordBreak(int nCode, LONG nStartChar)
7957 ATLASSERT(::IsWindow(m_hWnd));
7958 return (DWORD)::SendMessage(m_hWnd, EM_FINDWORDBREAK, nCode, nStartChar);
7961 // Additional operations
7962 void ScrollCaret()
7964 ATLASSERT(::IsWindow(m_hWnd));
7965 ::SendMessage(m_hWnd, EM_SCROLLCARET, 0, 0L);
7968 int InsertText(long nInsertAfterChar, LPCTSTR lpstrText, BOOL bCanUndo = FALSE)
7970 int nRet = SetSel(nInsertAfterChar, nInsertAfterChar);
7971 ReplaceSel(lpstrText, bCanUndo);
7972 return nRet;
7975 int AppendText(LPCTSTR lpstrText, BOOL bCanUndo = FALSE)
7977 return InsertText(GetWindowTextLength(), lpstrText, bCanUndo);
7980 // Clipboard operations
7981 BOOL Undo()
7983 ATLASSERT(::IsWindow(m_hWnd));
7984 return (BOOL)::SendMessage(m_hWnd, EM_UNDO, 0, 0L);
7987 void Clear()
7989 ATLASSERT(::IsWindow(m_hWnd));
7990 ::SendMessage(m_hWnd, WM_CLEAR, 0, 0L);
7993 void Copy()
7995 ATLASSERT(::IsWindow(m_hWnd));
7996 ::SendMessage(m_hWnd, WM_COPY, 0, 0L);
7999 void Cut()
8001 ATLASSERT(::IsWindow(m_hWnd));
8002 ::SendMessage(m_hWnd, WM_CUT, 0, 0L);
8005 void Paste()
8007 ATLASSERT(::IsWindow(m_hWnd));
8008 ::SendMessage(m_hWnd, WM_PASTE, 0, 0L);
8011 // OLE support
8012 IRichEditOle* GetOleInterface() const
8014 ATLASSERT(::IsWindow(m_hWnd));
8015 IRichEditOle *pRichEditOle = NULL;
8016 ::SendMessage(m_hWnd, EM_GETOLEINTERFACE, 0, (LPARAM)&pRichEditOle);
8017 return pRichEditOle;
8020 BOOL SetOleCallback(IRichEditOleCallback* pCallback)
8022 ATLASSERT(::IsWindow(m_hWnd));
8023 return (BOOL)::SendMessage(m_hWnd, EM_SETOLECALLBACK, 0, (LPARAM)pCallback);
8026 #if (_RICHEDIT_VER >= 0x0200)
8027 BOOL Redo()
8029 ATLASSERT(::IsWindow(m_hWnd));
8030 return (BOOL)::SendMessage(m_hWnd, EM_REDO, 0, 0L);
8033 void StopGroupTyping()
8035 ATLASSERT(::IsWindow(m_hWnd));
8036 ::SendMessage(m_hWnd, EM_STOPGROUPTYPING, 0, 0L);
8039 void ShowScrollBar(int nBarType, BOOL bVisible = TRUE)
8041 ATLASSERT(::IsWindow(m_hWnd));
8042 ::SendMessage(m_hWnd, EM_SHOWSCROLLBAR, nBarType, bVisible);
8044 #endif // (_RICHEDIT_VER >= 0x0200)
8046 #if (_RICHEDIT_VER >= 0x0300)
8047 BOOL SetTabStops(int nTabStops, LPINT rgTabStops)
8049 ATLASSERT(::IsWindow(m_hWnd));
8050 return (BOOL)::SendMessage(m_hWnd, EM_SETTABSTOPS, nTabStops, (LPARAM)rgTabStops);
8053 BOOL SetTabStops()
8055 ATLASSERT(::IsWindow(m_hWnd));
8056 return (BOOL)::SendMessage(m_hWnd, EM_SETTABSTOPS, 0, 0L);
8059 BOOL SetTabStops(const int& cxEachStop) // takes an 'int'
8061 ATLASSERT(::IsWindow(m_hWnd));
8062 return (BOOL)::SendMessage(m_hWnd, EM_SETTABSTOPS, 1, (LPARAM)(LPINT)&cxEachStop);
8064 #endif // (_RICHEDIT_VER >= 0x0300)
8067 typedef CRichEditCtrlT<ATL::CWindow> CRichEditCtrl;
8069 #endif // !_WIN32_WCE
8072 ///////////////////////////////////////////////////////////////////////////////
8073 // CRichEditCommands - message handlers for standard EDIT commands
8075 #ifndef _WIN32_WCE
8077 // Chain to CRichEditCommands message map. Your class must also derive from CRichEditCtrl.
8078 // Example:
8079 // class CMyRichEdit : public CWindowImpl<CMyRichEdit, CRichEditCtrl>,
8080 // public CRichEditCommands<CMyRichEdit>
8081 // {
8082 // public:
8083 // BEGIN_MSG_MAP(CMyRichEdit)
8084 // // your handlers...
8085 // CHAIN_MSG_MAP_ALT(CRichEditCommands<CMyRichEdit>, 1)
8086 // END_MSG_MAP()
8087 // // other stuff...
8088 // };
8090 template <class T>
8091 class CRichEditCommands : public CEditCommands< T >
8093 public:
8094 BEGIN_MSG_MAP(CRichEditCommands< T >)
8095 ALT_MSG_MAP(1)
8096 COMMAND_ID_HANDLER(ID_EDIT_CLEAR, CEditCommands< T >::OnEditClear)
8097 COMMAND_ID_HANDLER(ID_EDIT_CLEAR_ALL, CEditCommands< T >::OnEditClearAll)
8098 COMMAND_ID_HANDLER(ID_EDIT_COPY, CEditCommands< T >::OnEditCopy)
8099 COMMAND_ID_HANDLER(ID_EDIT_CUT, CEditCommands< T >::OnEditCut)
8100 COMMAND_ID_HANDLER(ID_EDIT_PASTE, CEditCommands< T >::OnEditPaste)
8101 COMMAND_ID_HANDLER(ID_EDIT_SELECT_ALL, CEditCommands< T >::OnEditSelectAll)
8102 COMMAND_ID_HANDLER(ID_EDIT_UNDO, CEditCommands< T >::OnEditUndo)
8103 #if (_RICHEDIT_VER >= 0x0200)
8104 COMMAND_ID_HANDLER(ID_EDIT_REDO, OnEditRedo)
8105 #endif // (_RICHEDIT_VER >= 0x0200)
8106 END_MSG_MAP()
8108 #if (_RICHEDIT_VER >= 0x0200)
8109 LRESULT OnEditRedo(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
8111 T* pT = static_cast<T*>(this);
8112 pT->Redo();
8113 return 0;
8115 #endif // (_RICHEDIT_VER >= 0x0200)
8117 // State (update UI) helpers
8118 BOOL CanCut() const
8119 { return HasSelection(); }
8121 BOOL CanCopy() const
8122 { return HasSelection(); }
8124 BOOL CanClear() const
8125 { return HasSelection(); }
8127 // Implementation
8128 BOOL HasSelection() const
8130 const T* pT = static_cast<const T*>(this);
8131 return (pT->GetSelectionType() != SEL_EMPTY);
8135 #endif // _WIN32_WCE
8138 ///////////////////////////////////////////////////////////////////////////////
8139 // CDragListBox
8141 #ifndef _WIN32_WCE
8143 template <class TBase>
8144 class CDragListBoxT : public CListBoxT< TBase >
8146 public:
8147 // Constructors
8148 CDragListBoxT(HWND hWnd = NULL) : CListBoxT< TBase >(hWnd)
8151 CDragListBoxT< TBase >& operator =(HWND hWnd)
8153 m_hWnd = hWnd;
8154 return *this;
8157 HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
8158 DWORD dwStyle = 0, DWORD dwExStyle = 0,
8159 ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
8161 HWND hWnd = TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
8162 if(hWnd != NULL)
8163 MakeDragList();
8164 return hWnd;
8167 // Operations
8168 BOOL MakeDragList()
8170 ATLASSERT(::IsWindow(m_hWnd));
8171 ATLASSERT((GetStyle() & (LBS_MULTIPLESEL | LBS_EXTENDEDSEL)) == 0);
8172 return ::MakeDragList(m_hWnd);
8175 int LBItemFromPt(POINT pt, BOOL bAutoScroll = TRUE)
8177 ATLASSERT(::IsWindow(m_hWnd));
8178 return ::LBItemFromPt(m_hWnd, pt, bAutoScroll);
8181 void DrawInsert(int nItem)
8183 ATLASSERT(::IsWindow(m_hWnd));
8184 ::DrawInsert(GetParent(), m_hWnd, nItem);
8187 static UINT GetDragListMessage()
8189 static UINT uDragListMessage = 0;
8190 if(uDragListMessage == 0)
8192 CStaticDataInitCriticalSectionLock lock;
8193 if(FAILED(lock.Lock()))
8195 ATLTRACE2(atlTraceUI, 0, _T("ERROR : Unable to lock critical section in CDragListBox::GetDragListMessage.\n"));
8196 ATLASSERT(FALSE);
8197 return 0;
8200 if(uDragListMessage == 0)
8201 uDragListMessage = ::RegisterWindowMessage(DRAGLISTMSGSTRING);
8203 lock.Unlock();
8205 ATLASSERT(uDragListMessage != 0);
8206 return uDragListMessage;
8210 typedef CDragListBoxT<ATL::CWindow> CDragListBox;
8212 template <class T>
8213 class CDragListNotifyImpl
8215 public:
8216 BEGIN_MSG_MAP(CDragListNotifyImpl< T >)
8217 MESSAGE_HANDLER(CDragListBox::GetDragListMessage(), OnDragListNotify)
8218 END_MSG_MAP()
8220 LRESULT OnDragListNotify(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
8222 uMsg; // avoid level 4 warning
8223 ATLASSERT(uMsg == CDragListBox::GetDragListMessage());
8224 T* pT = static_cast<T*>(this);
8225 LPDRAGLISTINFO lpDragListInfo = (LPDRAGLISTINFO)lParam;
8226 LRESULT lRet = 0;
8227 switch(lpDragListInfo->uNotification)
8229 case DL_BEGINDRAG:
8230 lRet = (LPARAM)pT->OnBeginDrag((int)wParam, lpDragListInfo->hWnd, lpDragListInfo->ptCursor);
8231 break;
8232 case DL_CANCELDRAG:
8233 pT->OnCancelDrag((int)wParam, lpDragListInfo->hWnd, lpDragListInfo->ptCursor);
8234 break;
8235 case DL_DRAGGING:
8236 lRet = (LPARAM)pT->OnDragging((int)wParam, lpDragListInfo->hWnd, lpDragListInfo->ptCursor);
8237 break;
8238 case DL_DROPPED:
8239 pT->OnDropped((int)wParam, lpDragListInfo->hWnd, lpDragListInfo->ptCursor);
8240 break;
8241 default:
8242 ATLTRACE2(atlTraceUI, 0, _T("Unknown DragListBox notification\n"));
8243 bHandled = FALSE; // don't handle it
8244 break;
8246 return lRet;
8249 // Overrideables
8250 BOOL OnBeginDrag(int /*nCtlID*/, HWND /*hWndDragList*/, POINT /*ptCursor*/)
8252 return TRUE; // allow dragging
8255 void OnCancelDrag(int /*nCtlID*/, HWND /*hWndDragList*/, POINT /*ptCursor*/)
8257 // nothing to do
8260 int OnDragging(int /*nCtlID*/, HWND /*hWndDragList*/, POINT /*ptCursor*/)
8262 return 0; // don't change cursor
8265 void OnDropped(int /*nCtlID*/, HWND /*hWndDragList*/, POINT /*ptCursor*/)
8267 // nothing to do
8271 #endif // _WIN32_WCE
8274 ///////////////////////////////////////////////////////////////////////////////
8275 // CReBarCtrl
8277 template <class TBase>
8278 class CReBarCtrlT : public TBase
8280 public:
8281 // Constructors
8282 CReBarCtrlT(HWND hWnd = NULL) : TBase(hWnd)
8285 CReBarCtrlT< TBase >& operator =(HWND hWnd)
8287 m_hWnd = hWnd;
8288 return *this;
8291 HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
8292 DWORD dwStyle = 0, DWORD dwExStyle = 0,
8293 ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
8295 return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
8298 // Attributes
8299 static LPCTSTR GetWndClassName()
8301 return REBARCLASSNAME;
8304 UINT GetBandCount() const
8306 ATLASSERT(::IsWindow(m_hWnd));
8307 return (UINT)::SendMessage(m_hWnd, RB_GETBANDCOUNT, 0, 0L);
8310 BOOL GetBandInfo(int nBand, LPREBARBANDINFO lprbbi) const
8312 ATLASSERT(::IsWindow(m_hWnd));
8313 return (BOOL)::SendMessage(m_hWnd, RB_GETBANDINFO, nBand, (LPARAM)lprbbi);
8316 BOOL SetBandInfo(int nBand, LPREBARBANDINFO lprbbi)
8318 ATLASSERT(::IsWindow(m_hWnd));
8319 return (BOOL)::SendMessage(m_hWnd, RB_SETBANDINFO, nBand, (LPARAM)lprbbi);
8322 BOOL GetBarInfo(LPREBARINFO lprbi) const
8324 ATLASSERT(::IsWindow(m_hWnd));
8325 return (BOOL)::SendMessage(m_hWnd, RB_GETBARINFO, 0, (LPARAM)lprbi);
8328 BOOL SetBarInfo(LPREBARINFO lprbi)
8330 ATLASSERT(::IsWindow(m_hWnd));
8331 return (BOOL)::SendMessage(m_hWnd, RB_SETBARINFO, 0, (LPARAM)lprbi);
8334 CImageList GetImageList() const
8336 ATLASSERT(::IsWindow(m_hWnd));
8337 REBARINFO rbi = { 0 };
8338 rbi.cbSize = sizeof(REBARINFO);
8339 rbi.fMask = RBIM_IMAGELIST;
8340 if( (BOOL)::SendMessage(m_hWnd, RB_GETBARINFO, 0, (LPARAM)&rbi) == FALSE ) return CImageList();
8341 return CImageList(rbi.himl);
8344 BOOL SetImageList(HIMAGELIST hImageList)
8346 ATLASSERT(::IsWindow(m_hWnd));
8347 REBARINFO rbi = { 0 };
8348 rbi.cbSize = sizeof(REBARINFO);
8349 rbi.fMask = RBIM_IMAGELIST;
8350 rbi.himl = hImageList;
8351 return (BOOL)::SendMessage(m_hWnd, RB_SETBARINFO, 0, (LPARAM)&rbi);
8354 UINT GetRowCount() const
8356 ATLASSERT(::IsWindow(m_hWnd));
8357 return (UINT)::SendMessage(m_hWnd, RB_GETROWCOUNT, 0, 0L);
8360 UINT GetRowHeight(int nBand) const
8362 ATLASSERT(::IsWindow(m_hWnd));
8363 return (UINT)::SendMessage(m_hWnd, RB_GETROWHEIGHT, nBand, 0L);
8366 #if (_WIN32_IE >= 0x0400)
8367 COLORREF GetTextColor() const
8369 ATLASSERT(::IsWindow(m_hWnd));
8370 return (COLORREF)::SendMessage(m_hWnd, RB_GETTEXTCOLOR, 0, 0L);
8373 COLORREF SetTextColor(COLORREF clr)
8375 ATLASSERT(::IsWindow(m_hWnd));
8376 return (COLORREF)::SendMessage(m_hWnd, RB_SETTEXTCOLOR, 0, (LPARAM)clr);
8379 COLORREF GetBkColor() const
8381 ATLASSERT(::IsWindow(m_hWnd));
8382 return (COLORREF)::SendMessage(m_hWnd, RB_GETBKCOLOR, 0, 0L);
8385 COLORREF SetBkColor(COLORREF clr)
8387 ATLASSERT(::IsWindow(m_hWnd));
8388 return (COLORREF)::SendMessage(m_hWnd, RB_SETBKCOLOR, 0, (LPARAM)clr);
8391 UINT GetBarHeight() const
8393 ATLASSERT(::IsWindow(m_hWnd));
8394 return (UINT)::SendMessage(m_hWnd, RB_GETBARHEIGHT, 0, 0L);
8397 BOOL GetRect(int nBand, LPRECT lpRect) const
8399 ATLASSERT(::IsWindow(m_hWnd));
8400 return (BOOL)::SendMessage(m_hWnd, RB_GETRECT, nBand, (LPARAM)lpRect);
8403 #ifndef _WIN32_WCE
8404 CToolTipCtrl GetToolTips() const
8406 ATLASSERT(::IsWindow(m_hWnd));
8407 return CToolTipCtrl((HWND)::SendMessage(m_hWnd, RB_GETTOOLTIPS, 0, 0L));
8410 void SetToolTips(HWND hwndToolTip)
8412 ATLASSERT(::IsWindow(m_hWnd));
8413 ::SendMessage(m_hWnd, RB_SETTOOLTIPS, (WPARAM)hwndToolTip, 0L);
8415 #endif // !_WIN32_WCE
8417 void GetBandBorders(int nBand, LPRECT lpRect) const
8419 ATLASSERT(::IsWindow(m_hWnd));
8420 ATLASSERT(lpRect != NULL);
8421 ::SendMessage(m_hWnd, RB_GETBANDBORDERS, nBand, (LPARAM)lpRect);
8424 #ifndef _WIN32_WCE
8425 BOOL GetColorScheme(LPCOLORSCHEME lpColorScheme) const
8427 ATLASSERT(::IsWindow(m_hWnd));
8428 ATLASSERT(lpColorScheme != NULL);
8429 return (BOOL)::SendMessage(m_hWnd, RB_GETCOLORSCHEME, 0, (LPARAM)lpColorScheme);
8432 void SetColorScheme(LPCOLORSCHEME lpColorScheme)
8434 ATLASSERT(::IsWindow(m_hWnd));
8435 ATLASSERT(lpColorScheme != NULL);
8436 ::SendMessage(m_hWnd, RB_SETCOLORSCHEME, 0, (LPARAM)lpColorScheme);
8439 HPALETTE GetPalette() const
8441 ATLASSERT(::IsWindow(m_hWnd));
8442 return (HPALETTE)::SendMessage(m_hWnd, RB_GETPALETTE, 0, 0L);
8445 HPALETTE SetPalette(HPALETTE hPalette)
8447 ATLASSERT(::IsWindow(m_hWnd));
8448 return (HPALETTE)::SendMessage(m_hWnd, RB_SETPALETTE, 0, (LPARAM)hPalette);
8451 BOOL GetUnicodeFormat() const
8453 ATLASSERT(::IsWindow(m_hWnd));
8454 return (BOOL)::SendMessage(m_hWnd, RB_GETUNICODEFORMAT, 0, 0L);
8457 BOOL SetUnicodeFormat(BOOL bUnicode = TRUE)
8459 ATLASSERT(::IsWindow(m_hWnd));
8460 return (BOOL)::SendMessage(m_hWnd, RB_SETUNICODEFORMAT, bUnicode, 0L);
8462 #endif // !_WIN32_WCE
8463 #endif // (_WIN32_IE >= 0x0400)
8465 #if (_WIN32_WINNT >= 0x0501)
8466 // requires uxtheme.h to be included to use MARGINS struct
8467 #ifndef _UXTHEME_H_
8468 typedef struct _MARGINS* PMARGINS;
8469 #endif // !_UXTHEME_H_
8470 void GetBandMargins(PMARGINS pMargins) const
8472 ATLASSERT(::IsWindow(m_hWnd));
8473 ::SendMessage(m_hWnd, RB_GETBANDMARGINS, 0, (LPARAM)pMargins);
8476 void SetWindowTheme(LPCWSTR lpstrTheme)
8478 ATLASSERT(::IsWindow(m_hWnd));
8479 ::SendMessage(m_hWnd, RB_SETWINDOWTHEME, 0, (LPARAM)lpstrTheme);
8481 #endif // (_WIN32_WINNT >= 0x0501)
8483 #if (_WIN32_IE >= 0x0600)
8484 DWORD GetExtendedStyle() const
8486 ATLASSERT(::IsWindow(m_hWnd));
8487 return (DWORD)::SendMessage(m_hWnd, RB_GETEXTENDEDSTYLE, 0, 0L);
8490 DWORD SetExtendedStyle(DWORD dwStyle, DWORD dwMask)
8492 ATLASSERT(::IsWindow(m_hWnd));
8493 return (DWORD)::SendMessage(m_hWnd, RB_SETEXTENDEDSTYLE, dwMask, dwStyle);
8495 #endif // (_WIN32_IE >= 0x0600)
8497 // Operations
8498 BOOL InsertBand(int nBand, LPREBARBANDINFO lprbbi)
8500 ATLASSERT(::IsWindow(m_hWnd));
8501 return (BOOL)::SendMessage(m_hWnd, RB_INSERTBAND, nBand, (LPARAM)lprbbi);
8504 BOOL AddBand(LPREBARBANDINFO lprbbi)
8506 return InsertBand(-1, lprbbi);
8509 BOOL DeleteBand(int nBand)
8511 ATLASSERT(::IsWindow(m_hWnd));
8512 return (BOOL)::SendMessage(m_hWnd, RB_DELETEBAND, nBand, 0L);
8515 ATL::CWindow SetNotifyWnd(HWND hWnd)
8517 ATLASSERT(::IsWindow(m_hWnd));
8518 return ATL::CWindow((HWND)::SendMessage(m_hWnd, RB_SETPARENT, (WPARAM)hWnd, 0L));
8521 #if (_WIN32_IE >= 0x0400)
8522 void BeginDrag(int nBand, DWORD dwPos)
8524 ATLASSERT(::IsWindow(m_hWnd));
8525 ::SendMessage(m_hWnd, RB_BEGINDRAG, nBand, dwPos);
8528 void BeginDrag(int nBand, int xPos, int yPos)
8530 ATLASSERT(::IsWindow(m_hWnd));
8531 ::SendMessage(m_hWnd, RB_BEGINDRAG, nBand, MAKELPARAM(xPos, yPos));
8534 void EndDrag()
8536 ATLASSERT(::IsWindow(m_hWnd));
8537 ::SendMessage(m_hWnd, RB_ENDDRAG, 0, 0L);
8540 void DragMove(DWORD dwPos)
8542 ATLASSERT(::IsWindow(m_hWnd));
8543 ::SendMessage(m_hWnd, RB_DRAGMOVE, 0, dwPos);
8546 void DragMove(int xPos, int yPos)
8548 ATLASSERT(::IsWindow(m_hWnd));
8549 ::SendMessage(m_hWnd, RB_DRAGMOVE, 0, MAKELPARAM(xPos, yPos));
8552 #ifndef _WIN32_WCE
8553 void GetDropTarget(IDropTarget** ppDropTarget) const
8555 ATLASSERT(::IsWindow(m_hWnd));
8556 ::SendMessage(m_hWnd, RB_GETDROPTARGET, 0, (LPARAM)ppDropTarget);
8558 #endif // !_WIN32_WCE
8560 void MaximizeBand(int nBand, BOOL bIdeal = FALSE)
8562 ATLASSERT(::IsWindow(m_hWnd));
8563 ::SendMessage(m_hWnd, RB_MAXIMIZEBAND, nBand, bIdeal);
8566 void MinimizeBand(int nBand)
8568 ATLASSERT(::IsWindow(m_hWnd));
8569 ::SendMessage(m_hWnd, RB_MINIMIZEBAND, nBand, 0L);
8572 BOOL SizeToRect(LPRECT lpRect)
8574 ATLASSERT(::IsWindow(m_hWnd));
8575 return (BOOL)::SendMessage(m_hWnd, RB_SIZETORECT, 0, (LPARAM)lpRect);
8578 int IdToIndex(UINT uBandID) const
8580 ATLASSERT(::IsWindow(m_hWnd));
8581 return (int)::SendMessage(m_hWnd, RB_IDTOINDEX, uBandID, 0L);
8584 int HitTest(LPRBHITTESTINFO lprbht) const
8586 ATLASSERT(::IsWindow(m_hWnd));
8587 return (int)::SendMessage(m_hWnd, RB_HITTEST, 0, (LPARAM)lprbht);
8590 BOOL ShowBand(int nBand, BOOL bShow)
8592 ATLASSERT(::IsWindow(m_hWnd));
8593 return (BOOL)::SendMessage(m_hWnd, RB_SHOWBAND, nBand, bShow);
8596 #ifndef _WIN32_WCE
8597 BOOL MoveBand(int nBand, int nNewPos)
8599 ATLASSERT(::IsWindow(m_hWnd));
8600 ATLASSERT(nNewPos >= 0 && nNewPos <= ((int)GetBandCount() - 1));
8601 return (BOOL)::SendMessage(m_hWnd, RB_MOVEBAND, nBand, nNewPos);
8603 #endif // !_WIN32_WCE
8604 #endif // (_WIN32_IE >= 0x0400)
8606 #if (_WIN32_IE >= 0x0500) && !defined(_WIN32_WCE)
8607 void PushChevron(int nBand, LPARAM lAppValue)
8609 ATLASSERT(::IsWindow(m_hWnd));
8610 ::SendMessage(m_hWnd, RB_PUSHCHEVRON, nBand, lAppValue);
8612 #endif // (_WIN32_IE >= 0x0500) && !defined(_WIN32_WCE)
8614 // Extra operations
8615 #if (_WIN32_IE >= 0x0400)
8616 void LockBands(bool bLock)
8618 int nBandCount = GetBandCount();
8619 for(int i =0; i < nBandCount; i++)
8621 REBARBANDINFO rbbi = { RunTimeHelper::SizeOf_REBARBANDINFO() };
8622 rbbi.fMask = RBBIM_STYLE;
8623 BOOL bRet = GetBandInfo(i, &rbbi);
8624 ATLASSERT(bRet);
8626 if((rbbi.fStyle & RBBS_GRIPPERALWAYS) == 0)
8628 rbbi.fStyle |= RBBS_GRIPPERALWAYS;
8629 bRet = SetBandInfo(i, &rbbi);
8630 ATLASSERT(bRet);
8631 rbbi.fStyle &= ~RBBS_GRIPPERALWAYS;
8634 if(bLock)
8635 rbbi.fStyle |= RBBS_NOGRIPPER;
8636 else
8637 rbbi.fStyle &= ~RBBS_NOGRIPPER;
8639 bRet = SetBandInfo(i, &rbbi);
8640 ATLASSERT(bRet);
8643 #endif // (_WIN32_IE >= 0x0400)
8645 #if (_WIN32_WINNT >= 0x0600)
8646 BOOL SetBandWidth(int nBand, int cxWidth)
8648 ATLASSERT(::IsWindow(m_hWnd));
8649 return (BOOL)::SendMessage(m_hWnd, RB_SETBANDWIDTH, nBand, cxWidth);
8651 #endif // (_WIN32_WINNT >= 0x0600)
8654 typedef CReBarCtrlT<ATL::CWindow> CReBarCtrl;
8657 ///////////////////////////////////////////////////////////////////////////////
8658 // CComboBoxEx
8660 #ifndef _WIN32_WCE
8662 template <class TBase>
8663 class CComboBoxExT : public CComboBoxT< TBase >
8665 public:
8666 // Constructors
8667 CComboBoxExT(HWND hWnd = NULL) : CComboBoxT< TBase >(hWnd)
8670 CComboBoxExT< TBase >& operator =(HWND hWnd)
8672 m_hWnd = hWnd;
8673 return *this;
8676 HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
8677 DWORD dwStyle = 0, DWORD dwExStyle = 0,
8678 ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
8680 return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
8683 // Attributes
8684 static LPCTSTR GetWndClassName()
8686 return WC_COMBOBOXEX;
8689 CImageList GetImageList() const
8691 ATLASSERT(::IsWindow(m_hWnd));
8692 return CImageList((HIMAGELIST)::SendMessage(m_hWnd, CBEM_GETIMAGELIST, 0, 0L));
8695 CImageList SetImageList(HIMAGELIST hImageList)
8697 ATLASSERT(::IsWindow(m_hWnd));
8698 return CImageList((HIMAGELIST)::SendMessage(m_hWnd, CBEM_SETIMAGELIST, 0, (LPARAM)hImageList));
8701 #if (_WIN32_IE >= 0x0400)
8702 DWORD GetExtendedStyle() const
8704 ATLASSERT(::IsWindow(m_hWnd));
8705 return (DWORD)::SendMessage(m_hWnd, CBEM_GETEXTENDEDSTYLE, 0, 0L);
8708 DWORD SetExtendedStyle(DWORD dwExMask, DWORD dwExStyle)
8710 ATLASSERT(::IsWindow(m_hWnd));
8711 return (DWORD)::SendMessage(m_hWnd, CBEM_SETEXTENDEDSTYLE, dwExMask, dwExStyle);
8714 BOOL GetUnicodeFormat() const
8716 ATLASSERT(::IsWindow(m_hWnd));
8717 return (BOOL)::SendMessage(m_hWnd, CBEM_GETUNICODEFORMAT, 0, 0L);
8720 BOOL SetUnicodeFormat(BOOL bUnicode = TRUE)
8722 ATLASSERT(::IsWindow(m_hWnd));
8723 return (BOOL)::SendMessage(m_hWnd, CBEM_SETUNICODEFORMAT, bUnicode, 0L);
8725 #endif // (_WIN32_IE >= 0x0400)
8727 #if (_WIN32_WINNT >= 0x0501)
8728 void SetWindowTheme(LPCWSTR lpstrTheme)
8730 ATLASSERT(::IsWindow(m_hWnd));
8731 ::SendMessage(m_hWnd, CBEM_SETWINDOWTHEME, 0, (LPARAM)lpstrTheme);
8733 #endif // (_WIN32_WINNT >= 0x0501)
8735 // Operations
8736 int InsertItem(const COMBOBOXEXITEM* lpcCBItem)
8738 ATLASSERT(::IsWindow(m_hWnd));
8739 return (int)::SendMessage(m_hWnd, CBEM_INSERTITEM, 0, (LPARAM)lpcCBItem);
8742 int InsertItem(UINT nMask, int nIndex, LPCTSTR lpszItem, int nImage, int nSelImage,
8743 int iIndent, int iOverlay, LPARAM lParam)
8745 ATLASSERT(::IsWindow(m_hWnd));
8746 COMBOBOXEXITEM cbex = { 0 };
8747 cbex.mask = nMask;
8748 cbex.iItem = nIndex;
8749 cbex.pszText = (LPTSTR) lpszItem;
8750 cbex.iImage = nImage;
8751 cbex.iSelectedImage = nSelImage;
8752 cbex.iIndent = iIndent;
8753 cbex.iOverlay = iOverlay;
8754 cbex.lParam = lParam;
8755 return (int)::SendMessage(m_hWnd, CBEM_INSERTITEM, 0, (LPARAM)&cbex);
8758 int InsertItem(int nIndex, LPCTSTR lpszItem, int nImage, int nSelImage, int iIndent, LPARAM lParam = 0)
8760 ATLASSERT(::IsWindow(m_hWnd));
8761 COMBOBOXEXITEM cbex = { 0 };
8762 cbex.mask = CBEIF_TEXT | CBEIF_IMAGE | CBEIF_SELECTEDIMAGE | CBEIF_INDENT | CBEIF_LPARAM;
8763 cbex.iItem = nIndex;
8764 cbex.pszText = (LPTSTR) lpszItem;
8765 cbex.iImage = nImage;
8766 cbex.iSelectedImage = nSelImage;
8767 cbex.iIndent = iIndent;
8768 cbex.lParam = lParam;
8769 return (int)::SendMessage(m_hWnd, CBEM_INSERTITEM, 0, (LPARAM)&cbex);
8772 int AddItem(UINT nMask, LPCTSTR lpszItem, int nImage, int nSelImage, int iIndent, int iOverlay, LPARAM lParam)
8774 return InsertItem(nMask, -1, lpszItem, nImage, nSelImage, iIndent, iOverlay, lParam);
8777 int AddItem(LPCTSTR lpszItem, int nImage, int nSelImage, int iIndent, LPARAM lParam = 0)
8779 return InsertItem(-1, lpszItem, nImage, nSelImage, iIndent, lParam);
8782 int DeleteItem(int nIndex)
8784 ATLASSERT(::IsWindow(m_hWnd));
8785 return (int)::SendMessage(m_hWnd, CBEM_DELETEITEM, nIndex, 0L);
8788 BOOL GetItem(PCOMBOBOXEXITEM pCBItem) const
8790 ATLASSERT(::IsWindow(m_hWnd));
8791 return (BOOL)::SendMessage(m_hWnd, CBEM_GETITEM, 0, (LPARAM)pCBItem);
8794 BOOL SetItem(const COMBOBOXEXITEM* lpcCBItem)
8796 ATLASSERT(::IsWindow(m_hWnd));
8797 return (BOOL)::SendMessage(m_hWnd, CBEM_SETITEM, 0, (LPARAM)lpcCBItem);
8800 int SetItem(int nIndex, UINT nMask, LPCTSTR lpszItem, int nImage, int nSelImage,
8801 int iIndent, int iOverlay, LPARAM lParam)
8803 ATLASSERT(::IsWindow(m_hWnd));
8804 COMBOBOXEXITEM cbex = { 0 };
8805 cbex.mask = nMask;
8806 cbex.iItem = nIndex;
8807 cbex.pszText = (LPTSTR) lpszItem;
8808 cbex.iImage = nImage;
8809 cbex.iSelectedImage = nSelImage;
8810 cbex.iIndent = iIndent;
8811 cbex.iOverlay = iOverlay;
8812 cbex.lParam = lParam;
8813 return (int)::SendMessage(m_hWnd, CBEM_SETITEM, 0, (LPARAM)&cbex);
8816 BOOL GetItemText(int nIndex, LPTSTR lpszItem, int nLen) const
8818 ATLASSERT(::IsWindow(m_hWnd));
8819 ATLASSERT(lpszItem != NULL);
8821 COMBOBOXEXITEM cbex = { 0 };
8822 cbex.mask = CBEIF_TEXT;
8823 cbex.iItem = nIndex;
8824 cbex.pszText = lpszItem;
8825 cbex.cchTextMax = nLen;
8827 return (BOOL)::SendMessage(m_hWnd, CBEM_GETITEM, 0, (LPARAM)&cbex);
8830 #ifndef _ATL_NO_COM
8831 BOOL GetItemText(int nIndex, BSTR& bstrText) const
8833 USES_CONVERSION;
8834 ATLASSERT(::IsWindow(m_hWnd));
8835 ATLASSERT(bstrText == NULL);
8837 COMBOBOXEXITEM cbex = { 0 };
8838 cbex.mask = CBEIF_TEXT;
8839 cbex.iItem = nIndex;
8841 LPTSTR lpstrText = NULL;
8842 BOOL bRet = FALSE;
8843 for(int nLen = 256; ; nLen *= 2)
8845 ATLTRY(lpstrText = new TCHAR[nLen]);
8846 if(lpstrText == NULL)
8847 break;
8848 lpstrText[0] = NULL;
8849 cbex.pszText = lpstrText;
8850 cbex.cchTextMax = nLen;
8851 bRet = (BOOL)::SendMessage(m_hWnd, CBEM_GETITEM, 0, (LPARAM)&cbex);
8852 if(!bRet || (lstrlen(cbex.pszText) < nLen - 1))
8853 break;
8854 delete [] lpstrText;
8855 lpstrText = NULL;
8858 if(lpstrText != NULL)
8860 if(bRet)
8861 bstrText = ::SysAllocString(T2OLE(lpstrText));
8862 delete [] lpstrText;
8865 return (bstrText != NULL) ? TRUE : FALSE;
8867 #endif // !_ATL_NO_COM
8869 #if defined(_WTL_USE_CSTRING) || defined(__ATLSTR_H__)
8870 BOOL GetItemText(int nIndex, _CSTRING_NS::CString& strText) const
8872 ATLASSERT(::IsWindow(m_hWnd));
8874 COMBOBOXEXITEM cbex = { 0 };
8875 cbex.mask = CBEIF_TEXT;
8876 cbex.iItem = nIndex;
8878 strText.Empty();
8879 BOOL bRet = FALSE;
8880 for(int nLen = 256; ; nLen *= 2)
8882 cbex.pszText = strText.GetBufferSetLength(nLen);
8883 if(cbex.pszText == NULL)
8885 bRet = FALSE;
8886 break;
8888 cbex.cchTextMax = nLen;
8889 bRet = (BOOL)::SendMessage(m_hWnd, CBEM_GETITEM, 0, (LPARAM)&cbex);
8890 if(!bRet || (lstrlen(cbex.pszText) < nLen - 1))
8891 break;
8893 strText.ReleaseBuffer();
8894 return bRet;
8896 #endif // defined(_WTL_USE_CSTRING) || defined(__ATLSTR_H__)
8898 BOOL SetItemText(int nIndex, LPCTSTR lpszItem)
8900 ATLASSERT(::IsWindow(m_hWnd));
8901 return SetItem(nIndex, CBEIF_TEXT, lpszItem, 0, 0, 0, 0, 0);
8904 CComboBox GetComboCtrl() const
8906 ATLASSERT(::IsWindow(m_hWnd));
8907 return CComboBox((HWND)::SendMessage(m_hWnd, CBEM_GETCOMBOCONTROL, 0, 0L));
8910 CEdit GetEditCtrl() const
8912 ATLASSERT(::IsWindow(m_hWnd));
8913 return CEdit((HWND)::SendMessage(m_hWnd, CBEM_GETEDITCONTROL, 0, 0L));
8916 BOOL HasEditChanged() const
8918 ATLASSERT(::IsWindow(m_hWnd));
8919 return (BOOL)::SendMessage(m_hWnd, CBEM_HASEDITCHANGED, 0, 0L);
8922 // Non-functional
8923 int AddString(LPCTSTR /*lpszItem*/)
8925 ATLASSERT(FALSE); // Not available in CComboBoxEx; use InsertItem
8926 return 0;
8929 int InsertString(int /*nIndex*/, LPCTSTR /*lpszString*/)
8931 ATLASSERT(FALSE); // Not available in CComboBoxEx; use InsertItem
8932 return 0;
8935 int Dir(UINT /*attr*/, LPCTSTR /*lpszWildCard*/)
8937 ATLASSERT(FALSE); // Not available in CComboBoxEx
8938 return 0;
8941 int FindString(int /*nStartAfter*/, LPCTSTR /*lpszString*/) const
8943 ATLASSERT(FALSE); // Not available in CComboBoxEx; try FindStringExact
8944 return 0;
8948 typedef CComboBoxExT<ATL::CWindow> CComboBoxEx;
8950 #endif // !_WIN32_WCE
8953 ///////////////////////////////////////////////////////////////////////////////
8954 // CMonthCalendarCtrl
8956 template <class TBase>
8957 class CMonthCalendarCtrlT : public TBase
8959 public:
8960 // Constructors
8961 CMonthCalendarCtrlT(HWND hWnd = NULL) : TBase(hWnd)
8964 CMonthCalendarCtrlT< TBase >& operator =(HWND hWnd)
8966 m_hWnd = hWnd;
8967 return *this;
8970 HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
8971 DWORD dwStyle = 0, DWORD dwExStyle = 0,
8972 ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
8974 return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
8977 // Attributes
8978 static LPCTSTR GetWndClassName()
8980 return MONTHCAL_CLASS;
8983 COLORREF GetColor(int nColorType) const
8985 ATLASSERT(::IsWindow(m_hWnd));
8986 return (COLORREF)::SendMessage(m_hWnd, MCM_GETCOLOR, nColorType, 0L);
8989 COLORREF SetColor(int nColorType, COLORREF clr)
8991 ATLASSERT(::IsWindow(m_hWnd));
8992 return (COLORREF)::SendMessage(m_hWnd, MCM_SETCOLOR, nColorType, clr);
8995 BOOL GetCurSel(LPSYSTEMTIME lpSysTime) const
8997 ATLASSERT(::IsWindow(m_hWnd));
8998 return (BOOL)::SendMessage(m_hWnd, MCM_GETCURSEL, 0, (LPARAM)lpSysTime);
9001 BOOL SetCurSel(LPSYSTEMTIME lpSysTime)
9003 ATLASSERT(::IsWindow(m_hWnd));
9004 return (BOOL)::SendMessage(m_hWnd, MCM_SETCURSEL, 0, (LPARAM)lpSysTime);
9007 int GetFirstDayOfWeek(BOOL* pbLocaleVal = NULL) const
9009 ATLASSERT(::IsWindow(m_hWnd));
9010 DWORD dwRet = (DWORD)::SendMessage(m_hWnd, MCM_GETFIRSTDAYOFWEEK, 0, 0L);
9011 if(pbLocaleVal != NULL)
9012 *pbLocaleVal = (BOOL)HIWORD(dwRet);
9013 return (int)(short)LOWORD(dwRet);
9016 int SetFirstDayOfWeek(int nDay, BOOL* pbLocaleVal = NULL)
9018 ATLASSERT(::IsWindow(m_hWnd));
9019 DWORD dwRet = (DWORD)::SendMessage(m_hWnd, MCM_SETFIRSTDAYOFWEEK, 0, nDay);
9020 if(pbLocaleVal != NULL)
9021 *pbLocaleVal = (BOOL)HIWORD(dwRet);
9022 return (int)(short)LOWORD(dwRet);
9025 int GetMaxSelCount() const
9027 ATLASSERT(::IsWindow(m_hWnd));
9028 return (int)::SendMessage(m_hWnd, MCM_GETMAXSELCOUNT, 0, 0L);
9031 BOOL SetMaxSelCount(int nMax)
9033 ATLASSERT(::IsWindow(m_hWnd));
9034 return (BOOL)::SendMessage(m_hWnd, MCM_SETMAXSELCOUNT, nMax, 0L);
9037 int GetMonthDelta() const
9039 ATLASSERT(::IsWindow(m_hWnd));
9040 return (int)::SendMessage(m_hWnd, MCM_GETMONTHDELTA, 0, 0L);
9043 int SetMonthDelta(int nDelta)
9045 ATLASSERT(::IsWindow(m_hWnd));
9046 return (int)::SendMessage(m_hWnd, MCM_SETMONTHDELTA, nDelta, 0L);
9049 DWORD GetRange(LPSYSTEMTIME lprgSysTimeArray) const
9051 ATLASSERT(::IsWindow(m_hWnd));
9052 return (DWORD)::SendMessage(m_hWnd, MCM_GETRANGE, 0, (LPARAM)lprgSysTimeArray);
9055 BOOL SetRange(DWORD dwFlags, LPSYSTEMTIME lprgSysTimeArray)
9057 ATLASSERT(::IsWindow(m_hWnd));
9058 return (BOOL)::SendMessage(m_hWnd, MCM_SETRANGE, dwFlags, (LPARAM)lprgSysTimeArray);
9061 BOOL GetSelRange(LPSYSTEMTIME lprgSysTimeArray) const
9063 ATLASSERT(::IsWindow(m_hWnd));
9064 return (BOOL)::SendMessage(m_hWnd, MCM_GETSELRANGE, 0, (LPARAM)lprgSysTimeArray);
9067 BOOL SetSelRange(LPSYSTEMTIME lprgSysTimeArray)
9069 ATLASSERT(::IsWindow(m_hWnd));
9070 return (BOOL)::SendMessage(m_hWnd, MCM_SETSELRANGE, 0, (LPARAM)lprgSysTimeArray);
9073 BOOL GetToday(LPSYSTEMTIME lpSysTime) const
9075 ATLASSERT(::IsWindow(m_hWnd));
9076 return (BOOL)::SendMessage(m_hWnd, MCM_GETTODAY, 0, (LPARAM)lpSysTime);
9079 void SetToday(LPSYSTEMTIME lpSysTime)
9081 ATLASSERT(::IsWindow(m_hWnd));
9082 ::SendMessage(m_hWnd, MCM_SETTODAY, 0, (LPARAM)lpSysTime);
9085 BOOL GetMinReqRect(LPRECT lpRectInfo) const
9087 ATLASSERT(::IsWindow(m_hWnd));
9088 return (BOOL)::SendMessage(m_hWnd, MCM_GETMINREQRECT, 0, (LPARAM)lpRectInfo);
9091 int GetMaxTodayWidth() const
9093 ATLASSERT(::IsWindow(m_hWnd));
9094 return (int)::SendMessage(m_hWnd, MCM_GETMAXTODAYWIDTH, 0, 0L);
9097 #if (_WIN32_IE >= 0x0400) && !defined(_WIN32_WCE)
9098 BOOL GetUnicodeFormat() const
9100 ATLASSERT(::IsWindow(m_hWnd));
9101 return (BOOL)::SendMessage(m_hWnd, MCM_GETUNICODEFORMAT, 0, 0L);
9104 BOOL SetUnicodeFormat(BOOL bUnicode = TRUE)
9106 ATLASSERT(::IsWindow(m_hWnd));
9107 return (BOOL)::SendMessage(m_hWnd, MCM_SETUNICODEFORMAT, bUnicode, 0L);
9109 #endif // (_WIN32_IE >= 0x0400) && !defined(_WIN32_WCE)
9111 #if defined(NTDDI_VERSION) && (NTDDI_VERSION >= NTDDI_LONGHORN)
9112 DWORD GetCurrentView() const
9114 ATLASSERT(::IsWindow(m_hWnd));
9115 return (DWORD)::SendMessage(m_hWnd, MCM_GETCURRENTVIEW, 0, 0L);
9118 BOOL SetCurrentView(DWORD dwView)
9120 ATLASSERT(::IsWindow(m_hWnd));
9121 return (BOOL)::SendMessage(m_hWnd, MCM_SETCURRENTVIEW, 0, dwView);
9124 DWORD GetCalendarCount() const
9126 ATLASSERT(::IsWindow(m_hWnd));
9127 return (DWORD)::SendMessage(m_hWnd, MCM_GETCALENDARCOUNT, 0, 0L);
9130 BOOL GetCalendarGridInfo(PMCGRIDINFO pGridInfo) const
9132 ATLASSERT(::IsWindow(m_hWnd));
9133 return (BOOL)::SendMessage(m_hWnd, MCM_GETCALENDARGRIDINFO, 0, (LPARAM)pGridInfo);
9136 CALID GetCALID() const
9138 ATLASSERT(::IsWindow(m_hWnd));
9139 return (CALID)::SendMessage(m_hWnd, MCM_GETCALID, 0, 0L);
9142 void SetCALID(CALID calid)
9144 ATLASSERT(::IsWindow(m_hWnd));
9145 ::SendMessage(m_hWnd, MCM_SETCALID, (LPARAM)calid, 0L);
9148 int GetCalendarBorder() const
9150 ATLASSERT(::IsWindow(m_hWnd));
9151 return (int)::SendMessage(m_hWnd, MCM_GETCALENDARBORDER, 0, 0L);
9154 void SetCalendarBorder(int cxyBorder, BOOL bSet = TRUE)
9156 ATLASSERT(::IsWindow(m_hWnd));
9157 ::SendMessage(m_hWnd, MCM_SETCALENDARBORDER, (WPARAM)bSet, (LPARAM)cxyBorder);
9159 #endif // defined(NTDDI_VERSION) && (NTDDI_VERSION >= NTDDI_LONGHORN)
9161 // Operations
9162 int GetMonthRange(DWORD dwFlags, LPSYSTEMTIME lprgSysTimeArray) const
9164 ATLASSERT(::IsWindow(m_hWnd));
9165 return (int)::SendMessage(m_hWnd, MCM_GETMONTHRANGE, dwFlags, (LPARAM)lprgSysTimeArray);
9168 BOOL SetDayState(int nMonths, LPMONTHDAYSTATE lpDayStateArray)
9170 ATLASSERT(::IsWindow(m_hWnd));
9171 return (BOOL)::SendMessage(m_hWnd, MCM_SETDAYSTATE, nMonths, (LPARAM)lpDayStateArray);
9174 DWORD HitTest(PMCHITTESTINFO pMCHitTest) const
9176 ATLASSERT(::IsWindow(m_hWnd));
9177 return (DWORD)::SendMessage(m_hWnd, MCM_HITTEST, 0, (LPARAM)pMCHitTest);
9180 #if defined(NTDDI_VERSION) && (NTDDI_VERSION >= NTDDI_LONGHORN)
9181 void SizeRectToMin(LPRECT lpRect)
9183 ATLASSERT(::IsWindow(m_hWnd));
9184 ::SendMessage(m_hWnd, MCM_SIZERECTTOMIN, 0, (LPARAM)lpRect);
9186 #endif // defined(NTDDI_VERSION) && (NTDDI_VERSION >= NTDDI_LONGHORN)
9189 typedef CMonthCalendarCtrlT<ATL::CWindow> CMonthCalendarCtrl;
9192 ///////////////////////////////////////////////////////////////////////////////
9193 // CDateTimePickerCtrl
9195 template <class TBase>
9196 class CDateTimePickerCtrlT : public TBase
9198 public:
9199 // Constructors
9200 CDateTimePickerCtrlT(HWND hWnd = NULL) : TBase(hWnd)
9203 CDateTimePickerCtrlT< TBase >& operator =(HWND hWnd)
9205 m_hWnd = hWnd;
9206 return *this;
9209 HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
9210 DWORD dwStyle = 0, DWORD dwExStyle = 0,
9211 ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
9213 return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
9216 // Operations
9217 static LPCTSTR GetWndClassName()
9219 return DATETIMEPICK_CLASS;
9222 BOOL SetFormat(LPCTSTR lpszFormat)
9224 ATLASSERT(::IsWindow(m_hWnd));
9225 return (BOOL)::SendMessage(m_hWnd, DTM_SETFORMAT, 0, (LPARAM)lpszFormat);
9228 COLORREF GetMonthCalColor(int nColorType) const
9230 ATLASSERT(::IsWindow(m_hWnd));
9231 return (COLORREF)::SendMessage(m_hWnd, DTM_GETMCCOLOR, nColorType, 0L);
9234 COLORREF SetMonthCalColor(int nColorType, COLORREF clr)
9236 ATLASSERT(::IsWindow(m_hWnd));
9237 return (COLORREF)::SendMessage(m_hWnd, DTM_SETMCCOLOR, nColorType, clr);
9240 DWORD GetRange(LPSYSTEMTIME lpSysTimeArray) const
9242 ATLASSERT(::IsWindow(m_hWnd));
9243 return (DWORD)::SendMessage(m_hWnd, DTM_GETRANGE, 0, (LPARAM)lpSysTimeArray);
9246 BOOL SetRange(DWORD dwFlags, LPSYSTEMTIME lpSysTimeArray)
9248 ATLASSERT(::IsWindow(m_hWnd));
9249 return (BOOL)::SendMessage(m_hWnd, DTM_SETRANGE, dwFlags, (LPARAM)lpSysTimeArray);
9252 DWORD GetSystemTime(LPSYSTEMTIME lpSysTime) const
9254 ATLASSERT(::IsWindow(m_hWnd));
9255 return (DWORD)::SendMessage(m_hWnd, DTM_GETSYSTEMTIME, 0, (LPARAM)lpSysTime);
9258 BOOL SetSystemTime(DWORD dwFlags, LPSYSTEMTIME lpSysTime)
9260 ATLASSERT(::IsWindow(m_hWnd));
9261 return (BOOL)::SendMessage(m_hWnd, DTM_SETSYSTEMTIME, dwFlags, (LPARAM)lpSysTime);
9264 CMonthCalendarCtrl GetMonthCal() const
9266 ATLASSERT(::IsWindow(m_hWnd));
9267 return CMonthCalendarCtrl((HWND)::SendMessage(m_hWnd, DTM_GETMONTHCAL, 0, 0L));
9270 #if (_WIN32_IE >= 0x0400)
9271 CFontHandle GetMonthCalFont() const
9273 ATLASSERT(::IsWindow(m_hWnd));
9274 return CFontHandle((HFONT)::SendMessage(m_hWnd, DTM_GETMCFONT, 0, 0L));
9277 void SetMonthCalFont(HFONT hFont, BOOL bRedraw = TRUE)
9279 ATLASSERT(::IsWindow(m_hWnd));
9280 ::SendMessage(m_hWnd, DTM_SETMCFONT, (WPARAM)hFont, MAKELPARAM(bRedraw, 0));
9282 #endif // (_WIN32_IE >= 0x0400)
9284 #if defined(NTDDI_VERSION) && (NTDDI_VERSION >= NTDDI_LONGHORN)
9285 DWORD GetMonthCalStyle() const
9287 ATLASSERT(::IsWindow(m_hWnd));
9288 return (DWORD)::SendMessage(m_hWnd, DTM_GETMCSTYLE, 0, 0L);
9291 DWORD SetMonthCalStyle(DWORD dwStyle)
9293 ATLASSERT(::IsWindow(m_hWnd));
9294 return (DWORD)::SendMessage(m_hWnd, DTM_SETMCSTYLE, 0, (LPARAM)dwStyle);
9297 void GetDateTimePickerInfo(LPDATETIMEPICKERINFO lpPickerInfo) const
9299 ATLASSERT(::IsWindow(m_hWnd));
9300 ::SendMessage(m_hWnd, DTM_GETDATETIMEPICKERINFO, 0, (LPARAM)lpPickerInfo);
9303 BOOL GetIdealSize(LPSIZE lpSize) const
9305 ATLASSERT(::IsWindow(m_hWnd));
9306 return (BOOL)::SendMessage(m_hWnd, DTM_GETIDEALSIZE, 0, (LPARAM)lpSize);
9309 void CloseMonthCal()
9311 ATLASSERT(::IsWindow(m_hWnd));
9312 ::SendMessage(m_hWnd, DTM_CLOSEMONTHCAL, 0, 0L);
9314 #endif // defined(NTDDI_VERSION) && (NTDDI_VERSION >= NTDDI_LONGHORN)
9317 typedef CDateTimePickerCtrlT<ATL::CWindow> CDateTimePickerCtrl;
9320 ///////////////////////////////////////////////////////////////////////////////
9321 // CFlatScrollBarImpl - support for flat scroll bars
9323 #if (_WIN32_IE >= 0x0400) && !defined(_WIN32_WCE)
9325 template <class T>
9326 class CFlatScrollBarImpl
9328 public:
9329 // Initialization
9330 BOOL FlatSB_Initialize()
9332 T* pT = static_cast<T*>(this);
9333 ATLASSERT(::IsWindow(pT->m_hWnd));
9334 return ::InitializeFlatSB(pT->m_hWnd);
9337 HRESULT FlatSB_Uninitialize()
9339 T* pT = static_cast<T*>(this);
9340 ATLASSERT(::IsWindow(pT->m_hWnd));
9341 return ::UninitializeFlatSB(pT->m_hWnd);
9344 // Flat scroll bar properties
9345 BOOL FlatSB_GetScrollProp(UINT uIndex, LPINT lpnValue) const
9347 const T* pT = static_cast<const T*>(this);
9348 ATLASSERT(::IsWindow(pT->m_hWnd));
9349 return ::FlatSB_GetScrollProp(pT->m_hWnd, uIndex, lpnValue);
9352 BOOL FlatSB_SetScrollProp(UINT uIndex, int nValue, BOOL bRedraw = TRUE)
9354 T* pT = static_cast<T*>(this);
9355 ATLASSERT(::IsWindow(pT->m_hWnd));
9356 return ::FlatSB_SetScrollProp(pT->m_hWnd, uIndex, nValue, bRedraw);
9359 // Attributes
9360 int FlatSB_GetScrollPos(int nBar) const
9362 const T* pT = static_cast<const T*>(this);
9363 ATLASSERT(::IsWindow(pT->m_hWnd));
9364 return ::FlatSB_GetScrollPos(pT->m_hWnd, nBar);
9367 int FlatSB_SetScrollPos(int nBar, int nPos, BOOL bRedraw = TRUE)
9369 T* pT = static_cast<T*>(this);
9370 ATLASSERT(::IsWindow(pT->m_hWnd));
9371 return ::FlatSB_SetScrollPos(pT->m_hWnd, nBar, nPos, bRedraw);
9374 BOOL FlatSB_GetScrollRange(int nBar, LPINT lpMinPos, LPINT lpMaxPos) const
9376 const T* pT = static_cast<const T*>(this);
9377 ATLASSERT(::IsWindow(pT->m_hWnd));
9378 return ::FlatSB_GetScrollRange(pT->m_hWnd, nBar, lpMinPos, lpMaxPos);
9381 BOOL FlatSB_SetScrollRange(int nBar, int nMinPos, int nMaxPos, BOOL bRedraw = TRUE)
9383 T* pT = static_cast<T*>(this);
9384 ATLASSERT(::IsWindow(pT->m_hWnd));
9385 return ::FlatSB_SetScrollRange(pT->m_hWnd, nBar, nMinPos, nMaxPos, bRedraw);
9388 BOOL FlatSB_GetScrollInfo(int nBar, LPSCROLLINFO lpScrollInfo) const
9390 const T* pT = static_cast<const T*>(this);
9391 ATLASSERT(::IsWindow(pT->m_hWnd));
9392 return ::FlatSB_GetScrollInfo(pT->m_hWnd, nBar, lpScrollInfo);
9395 int FlatSB_SetScrollInfo(int nBar, LPSCROLLINFO lpScrollInfo, BOOL bRedraw = TRUE)
9397 T* pT = static_cast<T*>(this);
9398 ATLASSERT(::IsWindow(pT->m_hWnd));
9399 return ::FlatSB_SetScrollInfo(pT->m_hWnd, nBar, lpScrollInfo, bRedraw);
9402 // Operations
9403 BOOL FlatSB_ShowScrollBar(UINT nBar, BOOL bShow = TRUE)
9405 T* pT = static_cast<T*>(this);
9406 ATLASSERT(::IsWindow(pT->m_hWnd));
9407 return ::FlatSB_ShowScrollBar(pT->m_hWnd, nBar, bShow);
9410 BOOL FlatSB_EnableScrollBar(UINT uSBFlags, UINT uArrowFlags = ESB_ENABLE_BOTH)
9412 T* pT = static_cast<T*>(this);
9413 ATLASSERT(::IsWindow(pT->m_hWnd));
9414 return ::FlatSB_EnableScrollBar(pT->m_hWnd, uSBFlags, uArrowFlags);
9418 template <class TBase>
9419 class CFlatScrollBarT : public TBase, public CFlatScrollBarImpl<CFlatScrollBarT< TBase > >
9421 public:
9422 CFlatScrollBarT(HWND hWnd = NULL) : TBase(hWnd)
9425 CFlatScrollBarT< TBase >& operator =(HWND hWnd)
9427 m_hWnd = hWnd;
9428 return *this;
9432 typedef CFlatScrollBarT<ATL::CWindow> CFlatScrollBar;
9434 #endif // (_WIN32_IE >= 0x0400) && !defined(_WIN32_WCE)
9437 ///////////////////////////////////////////////////////////////////////////////
9438 // CIPAddressCtrl
9440 #if (_WIN32_IE >= 0x0400)
9442 template <class TBase>
9443 class CIPAddressCtrlT : public TBase
9445 public:
9446 // Constructors
9447 CIPAddressCtrlT(HWND hWnd = NULL) : TBase(hWnd)
9450 CIPAddressCtrlT< TBase >& operator =(HWND hWnd)
9452 m_hWnd = hWnd;
9453 return *this;
9456 HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
9457 DWORD dwStyle = 0, DWORD dwExStyle = 0,
9458 ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
9460 return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
9463 // Atteributes
9464 static LPCTSTR GetWndClassName()
9466 return WC_IPADDRESS;
9469 BOOL IsBlank() const
9471 ATLASSERT(::IsWindow(m_hWnd));
9472 return (BOOL)::SendMessage(m_hWnd, IPM_ISBLANK, 0, 0L);
9475 int GetAddress(LPDWORD lpdwAddress) const
9477 ATLASSERT(::IsWindow(m_hWnd));
9478 return (int)::SendMessage(m_hWnd, IPM_GETADDRESS, 0, (LPARAM)lpdwAddress);
9481 void SetAddress(DWORD dwAddress)
9483 ATLASSERT(::IsWindow(m_hWnd));
9484 ::SendMessage(m_hWnd, IPM_SETADDRESS, 0, dwAddress);
9487 void ClearAddress()
9489 ATLASSERT(::IsWindow(m_hWnd));
9490 ::SendMessage(m_hWnd, IPM_CLEARADDRESS, 0, 0L);
9493 void SetRange(int nField, WORD wRange)
9495 ATLASSERT(::IsWindow(m_hWnd));
9496 ::SendMessage(m_hWnd, IPM_SETRANGE, nField, wRange);
9499 void SetRange(int nField, BYTE nMin, BYTE nMax)
9501 ATLASSERT(::IsWindow(m_hWnd));
9502 ::SendMessage(m_hWnd, IPM_SETRANGE, nField, MAKEIPRANGE(nMin, nMax));
9505 void SetFocus(int nField)
9507 ATLASSERT(::IsWindow(m_hWnd));
9508 ::SendMessage(m_hWnd, IPM_SETFOCUS, nField, 0L);
9512 typedef CIPAddressCtrlT<ATL::CWindow> CIPAddressCtrl;
9514 #endif // (_WIN32_IE >= 0x0400)
9517 ///////////////////////////////////////////////////////////////////////////////
9518 // CPagerCtrl
9520 #if (_WIN32_IE >= 0x0400) && !defined(_WIN32_WCE)
9522 template <class TBase>
9523 class CPagerCtrlT : public TBase
9525 public:
9526 // Constructors
9527 CPagerCtrlT(HWND hWnd = NULL) : TBase(hWnd)
9530 CPagerCtrlT< TBase >& operator =(HWND hWnd)
9532 m_hWnd = hWnd;
9533 return *this;
9536 HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
9537 DWORD dwStyle = 0, DWORD dwExStyle = 0,
9538 ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
9540 return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
9543 // Attributes
9544 static LPCTSTR GetWndClassName()
9546 return WC_PAGESCROLLER;
9549 int GetButtonSize() const
9551 ATLASSERT(::IsWindow(m_hWnd));
9552 return (int)::SendMessage(m_hWnd, PGM_GETBUTTONSIZE, 0, 0L);
9555 int SetButtonSize(int nButtonSize)
9557 ATLASSERT(::IsWindow(m_hWnd));
9558 return (int)::SendMessage(m_hWnd, PGM_SETBUTTONSIZE, 0, nButtonSize);
9561 DWORD GetButtonState(int nButton) const
9563 ATLASSERT(::IsWindow(m_hWnd));
9564 ATLASSERT(nButton == PGB_TOPORLEFT || nButton == PGB_BOTTOMORRIGHT);
9565 return (DWORD)::SendMessage(m_hWnd, PGM_GETBUTTONSTATE, 0, nButton);
9568 COLORREF GetBkColor() const
9570 ATLASSERT(::IsWindow(m_hWnd));
9571 return (COLORREF)::SendMessage(m_hWnd, PGM_GETBKCOLOR, 0, 0L);
9574 COLORREF SetBkColor(COLORREF clrBk)
9576 ATLASSERT(::IsWindow(m_hWnd));
9577 return (COLORREF)::SendMessage(m_hWnd, PGM_SETBKCOLOR, 0, (LPARAM)clrBk);
9580 int GetBorder() const
9582 ATLASSERT(::IsWindow(m_hWnd));
9583 return (int)::SendMessage(m_hWnd, PGM_GETBORDER, 0, 0L);
9586 int SetBorder(int nBorderSize)
9588 ATLASSERT(::IsWindow(m_hWnd));
9589 return (int)::SendMessage(m_hWnd, PGM_SETBORDER, 0, nBorderSize);
9592 int GetPos() const
9594 ATLASSERT(::IsWindow(m_hWnd));
9595 return (int)::SendMessage(m_hWnd, PGM_GETPOS, 0, 0L);
9598 int SetPos(int nPos)
9600 ATLASSERT(::IsWindow(m_hWnd));
9601 return (int)::SendMessage(m_hWnd, PGM_SETPOS, 0, nPos);
9604 // Operations
9605 void SetChild(HWND hWndChild)
9607 ATLASSERT(::IsWindow(m_hWnd));
9608 ::SendMessage(m_hWnd, PGM_SETCHILD, 0, (LPARAM)hWndChild);
9611 void ForwardMouse(BOOL bForward = TRUE)
9613 ATLASSERT(::IsWindow(m_hWnd));
9614 ::SendMessage(m_hWnd, PGM_FORWARDMOUSE, bForward, 0L);
9617 void RecalcSize()
9619 ATLASSERT(::IsWindow(m_hWnd));
9620 ::SendMessage(m_hWnd, PGM_RECALCSIZE, 0, 0L);
9623 void GetDropTarget(IDropTarget** ppDropTarget)
9625 ATLASSERT(::IsWindow(m_hWnd));
9626 ATLASSERT(ppDropTarget != NULL);
9627 ::SendMessage(m_hWnd, PGM_GETDROPTARGET, 0, (LPARAM)ppDropTarget);
9631 typedef CPagerCtrlT<ATL::CWindow> CPagerCtrl;
9633 #endif // (_WIN32_IE >= 0x0400) && !defined(_WIN32_WCE)
9636 ///////////////////////////////////////////////////////////////////////////////
9637 // CLinkCtrl - Windows SYSLINK control
9639 #if (_WIN32_WINNT >= 0x0501) && !defined(_WIN32_WCE)
9641 template <class TBase>
9642 class CLinkCtrlT : public TBase
9644 public:
9645 // Constructors
9646 CLinkCtrlT(HWND hWnd = NULL) : TBase(hWnd)
9649 CLinkCtrlT< TBase >& operator =(HWND hWnd)
9651 m_hWnd = hWnd;
9652 return *this;
9655 HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
9656 DWORD dwStyle = 0, DWORD dwExStyle = 0,
9657 ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
9659 return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
9662 // Attributes
9663 static LPCTSTR GetWndClassName()
9665 #ifdef _UNICODE
9666 return WC_LINK;
9667 #else // !_UNICODE
9668 return "SysLink";
9669 #endif // !_UNICODE
9672 int GetIdealHeight(int cxMaxWidth = 0) const
9674 ATLASSERT(::IsWindow(m_hWnd));
9675 return (int)::SendMessage(m_hWnd, LM_GETIDEALHEIGHT, cxMaxWidth, 0L);
9678 BOOL GetItem(PLITEM pLItem) const
9680 ATLASSERT(::IsWindow(m_hWnd));
9681 return (BOOL)::SendMessage(m_hWnd, LM_GETITEM, 0, (LPARAM)pLItem);
9684 BOOL SetItem(PLITEM pLItem)
9686 ATLASSERT(::IsWindow(m_hWnd));
9687 return (BOOL)::SendMessage(m_hWnd, LM_SETITEM, 0, (LPARAM)pLItem);
9690 // Vista only
9691 int GetIdealSize(SIZE& size, int cxMaxWidth = 0) const
9693 #ifndef LM_GETIDEALSIZE
9694 const UINT LM_GETIDEALSIZE = LM_GETIDEALHEIGHT;
9695 #endif
9696 ATLASSERT(::IsWindow(m_hWnd));
9697 return (int)::SendMessage(m_hWnd, LM_GETIDEALSIZE, cxMaxWidth, (LPARAM)&size);
9700 // Operations
9701 BOOL HitTest(PLHITTESTINFO pLHitTestInfo) const
9703 ATLASSERT(::IsWindow(m_hWnd));
9704 return (BOOL)::SendMessage(m_hWnd, LM_HITTEST, 0, (LPARAM)pLHitTestInfo);
9708 typedef CLinkCtrlT<ATL::CWindow> CLinkCtrl;
9710 #endif // (_WIN32_WINNT >= 0x0501) && !defined(_WIN32_WCE)
9713 ///////////////////////////////////////////////////////////////////////////////
9714 // CCustomDraw - MI class for custom-draw support
9716 template <class T>
9717 class CCustomDraw
9719 public:
9720 #if (_ATL_VER < 0x0700)
9721 BOOL m_bHandledCD;
9723 BOOL IsMsgHandled() const
9725 return m_bHandledCD;
9728 void SetMsgHandled(BOOL bHandled)
9730 m_bHandledCD = bHandled;
9732 #endif // !(_ATL_VER < 0x0700)
9734 // Message map and handlers
9735 BEGIN_MSG_MAP(CCustomDraw< T >)
9736 NOTIFY_CODE_HANDLER(NM_CUSTOMDRAW, OnCustomDraw)
9737 ALT_MSG_MAP(1)
9738 REFLECTED_NOTIFY_CODE_HANDLER(NM_CUSTOMDRAW, OnCustomDraw)
9739 END_MSG_MAP()
9741 // message handler
9742 LRESULT OnCustomDraw(int idCtrl, LPNMHDR pnmh, BOOL& bHandled)
9744 T* pT = static_cast<T*>(this);
9745 pT->SetMsgHandled(TRUE);
9746 LPNMCUSTOMDRAW lpNMCustomDraw = (LPNMCUSTOMDRAW)pnmh;
9747 DWORD dwRet = 0;
9748 switch(lpNMCustomDraw->dwDrawStage)
9750 case CDDS_PREPAINT:
9751 dwRet = pT->OnPrePaint(idCtrl, lpNMCustomDraw);
9752 break;
9753 case CDDS_POSTPAINT:
9754 dwRet = pT->OnPostPaint(idCtrl, lpNMCustomDraw);
9755 break;
9756 case CDDS_PREERASE:
9757 dwRet = pT->OnPreErase(idCtrl, lpNMCustomDraw);
9758 break;
9759 case CDDS_POSTERASE:
9760 dwRet = pT->OnPostErase(idCtrl, lpNMCustomDraw);
9761 break;
9762 case CDDS_ITEMPREPAINT:
9763 dwRet = pT->OnItemPrePaint(idCtrl, lpNMCustomDraw);
9764 break;
9765 case CDDS_ITEMPOSTPAINT:
9766 dwRet = pT->OnItemPostPaint(idCtrl, lpNMCustomDraw);
9767 break;
9768 case CDDS_ITEMPREERASE:
9769 dwRet = pT->OnItemPreErase(idCtrl, lpNMCustomDraw);
9770 break;
9771 case CDDS_ITEMPOSTERASE:
9772 dwRet = pT->OnItemPostErase(idCtrl, lpNMCustomDraw);
9773 break;
9774 #if (_WIN32_IE >= 0x0400)
9775 case (CDDS_ITEMPREPAINT | CDDS_SUBITEM):
9776 dwRet = pT->OnSubItemPrePaint(idCtrl, lpNMCustomDraw);
9777 break;
9778 #endif // (_WIN32_IE >= 0x0400)
9779 default:
9780 pT->SetMsgHandled(FALSE);
9781 break;
9783 bHandled = pT->IsMsgHandled();
9784 return dwRet;
9787 // Overrideables
9788 DWORD OnPrePaint(int /*idCtrl*/, LPNMCUSTOMDRAW /*lpNMCustomDraw*/)
9790 return CDRF_DODEFAULT;
9793 DWORD OnPostPaint(int /*idCtrl*/, LPNMCUSTOMDRAW /*lpNMCustomDraw*/)
9795 return CDRF_DODEFAULT;
9798 DWORD OnPreErase(int /*idCtrl*/, LPNMCUSTOMDRAW /*lpNMCustomDraw*/)
9800 return CDRF_DODEFAULT;
9803 DWORD OnPostErase(int /*idCtrl*/, LPNMCUSTOMDRAW /*lpNMCustomDraw*/)
9805 return CDRF_DODEFAULT;
9808 DWORD OnItemPrePaint(int /*idCtrl*/, LPNMCUSTOMDRAW /*lpNMCustomDraw*/)
9810 return CDRF_DODEFAULT;
9813 DWORD OnItemPostPaint(int /*idCtrl*/, LPNMCUSTOMDRAW /*lpNMCustomDraw*/)
9815 return CDRF_DODEFAULT;
9818 DWORD OnItemPreErase(int /*idCtrl*/, LPNMCUSTOMDRAW /*lpNMCustomDraw*/)
9820 return CDRF_DODEFAULT;
9823 DWORD OnItemPostErase(int /*idCtrl*/, LPNMCUSTOMDRAW /*lpNMCustomDraw*/)
9825 return CDRF_DODEFAULT;
9828 #if (_WIN32_IE >= 0x0400)
9829 DWORD OnSubItemPrePaint(int /*idCtrl*/, LPNMCUSTOMDRAW /*lpNMCustomDraw*/)
9831 return CDRF_DODEFAULT;
9833 #endif // (_WIN32_IE >= 0x0400)
9837 // --- Windows CE common controls ---
9839 #ifdef _WIN32_WCE
9841 ///////////////////////////////////////////////////////////////////////////////
9842 // CCECommandBarCtrl
9844 template <class TBase>
9845 class CCECommandBarCtrlT : public TBase
9847 public:
9848 // Constructors
9849 CCECommandBarCtrlT(HWND hWnd = NULL) : TBase(hWnd) { }
9851 CCECommandBarCtrlT< TBase >& operator=(HWND hWnd)
9853 m_hWnd = hWnd;
9854 return *this;
9857 // Attributes
9858 BOOL IsVisible() const
9860 return IsWindowVisible();
9863 int GetHeight() const
9865 ATLASSERT(::IsWindow(m_hWnd));
9866 return ::CommandBar_Height(m_hWnd);
9869 HMENU GetMenu(WORD wButton) const
9871 ATLASSERT(::IsWindow(m_hWnd));
9872 return ::CommandBar_GetMenu(m_hWnd, wButton);
9875 // Operations
9876 HWND Create(HWND hWndParent, int nCmdBarID)
9878 m_hWnd = ::CommandBar_Create(ModuleHelper::GetModuleInstance(), hWndParent, nCmdBarID);
9879 ATLASSERT(::IsWindow(m_hWnd));
9880 return m_hWnd;
9883 void Destroy()
9885 DestroyWindow();
9888 BOOL Show(BOOL bShow = TRUE)
9890 ATLASSERT(::IsWindow(m_hWnd));
9891 return ::CommandBar_Show(m_hWnd, bShow);
9894 BOOL DrawMenuBar(WORD wButton)
9896 ATLASSERT(::IsWindow(m_hWnd));
9897 return ::CommandBar_DrawMenuBar(m_hWnd, wButton);
9900 BOOL AddAdornments(DWORD dwFlags = 0)
9902 ATLASSERT(::IsWindow(m_hWnd));
9903 return ::CommandBar_AddAdornments(m_hWnd, dwFlags, 0);
9906 int AddBitmap(int nBitmapID, int nNumImages)
9908 ATLASSERT(::IsWindow(m_hWnd));
9909 return ::CommandBar_AddBitmap(m_hWnd, ModuleHelper::GetResourceInstance(), nBitmapID, nNumImages, 16, 16);
9912 BOOL AddButtons(UINT uNumButtons, LPTBBUTTON lpButtons)
9914 ATLASSERT(::IsWindow(m_hWnd));
9915 return CommandBar_AddButtons(m_hWnd, uNumButtons, lpButtons);
9918 BOOL AddToolTips(UINT uNumToolTips, LPTSTR lpToolTips)
9920 ATLASSERT(::IsWindow(m_hWnd));
9921 return CommandBar_AddToolTips(m_hWnd, uNumToolTips, lpToolTips);
9924 BOOL InsertButton(int nButton, LPTBBUTTON lpButton)
9926 ATLASSERT(::IsWindow(m_hWnd));
9927 return CommandBar_InsertButton(m_hWnd, nButton, lpButton);
9930 HWND InsertComboBox(int nWidth, UINT dwStyle, WORD wComboBoxID, WORD wButton)
9932 ATLASSERT(::IsWindow(m_hWnd));
9933 return ::CommandBar_InsertComboBox(m_hWnd, ModuleHelper::GetModuleInstance(), nWidth, dwStyle, wComboBoxID, wButton);
9936 BOOL InsertMenubar(WORD wMenuID, WORD wButton)
9938 ATLASSERT(::IsWindow(m_hWnd));
9939 return ::CommandBar_InsertMenubar(m_hWnd, ModuleHelper::GetResourceInstance(), wMenuID, wButton);
9942 BOOL InsertMenubarEx(ATL::_U_STRINGorID menu, WORD wButton)
9944 ATLASSERT(::IsWindow(m_hWnd));
9945 return ::CommandBar_InsertMenubarEx(m_hWnd, ModuleHelper::GetResourceInstance(), (LPTSTR)menu.m_lpstr, wButton);
9948 BOOL IsCommandBarMessage(LPMSG lpMsg)
9950 ATLASSERT(::IsWindow(m_hWnd));
9951 return ::IsCommandBarMessage(m_hWnd, lpMsg);
9955 #if defined(_AYGSHELL_H_) || defined(__AYGSHELL_H__) // PPC MenuBar
9956 typedef CCECommandBarCtrlT<CToolBarCtrl> CMenuBarCtrl;
9957 #else
9958 typedef CCECommandBarCtrlT<CToolBarCtrl> CCECommandBarCtrl;
9959 #endif // defined(_AYGSHELL_H_) || defined(__AYGSHELL_H__)
9961 ///////////////////////////////////////////////////////////////////////////////
9962 // CCECommandBandsCtrl
9964 template <class TBase>
9965 class CCECommandBandsCtrlT : public TBase
9967 public:
9968 // Constructors
9969 CCECommandBandsCtrlT(HWND hWnd = NULL) : TBase(hWnd) { }
9971 CCECommandBandsCtrlT< TBase >& operator=(HWND hWnd)
9973 m_hWnd = hWnd;
9974 return *this;
9977 // Attributes
9978 BOOL IsVisible() const
9980 return IsWindowVisible();
9983 #if (_WIN32_IE >= 0x0400)
9984 UINT GetHeight() const
9986 ATLASSERT(::IsWindow(m_hWnd));
9987 return CommandBands_Height(m_hWnd);
9989 #endif // (_WIN32_IE >= 0x0400)
9991 HWND GetCommandBar(UINT uBand) const
9993 ATLASSERT(::IsWindow(m_hWnd));
9994 return ::CommandBands_GetCommandBar(m_hWnd, uBand);
9997 BOOL GetRestoreInformation(UINT uBand, LPCOMMANDBANDSRESTOREINFO pcbr) const
9999 ATLASSERT(::IsWindow(m_hWnd));
10000 return ::CommandBands_GetRestoreInformation(m_hWnd, uBand, pcbr);
10003 // Operations
10004 HWND Create(HWND hWndParent, UINT wID, DWORD dwStyles, HIMAGELIST hImageList = NULL)
10006 m_hWnd = ::CommandBands_Create(ModuleHelper::GetModuleInstance(), hWndParent, wID, dwStyles, hImageList);
10007 ATLASSERT(::IsWindow(m_hWnd));
10008 return m_hWnd;
10011 BOOL AddAdornments(DWORD dwFlags = 0, LPREBARBANDINFO prbbi = NULL)
10013 ATLASSERT(::IsWindow(m_hWnd));
10014 return ::CommandBands_AddAdornments(m_hWnd, ModuleHelper::GetModuleInstance(), dwFlags, prbbi);
10017 BOOL AddBands(UINT uBandCount, LPREBARBANDINFO prbbi)
10019 ATLASSERT(::IsWindow(m_hWnd));
10020 return ::CommandBands_AddBands(m_hWnd, ModuleHelper::GetModuleInstance(), uBandCount, prbbi);
10023 BOOL Show(BOOL bShow = TRUE)
10025 ATLASSERT(::IsWindow(m_hWnd));
10026 return ::CommandBands_Show(m_hWnd, bShow);
10030 typedef CCECommandBandsCtrlT<ATL::CWindow> CCECommandBandsCtrl;
10032 #endif // _WIN32_WCE
10034 }; // namespace WTL
10036 #endif // __ATLCTRLS_H__