1 // Windows Template Library - WTL version 10.0
2 // Copyright (C) Microsoft Corporation, WTL Team. 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 Public License (http://opensource.org/licenses/MS-PL)
7 // which can be found in the file MS-PL.txt at the root folder.
8
9 #ifndef __ATLCTRLS_H__
10 #define __ATLCTRLS_H__
11
12 #pragma once
13
14 #ifndef __ATLAPP_H__
15 #error atlctrls.h requires atlapp.h to be included first
16 #endif
17
18 #ifndef __ATLWIN_H__
19 #error atlctrls.h requires atlwin.h to be included first
20 #endif
21
22 #include <richedit.h>
23 #include <richole.h>
24
25 #if (_RICHEDIT_VER < 0x0300)
26 #error WTL10 requires RichEdit version 3 or higher
27 #endif
28
29 // protect template members from windowsx.h macros
30 #ifdef _INC_WINDOWSX
31 #undef GetNextSibling
32 #undef GetPrevSibling
33 #endif // _INC_WINDOWSX
34
35
36 ///////////////////////////////////////////////////////////////////////////////
37 // Classes in this file:
38 //
39 // CStaticT<TBase> - CStatic
40 // CButtonT<TBase> - CButton
41 // CListBoxT<TBase> - CListBox
42 // CComboBoxT<TBase> - CComboBox
43 // CEditT<TBase> - CEdit
44 // CEditCommands<T>
45 // CScrollBarT<TBase> - CScrollBar
46 //
47 // CImageListT<t_bManaged> - CImageList, CImageListManaged
48 // CListViewCtrlT<TBase> - CListViewCtrl
49 // CTreeViewCtrlT<TBase> - CTreeViewCtrl
50 // CTreeItemT<TBase> - CTreeItem
51 // CTreeViewCtrlExT<TBase> - CTreeViewCtrlEx
52 // CHeaderCtrlT<TBase> - CHeaderCtrl
53 // CToolBarCtrlT<TBase> - CToolBarCtrl
54 // CStatusBarCtrlT<TBase> - CStatusBarCtrl
55 // CTabCtrlT<TBase> - CTabCtrl
56 // CToolInfo
57 // CToolTipCtrlT<TBase> - CToolTipCtrl
58 // CTrackBarCtrlT<TBase> - CTrackBarCtrl
59 // CUpDownCtrlT<TBase> - CUpDownCtrl
60 // CProgressBarCtrlT<TBase> - CProgressBarCtrl
61 // CHotKeyCtrlT<TBase> - CHotKeyCtrl
62 // CAnimateCtrlT<TBase> - CAnimateCtrl
63 // CRichEditCtrlT<TBase> - CRichEditCtrl
64 // CRichEditCommands<T>
65 // CDragListBoxT<TBase> - CDragListBox
66 // CDragListNotifyImpl<T>
67 // CReBarCtrlT<TBase> - CReBarCtrl
68 // CComboBoxExT<TBase> - CComboBoxEx
69 // CDateTimePickerCtrlT<TBase> - CDateTimePickerCtrl
70 // CMonthCalendarCtrlT<TBase> - CMonthCalendarCtrl
71 // CFlatScrollBarImpl<T>
72 // CFlatScrollBarT<TBase> - CFlatScrollBar
73 // CIPAddressCtrlT<TBase> - CIPAddressCtrl
74 // CPagerCtrlT<TBase> - CPagerCtrl
75 // CLinkCtrlT<TBase> - CLinkCtrl
76 //
77 // CCustomDraw<T>
78
79
80 namespace WTL
81 {
82
83 // These are wrapper classes for Windows standard and common controls.
84 // To implement a window based on a control, use following:
85 // Example: Implementing a window based on a list box
86 //
87 // class CMyListBox : CWindowImpl<CMyListBox, CListBox>
88 // {
89 // public:
90 // BEGIN_MSG_MAP(CMyListBox)
91 // // put your message handler entries here
92 // END_MSG_MAP()
93 // };
94
95
96
97 // --- Standard Windows controls ---
98
99 ///////////////////////////////////////////////////////////////////////////////
100 // CStatic - client side for a Windows STATIC control
101
102 template <class TBase>
103 class CStaticT : public TBase
104 {
105 public:
106 // Constructors
TBase(hWnd)107 CStaticT(HWND hWnd = NULL) : TBase(hWnd)
108 { }
109
110 CStaticT< TBase >& operator =(HWND hWnd)
111 {
112 this->m_hWnd = hWnd;
113 return *this;
114 }
115
116 HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
117 DWORD dwStyle = 0, DWORD dwExStyle = 0,
118 ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
119 {
120 return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
121 }
122
123 // Attributes
GetWndClassName()124 static LPCTSTR GetWndClassName()
125 {
126 return _T("STATIC");
127 }
128
GetIcon()129 HICON GetIcon() const
130 {
131 ATLASSERT(::IsWindow(this->m_hWnd));
132 return (HICON)::SendMessage(this->m_hWnd, STM_GETICON, 0, 0L);
133 }
134
SetIcon(HICON hIcon)135 HICON SetIcon(HICON hIcon)
136 {
137 ATLASSERT(::IsWindow(this->m_hWnd));
138 return (HICON)::SendMessage(this->m_hWnd, STM_SETICON, (WPARAM)hIcon, 0L);
139 }
140
GetEnhMetaFile()141 HENHMETAFILE GetEnhMetaFile() const
142 {
143 ATLASSERT(::IsWindow(this->m_hWnd));
144 return (HENHMETAFILE)::SendMessage(this->m_hWnd, STM_GETIMAGE, IMAGE_ENHMETAFILE, 0L);
145 }
146
SetEnhMetaFile(HENHMETAFILE hMetaFile)147 HENHMETAFILE SetEnhMetaFile(HENHMETAFILE hMetaFile)
148 {
149 ATLASSERT(::IsWindow(this->m_hWnd));
150 return (HENHMETAFILE)::SendMessage(this->m_hWnd, STM_SETIMAGE, IMAGE_ENHMETAFILE, (LPARAM)hMetaFile);
151 }
152
GetBitmap()153 CBitmapHandle GetBitmap() const
154 {
155 ATLASSERT(::IsWindow(this->m_hWnd));
156 return CBitmapHandle((HBITMAP)::SendMessage(this->m_hWnd, STM_GETIMAGE, IMAGE_BITMAP, 0L));
157 }
158
SetBitmap(HBITMAP hBitmap)159 CBitmapHandle SetBitmap(HBITMAP hBitmap)
160 {
161 ATLASSERT(::IsWindow(this->m_hWnd));
162 return CBitmapHandle((HBITMAP)::SendMessage(this->m_hWnd, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBitmap));
163 }
164
GetCursor()165 HCURSOR GetCursor() const
166 {
167 ATLASSERT(::IsWindow(this->m_hWnd));
168 return (HCURSOR)::SendMessage(this->m_hWnd, STM_GETIMAGE, IMAGE_CURSOR, 0L);
169 }
170
SetCursor(HCURSOR hCursor)171 HCURSOR SetCursor(HCURSOR hCursor)
172 {
173 ATLASSERT(::IsWindow(this->m_hWnd));
174 return (HCURSOR)::SendMessage(this->m_hWnd, STM_SETIMAGE, IMAGE_CURSOR, (LPARAM)hCursor);
175 }
176 };
177
178 typedef CStaticT<ATL::CWindow> CStatic;
179
180
181 ///////////////////////////////////////////////////////////////////////////////
182 // CButton - client side for a Windows BUTTON control
183
184 template <class TBase>
185 class CButtonT : public TBase
186 {
187 public:
188 // Constructors
TBase(hWnd)189 CButtonT(HWND hWnd = NULL) : TBase(hWnd)
190 { }
191
192 CButtonT< TBase >& operator =(HWND hWnd)
193 {
194 this->m_hWnd = hWnd;
195 return *this;
196 }
197
198 HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
199 DWORD dwStyle = 0, DWORD dwExStyle = 0,
200 ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
201 {
202 return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
203 }
204
205 // Attributes
GetWndClassName()206 static LPCTSTR GetWndClassName()
207 {
208 return _T("BUTTON");
209 }
210
GetState()211 UINT GetState() const
212 {
213 ATLASSERT(::IsWindow(this->m_hWnd));
214 return (UINT)::SendMessage(this->m_hWnd, BM_GETSTATE, 0, 0L);
215 }
216
SetState(BOOL bHighlight)217 void SetState(BOOL bHighlight)
218 {
219 ATLASSERT(::IsWindow(this->m_hWnd));
220 ::SendMessage(this->m_hWnd, BM_SETSTATE, bHighlight, 0L);
221 }
222
GetCheck()223 int GetCheck() const
224 {
225 ATLASSERT(::IsWindow(this->m_hWnd));
226 return (int)::SendMessage(this->m_hWnd, BM_GETCHECK, 0, 0L);
227 }
228
SetCheck(int nCheck)229 void SetCheck(int nCheck)
230 {
231 ATLASSERT(::IsWindow(this->m_hWnd));
232 ::SendMessage(this->m_hWnd, BM_SETCHECK, nCheck, 0L);
233 }
234
GetButtonStyle()235 UINT GetButtonStyle() const
236 {
237 ATLASSERT(::IsWindow(this->m_hWnd));
238 return (UINT)::GetWindowLong(this->m_hWnd, GWL_STYLE) & 0xFFFF;
239 }
240
241 void SetButtonStyle(UINT nStyle, BOOL bRedraw = TRUE)
242 {
243 ATLASSERT(::IsWindow(this->m_hWnd));
244 ::SendMessage(this->m_hWnd, BM_SETSTYLE, nStyle, (LPARAM)bRedraw);
245 }
246
GetIcon()247 HICON GetIcon() const
248 {
249 ATLASSERT(::IsWindow(this->m_hWnd));
250 return (HICON)::SendMessage(this->m_hWnd, BM_GETIMAGE, IMAGE_ICON, 0L);
251 }
252
SetIcon(HICON hIcon)253 HICON SetIcon(HICON hIcon)
254 {
255 ATLASSERT(::IsWindow(this->m_hWnd));
256 return (HICON)::SendMessage(this->m_hWnd, BM_SETIMAGE, IMAGE_ICON, (LPARAM)hIcon);
257 }
258
GetBitmap()259 CBitmapHandle GetBitmap() const
260 {
261 ATLASSERT(::IsWindow(this->m_hWnd));
262 return CBitmapHandle((HBITMAP)::SendMessage(this->m_hWnd, BM_GETIMAGE, IMAGE_BITMAP, 0L));
263 }
264
SetBitmap(HBITMAP hBitmap)265 CBitmapHandle SetBitmap(HBITMAP hBitmap)
266 {
267 ATLASSERT(::IsWindow(this->m_hWnd));
268 return CBitmapHandle((HBITMAP)::SendMessage(this->m_hWnd, BM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBitmap));
269 }
270
GetIdealSize(LPSIZE lpSize)271 BOOL GetIdealSize(LPSIZE lpSize) const
272 {
273 ATLASSERT(::IsWindow(this->m_hWnd));
274 return (BOOL)::SendMessage(this->m_hWnd, BCM_GETIDEALSIZE, 0, (LPARAM)lpSize);
275 }
276
GetImageList(PBUTTON_IMAGELIST pButtonImagelist)277 BOOL GetImageList(PBUTTON_IMAGELIST pButtonImagelist) const
278 {
279 ATLASSERT(::IsWindow(this->m_hWnd));
280 return (BOOL)::SendMessage(this->m_hWnd, BCM_GETIMAGELIST, 0, (LPARAM)pButtonImagelist);
281 }
282
SetImageList(PBUTTON_IMAGELIST pButtonImagelist)283 BOOL SetImageList(PBUTTON_IMAGELIST pButtonImagelist)
284 {
285 ATLASSERT(::IsWindow(this->m_hWnd));
286 return (BOOL)::SendMessage(this->m_hWnd, BCM_SETIMAGELIST, 0, (LPARAM)pButtonImagelist);
287 }
288
GetTextMargin(LPRECT lpRect)289 BOOL GetTextMargin(LPRECT lpRect) const
290 {
291 ATLASSERT(::IsWindow(this->m_hWnd));
292 return (BOOL)::SendMessage(this->m_hWnd, BCM_GETTEXTMARGIN, 0, (LPARAM)lpRect);
293 }
294
SetTextMargin(LPRECT lpRect)295 BOOL SetTextMargin(LPRECT lpRect)
296 {
297 ATLASSERT(::IsWindow(this->m_hWnd));
298 return (BOOL)::SendMessage(this->m_hWnd, BCM_SETTEXTMARGIN, 0, (LPARAM)lpRect);
299 }
300
301 #if (WINVER >= 0x0600)
SetDontClick(BOOL bDontClick)302 void SetDontClick(BOOL bDontClick)
303 {
304 ATLASSERT(::IsWindow(this->m_hWnd));
305 ::SendMessage(this->m_hWnd, BM_SETDONTCLICK, (WPARAM)bDontClick, 0L);
306 }
307 #endif // (WINVER >= 0x0600)
308
309 #if (_WIN32_WINNT >= 0x0600)
SetDropDownState(BOOL bDropDown)310 BOOL SetDropDownState(BOOL bDropDown)
311 {
312 ATLASSERT(::IsWindow(this->m_hWnd));
313 ATLASSERT((this->GetStyle() & (BS_SPLITBUTTON | BS_DEFSPLITBUTTON)) != 0);
314 return (BOOL)::SendMessage(this->m_hWnd, BCM_SETDROPDOWNSTATE, (WPARAM)bDropDown, 0L);
315 }
316
GetSplitInfo(PBUTTON_SPLITINFO pSplitInfo)317 BOOL GetSplitInfo(PBUTTON_SPLITINFO pSplitInfo) const
318 {
319 ATLASSERT(::IsWindow(this->m_hWnd));
320 ATLASSERT((this->GetStyle() & (BS_SPLITBUTTON | BS_DEFSPLITBUTTON)) != 0);
321 return (BOOL)::SendMessage(this->m_hWnd, BCM_GETSPLITINFO, 0, (LPARAM)pSplitInfo);
322 }
323
SetSplitInfo(PBUTTON_SPLITINFO pSplitInfo)324 BOOL SetSplitInfo(PBUTTON_SPLITINFO pSplitInfo)
325 {
326 ATLASSERT(::IsWindow(this->m_hWnd));
327 ATLASSERT((this->GetStyle() & (BS_SPLITBUTTON | BS_DEFSPLITBUTTON)) != 0);
328 return (BOOL)::SendMessage(this->m_hWnd, BCM_SETSPLITINFO, 0, (LPARAM)pSplitInfo);
329 }
330
GetNoteLength()331 int GetNoteLength() const
332 {
333 ATLASSERT(::IsWindow(this->m_hWnd));
334 ATLASSERT((this->GetStyle() & (BS_COMMANDLINK | BS_DEFCOMMANDLINK)) != 0);
335 return (int)::SendMessage(this->m_hWnd, BCM_GETNOTELENGTH, 0, 0L);
336 }
337
GetNote(LPWSTR lpstrNoteText,int cchNoteText)338 BOOL GetNote(LPWSTR lpstrNoteText, int cchNoteText) const
339 {
340 ATLASSERT(::IsWindow(this->m_hWnd));
341 ATLASSERT((this->GetStyle() & (BS_COMMANDLINK | BS_DEFCOMMANDLINK)) != 0);
342 return (BOOL)::SendMessage(this->m_hWnd, BCM_GETNOTE, cchNoteText, (LPARAM)lpstrNoteText);
343 }
344
SetNote(LPCWSTR lpstrNoteText)345 BOOL SetNote(LPCWSTR lpstrNoteText)
346 {
347 ATLASSERT(::IsWindow(this->m_hWnd));
348 ATLASSERT((this->GetStyle() & (BS_COMMANDLINK | BS_DEFCOMMANDLINK)) != 0);
349 return (BOOL)::SendMessage(this->m_hWnd, BCM_SETNOTE, 0, (LPARAM)lpstrNoteText);
350 }
351
SetElevationRequiredState(BOOL bSet)352 LRESULT SetElevationRequiredState(BOOL bSet)
353 {
354 ATLASSERT(::IsWindow(this->m_hWnd));
355 return ::SendMessage(this->m_hWnd, BCM_SETSHIELD, 0, (LPARAM)bSet);
356 }
357 #endif // (_WIN32_WINNT >= 0x0600)
358
359 // Operations
Click()360 void Click()
361 {
362 ATLASSERT(::IsWindow(this->m_hWnd));
363 ::SendMessage(this->m_hWnd, BM_CLICK, 0, 0L);
364 }
365 };
366
367 typedef CButtonT<ATL::CWindow> CButton;
368
369
370 ///////////////////////////////////////////////////////////////////////////////
371 // CListBox - client side for a Windows LISTBOX control
372
373 template <class TBase>
374 class CListBoxT : public TBase
375 {
376 public:
377 // Constructors
TBase(hWnd)378 CListBoxT(HWND hWnd = NULL) : TBase(hWnd)
379 { }
380
381 CListBoxT< TBase >& operator =(HWND hWnd)
382 {
383 this->m_hWnd = hWnd;
384 return *this;
385 }
386
387 HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
388 DWORD dwStyle = 0, DWORD dwExStyle = 0,
389 ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
390 {
391 return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
392 }
393
394 // Attributes
GetWndClassName()395 static LPCTSTR GetWndClassName()
396 {
397 return _T("LISTBOX");
398 }
399
400 // for entire listbox
GetCount()401 int GetCount() const
402 {
403 ATLASSERT(::IsWindow(this->m_hWnd));
404 return (int)::SendMessage(this->m_hWnd, LB_GETCOUNT, 0, 0L);
405 }
406
SetCount(int cItems)407 int SetCount(int cItems)
408 {
409 ATLASSERT(::IsWindow(this->m_hWnd));
410 ATLASSERT(((this->GetStyle() & LBS_NODATA) != 0) && ((this->GetStyle() & LBS_HASSTRINGS) == 0));
411 return (int)::SendMessage(this->m_hWnd, LB_SETCOUNT, cItems, 0L);
412 }
413
GetHorizontalExtent()414 int GetHorizontalExtent() const
415 {
416 ATLASSERT(::IsWindow(this->m_hWnd));
417 return (int)::SendMessage(this->m_hWnd, LB_GETHORIZONTALEXTENT, 0, 0L);
418 }
419
SetHorizontalExtent(int cxExtent)420 void SetHorizontalExtent(int cxExtent)
421 {
422 ATLASSERT(::IsWindow(this->m_hWnd));
423 ::SendMessage(this->m_hWnd, LB_SETHORIZONTALEXTENT, cxExtent, 0L);
424 }
425
GetTopIndex()426 int GetTopIndex() const
427 {
428 ATLASSERT(::IsWindow(this->m_hWnd));
429 return (int)::SendMessage(this->m_hWnd, LB_GETTOPINDEX, 0, 0L);
430 }
431
SetTopIndex(int nIndex)432 int SetTopIndex(int nIndex)
433 {
434 ATLASSERT(::IsWindow(this->m_hWnd));
435 return (int)::SendMessage(this->m_hWnd, LB_SETTOPINDEX, nIndex, 0L);
436 }
437
GetLocale()438 LCID GetLocale() const
439 {
440 ATLASSERT(::IsWindow(this->m_hWnd));
441 return (LCID)::SendMessage(this->m_hWnd, LB_GETLOCALE, 0, 0L);
442 }
443
SetLocale(LCID nNewLocale)444 LCID SetLocale(LCID nNewLocale)
445 {
446 ATLASSERT(::IsWindow(this->m_hWnd));
447 return (LCID)::SendMessage(this->m_hWnd, LB_SETLOCALE, (WPARAM)nNewLocale, 0L);
448 }
449
GetListBoxInfo()450 DWORD GetListBoxInfo() const
451 {
452 ATLASSERT(::IsWindow(this->m_hWnd));
453 return (DWORD)::SendMessage(this->m_hWnd, LB_GETLISTBOXINFO, 0, 0L);
454 }
455
456 // for single-selection listboxes
GetCurSel()457 int GetCurSel() const
458 {
459 ATLASSERT(::IsWindow(this->m_hWnd));
460 ATLASSERT((this->GetStyle() & (LBS_MULTIPLESEL | LBS_EXTENDEDSEL)) == 0);
461 return (int)::SendMessage(this->m_hWnd, LB_GETCURSEL, 0, 0L);
462 }
463
SetCurSel(int nSelect)464 int SetCurSel(int nSelect)
465 {
466 ATLASSERT(::IsWindow(this->m_hWnd));
467 ATLASSERT((this->GetStyle() & (LBS_MULTIPLESEL | LBS_EXTENDEDSEL)) == 0);
468 return (int)::SendMessage(this->m_hWnd, LB_SETCURSEL, nSelect, 0L);
469 }
470
471 // for multiple-selection listboxes
GetSel(int nIndex)472 int GetSel(int nIndex) const // also works for single-selection
473 {
474 ATLASSERT(::IsWindow(this->m_hWnd));
475 return (int)::SendMessage(this->m_hWnd, LB_GETSEL, nIndex, 0L);
476 }
477
478 int SetSel(int nIndex, BOOL bSelect = TRUE)
479 {
480 ATLASSERT(::IsWindow(this->m_hWnd));
481 ATLASSERT((this->GetStyle() & (LBS_MULTIPLESEL | LBS_EXTENDEDSEL)) != 0);
482 return (int)::SendMessage(this->m_hWnd, LB_SETSEL, bSelect, nIndex);
483 }
484
GetSelCount()485 int GetSelCount() const
486 {
487 ATLASSERT(::IsWindow(this->m_hWnd));
488 ATLASSERT((this->GetStyle() & (LBS_MULTIPLESEL | LBS_EXTENDEDSEL)) != 0);
489 return (int)::SendMessage(this->m_hWnd, LB_GETSELCOUNT, 0, 0L);
490 }
491
GetSelItems(int nMaxItems,LPINT rgIndex)492 int GetSelItems(int nMaxItems, LPINT rgIndex) const
493 {
494 ATLASSERT(::IsWindow(this->m_hWnd));
495 ATLASSERT((this->GetStyle() & (LBS_MULTIPLESEL | LBS_EXTENDEDSEL)) != 0);
496 return (int)::SendMessage(this->m_hWnd, LB_GETSELITEMS, nMaxItems, (LPARAM)rgIndex);
497 }
498
GetAnchorIndex()499 int GetAnchorIndex() const
500 {
501 ATLASSERT(::IsWindow(this->m_hWnd));
502 ATLASSERT((this->GetStyle() & (LBS_MULTIPLESEL | LBS_EXTENDEDSEL)) != 0);
503 return (int)::SendMessage(this->m_hWnd, LB_GETANCHORINDEX, 0, 0L);
504 }
505
SetAnchorIndex(int nIndex)506 void SetAnchorIndex(int nIndex)
507 {
508 ATLASSERT(::IsWindow(this->m_hWnd));
509 ATLASSERT((this->GetStyle() & (LBS_MULTIPLESEL | LBS_EXTENDEDSEL)) != 0);
510 ::SendMessage(this->m_hWnd, LB_SETANCHORINDEX, nIndex, 0L);
511 }
512
GetCaretIndex()513 int GetCaretIndex() const
514 {
515 ATLASSERT(::IsWindow(this->m_hWnd));
516 return (int)::SendMessage(this->m_hWnd, LB_GETCARETINDEX, 0, 0);
517 }
518
519 int SetCaretIndex(int nIndex, BOOL bScroll = TRUE)
520 {
521 ATLASSERT(::IsWindow(this->m_hWnd));
522 return (int)::SendMessage(this->m_hWnd, LB_SETCARETINDEX, nIndex, MAKELONG(bScroll, 0));
523 }
524
525 // for listbox items
GetItemData(int nIndex)526 DWORD_PTR GetItemData(int nIndex) const
527 {
528 ATLASSERT(::IsWindow(this->m_hWnd));
529 return (DWORD_PTR)::SendMessage(this->m_hWnd, LB_GETITEMDATA, nIndex, 0L);
530 }
531
SetItemData(int nIndex,DWORD_PTR dwItemData)532 int SetItemData(int nIndex, DWORD_PTR dwItemData)
533 {
534 ATLASSERT(::IsWindow(this->m_hWnd));
535 return (int)::SendMessage(this->m_hWnd, LB_SETITEMDATA, nIndex, (LPARAM)dwItemData);
536 }
537
GetItemDataPtr(int nIndex)538 void* GetItemDataPtr(int nIndex) const
539 {
540 ATLASSERT(::IsWindow(this->m_hWnd));
541 return (void*)::SendMessage(this->m_hWnd, LB_GETITEMDATA, nIndex, 0L);
542 }
543
SetItemDataPtr(int nIndex,void * pData)544 int SetItemDataPtr(int nIndex, void* pData)
545 {
546 ATLASSERT(::IsWindow(this->m_hWnd));
547 return SetItemData(nIndex, (DWORD_PTR)pData);
548 }
549
GetItemRect(int nIndex,LPRECT lpRect)550 int GetItemRect(int nIndex, LPRECT lpRect) const
551 {
552 ATLASSERT(::IsWindow(this->m_hWnd));
553 return (int)::SendMessage(this->m_hWnd, LB_GETITEMRECT, nIndex, (LPARAM)lpRect);
554 }
555
GetText(int nIndex,LPTSTR lpszBuffer)556 int GetText(int nIndex, LPTSTR lpszBuffer) const
557 {
558 ATLASSERT(::IsWindow(this->m_hWnd));
559 return (int)::SendMessage(this->m_hWnd, LB_GETTEXT, nIndex, (LPARAM)lpszBuffer);
560 }
561
562 #ifdef _OLEAUTO_H_
GetTextBSTR(int nIndex,BSTR & bstrText)563 BOOL GetTextBSTR(int nIndex, BSTR& bstrText) const
564 {
565 USES_CONVERSION;
566 ATLASSERT(::IsWindow(this->m_hWnd));
567 ATLASSERT(bstrText == NULL);
568
569 int nLen = GetTextLen(nIndex);
570 if(nLen == LB_ERR)
571 return FALSE;
572
573 ATL::CTempBuffer<TCHAR, _WTL_STACK_ALLOC_THRESHOLD> buff;
574 LPTSTR lpstrText = buff.Allocate(nLen + 1);
575 if(lpstrText == NULL)
576 return FALSE;
577
578 if(GetText(nIndex, lpstrText) == LB_ERR)
579 return FALSE;
580
581 bstrText = ::SysAllocString(T2OLE(lpstrText));
582 return (bstrText != NULL) ? TRUE : FALSE;
583 }
584 #endif // _OLEAUTO_H_
585
586 #ifdef __ATLSTR_H__
GetText(int nIndex,ATL::CString & strText)587 int GetText(int nIndex, ATL::CString& strText) const
588 {
589 ATLASSERT(::IsWindow(this->m_hWnd));
590 int cchLen = GetTextLen(nIndex);
591 if(cchLen == LB_ERR)
592 return LB_ERR;
593 int nRet = LB_ERR;
594 LPTSTR lpstr = strText.GetBufferSetLength(cchLen);
595 if(lpstr != NULL)
596 {
597 nRet = GetText(nIndex, lpstr);
598 strText.ReleaseBuffer();
599 }
600 return nRet;
601 }
602 #endif // __ATLSTR_H__
603
GetTextLen(int nIndex)604 int GetTextLen(int nIndex) const
605 {
606 ATLASSERT(::IsWindow(this->m_hWnd));
607 return (int)::SendMessage(this->m_hWnd, LB_GETTEXTLEN, nIndex, 0L);
608 }
609
GetItemHeight(int nIndex)610 int GetItemHeight(int nIndex) const
611 {
612 ATLASSERT(::IsWindow(this->m_hWnd));
613 return (int)::SendMessage(this->m_hWnd, LB_GETITEMHEIGHT, nIndex, 0L);
614 }
615
SetItemHeight(int nIndex,UINT cyItemHeight)616 int SetItemHeight(int nIndex, UINT cyItemHeight)
617 {
618 ATLASSERT(::IsWindow(this->m_hWnd));
619 return (int)::SendMessage(this->m_hWnd, LB_SETITEMHEIGHT, nIndex, MAKELONG(cyItemHeight, 0));
620 }
621
622 // Settable only attributes
SetColumnWidth(int cxWidth)623 void SetColumnWidth(int cxWidth)
624 {
625 ATLASSERT(::IsWindow(this->m_hWnd));
626 ::SendMessage(this->m_hWnd, LB_SETCOLUMNWIDTH, cxWidth, 0L);
627 }
628
SetTabStops(int nTabStops,LPINT rgTabStops)629 BOOL SetTabStops(int nTabStops, LPINT rgTabStops)
630 {
631 ATLASSERT(::IsWindow(this->m_hWnd));
632 ATLASSERT((this->GetStyle() & LBS_USETABSTOPS) != 0);
633 return (BOOL)::SendMessage(this->m_hWnd, LB_SETTABSTOPS, nTabStops, (LPARAM)rgTabStops);
634 }
635
SetTabStops()636 BOOL SetTabStops()
637 {
638 ATLASSERT(::IsWindow(this->m_hWnd));
639 ATLASSERT((this->GetStyle() & LBS_USETABSTOPS) != 0);
640 return (BOOL)::SendMessage(this->m_hWnd, LB_SETTABSTOPS, 0, 0L);
641 }
642
SetTabStops(const int & cxEachStop)643 BOOL SetTabStops(const int& cxEachStop) // takes an 'int'
644 {
645 ATLASSERT(::IsWindow(this->m_hWnd));
646 ATLASSERT((this->GetStyle() & LBS_USETABSTOPS) != 0);
647 return (BOOL)::SendMessage(this->m_hWnd, LB_SETTABSTOPS, 1, (LPARAM)(LPINT)&cxEachStop);
648 }
649
650 // Operations
InitStorage(int nItems,UINT nBytes)651 int InitStorage(int nItems, UINT nBytes)
652 {
653 ATLASSERT(::IsWindow(this->m_hWnd));
654 return (int)::SendMessage(this->m_hWnd, LB_INITSTORAGE, (WPARAM)nItems, nBytes);
655 }
656
ResetContent()657 void ResetContent()
658 {
659 ATLASSERT(::IsWindow(this->m_hWnd));
660 ::SendMessage(this->m_hWnd, LB_RESETCONTENT, 0, 0L);
661 }
662
ItemFromPoint(POINT pt,BOOL & bOutside)663 UINT ItemFromPoint(POINT pt, BOOL& bOutside) const
664 {
665 ATLASSERT(::IsWindow(this->m_hWnd));
666 DWORD dw = (DWORD)::SendMessage(this->m_hWnd, LB_ITEMFROMPOINT, 0, MAKELPARAM(pt.x, pt.y));
667 bOutside = (BOOL)HIWORD(dw);
668 return (UINT)LOWORD(dw);
669 }
670
671 // manipulating listbox items
AddString(LPCTSTR lpszItem)672 int AddString(LPCTSTR lpszItem)
673 {
674 ATLASSERT(::IsWindow(this->m_hWnd));
675 return (int)::SendMessage(this->m_hWnd, LB_ADDSTRING, 0, (LPARAM)lpszItem);
676 }
677
DeleteString(UINT nIndex)678 int DeleteString(UINT nIndex)
679 {
680 ATLASSERT(::IsWindow(this->m_hWnd));
681 return (int)::SendMessage(this->m_hWnd, LB_DELETESTRING, nIndex, 0L);
682 }
683
InsertString(int nIndex,LPCTSTR lpszItem)684 int InsertString(int nIndex, LPCTSTR lpszItem)
685 {
686 ATLASSERT(::IsWindow(this->m_hWnd));
687 return (int)::SendMessage(this->m_hWnd, LB_INSERTSTRING, nIndex, (LPARAM)lpszItem);
688 }
689
Dir(UINT attr,LPCTSTR lpszWildCard)690 int Dir(UINT attr, LPCTSTR lpszWildCard)
691 {
692 ATLASSERT(::IsWindow(this->m_hWnd));
693 return (int)::SendMessage(this->m_hWnd, LB_DIR, attr, (LPARAM)lpszWildCard);
694 }
695
AddFile(LPCTSTR lpstrFileName)696 int AddFile(LPCTSTR lpstrFileName)
697 {
698 ATLASSERT(::IsWindow(this->m_hWnd));
699 return (int)::SendMessage(this->m_hWnd, LB_ADDFILE, 0, (LPARAM)lpstrFileName);
700 }
701
702 // selection helpers
FindString(int nStartAfter,LPCTSTR lpszItem)703 int FindString(int nStartAfter, LPCTSTR lpszItem) const
704 {
705 ATLASSERT(::IsWindow(this->m_hWnd));
706 return (int)::SendMessage(this->m_hWnd, LB_FINDSTRING, nStartAfter, (LPARAM)lpszItem);
707 }
708
FindStringExact(int nIndexStart,LPCTSTR lpszFind)709 int FindStringExact(int nIndexStart, LPCTSTR lpszFind) const
710 {
711 ATLASSERT(::IsWindow(this->m_hWnd));
712 return (int)::SendMessage(this->m_hWnd, LB_FINDSTRINGEXACT, nIndexStart, (LPARAM)lpszFind);
713 }
714
SelectString(int nStartAfter,LPCTSTR lpszItem)715 int SelectString(int nStartAfter, LPCTSTR lpszItem)
716 {
717 ATLASSERT(::IsWindow(this->m_hWnd));
718 return (int)::SendMessage(this->m_hWnd, LB_SELECTSTRING, nStartAfter, (LPARAM)lpszItem);
719 }
720
SelItemRange(BOOL bSelect,int nFirstItem,int nLastItem)721 int SelItemRange(BOOL bSelect, int nFirstItem, int nLastItem)
722 {
723 ATLASSERT(::IsWindow(this->m_hWnd));
724 ATLASSERT((this->GetStyle() & (LBS_MULTIPLESEL | LBS_EXTENDEDSEL)) != 0);
725 ATLASSERT(nFirstItem <= nLastItem);
726 return bSelect ? (int)::SendMessage(this->m_hWnd, LB_SELITEMRANGEEX, nFirstItem, nLastItem) : (int)::SendMessage(this->m_hWnd, LB_SELITEMRANGEEX, nLastItem, nFirstItem);
727 }
728 };
729
730 typedef CListBoxT<ATL::CWindow> CListBox;
731
732
733 ///////////////////////////////////////////////////////////////////////////////
734 // CComboBox - client side for a Windows COMBOBOX control
735
736 template <class TBase>
737 class CComboBoxT : public TBase
738 {
739 public:
740 // Constructors
TBase(hWnd)741 CComboBoxT(HWND hWnd = NULL) : TBase(hWnd)
742 { }
743
744 CComboBoxT< TBase >& operator =(HWND hWnd)
745 {
746 this->m_hWnd = hWnd;
747 return *this;
748 }
749
750 HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
751 DWORD dwStyle = 0, DWORD dwExStyle = 0,
752 ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
753 {
754 return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
755 }
756
757 // Attributes
GetWndClassName()758 static LPCTSTR GetWndClassName()
759 {
760 return _T("COMBOBOX");
761 }
762
763 // for entire combo box
GetCount()764 int GetCount() const
765 {
766 ATLASSERT(::IsWindow(this->m_hWnd));
767 return (int)::SendMessage(this->m_hWnd, CB_GETCOUNT, 0, 0L);
768 }
769
GetCurSel()770 int GetCurSel() const
771 {
772 ATLASSERT(::IsWindow(this->m_hWnd));
773 return (int)::SendMessage(this->m_hWnd, CB_GETCURSEL, 0, 0L);
774 }
775
SetCurSel(int nSelect)776 int SetCurSel(int nSelect)
777 {
778 ATLASSERT(::IsWindow(this->m_hWnd));
779 return (int)::SendMessage(this->m_hWnd, CB_SETCURSEL, nSelect, 0L);
780 }
781
GetLocale()782 LCID GetLocale() const
783 {
784 ATLASSERT(::IsWindow(this->m_hWnd));
785 return (LCID)::SendMessage(this->m_hWnd, CB_GETLOCALE, 0, 0L);
786 }
787
SetLocale(LCID nNewLocale)788 LCID SetLocale(LCID nNewLocale)
789 {
790 ATLASSERT(::IsWindow(this->m_hWnd));
791 return (LCID)::SendMessage(this->m_hWnd, CB_SETLOCALE, (WPARAM)nNewLocale, 0L);
792 }
793
GetTopIndex()794 int GetTopIndex() const
795 {
796 ATLASSERT(::IsWindow(this->m_hWnd));
797 return (int)::SendMessage(this->m_hWnd, CB_GETTOPINDEX, 0, 0L);
798 }
799
SetTopIndex(int nIndex)800 int SetTopIndex(int nIndex)
801 {
802 ATLASSERT(::IsWindow(this->m_hWnd));
803 return (int)::SendMessage(this->m_hWnd, CB_SETTOPINDEX, nIndex, 0L);
804 }
805
GetHorizontalExtent()806 UINT GetHorizontalExtent() const
807 {
808 ATLASSERT(::IsWindow(this->m_hWnd));
809 return (UINT)::SendMessage(this->m_hWnd, CB_GETHORIZONTALEXTENT, 0, 0L);
810 }
811
SetHorizontalExtent(UINT nExtent)812 void SetHorizontalExtent(UINT nExtent)
813 {
814 ATLASSERT(::IsWindow(this->m_hWnd));
815 ::SendMessage(this->m_hWnd, CB_SETHORIZONTALEXTENT, nExtent, 0L);
816 }
817
GetDroppedWidth()818 int GetDroppedWidth() const
819 {
820 ATLASSERT(::IsWindow(this->m_hWnd));
821 return (int)::SendMessage(this->m_hWnd, CB_GETDROPPEDWIDTH, 0, 0L);
822 }
823
SetDroppedWidth(UINT nWidth)824 int SetDroppedWidth(UINT nWidth)
825 {
826 ATLASSERT(::IsWindow(this->m_hWnd));
827 return (int)::SendMessage(this->m_hWnd, CB_SETDROPPEDWIDTH, nWidth, 0L);
828 }
829
GetComboBoxInfo(PCOMBOBOXINFO pComboBoxInfo)830 BOOL GetComboBoxInfo(PCOMBOBOXINFO pComboBoxInfo) const
831 {
832 ATLASSERT(::IsWindow(this->m_hWnd));
833 return (BOOL)::SendMessage(this->m_hWnd, CB_GETCOMBOBOXINFO, 0, (LPARAM)pComboBoxInfo);
834 }
835
836 // for edit control
GetEditSel()837 DWORD GetEditSel() const
838 {
839 ATLASSERT(::IsWindow(this->m_hWnd));
840 return (DWORD)::SendMessage(this->m_hWnd, CB_GETEDITSEL, 0, 0L);
841 }
842
SetEditSel(int nStartChar,int nEndChar)843 BOOL SetEditSel(int nStartChar, int nEndChar)
844 {
845 ATLASSERT(::IsWindow(this->m_hWnd));
846 return (BOOL)::SendMessage(this->m_hWnd, CB_SETEDITSEL, 0, MAKELONG(nStartChar, nEndChar));
847 }
848
849 // for combobox item
GetItemData(int nIndex)850 DWORD_PTR GetItemData(int nIndex) const
851 {
852 ATLASSERT(::IsWindow(this->m_hWnd));
853 return (DWORD_PTR)::SendMessage(this->m_hWnd, CB_GETITEMDATA, nIndex, 0L);
854 }
855
SetItemData(int nIndex,DWORD_PTR dwItemData)856 int SetItemData(int nIndex, DWORD_PTR dwItemData)
857 {
858 ATLASSERT(::IsWindow(this->m_hWnd));
859 return (int)::SendMessage(this->m_hWnd, CB_SETITEMDATA, nIndex, (LPARAM)dwItemData);
860 }
861
GetItemDataPtr(int nIndex)862 void* GetItemDataPtr(int nIndex) const
863 {
864 ATLASSERT(::IsWindow(this->m_hWnd));
865 return (void*)GetItemData(nIndex);
866 }
867
SetItemDataPtr(int nIndex,void * pData)868 int SetItemDataPtr(int nIndex, void* pData)
869 {
870 ATLASSERT(::IsWindow(this->m_hWnd));
871 return SetItemData(nIndex, (DWORD_PTR)pData);
872 }
873
GetLBText(int nIndex,LPTSTR lpszText)874 int GetLBText(int nIndex, LPTSTR lpszText) const
875 {
876 ATLASSERT(::IsWindow(this->m_hWnd));
877 return (int)::SendMessage(this->m_hWnd, CB_GETLBTEXT, nIndex, (LPARAM)lpszText);
878 }
879
GetLBTextBSTR(int nIndex,BSTR & bstrText)880 BOOL GetLBTextBSTR(int nIndex, BSTR& bstrText) const
881 {
882 USES_CONVERSION;
883 ATLASSERT(::IsWindow(this->m_hWnd));
884 ATLASSERT(bstrText == NULL);
885
886 int nLen = GetLBTextLen(nIndex);
887 if(nLen == CB_ERR)
888 return FALSE;
889
890 ATL::CTempBuffer<TCHAR, _WTL_STACK_ALLOC_THRESHOLD> buff;
891 LPTSTR lpstrText = buff.Allocate(nLen + 1);
892 if(lpstrText == NULL)
893 return FALSE;
894
895 if(GetLBText(nIndex, lpstrText) == CB_ERR)
896 return FALSE;
897
898 bstrText = ::SysAllocString(T2OLE(lpstrText));
899 return (bstrText != NULL) ? TRUE : FALSE;
900 }
901
902 #ifdef __ATLSTR_H__
GetLBText(int nIndex,ATL::CString & strText)903 int GetLBText(int nIndex, ATL::CString& strText) const
904 {
905 ATLASSERT(::IsWindow(this->m_hWnd));
906 int cchLen = GetLBTextLen(nIndex);
907 if(cchLen == CB_ERR)
908 return CB_ERR;
909 int nRet = CB_ERR;
910 LPTSTR lpstr = strText.GetBufferSetLength(cchLen);
911 if(lpstr != NULL)
912 {
913 nRet = GetLBText(nIndex, lpstr);
914 strText.ReleaseBuffer();
915 }
916 return nRet;
917 }
918 #endif // __ATLSTR_H__
919
GetLBTextLen(int nIndex)920 int GetLBTextLen(int nIndex) const
921 {
922 ATLASSERT(::IsWindow(this->m_hWnd));
923 return (int)::SendMessage(this->m_hWnd, CB_GETLBTEXTLEN, nIndex, 0L);
924 }
925
GetItemHeight(int nIndex)926 int GetItemHeight(int nIndex) const
927 {
928 ATLASSERT(::IsWindow(this->m_hWnd));
929 return (int)::SendMessage(this->m_hWnd, CB_GETITEMHEIGHT, nIndex, 0L);
930 }
931
SetItemHeight(int nIndex,UINT cyItemHeight)932 int SetItemHeight(int nIndex, UINT cyItemHeight)
933 {
934 ATLASSERT(::IsWindow(this->m_hWnd));
935 return (int)::SendMessage(this->m_hWnd, CB_SETITEMHEIGHT, nIndex, MAKELONG(cyItemHeight, 0));
936 }
937
GetExtendedUI()938 BOOL GetExtendedUI() const
939 {
940 ATLASSERT(::IsWindow(this->m_hWnd));
941 return (BOOL)::SendMessage(this->m_hWnd, CB_GETEXTENDEDUI, 0, 0L);
942 }
943
944 int SetExtendedUI(BOOL bExtended = TRUE)
945 {
946 ATLASSERT(::IsWindow(this->m_hWnd));
947 return (int)::SendMessage(this->m_hWnd, CB_SETEXTENDEDUI, bExtended, 0L);
948 }
949
GetDroppedControlRect(LPRECT lprect)950 void GetDroppedControlRect(LPRECT lprect) const
951 {
952 ATLASSERT(::IsWindow(this->m_hWnd));
953 ::SendMessage(this->m_hWnd, CB_GETDROPPEDCONTROLRECT, 0, (LPARAM)lprect);
954 }
955
GetDroppedState()956 BOOL GetDroppedState() const
957 {
958 ATLASSERT(::IsWindow(this->m_hWnd));
959 return (BOOL)::SendMessage(this->m_hWnd, CB_GETDROPPEDSTATE, 0, 0L);
960 }
961
GetMinVisible()962 int GetMinVisible() const
963 {
964 ATLASSERT(::IsWindow(this->m_hWnd));
965 return (int)::SendMessage(this->m_hWnd, CB_GETMINVISIBLE, 0, 0L);
966 }
967
SetMinVisible(int nMinVisible)968 BOOL SetMinVisible(int nMinVisible)
969 {
970 ATLASSERT(::IsWindow(this->m_hWnd));
971 return (BOOL)::SendMessage(this->m_hWnd, CB_SETMINVISIBLE, nMinVisible, 0L);
972 }
973
974 // Vista only
GetCueBannerText(LPWSTR lpwText,int cchText)975 BOOL GetCueBannerText(LPWSTR lpwText, int cchText) const
976 {
977 ATLASSERT(::IsWindow(this->m_hWnd));
978 return (BOOL)::SendMessage(this->m_hWnd, CB_GETCUEBANNER, (WPARAM)lpwText, cchText);
979 }
980
981 // Vista only
SetCueBannerText(LPCWSTR lpcwText)982 BOOL SetCueBannerText(LPCWSTR lpcwText)
983 {
984 ATLASSERT(::IsWindow(this->m_hWnd));
985 return (BOOL)::SendMessage(this->m_hWnd, CB_SETCUEBANNER, 0, (LPARAM)lpcwText);
986 }
987
988 // Operations
InitStorage(int nItems,UINT nBytes)989 int InitStorage(int nItems, UINT nBytes)
990 {
991 ATLASSERT(::IsWindow(this->m_hWnd));
992 return (int)::SendMessage(this->m_hWnd, CB_INITSTORAGE, (WPARAM)nItems, nBytes);
993 }
994
ResetContent()995 void ResetContent()
996 {
997 ATLASSERT(::IsWindow(this->m_hWnd));
998 ::SendMessage(this->m_hWnd, CB_RESETCONTENT, 0, 0L);
999 }
1000
1001 // for edit control
LimitText(int nMaxChars)1002 BOOL LimitText(int nMaxChars)
1003 {
1004 ATLASSERT(::IsWindow(this->m_hWnd));
1005 return (BOOL)::SendMessage(this->m_hWnd, CB_LIMITTEXT, nMaxChars, 0L);
1006 }
1007
1008 // for drop-down combo boxes
1009 void ShowDropDown(BOOL bShowIt = TRUE)
1010 {
1011 ATLASSERT(::IsWindow(this->m_hWnd));
1012 ::SendMessage(this->m_hWnd, CB_SHOWDROPDOWN, bShowIt, 0L);
1013 }
1014
1015 // manipulating listbox items
AddString(LPCTSTR lpszString)1016 int AddString(LPCTSTR lpszString)
1017 {
1018 ATLASSERT(::IsWindow(this->m_hWnd));
1019 return (int)::SendMessage(this->m_hWnd, CB_ADDSTRING, 0, (LPARAM)lpszString);
1020 }
1021
DeleteString(UINT nIndex)1022 int DeleteString(UINT nIndex)
1023 {
1024 ATLASSERT(::IsWindow(this->m_hWnd));
1025 return (int)::SendMessage(this->m_hWnd, CB_DELETESTRING, nIndex, 0L);
1026 }
1027
InsertString(int nIndex,LPCTSTR lpszString)1028 int InsertString(int nIndex, LPCTSTR lpszString)
1029 {
1030 ATLASSERT(::IsWindow(this->m_hWnd));
1031 return (int)::SendMessage(this->m_hWnd, CB_INSERTSTRING, nIndex, (LPARAM)lpszString);
1032 }
1033
Dir(UINT attr,LPCTSTR lpszWildCard)1034 int Dir(UINT attr, LPCTSTR lpszWildCard)
1035 {
1036 ATLASSERT(::IsWindow(this->m_hWnd));
1037 return (int)::SendMessage(this->m_hWnd, CB_DIR, attr, (LPARAM)lpszWildCard);
1038 }
1039
1040 // selection helpers
FindString(int nStartAfter,LPCTSTR lpszString)1041 int FindString(int nStartAfter, LPCTSTR lpszString) const
1042 {
1043 ATLASSERT(::IsWindow(this->m_hWnd));
1044 return (int)::SendMessage(this->m_hWnd, CB_FINDSTRING, nStartAfter, (LPARAM)lpszString);
1045 }
1046
FindStringExact(int nIndexStart,LPCTSTR lpszFind)1047 int FindStringExact(int nIndexStart, LPCTSTR lpszFind) const
1048 {
1049 ATLASSERT(::IsWindow(this->m_hWnd));
1050 return (int)::SendMessage(this->m_hWnd, CB_FINDSTRINGEXACT, nIndexStart, (LPARAM)lpszFind);
1051 }
1052
SelectString(int nStartAfter,LPCTSTR lpszString)1053 int SelectString(int nStartAfter, LPCTSTR lpszString)
1054 {
1055 ATLASSERT(::IsWindow(this->m_hWnd));
1056 return (int)::SendMessage(this->m_hWnd, CB_SELECTSTRING, nStartAfter, (LPARAM)lpszString);
1057 }
1058
1059 // Clipboard operations
Clear()1060 void Clear()
1061 {
1062 ATLASSERT(::IsWindow(this->m_hWnd));
1063 ::SendMessage(this->m_hWnd, WM_CLEAR, 0, 0L);
1064 }
1065
Copy()1066 void Copy()
1067 {
1068 ATLASSERT(::IsWindow(this->m_hWnd));
1069 ::SendMessage(this->m_hWnd, WM_COPY, 0, 0L);
1070 }
1071
Cut()1072 void Cut()
1073 {
1074 ATLASSERT(::IsWindow(this->m_hWnd));
1075 ::SendMessage(this->m_hWnd, WM_CUT, 0, 0L);
1076 }
1077
Paste()1078 void Paste()
1079 {
1080 ATLASSERT(::IsWindow(this->m_hWnd));
1081 ::SendMessage(this->m_hWnd, WM_PASTE, 0, 0L);
1082 }
1083 };
1084
1085 typedef CComboBoxT<ATL::CWindow> CComboBox;
1086
1087
1088 ///////////////////////////////////////////////////////////////////////////////
1089 // CEdit - client side for a Windows EDIT control
1090
1091 template <class TBase>
1092 class CEditT : public TBase
1093 {
1094 public:
1095 // Constructors
TBase(hWnd)1096 CEditT(HWND hWnd = NULL) : TBase(hWnd)
1097 { }
1098
1099 CEditT< TBase >& operator =(HWND hWnd)
1100 {
1101 this->m_hWnd = hWnd;
1102 return *this;
1103 }
1104
1105 HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
1106 DWORD dwStyle = 0, DWORD dwExStyle = 0,
1107 ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
1108 {
1109 return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
1110 }
1111
1112 // Attributes
GetWndClassName()1113 static LPCTSTR GetWndClassName()
1114 {
1115 return _T("EDIT");
1116 }
1117
CanUndo()1118 BOOL CanUndo() const
1119 {
1120 ATLASSERT(::IsWindow(this->m_hWnd));
1121 return (BOOL)::SendMessage(this->m_hWnd, EM_CANUNDO, 0, 0L);
1122 }
1123
GetLineCount()1124 int GetLineCount() const
1125 {
1126 ATLASSERT(::IsWindow(this->m_hWnd));
1127 return (int)::SendMessage(this->m_hWnd, EM_GETLINECOUNT, 0, 0L);
1128 }
1129
GetModify()1130 BOOL GetModify() const
1131 {
1132 ATLASSERT(::IsWindow(this->m_hWnd));
1133 return (BOOL)::SendMessage(this->m_hWnd, EM_GETMODIFY, 0, 0L);
1134 }
1135
1136 void SetModify(BOOL bModified = TRUE)
1137 {
1138 ATLASSERT(::IsWindow(this->m_hWnd));
1139 ::SendMessage(this->m_hWnd, EM_SETMODIFY, bModified, 0L);
1140 }
1141
GetRect(LPRECT lpRect)1142 void GetRect(LPRECT lpRect) const
1143 {
1144 ATLASSERT(::IsWindow(this->m_hWnd));
1145 ::SendMessage(this->m_hWnd, EM_GETRECT, 0, (LPARAM)lpRect);
1146 }
1147
GetSel()1148 DWORD GetSel() const
1149 {
1150 ATLASSERT(::IsWindow(this->m_hWnd));
1151 return (DWORD)::SendMessage(this->m_hWnd, EM_GETSEL, 0, 0L);
1152 }
1153
GetSel(int & nStartChar,int & nEndChar)1154 void GetSel(int& nStartChar, int& nEndChar) const
1155 {
1156 ATLASSERT(::IsWindow(this->m_hWnd));
1157 ::SendMessage(this->m_hWnd, EM_GETSEL, (WPARAM)&nStartChar, (LPARAM)&nEndChar);
1158 }
1159
GetHandle()1160 HLOCAL GetHandle() const
1161 {
1162 ATLASSERT(::IsWindow(this->m_hWnd));
1163 return (HLOCAL)::SendMessage(this->m_hWnd, EM_GETHANDLE, 0, 0L);
1164 }
1165
SetHandle(HLOCAL hBuffer)1166 void SetHandle(HLOCAL hBuffer)
1167 {
1168 ATLASSERT(::IsWindow(this->m_hWnd));
1169 ::SendMessage(this->m_hWnd, EM_SETHANDLE, (WPARAM)hBuffer, 0L);
1170 }
1171
GetMargins()1172 DWORD GetMargins() const
1173 {
1174 ATLASSERT(::IsWindow(this->m_hWnd));
1175 return (DWORD)::SendMessage(this->m_hWnd, EM_GETMARGINS, 0, 0L);
1176 }
1177
GetMargins(UINT & nLeft,UINT & nRight)1178 void GetMargins(UINT& nLeft, UINT& nRight) const
1179 {
1180 ATLASSERT(::IsWindow(this->m_hWnd));
1181 DWORD dwRet = (DWORD)::SendMessage(this->m_hWnd, EM_GETMARGINS, 0, 0L);
1182 nLeft = LOWORD(dwRet);
1183 nRight = HIWORD(dwRet);
1184 }
1185
1186 void SetMargins(UINT nLeft, UINT nRight, WORD wFlags = EC_LEFTMARGIN | EC_RIGHTMARGIN)
1187 {
1188 ATLASSERT(::IsWindow(this->m_hWnd));
1189 ::SendMessage(this->m_hWnd, EM_SETMARGINS, wFlags, MAKELONG(nLeft, nRight));
1190 }
1191
GetLimitText()1192 UINT GetLimitText() const
1193 {
1194 ATLASSERT(::IsWindow(this->m_hWnd));
1195 return (UINT)::SendMessage(this->m_hWnd, EM_GETLIMITTEXT, 0, 0L);
1196 }
1197
SetLimitText(UINT nMax)1198 void SetLimitText(UINT nMax)
1199 {
1200 ATLASSERT(::IsWindow(this->m_hWnd));
1201 ::SendMessage(this->m_hWnd, EM_SETLIMITTEXT, nMax, 0L);
1202 }
1203
PosFromChar(UINT nChar)1204 POINT PosFromChar(UINT nChar) const
1205 {
1206 ATLASSERT(::IsWindow(this->m_hWnd));
1207 DWORD dwRet = (DWORD)::SendMessage(this->m_hWnd, EM_POSFROMCHAR, nChar, 0);
1208 POINT point = { GET_X_LPARAM(dwRet), GET_Y_LPARAM(dwRet) };
1209 return point;
1210 }
1211
1212 int CharFromPos(POINT pt, int* pLine = NULL) const
1213 {
1214 ATLASSERT(::IsWindow(this->m_hWnd));
1215 DWORD dwRet = (DWORD)::SendMessage(this->m_hWnd, EM_CHARFROMPOS, 0, MAKELPARAM(pt.x, pt.y));
1216 if(pLine != NULL)
1217 *pLine = (int)(short)HIWORD(dwRet);
1218 return (int)(short)LOWORD(dwRet);
1219 }
1220
1221 // NOTE: first word in lpszBuffer must contain the size of the buffer!
GetLine(int nIndex,LPTSTR lpszBuffer)1222 int GetLine(int nIndex, LPTSTR lpszBuffer) const
1223 {
1224 ATLASSERT(::IsWindow(this->m_hWnd));
1225 return (int)::SendMessage(this->m_hWnd, EM_GETLINE, nIndex, (LPARAM)lpszBuffer);
1226 }
1227
GetLine(int nIndex,LPTSTR lpszBuffer,int nMaxLength)1228 int GetLine(int nIndex, LPTSTR lpszBuffer, int nMaxLength) const
1229 {
1230 ATLASSERT(::IsWindow(this->m_hWnd));
1231 *(LPWORD)lpszBuffer = (WORD)nMaxLength;
1232 return (int)::SendMessage(this->m_hWnd, EM_GETLINE, nIndex, (LPARAM)lpszBuffer);
1233 }
1234
GetPasswordChar()1235 TCHAR GetPasswordChar() const
1236 {
1237 ATLASSERT(::IsWindow(this->m_hWnd));
1238 return (TCHAR)::SendMessage(this->m_hWnd, EM_GETPASSWORDCHAR, 0, 0L);
1239 }
1240
SetPasswordChar(TCHAR ch)1241 void SetPasswordChar(TCHAR ch)
1242 {
1243 ATLASSERT(::IsWindow(this->m_hWnd));
1244 ::SendMessage(this->m_hWnd, EM_SETPASSWORDCHAR, ch, 0L);
1245 }
1246
GetWordBreakProc()1247 EDITWORDBREAKPROC GetWordBreakProc() const
1248 {
1249 ATLASSERT(::IsWindow(this->m_hWnd));
1250 return (EDITWORDBREAKPROC)::SendMessage(this->m_hWnd, EM_GETWORDBREAKPROC, 0, 0L);
1251 }
1252
SetWordBreakProc(EDITWORDBREAKPROC ewbprc)1253 void SetWordBreakProc(EDITWORDBREAKPROC ewbprc)
1254 {
1255 ATLASSERT(::IsWindow(this->m_hWnd));
1256 ::SendMessage(this->m_hWnd, EM_SETWORDBREAKPROC, 0, (LPARAM)ewbprc);
1257 }
1258
GetFirstVisibleLine()1259 int GetFirstVisibleLine() const
1260 {
1261 ATLASSERT(::IsWindow(this->m_hWnd));
1262 return (int)::SendMessage(this->m_hWnd, EM_GETFIRSTVISIBLELINE, 0, 0L);
1263 }
1264
GetThumb()1265 int GetThumb() const
1266 {
1267 ATLASSERT(::IsWindow(this->m_hWnd));
1268 ATLASSERT((this->GetStyle() & ES_MULTILINE) != 0);
1269 return (int)::SendMessage(this->m_hWnd, EM_GETTHUMB, 0, 0L);
1270 }
1271
1272 BOOL SetReadOnly(BOOL bReadOnly = TRUE)
1273 {
1274 ATLASSERT(::IsWindow(this->m_hWnd));
1275 return (BOOL)::SendMessage(this->m_hWnd, EM_SETREADONLY, bReadOnly, 0L);
1276 }
1277
GetImeStatus(UINT uStatus)1278 UINT GetImeStatus(UINT uStatus) const
1279 {
1280 ATLASSERT(::IsWindow(this->m_hWnd));
1281 return (UINT)::SendMessage(this->m_hWnd, EM_GETIMESTATUS, uStatus, 0L);
1282 }
1283
SetImeStatus(UINT uStatus,UINT uData)1284 UINT SetImeStatus(UINT uStatus, UINT uData)
1285 {
1286 ATLASSERT(::IsWindow(this->m_hWnd));
1287 return (UINT)::SendMessage(this->m_hWnd, EM_SETIMESTATUS, uStatus, uData);
1288 }
1289
GetCueBannerText(LPCWSTR lpstrText,int cchText)1290 BOOL GetCueBannerText(LPCWSTR lpstrText, int cchText) const
1291 {
1292 ATLASSERT(::IsWindow(this->m_hWnd));
1293 return (BOOL)::SendMessage(this->m_hWnd, EM_GETCUEBANNER, (WPARAM)lpstrText, cchText);
1294 }
1295
1296 // bKeepWithFocus - Vista only
1297 BOOL SetCueBannerText(LPCWSTR lpstrText, BOOL bKeepWithFocus = FALSE)
1298 {
1299 ATLASSERT(::IsWindow(this->m_hWnd));
1300 return (BOOL)::SendMessage(this->m_hWnd, EM_SETCUEBANNER, (WPARAM)bKeepWithFocus, (LPARAM)(lpstrText));
1301 }
1302
1303 // Operations
EmptyUndoBuffer()1304 void EmptyUndoBuffer()
1305 {
1306 ATLASSERT(::IsWindow(this->m_hWnd));
1307 ::SendMessage(this->m_hWnd, EM_EMPTYUNDOBUFFER, 0, 0L);
1308 }
1309
FmtLines(BOOL bAddEOL)1310 BOOL FmtLines(BOOL bAddEOL)
1311 {
1312 ATLASSERT(::IsWindow(this->m_hWnd));
1313 return (BOOL)::SendMessage(this->m_hWnd, EM_FMTLINES, bAddEOL, 0L);
1314 }
1315
1316 void LimitText(int nChars = 0)
1317 {
1318 ATLASSERT(::IsWindow(this->m_hWnd));
1319 ::SendMessage(this->m_hWnd, EM_LIMITTEXT, nChars, 0L);
1320 }
1321
1322 int LineFromChar(int nIndex = -1) const
1323 {
1324 ATLASSERT(::IsWindow(this->m_hWnd));
1325 return (int)::SendMessage(this->m_hWnd, EM_LINEFROMCHAR, nIndex, 0L);
1326 }
1327
1328 int LineIndex(int nLine = -1) const
1329 {
1330 ATLASSERT(::IsWindow(this->m_hWnd));
1331 return (int)::SendMessage(this->m_hWnd, EM_LINEINDEX, nLine, 0L);
1332 }
1333
1334 int LineLength(int nLine = -1) const
1335 {
1336 ATLASSERT(::IsWindow(this->m_hWnd));
1337 return (int)::SendMessage(this->m_hWnd, EM_LINELENGTH, nLine, 0L);
1338 }
1339
1340 void LineScroll(int nLines, int nChars = 0)
1341 {
1342 ATLASSERT(::IsWindow(this->m_hWnd));
1343 ::SendMessage(this->m_hWnd, EM_LINESCROLL, nChars, nLines);
1344 }
1345
1346 void ReplaceSel(LPCTSTR lpszNewText, BOOL bCanUndo = FALSE)
1347 {
1348 ATLASSERT(::IsWindow(this->m_hWnd));
1349 ::SendMessage(this->m_hWnd, EM_REPLACESEL, (WPARAM) bCanUndo, (LPARAM)lpszNewText);
1350 }
1351
SetRect(LPCRECT lpRect)1352 void SetRect(LPCRECT lpRect)
1353 {
1354 ATLASSERT(::IsWindow(this->m_hWnd));
1355 ::SendMessage(this->m_hWnd, EM_SETRECT, 0, (LPARAM)lpRect);
1356 }
1357
SetRectNP(LPCRECT lpRect)1358 void SetRectNP(LPCRECT lpRect)
1359 {
1360 ATLASSERT(::IsWindow(this->m_hWnd));
1361 ::SendMessage(this->m_hWnd, EM_SETRECTNP, 0, (LPARAM)lpRect);
1362 }
1363
1364 void SetSel(DWORD dwSelection, BOOL bNoScroll = FALSE)
1365 {
1366 ATLASSERT(::IsWindow(this->m_hWnd));
1367 ::SendMessage(this->m_hWnd, EM_SETSEL, LOWORD(dwSelection), HIWORD(dwSelection));
1368 if(!bNoScroll)
1369 ::SendMessage(this->m_hWnd, EM_SCROLLCARET, 0, 0L);
1370 }
1371
1372 void SetSel(int nStartChar, int nEndChar, BOOL bNoScroll = FALSE)
1373 {
1374 ATLASSERT(::IsWindow(this->m_hWnd));
1375 ::SendMessage(this->m_hWnd, EM_SETSEL, nStartChar, nEndChar);
1376 if(!bNoScroll)
1377 ::SendMessage(this->m_hWnd, EM_SCROLLCARET, 0, 0L);
1378 }
1379
1380 void SetSelAll(BOOL bNoScroll = FALSE)
1381 {
1382 SetSel(0, -1, bNoScroll);
1383 }
1384
1385 void SetSelNone(BOOL bNoScroll = FALSE)
1386 {
1387 SetSel(-1, 0, bNoScroll);
1388 }
1389
SetTabStops(int nTabStops,LPINT rgTabStops)1390 BOOL SetTabStops(int nTabStops, LPINT rgTabStops)
1391 {
1392 ATLASSERT(::IsWindow(this->m_hWnd));
1393 return (BOOL)::SendMessage(this->m_hWnd, EM_SETTABSTOPS, nTabStops, (LPARAM)rgTabStops);
1394 }
1395
SetTabStops()1396 BOOL SetTabStops()
1397 {
1398 ATLASSERT(::IsWindow(this->m_hWnd));
1399 return (BOOL)::SendMessage(this->m_hWnd, EM_SETTABSTOPS, 0, 0L);
1400 }
1401
SetTabStops(const int & cxEachStop)1402 BOOL SetTabStops(const int& cxEachStop) // takes an 'int'
1403 {
1404 ATLASSERT(::IsWindow(this->m_hWnd));
1405 return (BOOL)::SendMessage(this->m_hWnd, EM_SETTABSTOPS, 1, (LPARAM)(LPINT)&cxEachStop);
1406 }
1407
ScrollCaret()1408 void ScrollCaret()
1409 {
1410 ATLASSERT(::IsWindow(this->m_hWnd));
1411 ::SendMessage(this->m_hWnd, EM_SCROLLCARET, 0, 0L);
1412 }
1413
Scroll(int nScrollAction)1414 int Scroll(int nScrollAction)
1415 {
1416 ATLASSERT(::IsWindow(this->m_hWnd));
1417 ATLASSERT((this->GetStyle() & ES_MULTILINE) != 0);
1418 LRESULT lRet = ::SendMessage(this->m_hWnd, EM_SCROLL, nScrollAction, 0L);
1419 if(!(BOOL)HIWORD(lRet))
1420 return -1; // failed
1421 return (int)(short)LOWORD(lRet);
1422
1423 }
1424
1425 void InsertText(int nInsertAfterChar, LPCTSTR lpstrText, BOOL bNoScroll = FALSE, BOOL bCanUndo = FALSE)
1426 {
1427 SetSel(nInsertAfterChar, nInsertAfterChar, bNoScroll);
1428 ReplaceSel(lpstrText, bCanUndo);
1429 }
1430
1431 void AppendText(LPCTSTR lpstrText, BOOL bNoScroll = FALSE, BOOL bCanUndo = FALSE)
1432 {
1433 InsertText(this->GetWindowTextLength(), lpstrText, bNoScroll, bCanUndo);
1434 }
1435
ShowBalloonTip(PEDITBALLOONTIP pEditBaloonTip)1436 BOOL ShowBalloonTip(PEDITBALLOONTIP pEditBaloonTip)
1437 {
1438 ATLASSERT(::IsWindow(this->m_hWnd));
1439 return (BOOL)::SendMessage(this->m_hWnd, EM_SHOWBALLOONTIP, 0, (LPARAM)pEditBaloonTip);
1440 }
1441
HideBalloonTip()1442 BOOL HideBalloonTip()
1443 {
1444 ATLASSERT(::IsWindow(this->m_hWnd));
1445 return (BOOL)::SendMessage(this->m_hWnd, EM_HIDEBALLOONTIP, 0, 0L);
1446 }
1447
1448 #if (_WIN32_WINNT >= 0x0600)
GetHilite()1449 DWORD GetHilite() const
1450 {
1451 ATLASSERT(::IsWindow(this->m_hWnd));
1452 return (DWORD)::SendMessage(this->m_hWnd, EM_GETHILITE, 0, 0L);
1453 }
1454
GetHilite(int & nStartChar,int & nEndChar)1455 void GetHilite(int& nStartChar, int& nEndChar) const
1456 {
1457 ATLASSERT(::IsWindow(this->m_hWnd));
1458 DWORD dwRet = (DWORD)::SendMessage(this->m_hWnd, EM_GETHILITE, 0, 0L);
1459 nStartChar = (int)(short)LOWORD(dwRet);
1460 nEndChar = (int)(short)HIWORD(dwRet);
1461 }
1462
SetHilite(int nStartChar,int nEndChar)1463 void SetHilite(int nStartChar, int nEndChar)
1464 {
1465 ATLASSERT(::IsWindow(this->m_hWnd));
1466 ::SendMessage(this->m_hWnd, EM_SETHILITE, nStartChar, nEndChar);
1467 }
1468 #endif // (_WIN32_WINNT >= 0x0600)
1469
1470 // Clipboard operations
Undo()1471 BOOL Undo()
1472 {
1473 ATLASSERT(::IsWindow(this->m_hWnd));
1474 return (BOOL)::SendMessage(this->m_hWnd, EM_UNDO, 0, 0L);
1475 }
1476
Clear()1477 void Clear()
1478 {
1479 ATLASSERT(::IsWindow(this->m_hWnd));
1480 ::SendMessage(this->m_hWnd, WM_CLEAR, 0, 0L);
1481 }
1482
Copy()1483 void Copy()
1484 {
1485 ATLASSERT(::IsWindow(this->m_hWnd));
1486 ::SendMessage(this->m_hWnd, WM_COPY, 0, 0L);
1487 }
1488
Cut()1489 void Cut()
1490 {
1491 ATLASSERT(::IsWindow(this->m_hWnd));
1492 ::SendMessage(this->m_hWnd, WM_CUT, 0, 0L);
1493 }
1494
Paste()1495 void Paste()
1496 {
1497 ATLASSERT(::IsWindow(this->m_hWnd));
1498 ::SendMessage(this->m_hWnd, WM_PASTE, 0, 0L);
1499 }
1500
1501 // New messages added in Windows 10.0.17763
1502 #if defined(NTDDI_VERSION) && defined(NTDDI_WIN10_RS5) && (NTDDI_VERSION >= NTDDI_WIN10_RS5)
SetExtendedStyle(DWORD dwStyle,DWORD dwMask)1503 DWORD SetExtendedStyle(DWORD dwStyle, DWORD dwMask)
1504 {
1505 ATLASSERT(::IsWindow(this->m_hWnd));
1506 return ::SendMessage(this->m_hWnd, EM_SETEXTENDEDSTYLE, dwMask, dwStyle);
1507 }
1508
GetExtendedStyle()1509 DWORD GetExtendedStyle() const
1510 {
1511 ATLASSERT(::IsWindow(this->m_hWnd));
1512 return ::SendMessage(this->m_hWnd, EM_GETEXTENDEDSTYLE, 0, 0L);
1513 }
1514
SetEndOfLine(EC_ENDOFLINE eolType)1515 BOOL SetEndOfLine(EC_ENDOFLINE eolType)
1516 {
1517 ATLASSERT(::IsWindow(this->m_hWnd));
1518 return (BOOL)::SendMessage(this->m_hWnd, EM_SETENDOFLINE, eolType, 0L);
1519 }
1520
GetEndOfLine()1521 EC_ENDOFLINE GetEndOfLine() const
1522 {
1523 ATLASSERT(::IsWindow(this->m_hWnd));
1524 return (EC_ENDOFLINE)::SendMessage(this->m_hWnd, EM_GETENDOFLINE, 0, 0L);
1525 }
1526
EnableSearchWeb(BOOL bEnable)1527 BOOL EnableSearchWeb(BOOL bEnable)
1528 {
1529 ATLASSERT(::IsWindow(this->m_hWnd));
1530 return (BOOL)::SendMessage(this->m_hWnd, EM_ENABLESEARCHWEB, (WPARAM)bEnable, 0L);
1531 }
1532
SearchWeb()1533 void SearchWeb()
1534 {
1535 ATLASSERT(::IsWindow(this->m_hWnd));
1536 ::SendMessage(this->m_hWnd, EM_SEARCHWEB, 0, 0L);
1537 }
1538
SetCaretIndex(DWORD dwCaretIndex)1539 BOOL SetCaretIndex(DWORD dwCaretIndex)
1540 {
1541 ATLASSERT(::IsWindow(this->m_hWnd));
1542 return (BOOL)::SendMessage(this->m_hWnd, EM_SETCARETINDEX, dwCaretIndex, 0L);
1543 }
1544
GetCaretIndex()1545 DWORD GetCaretIndex() const
1546 {
1547 ATLASSERT(::IsWindow(this->m_hWnd));
1548 return ::SendMessage(this->m_hWnd, EM_GETCARETINDEX, 0, 0L);
1549 }
1550
GetZoom(int & nNum,int & nDen)1551 BOOL GetZoom(int& nNum, int& nDen) const
1552 {
1553 ATLASSERT(::IsWindow(this->m_hWnd));
1554 return (BOOL)::SendMessage(this->m_hWnd, EM_GETZOOM, (WPARAM)&nNum, (LPARAM)&nDen);
1555 }
1556
SetZoom(int nNum,int nDen)1557 BOOL SetZoom(int nNum, int nDen)
1558 {
1559 ATLASSERT(::IsWindow(this->m_hWnd));
1560 ATLASSERT((nNum >= 0) && (nNum <= 64));
1561 ATLASSERT((nDen >= 0) && (nDen <= 64));
1562 return (BOOL)::SendMessage(this->m_hWnd, EM_SETZOOM, nNum, nDen);
1563 }
1564
GetFileLineFromChar(DWORD dwCharIndex)1565 DWORD GetFileLineFromChar(DWORD dwCharIndex) const
1566 {
1567 ATLASSERT(::IsWindow(this->m_hWnd));
1568 return ::SendMessage(this->m_hWnd, EM_FILELINEFROMCHAR, dwCharIndex, 0L);
1569 }
1570
GetFileLineIndex(DWORD dwLineNum)1571 DWORD GetFileLineIndex(DWORD dwLineNum) const
1572 {
1573 ATLASSERT(::IsWindow(this->m_hWnd));
1574 return ::SendMessage(this->m_hWnd, EM_FILELINEINDEX, dwLineNum, 0L);
1575 }
1576
GetFileLineLength(DWORD dwCharIndex)1577 DWORD GetFileLineLength(DWORD dwCharIndex) const
1578 {
1579 ATLASSERT(::IsWindow(this->m_hWnd));
1580 return ::SendMessage(this->m_hWnd, EM_FILELINELENGTH, dwCharIndex, 0L);
1581 }
1582
GetFileLine(DWORD dwLineNum,LPTSTR lpstrLine,WORD wLen)1583 DWORD GetFileLine(DWORD dwLineNum, LPTSTR lpstrLine, WORD wLen) const
1584 {
1585 ATLASSERT(::IsWindow(this->m_hWnd));
1586 WORD* pw = (WORD*)lpstrLine;
1587 *pw = wLen;
1588 return ::SendMessage(this->m_hWnd, EM_GETFILELINE, dwLineNum, (LPARAM)lpstrLine);
1589 }
1590
1591 #ifdef __ATLSTR_H__
GetFileLine(DWORD dwLineNum)1592 ATL::CString GetFileLine(DWORD dwLineNum) const
1593 {
1594 ATL::CString strLine;
1595 DWORD dwCharIndex = GetFileLineIndex(dwLineNum);
1596 if(dwCharIndex != (DWORD)-1)
1597 {
1598 DWORD dwLen = GetFileLineLength(dwCharIndex);
1599 if(dwLen > 0)
1600 {
1601 LPTSTR lpstrLine = strLine.GetBufferSetLength(dwLen);
1602 ATLVERIFY(GetFileLine(dwLineNum, lpstrLine, (WORD)dwLen) == dwLen);
1603 strLine.ReleaseBuffer();
1604 }
1605 }
1606
1607 return strLine;
1608 }
1609 #endif // __ATLSTR_H__
1610
GetFileLineCount()1611 DWORD GetFileLineCount() const
1612 {
1613 ATLASSERT(::IsWindow(this->m_hWnd));
1614 return ::SendMessage(this->m_hWnd, EM_GETFILELINECOUNT, 0, 0L);
1615 }
1616 #endif // defined(NTDDI_VERSION) && defined(NTDDI_WIN10_RS5) && (NTDDI_VERSION >= NTDDI_WIN10_RS5)
1617 };
1618
1619 typedef CEditT<ATL::CWindow> CEdit;
1620
1621
1622 ///////////////////////////////////////////////////////////////////////////////
1623 // CEditCommands - message handlers for standard EDIT commands
1624
1625 // Chain to CEditCommands message map. Your class must also derive from CEdit.
1626 // Example:
1627 // class CMyEdit : public CWindowImpl<CMyEdit, CEdit>,
1628 // public CEditCommands<CMyEdit>
1629 // {
1630 // public:
1631 // BEGIN_MSG_MAP(CMyEdit)
1632 // // your handlers...
1633 // CHAIN_MSG_MAP_ALT(CEditCommands<CMyEdit>, 1)
1634 // END_MSG_MAP()
1635 // // other stuff...
1636 // };
1637
1638 template <class T>
1639 class CEditCommands
1640 {
1641 public:
BEGIN_MSG_MAP(CEditCommands<T>)1642 BEGIN_MSG_MAP(CEditCommands< T >)
1643 ALT_MSG_MAP(1)
1644 COMMAND_ID_HANDLER(ID_EDIT_CLEAR, OnEditClear)
1645 COMMAND_ID_HANDLER(ID_EDIT_CLEAR_ALL, OnEditClearAll)
1646 COMMAND_ID_HANDLER(ID_EDIT_COPY, OnEditCopy)
1647 COMMAND_ID_HANDLER(ID_EDIT_CUT, OnEditCut)
1648 COMMAND_ID_HANDLER(ID_EDIT_PASTE, OnEditPaste)
1649 COMMAND_ID_HANDLER(ID_EDIT_SELECT_ALL, OnEditSelectAll)
1650 COMMAND_ID_HANDLER(ID_EDIT_UNDO, OnEditUndo)
1651 END_MSG_MAP()
1652
1653 LRESULT OnEditClear(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
1654 {
1655 T* pT = static_cast<T*>(this);
1656 pT->Clear();
1657 return 0;
1658 }
1659
OnEditClearAll(WORD,WORD,HWND,BOOL &)1660 LRESULT OnEditClearAll(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
1661 {
1662 T* pT = static_cast<T*>(this);
1663 pT->SetSel(0, -1);
1664 pT->Clear();
1665 return 0;
1666 }
1667
OnEditCopy(WORD,WORD,HWND,BOOL &)1668 LRESULT OnEditCopy(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
1669 {
1670 T* pT = static_cast<T*>(this);
1671 pT->Copy();
1672 return 0;
1673 }
1674
OnEditCut(WORD,WORD,HWND,BOOL &)1675 LRESULT OnEditCut(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
1676 {
1677 T* pT = static_cast<T*>(this);
1678 pT->Cut();
1679 return 0;
1680 }
1681
OnEditPaste(WORD,WORD,HWND,BOOL &)1682 LRESULT OnEditPaste(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
1683 {
1684 T* pT = static_cast<T*>(this);
1685 pT->Paste();
1686 return 0;
1687 }
1688
OnEditSelectAll(WORD,WORD,HWND,BOOL &)1689 LRESULT OnEditSelectAll(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
1690 {
1691 T* pT = static_cast<T*>(this);
1692 pT->SetSel(0, -1);
1693 return 0;
1694 }
1695
OnEditUndo(WORD,WORD,HWND,BOOL &)1696 LRESULT OnEditUndo(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
1697 {
1698 T* pT = static_cast<T*>(this);
1699 pT->Undo();
1700 return 0;
1701 }
1702
1703 // State (update UI) helpers
CanCut()1704 BOOL CanCut() const
1705 { return HasSelection(); }
1706
CanCopy()1707 BOOL CanCopy() const
1708 { return HasSelection(); }
1709
CanClear()1710 BOOL CanClear() const
1711 { return HasSelection(); }
1712
CanSelectAll()1713 BOOL CanSelectAll() const
1714 { return HasText(); }
1715
CanFind()1716 BOOL CanFind() const
1717 { return HasText(); }
1718
CanRepeat()1719 BOOL CanRepeat() const
1720 { return HasText(); }
1721
CanReplace()1722 BOOL CanReplace() const
1723 { return HasText(); }
1724
CanClearAll()1725 BOOL CanClearAll() const
1726 { return HasText(); }
1727
1728 // Implementation
HasSelection()1729 BOOL HasSelection() const
1730 {
1731 const T* pT = static_cast<const T*>(this);
1732 int nMin = 0, nMax = 0;
1733 ::SendMessage(pT->m_hWnd, EM_GETSEL, (WPARAM)&nMin, (LPARAM)&nMax);
1734 return (nMin != nMax);
1735 }
1736
HasText()1737 BOOL HasText() const
1738 {
1739 const T* pT = static_cast<const T*>(this);
1740 return (pT->GetWindowTextLength() > 0);
1741 }
1742 };
1743
1744
1745 ///////////////////////////////////////////////////////////////////////////////
1746 // CScrollBar - client side for a Windows SCROLLBAR control
1747
1748 template <class TBase>
1749 class CScrollBarT : public TBase
1750 {
1751 public:
1752 // Constructors
TBase(hWnd)1753 CScrollBarT(HWND hWnd = NULL) : TBase(hWnd)
1754 { }
1755
1756 CScrollBarT< TBase >& operator =(HWND hWnd)
1757 {
1758 this->m_hWnd = hWnd;
1759 return *this;
1760 }
1761
1762 HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
1763 DWORD dwStyle = 0, DWORD dwExStyle = 0,
1764 ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
1765 {
1766 return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
1767 }
1768
1769 // Attributes
GetWndClassName()1770 static LPCTSTR GetWndClassName()
1771 {
1772 return _T("SCROLLBAR");
1773 }
1774
GetScrollPos()1775 int GetScrollPos() const
1776 {
1777 ATLASSERT(::IsWindow(this->m_hWnd));
1778 return ::GetScrollPos(this->m_hWnd, SB_CTL);
1779 }
1780
1781 int SetScrollPos(int nPos, BOOL bRedraw = TRUE)
1782 {
1783 ATLASSERT(::IsWindow(this->m_hWnd));
1784 return ::SetScrollPos(this->m_hWnd, SB_CTL, nPos, bRedraw);
1785 }
1786
GetScrollRange(LPINT lpMinPos,LPINT lpMaxPos)1787 void GetScrollRange(LPINT lpMinPos, LPINT lpMaxPos) const
1788 {
1789 ATLASSERT(::IsWindow(this->m_hWnd));
1790 ::GetScrollRange(this->m_hWnd, SB_CTL, lpMinPos, lpMaxPos);
1791 }
1792
1793 void SetScrollRange(int nMinPos, int nMaxPos, BOOL bRedraw = TRUE)
1794 {
1795 ATLASSERT(::IsWindow(this->m_hWnd));
1796 ::SetScrollRange(this->m_hWnd, SB_CTL, nMinPos, nMaxPos, bRedraw);
1797 }
1798
GetScrollInfo(LPSCROLLINFO lpScrollInfo)1799 BOOL GetScrollInfo(LPSCROLLINFO lpScrollInfo) const
1800 {
1801 ATLASSERT(::IsWindow(this->m_hWnd));
1802 return ::GetScrollInfo(this->m_hWnd, SB_CTL, lpScrollInfo);
1803 }
1804
1805 int SetScrollInfo(LPSCROLLINFO lpScrollInfo, BOOL bRedraw = TRUE)
1806 {
1807 ATLASSERT(::IsWindow(this->m_hWnd));
1808 return ::SetScrollInfo(this->m_hWnd, SB_CTL, lpScrollInfo, bRedraw);
1809 }
1810
GetScrollLimit()1811 int GetScrollLimit() const
1812 {
1813 SCROLLINFO info = { sizeof(SCROLLINFO), SIF_RANGE | SIF_PAGE };
1814 ::GetScrollInfo(this->m_hWnd, SB_CTL, &info);
1815 if(info.nPage > 1)
1816 info.nMax -= info.nPage - 1;
1817
1818 return info.nMax;
1819 }
1820
GetScrollBarInfo(PSCROLLBARINFO pScrollBarInfo)1821 BOOL GetScrollBarInfo(PSCROLLBARINFO pScrollBarInfo) const
1822 {
1823 ATLASSERT(::IsWindow(this->m_hWnd));
1824 return (BOOL)::SendMessage(this->m_hWnd, SBM_GETSCROLLBARINFO, 0, (LPARAM)pScrollBarInfo);
1825 }
1826
1827 // Operations
1828 void ShowScrollBar(BOOL bShow = TRUE)
1829 {
1830 ATLASSERT(::IsWindow(this->m_hWnd));
1831 ::ShowScrollBar(this->m_hWnd, SB_CTL, bShow);
1832 }
1833
1834 BOOL EnableScrollBar(UINT nArrowFlags = ESB_ENABLE_BOTH)
1835 {
1836 ATLASSERT(::IsWindow(this->m_hWnd));
1837 return ::EnableScrollBar(this->m_hWnd, SB_CTL, nArrowFlags);
1838 }
1839 };
1840
1841 typedef CScrollBarT<ATL::CWindow> CScrollBar;
1842
1843
1844 // --- Windows Common Controls ---
1845
1846 ///////////////////////////////////////////////////////////////////////////////
1847 // CImageList
1848
1849 // forward declarations
1850 template <bool t_bManaged> class CImageListT;
1851 typedef CImageListT<false> CImageList;
1852 typedef CImageListT<true> CImageListManaged;
1853
1854
1855 template <bool t_bManaged>
1856 class CImageListT
1857 {
1858 public:
1859 // Data members
1860 HIMAGELIST m_hImageList;
1861
1862 // Constructor/destructor/operators
m_hImageList(hImageList)1863 CImageListT(HIMAGELIST hImageList = NULL) : m_hImageList(hImageList)
1864 { }
1865
~CImageListT()1866 ~CImageListT()
1867 {
1868 if(t_bManaged && (m_hImageList != NULL))
1869 Destroy();
1870 }
1871
1872 CImageListT<t_bManaged>& operator =(HIMAGELIST hImageList)
1873 {
1874 Attach(hImageList);
1875 return *this;
1876 }
1877
Attach(HIMAGELIST hImageList)1878 void Attach(HIMAGELIST hImageList)
1879 {
1880 if(t_bManaged && (m_hImageList != NULL) && (m_hImageList != hImageList))
1881 ImageList_Destroy(m_hImageList);
1882 m_hImageList = hImageList;
1883 }
1884
Detach()1885 HIMAGELIST Detach()
1886 {
1887 HIMAGELIST hImageList = m_hImageList;
1888 m_hImageList = NULL;
1889 return hImageList;
1890 }
1891
HIMAGELIST()1892 operator HIMAGELIST() const { return m_hImageList; }
1893
IsNull()1894 bool IsNull() const { return (m_hImageList == NULL); }
1895
1896 // Attributes
GetImageCount()1897 int GetImageCount() const
1898 {
1899 ATLASSERT(m_hImageList != NULL);
1900 return ImageList_GetImageCount(m_hImageList);
1901 }
1902
GetBkColor()1903 COLORREF GetBkColor() const
1904 {
1905 ATLASSERT(m_hImageList != NULL);
1906 return ImageList_GetBkColor(m_hImageList);
1907 }
1908
SetBkColor(COLORREF cr)1909 COLORREF SetBkColor(COLORREF cr)
1910 {
1911 ATLASSERT(m_hImageList != NULL);
1912 return ImageList_SetBkColor(m_hImageList, cr);
1913 }
1914
GetImageInfo(int nImage,IMAGEINFO * pImageInfo)1915 BOOL GetImageInfo(int nImage, IMAGEINFO* pImageInfo) const
1916 {
1917 ATLASSERT(m_hImageList != NULL);
1918 return ImageList_GetImageInfo(m_hImageList, nImage, pImageInfo);
1919 }
1920
1921 HICON GetIcon(int nIndex, UINT uFlags = ILD_NORMAL) const
1922 {
1923 ATLASSERT(m_hImageList != NULL);
1924 return ImageList_GetIcon(m_hImageList, nIndex, uFlags);
1925 }
1926
GetIconSize(int & cx,int & cy)1927 BOOL GetIconSize(int& cx, int& cy) const
1928 {
1929 ATLASSERT(m_hImageList != NULL);
1930 return ImageList_GetIconSize(m_hImageList, &cx, &cy);
1931 }
1932
GetIconSize(SIZE & size)1933 BOOL GetIconSize(SIZE& size) const
1934 {
1935 ATLASSERT(m_hImageList != NULL);
1936 return ImageList_GetIconSize(m_hImageList, (int*)&size.cx, (int*)&size.cy);
1937 }
1938
SetIconSize(int cx,int cy)1939 BOOL SetIconSize(int cx, int cy)
1940 {
1941 ATLASSERT(m_hImageList != NULL);
1942 return ImageList_SetIconSize(m_hImageList, cx, cy);
1943 }
1944
SetIconSize(SIZE size)1945 BOOL SetIconSize(SIZE size)
1946 {
1947 ATLASSERT(m_hImageList != NULL);
1948 return ImageList_SetIconSize(m_hImageList, size.cx, size.cy);
1949 }
1950
SetImageCount(UINT uNewCount)1951 BOOL SetImageCount(UINT uNewCount)
1952 {
1953 ATLASSERT(m_hImageList != NULL);
1954 return ImageList_SetImageCount(m_hImageList, uNewCount);
1955 }
1956
SetOverlayImage(int nImage,int nOverlay)1957 BOOL SetOverlayImage(int nImage, int nOverlay)
1958 {
1959 ATLASSERT(m_hImageList != NULL);
1960 return ImageList_SetOverlayImage(m_hImageList, nImage, nOverlay);
1961 }
1962
1963 // Operations
Create(int cx,int cy,UINT nFlags,int nInitial,int nGrow)1964 BOOL Create(int cx, int cy, UINT nFlags, int nInitial, int nGrow)
1965 {
1966 ATLASSERT(m_hImageList == NULL);
1967 m_hImageList = ImageList_Create(cx, cy, nFlags, nInitial, nGrow);
1968 return (m_hImageList != NULL) ? TRUE : FALSE;
1969 }
1970
Create(ATL::_U_STRINGorID bitmap,int cx,int nGrow,COLORREF crMask)1971 BOOL Create(ATL::_U_STRINGorID bitmap, int cx, int nGrow, COLORREF crMask)
1972 {
1973 ATLASSERT(m_hImageList == NULL);
1974 m_hImageList = ImageList_LoadBitmap(ModuleHelper::GetResourceInstance(), bitmap.m_lpstr, cx, nGrow, crMask);
1975 return (m_hImageList != NULL) ? TRUE : FALSE;
1976 }
1977
1978 BOOL CreateFromImage(ATL::_U_STRINGorID image, int cx, int nGrow, COLORREF crMask, UINT uType, UINT uFlags = LR_DEFAULTCOLOR | LR_DEFAULTSIZE)
1979 {
1980 ATLASSERT(m_hImageList == NULL);
1981 m_hImageList = ImageList_LoadImage(ModuleHelper::GetResourceInstance(), image.m_lpstr, cx, nGrow, crMask, uType, uFlags);
1982 return (m_hImageList != NULL) ? TRUE : FALSE;
1983 }
1984
Merge(HIMAGELIST hImageList1,int nImage1,HIMAGELIST hImageList2,int nImage2,int dx,int dy)1985 BOOL Merge(HIMAGELIST hImageList1, int nImage1, HIMAGELIST hImageList2, int nImage2, int dx, int dy)
1986 {
1987 ATLASSERT(m_hImageList == NULL);
1988 m_hImageList = ImageList_Merge(hImageList1, nImage1, hImageList2, nImage2, dx, dy);
1989 return (m_hImageList != NULL) ? TRUE : FALSE;
1990 }
1991
1992 #ifdef __IStream_INTERFACE_DEFINED__
CreateFromStream(LPSTREAM lpStream)1993 BOOL CreateFromStream(LPSTREAM lpStream)
1994 {
1995 ATLASSERT(m_hImageList == NULL);
1996 m_hImageList = ImageList_Read(lpStream);
1997 return (m_hImageList != NULL) ? TRUE : FALSE;
1998 }
1999 #endif // __IStream_INTERFACE_DEFINED__
2000
Destroy()2001 BOOL Destroy()
2002 {
2003 if (m_hImageList == NULL)
2004 return FALSE;
2005 BOOL bRet = ImageList_Destroy(m_hImageList);
2006 if(bRet)
2007 m_hImageList = NULL;
2008 return bRet;
2009 }
2010
2011 int Add(HBITMAP hBitmap, HBITMAP hBitmapMask = NULL)
2012 {
2013 ATLASSERT(m_hImageList != NULL);
2014 return ImageList_Add(m_hImageList, hBitmap, hBitmapMask);
2015 }
2016
Add(HBITMAP hBitmap,COLORREF crMask)2017 int Add(HBITMAP hBitmap, COLORREF crMask)
2018 {
2019 ATLASSERT(m_hImageList != NULL);
2020 return ImageList_AddMasked(m_hImageList, hBitmap, crMask);
2021 }
2022
Remove(int nImage)2023 BOOL Remove(int nImage)
2024 {
2025 ATLASSERT(m_hImageList != NULL);
2026 return ImageList_Remove(m_hImageList, nImage);
2027 }
2028
RemoveAll()2029 BOOL RemoveAll()
2030 {
2031 ATLASSERT(m_hImageList != NULL);
2032 return ImageList_RemoveAll(m_hImageList);
2033 }
2034
Replace(int nImage,HBITMAP hBitmap,HBITMAP hBitmapMask)2035 BOOL Replace(int nImage, HBITMAP hBitmap, HBITMAP hBitmapMask)
2036 {
2037 ATLASSERT(m_hImageList != NULL);
2038 return ImageList_Replace(m_hImageList, nImage, hBitmap, hBitmapMask);
2039 }
2040
AddIcon(HICON hIcon)2041 int AddIcon(HICON hIcon)
2042 {
2043 ATLASSERT(m_hImageList != NULL);
2044 return ImageList_AddIcon(m_hImageList, hIcon);
2045 }
2046
ReplaceIcon(int nImage,HICON hIcon)2047 int ReplaceIcon(int nImage, HICON hIcon)
2048 {
2049 ATLASSERT(m_hImageList != NULL);
2050 return ImageList_ReplaceIcon(m_hImageList, nImage, hIcon);
2051 }
2052
ExtractIcon(int nImage)2053 HICON ExtractIcon(int nImage)
2054 {
2055 ATLASSERT(m_hImageList != NULL);
2056 return ImageList_ExtractIcon(NULL, m_hImageList, nImage);
2057 }
2058
Draw(HDC hDC,int nImage,int x,int y,UINT nStyle)2059 BOOL Draw(HDC hDC, int nImage, int x, int y, UINT nStyle)
2060 {
2061 ATLASSERT(m_hImageList != NULL);
2062 ATLASSERT(hDC != NULL);
2063 return ImageList_Draw(m_hImageList, nImage, hDC, x, y, nStyle);
2064 }
2065
Draw(HDC hDC,int nImage,POINT pt,UINT nStyle)2066 BOOL Draw(HDC hDC, int nImage, POINT pt, UINT nStyle)
2067 {
2068 ATLASSERT(m_hImageList != NULL);
2069 ATLASSERT(hDC != NULL);
2070 return ImageList_Draw(m_hImageList, nImage, hDC, pt.x, pt.y, nStyle);
2071 }
2072
DrawEx(int nImage,HDC hDC,int x,int y,int dx,int dy,COLORREF rgbBk,COLORREF rgbFg,UINT fStyle)2073 BOOL DrawEx(int nImage, HDC hDC, int x, int y, int dx, int dy, COLORREF rgbBk, COLORREF rgbFg, UINT fStyle)
2074 {
2075 ATLASSERT(m_hImageList != NULL);
2076 ATLASSERT(hDC != NULL);
2077 return ImageList_DrawEx(m_hImageList, nImage, hDC, x, y, dx, dy, rgbBk, rgbFg, fStyle);
2078 }
2079
DrawEx(int nImage,HDC hDC,RECT & rect,COLORREF rgbBk,COLORREF rgbFg,UINT fStyle)2080 BOOL DrawEx(int nImage, HDC hDC, RECT& rect, COLORREF rgbBk, COLORREF rgbFg, UINT fStyle)
2081 {
2082 ATLASSERT(m_hImageList != NULL);
2083 ATLASSERT(hDC != NULL);
2084 return ImageList_DrawEx(m_hImageList, nImage, hDC, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, rgbBk, rgbFg, fStyle);
2085 }
2086
DrawIndirect(IMAGELISTDRAWPARAMS * pimldp)2087 static BOOL DrawIndirect(IMAGELISTDRAWPARAMS* pimldp)
2088 {
2089 return ImageList_DrawIndirect(pimldp);
2090 }
2091
2092 BOOL Copy(int nSrc, int nDst, UINT uFlags = ILCF_MOVE)
2093 {
2094 ATLASSERT(m_hImageList != NULL);
2095 return ImageList_Copy(m_hImageList, nDst, m_hImageList, nSrc, uFlags);
2096 }
2097
2098 #ifdef __IStream_INTERFACE_DEFINED__
Read(LPSTREAM lpStream)2099 static HIMAGELIST Read(LPSTREAM lpStream)
2100 {
2101 return ImageList_Read(lpStream);
2102 }
2103
Write(LPSTREAM lpStream)2104 BOOL Write(LPSTREAM lpStream)
2105 {
2106 ATLASSERT(m_hImageList != NULL);
2107 return ImageList_Write(m_hImageList, lpStream);
2108 }
2109
ReadEx(DWORD dwFlags,LPSTREAM lpStream,REFIID riid,PVOID * ppv)2110 static HRESULT ReadEx(DWORD dwFlags, LPSTREAM lpStream, REFIID riid, PVOID* ppv)
2111 {
2112 return ImageList_ReadEx(dwFlags, lpStream, riid, ppv);
2113 }
2114
WriteEx(DWORD dwFlags,LPSTREAM lpStream)2115 HRESULT WriteEx(DWORD dwFlags, LPSTREAM lpStream)
2116 {
2117 ATLASSERT(m_hImageList != NULL);
2118 return ImageList_WriteEx(m_hImageList, dwFlags, lpStream);
2119 }
2120 #endif // __IStream_INTERFACE_DEFINED__
2121
2122 // Drag operations
BeginDrag(int nImage,POINT ptHotSpot)2123 BOOL BeginDrag(int nImage, POINT ptHotSpot)
2124 {
2125 ATLASSERT(m_hImageList != NULL);
2126 return ImageList_BeginDrag(m_hImageList, nImage, ptHotSpot.x, ptHotSpot.y);
2127 }
2128
BeginDrag(int nImage,int xHotSpot,int yHotSpot)2129 BOOL BeginDrag(int nImage, int xHotSpot, int yHotSpot)
2130 {
2131 ATLASSERT(m_hImageList != NULL);
2132 return ImageList_BeginDrag(m_hImageList, nImage, xHotSpot, yHotSpot);
2133 }
2134
EndDrag()2135 static void EndDrag()
2136 {
2137 ImageList_EndDrag();
2138 }
2139
DragMove(POINT pt)2140 static BOOL DragMove(POINT pt)
2141 {
2142 return ImageList_DragMove(pt.x, pt.y);
2143 }
2144
DragMove(int x,int y)2145 static BOOL DragMove(int x, int y)
2146 {
2147 return ImageList_DragMove(x, y);
2148 }
2149
SetDragCursorImage(int nDrag,POINT ptHotSpot)2150 BOOL SetDragCursorImage(int nDrag, POINT ptHotSpot)
2151 {
2152 ATLASSERT(m_hImageList != NULL);
2153 return ImageList_SetDragCursorImage(m_hImageList, nDrag, ptHotSpot.x, ptHotSpot.y);
2154 }
2155
SetDragCursorImage(int nDrag,int xHotSpot,int yHotSpot)2156 BOOL SetDragCursorImage(int nDrag, int xHotSpot, int yHotSpot)
2157 {
2158 ATLASSERT(m_hImageList != NULL);
2159 return ImageList_SetDragCursorImage(m_hImageList, nDrag, xHotSpot, yHotSpot);
2160 }
2161
2162 static BOOL DragShowNolock(BOOL bShow = TRUE)
2163 {
2164 return ImageList_DragShowNolock(bShow);
2165 }
2166
GetDragImage(LPPOINT lpPoint,LPPOINT lpPointHotSpot)2167 static CImageList GetDragImage(LPPOINT lpPoint, LPPOINT lpPointHotSpot)
2168 {
2169 return CImageList(ImageList_GetDragImage(lpPoint, lpPointHotSpot));
2170 }
2171
DragEnter(HWND hWnd,POINT point)2172 static BOOL DragEnter(HWND hWnd, POINT point)
2173 {
2174 return ImageList_DragEnter(hWnd, point.x, point.y);
2175 }
2176
DragEnter(HWND hWnd,int x,int y)2177 static BOOL DragEnter(HWND hWnd, int x, int y)
2178 {
2179 return ImageList_DragEnter(hWnd, x, y);
2180 }
2181
DragLeave(HWND hWnd)2182 static BOOL DragLeave(HWND hWnd)
2183 {
2184 return ImageList_DragLeave(hWnd);
2185 }
2186
Duplicate()2187 CImageList Duplicate() const
2188 {
2189 ATLASSERT(m_hImageList != NULL);
2190 return CImageList(ImageList_Duplicate(m_hImageList));
2191 }
2192
Duplicate(HIMAGELIST hImageList)2193 static CImageList Duplicate(HIMAGELIST hImageList)
2194 {
2195 ATLASSERT(hImageList != NULL);
2196 return CImageList(ImageList_Duplicate(hImageList));
2197 }
2198 };
2199
2200
2201 ///////////////////////////////////////////////////////////////////////////////
2202 // CToolTipCtrl
2203
2204 class CToolInfo : public TOOLINFO
2205 {
2206 public:
2207 CToolInfo(UINT nFlags, HWND hWnd, UINT_PTR nIDTool = 0, LPRECT lpRect = NULL, LPTSTR lpstrText = LPSTR_TEXTCALLBACK, LPARAM lUserParam = NULL)
2208 {
2209 Init(nFlags, hWnd, nIDTool, lpRect, lpstrText, lUserParam);
2210 }
2211
LPTOOLINFO()2212 operator LPTOOLINFO() { return this; }
2213
LPARAM()2214 operator LPARAM() { return (LPARAM)this; }
2215
2216 void Init(UINT nFlags, HWND hWnd, UINT_PTR nIDTool = 0, LPRECT lpRect = NULL, LPTSTR lpstrText = LPSTR_TEXTCALLBACK, LPARAM lUserParam = NULL)
2217 {
2218 ATLASSERT(::IsWindow(hWnd));
2219 memset(this, 0, sizeof(TOOLINFO));
2220 cbSize = RunTimeHelper::SizeOf_TOOLINFO();
2221 uFlags = nFlags;
2222 if(nIDTool == 0)
2223 {
2224 hwnd = ::GetParent(hWnd);
2225 uFlags |= TTF_IDISHWND;
2226 uId = (UINT_PTR)hWnd;
2227 }
2228 else
2229 {
2230 hwnd = hWnd;
2231 uId = nIDTool;
2232 }
2233 if(lpRect != NULL)
2234 rect = *lpRect;
2235 hinst = ModuleHelper::GetResourceInstance();
2236 lpszText = lpstrText;
2237 lParam = lUserParam;
2238 }
2239 };
2240
2241 template <class TBase>
2242 class CToolTipCtrlT : public TBase
2243 {
2244 public:
2245 // Constructors
TBase(hWnd)2246 CToolTipCtrlT(HWND hWnd = NULL) : TBase(hWnd)
2247 { }
2248
2249 CToolTipCtrlT< TBase >& operator =(HWND hWnd)
2250 {
2251 this->m_hWnd = hWnd;
2252 return *this;
2253 }
2254
2255 HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
2256 DWORD dwStyle = 0, DWORD dwExStyle = 0,
2257 ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
2258 {
2259 return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
2260 }
2261
2262 // Attributes
GetWndClassName()2263 static LPCTSTR GetWndClassName()
2264 {
2265 return TOOLTIPS_CLASS;
2266 }
2267
GetText(LPTOOLINFO lpToolInfo)2268 void GetText(LPTOOLINFO lpToolInfo) const
2269 {
2270 ATLASSERT(::IsWindow(this->m_hWnd));
2271 ::SendMessage(this->m_hWnd, TTM_GETTEXT, 0, (LPARAM)&lpToolInfo);
2272 }
2273
2274 void GetText(LPTSTR lpstrText, HWND hWnd, UINT_PTR nIDTool = 0) const
2275 {
2276 ATLASSERT(::IsWindow(this->m_hWnd));
2277 ATLASSERT(hWnd != NULL);
2278 CToolInfo ti(0, hWnd, nIDTool, NULL, lpstrText);
2279 ::SendMessage(this->m_hWnd, TTM_GETTEXT, 0, ti);
2280 }
2281
GetToolInfo(LPTOOLINFO lpToolInfo)2282 BOOL GetToolInfo(LPTOOLINFO lpToolInfo) const
2283 {
2284 ATLASSERT(::IsWindow(this->m_hWnd));
2285 return (BOOL)::SendMessage(this->m_hWnd, TTM_GETTOOLINFO, 0, (LPARAM)lpToolInfo);
2286 }
2287
GetToolInfo(HWND hWnd,UINT_PTR nIDTool,UINT * puFlags,LPRECT lpRect,LPTSTR lpstrText)2288 BOOL GetToolInfo(HWND hWnd, UINT_PTR nIDTool, UINT* puFlags, LPRECT lpRect, LPTSTR lpstrText) const
2289 {
2290 ATLASSERT(::IsWindow(this->m_hWnd));
2291 ATLASSERT(hWnd != NULL);
2292 ATLASSERT(puFlags != NULL);
2293 ATLASSERT(lpRect != NULL);
2294 CToolInfo ti(0, hWnd, nIDTool, NULL, lpstrText);
2295 BOOL bRet = (BOOL)::SendMessage(this->m_hWnd, TTM_GETTOOLINFO, 0, ti);
2296 if(bRet != FALSE)
2297 {
2298 *puFlags = ti.uFlags;
2299 *lpRect = ti.rect;
2300 }
2301 return bRet;
2302 }
2303
SetToolInfo(LPTOOLINFO lpToolInfo)2304 void SetToolInfo(LPTOOLINFO lpToolInfo)
2305 {
2306 ATLASSERT(::IsWindow(this->m_hWnd));
2307 ::SendMessage(this->m_hWnd, TTM_SETTOOLINFO, 0, (LPARAM)lpToolInfo);
2308 }
2309
SetToolRect(LPTOOLINFO lpToolInfo)2310 void SetToolRect(LPTOOLINFO lpToolInfo)
2311 {
2312 ATLASSERT(::IsWindow(this->m_hWnd));
2313 ::SendMessage(this->m_hWnd, TTM_NEWTOOLRECT, 0, (LPARAM)lpToolInfo);
2314 }
2315
SetToolRect(HWND hWnd,UINT_PTR nIDTool,LPCRECT lpRect)2316 void SetToolRect(HWND hWnd, UINT_PTR nIDTool, LPCRECT lpRect)
2317 {
2318 ATLASSERT(::IsWindow(this->m_hWnd));
2319 ATLASSERT(hWnd != NULL);
2320 ATLASSERT(nIDTool != 0);
2321
2322 CToolInfo ti(0, hWnd, nIDTool, (LPRECT)lpRect, NULL);
2323 ::SendMessage(this->m_hWnd, TTM_NEWTOOLRECT, 0, ti);
2324 }
2325
GetToolCount()2326 int GetToolCount() const
2327 {
2328 ATLASSERT(::IsWindow(this->m_hWnd));
2329 return (int)::SendMessage(this->m_hWnd, TTM_GETTOOLCOUNT, 0, 0L);
2330 }
2331
GetDelayTime(DWORD dwType)2332 int GetDelayTime(DWORD dwType) const
2333 {
2334 ATLASSERT(::IsWindow(this->m_hWnd));
2335 return (int)::SendMessage(this->m_hWnd, TTM_GETDELAYTIME, dwType, 0L);
2336 }
2337
SetDelayTime(DWORD dwType,int nTime)2338 void SetDelayTime(DWORD dwType, int nTime)
2339 {
2340 ATLASSERT(::IsWindow(this->m_hWnd));
2341 ::SendMessage(this->m_hWnd, TTM_SETDELAYTIME, dwType, MAKELPARAM(nTime, 0));
2342 }
2343
GetMargin(LPRECT lpRect)2344 void GetMargin(LPRECT lpRect) const
2345 {
2346 ATLASSERT(::IsWindow(this->m_hWnd));
2347 ::SendMessage(this->m_hWnd, TTM_GETMARGIN, 0, (LPARAM)lpRect);
2348 }
2349
SetMargin(LPRECT lpRect)2350 void SetMargin(LPRECT lpRect)
2351 {
2352 ATLASSERT(::IsWindow(this->m_hWnd));
2353 ::SendMessage(this->m_hWnd, TTM_SETMARGIN, 0, (LPARAM)lpRect);
2354 }
2355
GetMaxTipWidth()2356 int GetMaxTipWidth() const
2357 {
2358 ATLASSERT(::IsWindow(this->m_hWnd));
2359 return (int)::SendMessage(this->m_hWnd, TTM_GETMAXTIPWIDTH, 0, 0L);
2360 }
2361
SetMaxTipWidth(int nWidth)2362 int SetMaxTipWidth(int nWidth)
2363 {
2364 ATLASSERT(::IsWindow(this->m_hWnd));
2365 return (int)::SendMessage(this->m_hWnd, TTM_SETMAXTIPWIDTH, 0, nWidth);
2366 }
2367
GetTipBkColor()2368 COLORREF GetTipBkColor() const
2369 {
2370 ATLASSERT(::IsWindow(this->m_hWnd));
2371 return (COLORREF)::SendMessage(this->m_hWnd, TTM_GETTIPBKCOLOR, 0, 0L);
2372 }
2373
SetTipBkColor(COLORREF clr)2374 void SetTipBkColor(COLORREF clr)
2375 {
2376 ATLASSERT(::IsWindow(this->m_hWnd));
2377 ::SendMessage(this->m_hWnd, TTM_SETTIPBKCOLOR, (WPARAM)clr, 0L);
2378 }
2379
GetTipTextColor()2380 COLORREF GetTipTextColor() const
2381 {
2382 ATLASSERT(::IsWindow(this->m_hWnd));
2383 return (COLORREF)::SendMessage(this->m_hWnd, TTM_GETTIPTEXTCOLOR, 0, 0L);
2384 }
2385
SetTipTextColor(COLORREF clr)2386 void SetTipTextColor(COLORREF clr)
2387 {
2388 ATLASSERT(::IsWindow(this->m_hWnd));
2389 ::SendMessage(this->m_hWnd, TTM_SETTIPTEXTCOLOR, (WPARAM)clr, 0L);
2390 }
2391
GetCurrentTool(LPTOOLINFO lpToolInfo)2392 BOOL GetCurrentTool(LPTOOLINFO lpToolInfo) const
2393 {
2394 ATLASSERT(::IsWindow(this->m_hWnd));
2395 return (BOOL)::SendMessage(this->m_hWnd, TTM_GETCURRENTTOOL, 0, (LPARAM)lpToolInfo);
2396 }
2397
GetBubbleSize(LPTOOLINFO lpToolInfo)2398 SIZE GetBubbleSize(LPTOOLINFO lpToolInfo) const
2399 {
2400 ATLASSERT(::IsWindow(this->m_hWnd));
2401 DWORD dwRet = (DWORD)::SendMessage(this->m_hWnd, TTM_GETBUBBLESIZE, 0, (LPARAM)lpToolInfo);
2402 SIZE size = { GET_X_LPARAM(dwRet), GET_Y_LPARAM(dwRet) };
2403 return size;
2404 }
2405
SetTitle(UINT_PTR uIcon,LPCTSTR lpstrTitle)2406 BOOL SetTitle(UINT_PTR uIcon, LPCTSTR lpstrTitle)
2407 {
2408 ATLASSERT(::IsWindow(this->m_hWnd));
2409 return (BOOL)::SendMessage(this->m_hWnd, TTM_SETTITLE, uIcon, (LPARAM)lpstrTitle);
2410 }
2411
2412
SetTitle(HICON hIcon,LPCTSTR lpstrTitle)2413 BOOL SetTitle(HICON hIcon, LPCTSTR lpstrTitle)
2414 {
2415 ATLASSERT(::IsWindow(this->m_hWnd));
2416 return (BOOL)::SendMessage(this->m_hWnd, TTM_SETTITLE, (WPARAM)hIcon, (LPARAM)lpstrTitle);
2417 }
2418
GetTitle(PTTGETTITLE pTTGetTitle)2419 void GetTitle(PTTGETTITLE pTTGetTitle) const
2420 {
2421 ATLASSERT(::IsWindow(this->m_hWnd));
2422 ::SendMessage(this->m_hWnd, TTM_GETTITLE, 0, (LPARAM)pTTGetTitle);
2423 }
2424
SetWindowTheme(LPCWSTR lpstrTheme)2425 void SetWindowTheme(LPCWSTR lpstrTheme)
2426 {
2427 ATLASSERT(::IsWindow(this->m_hWnd));
2428 ::SendMessage(this->m_hWnd, TTM_SETWINDOWTHEME, 0, (LPARAM)lpstrTheme);
2429 }
2430
2431 // Operations
Activate(BOOL bActivate)2432 void Activate(BOOL bActivate)
2433 {
2434 ATLASSERT(::IsWindow(this->m_hWnd));
2435 ::SendMessage(this->m_hWnd, TTM_ACTIVATE, bActivate, 0L);
2436 }
2437
AddTool(LPTOOLINFO lpToolInfo)2438 BOOL AddTool(LPTOOLINFO lpToolInfo)
2439 {
2440 ATLASSERT(::IsWindow(this->m_hWnd));
2441 return (BOOL)::SendMessage(this->m_hWnd, TTM_ADDTOOL, 0, (LPARAM)lpToolInfo);
2442 }
2443
2444 BOOL AddTool(HWND hWnd, ATL::_U_STRINGorID text = LPSTR_TEXTCALLBACK, LPCRECT lpRectTool = NULL, UINT_PTR nIDTool = 0)
2445 {
2446 ATLASSERT(::IsWindow(this->m_hWnd));
2447 ATLASSERT(hWnd != NULL);
2448 // the toolrect and toolid must both be zero or both valid
2449 ATLASSERT(((lpRectTool != NULL) && (nIDTool != 0)) || ((lpRectTool == NULL) && (nIDTool == 0)));
2450
2451 CToolInfo ti(0, hWnd, nIDTool, (LPRECT)lpRectTool, (LPTSTR)text.m_lpstr);
2452 return (BOOL)::SendMessage(this->m_hWnd, TTM_ADDTOOL, 0, ti);
2453 }
2454
DelTool(LPTOOLINFO lpToolInfo)2455 void DelTool(LPTOOLINFO lpToolInfo)
2456 {
2457 ATLASSERT(::IsWindow(this->m_hWnd));
2458 ::SendMessage(this->m_hWnd, TTM_DELTOOL, 0, (LPARAM)lpToolInfo);
2459 }
2460
2461 void DelTool(HWND hWnd, UINT_PTR nIDTool = 0)
2462 {
2463 ATLASSERT(::IsWindow(this->m_hWnd));
2464 ATLASSERT(hWnd != NULL);
2465
2466 CToolInfo ti(0, hWnd, nIDTool, NULL, NULL);
2467 ::SendMessage(this->m_hWnd, TTM_DELTOOL, 0, ti);
2468 }
2469
HitTest(LPTTHITTESTINFO lpHitTestInfo)2470 BOOL HitTest(LPTTHITTESTINFO lpHitTestInfo) const
2471 {
2472 ATLASSERT(::IsWindow(this->m_hWnd));
2473 return (BOOL)::SendMessage(this->m_hWnd, TTM_HITTEST, 0, (LPARAM)lpHitTestInfo);
2474 }
2475
HitTest(HWND hWnd,POINT pt,LPTOOLINFO lpToolInfo)2476 BOOL HitTest(HWND hWnd, POINT pt, LPTOOLINFO lpToolInfo) const
2477 {
2478 ATLASSERT(::IsWindow(this->m_hWnd));
2479 ATLASSERT(hWnd != NULL);
2480 ATLASSERT(lpToolInfo != NULL);
2481
2482 TTHITTESTINFO hti = {};
2483 hti.ti.cbSize = RunTimeHelper::SizeOf_TOOLINFO();
2484 hti.hwnd = hWnd;
2485 hti.pt.x = pt.x;
2486 hti.pt.y = pt.y;
2487 if((BOOL)::SendMessage(this->m_hWnd, TTM_HITTEST, 0, (LPARAM)&hti) != FALSE)
2488 {
2489 *lpToolInfo = hti.ti;
2490 return TRUE;
2491 }
2492 return FALSE;
2493 }
2494
RelayEvent(LPMSG lpMsg)2495 void RelayEvent(LPMSG lpMsg)
2496 {
2497 ATLASSERT(::IsWindow(this->m_hWnd));
2498 ::SendMessage(this->m_hWnd, TTM_RELAYEVENT, 0, (LPARAM)lpMsg);
2499 }
2500
UpdateTipText(LPTOOLINFO lpToolInfo)2501 void UpdateTipText(LPTOOLINFO lpToolInfo)
2502 {
2503 ATLASSERT(::IsWindow(this->m_hWnd));
2504 ::SendMessage(this->m_hWnd, TTM_UPDATETIPTEXT, 0, (LPARAM)lpToolInfo);
2505 }
2506
2507 void UpdateTipText(ATL::_U_STRINGorID text, HWND hWnd, UINT_PTR nIDTool = 0)
2508 {
2509 ATLASSERT(::IsWindow(this->m_hWnd));
2510 ATLASSERT(hWnd != NULL);
2511
2512 CToolInfo ti(0, hWnd, nIDTool, NULL, (LPTSTR)text.m_lpstr);
2513 ::SendMessage(this->m_hWnd, TTM_UPDATETIPTEXT, 0, ti);
2514 }
2515
EnumTools(UINT_PTR nTool,LPTOOLINFO lpToolInfo)2516 BOOL EnumTools(UINT_PTR nTool, LPTOOLINFO lpToolInfo) const
2517 {
2518 ATLASSERT(::IsWindow(this->m_hWnd));
2519 return (BOOL)::SendMessage(this->m_hWnd, TTM_ENUMTOOLS, nTool, (LPARAM)lpToolInfo);
2520 }
2521
Pop()2522 void Pop()
2523 {
2524 ATLASSERT(::IsWindow(this->m_hWnd));
2525 ::SendMessage(this->m_hWnd, TTM_POP, 0, 0L);
2526 }
2527
TrackActivate(LPTOOLINFO lpToolInfo,BOOL bActivate)2528 void TrackActivate(LPTOOLINFO lpToolInfo, BOOL bActivate)
2529 {
2530 ATLASSERT(::IsWindow(this->m_hWnd));
2531 ::SendMessage(this->m_hWnd, TTM_TRACKACTIVATE, bActivate, (LPARAM)lpToolInfo);
2532 }
2533
TrackActivate(HWND hWnd,UINT_PTR nIDTool,BOOL bActivate)2534 void TrackActivate(HWND hWnd, UINT_PTR nIDTool, BOOL bActivate)
2535 {
2536 ATLASSERT(::IsWindow(this->m_hWnd));
2537 ATLASSERT(hWnd != NULL);
2538
2539 CToolInfo ti(0, hWnd, nIDTool);
2540 ::SendMessage(this->m_hWnd, TTM_TRACKACTIVATE, bActivate, ti);
2541 }
2542
TrackPosition(int xPos,int yPos)2543 void TrackPosition(int xPos, int yPos)
2544 {
2545 ATLASSERT(::IsWindow(this->m_hWnd));
2546 ::SendMessage(this->m_hWnd, TTM_TRACKPOSITION, 0, MAKELPARAM(xPos, yPos));
2547 }
2548
Update()2549 void Update()
2550 {
2551 ATLASSERT(::IsWindow(this->m_hWnd));
2552 ::SendMessage(this->m_hWnd, TTM_UPDATE, 0, 0L);
2553 }
2554
AdjustRect(LPRECT lpRect,BOOL bLarger)2555 BOOL AdjustRect(LPRECT lpRect, BOOL bLarger /*= TRUE*/)
2556 {
2557 ATLASSERT(::IsWindow(this->m_hWnd));
2558 return (BOOL)::SendMessage(this->m_hWnd, TTM_ADJUSTRECT, bLarger, (LPARAM)lpRect);
2559 }
2560
Popup()2561 void Popup()
2562 {
2563 ATLASSERT(::IsWindow(this->m_hWnd));
2564 ::SendMessage(this->m_hWnd, TTM_POPUP, 0, 0L);
2565 }
2566 };
2567
2568 typedef CToolTipCtrlT<ATL::CWindow> CToolTipCtrl;
2569
2570
2571 ///////////////////////////////////////////////////////////////////////////////
2572 // CHeaderCtrl
2573
2574 template <class TBase>
2575 class CHeaderCtrlT : public TBase
2576 {
2577 public:
2578 // Constructors
TBase(hWnd)2579 CHeaderCtrlT(HWND hWnd = NULL) : TBase(hWnd)
2580 { }
2581
2582 CHeaderCtrlT< TBase >& operator =(HWND hWnd)
2583 {
2584 this->m_hWnd = hWnd;
2585 return *this;
2586 }
2587
2588 HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
2589 DWORD dwStyle = 0, DWORD dwExStyle = 0,
2590 ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
2591 {
2592 return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
2593 }
2594
2595 // Attributes
GetWndClassName()2596 static LPCTSTR GetWndClassName()
2597 {
2598 return WC_HEADER;
2599 }
2600
GetItemCount()2601 int GetItemCount() const
2602 {
2603 ATLASSERT(::IsWindow(this->m_hWnd));
2604 return (int)::SendMessage(this->m_hWnd, HDM_GETITEMCOUNT, 0, 0L);
2605 }
2606
GetItem(int nIndex,LPHDITEM pHeaderItem)2607 BOOL GetItem(int nIndex, LPHDITEM pHeaderItem) const
2608 {
2609 ATLASSERT(::IsWindow(this->m_hWnd));
2610 return (BOOL)::SendMessage(this->m_hWnd, HDM_GETITEM, nIndex, (LPARAM)pHeaderItem);
2611 }
2612
SetItem(int nIndex,LPHDITEM pHeaderItem)2613 BOOL SetItem(int nIndex, LPHDITEM pHeaderItem)
2614 {
2615 ATLASSERT(::IsWindow(this->m_hWnd));
2616 return (BOOL)::SendMessage(this->m_hWnd, HDM_SETITEM, nIndex, (LPARAM)pHeaderItem);
2617 }
2618
GetImageList()2619 CImageList GetImageList() const
2620 {
2621 ATLASSERT(::IsWindow(this->m_hWnd));
2622 return CImageList((HIMAGELIST)::SendMessage(this->m_hWnd, HDM_GETIMAGELIST, 0, 0L));
2623 }
2624
SetImageList(HIMAGELIST hImageList)2625 CImageList SetImageList(HIMAGELIST hImageList)
2626 {
2627 ATLASSERT(::IsWindow(this->m_hWnd));
2628 return CImageList((HIMAGELIST)::SendMessage(this->m_hWnd, HDM_SETIMAGELIST, 0, (LPARAM)hImageList));
2629 }
2630
GetOrderArray(int nSize,int * lpnArray)2631 BOOL GetOrderArray(int nSize, int* lpnArray) const
2632 {
2633 ATLASSERT(::IsWindow(this->m_hWnd));
2634 return (BOOL)::SendMessage(this->m_hWnd, HDM_GETORDERARRAY, nSize, (LPARAM)lpnArray);
2635 }
2636
SetOrderArray(int nSize,int * lpnArray)2637 BOOL SetOrderArray(int nSize, int* lpnArray)
2638 {
2639 ATLASSERT(::IsWindow(this->m_hWnd));
2640 return (BOOL)::SendMessage(this->m_hWnd, HDM_SETORDERARRAY, nSize, (LPARAM)lpnArray);
2641 }
2642
GetItemRect(int nIndex,LPRECT lpItemRect)2643 BOOL GetItemRect(int nIndex, LPRECT lpItemRect) const
2644 {
2645 ATLASSERT(::IsWindow(this->m_hWnd));
2646 return (BOOL)::SendMessage(this->m_hWnd, HDM_GETITEMRECT, nIndex, (LPARAM)lpItemRect);
2647 }
2648
SetHotDivider(BOOL bPos,DWORD dwInputValue)2649 int SetHotDivider(BOOL bPos, DWORD dwInputValue)
2650 {
2651 ATLASSERT(::IsWindow(this->m_hWnd));
2652 return (int)::SendMessage(this->m_hWnd, HDM_SETHOTDIVIDER, bPos, dwInputValue);
2653 }
2654
GetUnicodeFormat()2655 BOOL GetUnicodeFormat() const
2656 {
2657 ATLASSERT(::IsWindow(this->m_hWnd));
2658 return (BOOL)::SendMessage(this->m_hWnd, HDM_GETUNICODEFORMAT, 0, 0L);
2659 }
2660
2661 BOOL SetUnicodeFormat(BOOL bUnicode = TRUE)
2662 {
2663 ATLASSERT(::IsWindow(this->m_hWnd));
2664 return (BOOL)::SendMessage(this->m_hWnd, HDM_SETUNICODEFORMAT, bUnicode, 0L);
2665 }
2666
GetBitmapMargin()2667 int GetBitmapMargin() const
2668 {
2669 ATLASSERT(::IsWindow(this->m_hWnd));
2670 return (int)::SendMessage(this->m_hWnd, HDM_GETBITMAPMARGIN, 0, 0L);
2671 }
2672
SetBitmapMargin(int nWidth)2673 int SetBitmapMargin(int nWidth)
2674 {
2675 ATLASSERT(::IsWindow(this->m_hWnd));
2676 return (int)::SendMessage(this->m_hWnd, HDM_SETBITMAPMARGIN, nWidth, 0L);
2677 }
2678
SetFilterChangeTimeout(DWORD dwTimeOut)2679 int SetFilterChangeTimeout(DWORD dwTimeOut)
2680 {
2681 ATLASSERT(::IsWindow(this->m_hWnd));
2682 return (int)::SendMessage(this->m_hWnd, HDM_SETFILTERCHANGETIMEOUT, 0, dwTimeOut);
2683 }
2684
2685 #if (_WIN32_WINNT >= 0x0600)
GetItemDropDownRect(int nIndex,LPRECT lpRect)2686 BOOL GetItemDropDownRect(int nIndex, LPRECT lpRect) const
2687 {
2688 ATLASSERT(::IsWindow(this->m_hWnd));
2689 return (BOOL)::SendMessage(this->m_hWnd, HDM_GETITEMDROPDOWNRECT, nIndex, (LPARAM)lpRect);
2690 }
2691
GetOverflowRect(LPRECT lpRect)2692 BOOL GetOverflowRect(LPRECT lpRect) const
2693 {
2694 ATLASSERT(::IsWindow(this->m_hWnd));
2695 return (BOOL)::SendMessage(this->m_hWnd, HDM_GETOVERFLOWRECT, 0, (LPARAM)lpRect);
2696 }
2697
GetFocusedItem()2698 int GetFocusedItem() const
2699 {
2700 ATLASSERT(::IsWindow(this->m_hWnd));
2701 return (int)::SendMessage(this->m_hWnd, HDM_GETFOCUSEDITEM, 0, 0L);
2702 }
2703
SetFocusedItem(int nIndex)2704 BOOL SetFocusedItem(int nIndex)
2705 {
2706 ATLASSERT(::IsWindow(this->m_hWnd));
2707 return (BOOL)::SendMessage(this->m_hWnd, HDM_SETFOCUSEDITEM, 0, nIndex);
2708 }
2709 #endif // (_WIN32_WINNT >= 0x0600)
2710
2711 // Operations
InsertItem(int nIndex,LPHDITEM phdi)2712 int InsertItem(int nIndex, LPHDITEM phdi)
2713 {
2714 ATLASSERT(::IsWindow(this->m_hWnd));
2715 return (int)::SendMessage(this->m_hWnd, HDM_INSERTITEM, nIndex, (LPARAM)phdi);
2716 }
2717
AddItem(LPHDITEM phdi)2718 int AddItem(LPHDITEM phdi)
2719 {
2720 return InsertItem(GetItemCount(), phdi);
2721 }
2722
DeleteItem(int nIndex)2723 BOOL DeleteItem(int nIndex)
2724 {
2725 ATLASSERT(::IsWindow(this->m_hWnd));
2726 return (BOOL)::SendMessage(this->m_hWnd, HDM_DELETEITEM, nIndex, 0L);
2727 }
2728
Layout(HD_LAYOUT * pHeaderLayout)2729 BOOL Layout(HD_LAYOUT* pHeaderLayout)
2730 {
2731 ATLASSERT(::IsWindow(this->m_hWnd));
2732 return (BOOL)::SendMessage(this->m_hWnd, HDM_LAYOUT, 0, (LPARAM)pHeaderLayout);
2733 }
2734
HitTest(LPHDHITTESTINFO lpHitTestInfo)2735 int HitTest(LPHDHITTESTINFO lpHitTestInfo) const
2736 {
2737 ATLASSERT(::IsWindow(this->m_hWnd));
2738 return (int)::SendMessage(this->m_hWnd, HDM_HITTEST, 0, (LPARAM)lpHitTestInfo);
2739 }
2740
OrderToIndex(int nOrder)2741 int OrderToIndex(int nOrder)
2742 {
2743 ATLASSERT(::IsWindow(this->m_hWnd));
2744 return (int)::SendMessage(this->m_hWnd, HDM_ORDERTOINDEX, nOrder, 0L);
2745 }
2746
CreateDragImage(int nIndex)2747 CImageList CreateDragImage(int nIndex)
2748 {
2749 ATLASSERT(::IsWindow(this->m_hWnd));
2750 return CImageList((HIMAGELIST)::SendMessage(this->m_hWnd, HDM_CREATEDRAGIMAGE, nIndex, 0L));
2751 }
2752
EditFilter(int nColumn,BOOL bDiscardChanges)2753 int EditFilter(int nColumn, BOOL bDiscardChanges)
2754 {
2755 ATLASSERT(::IsWindow(this->m_hWnd));
2756 return (int)::SendMessage(this->m_hWnd, HDM_EDITFILTER, nColumn, MAKELPARAM(bDiscardChanges, 0));
2757 }
2758
ClearFilter(int nColumn)2759 int ClearFilter(int nColumn)
2760 {
2761 ATLASSERT(::IsWindow(this->m_hWnd));
2762 return (int)::SendMessage(this->m_hWnd, HDM_CLEARFILTER, nColumn, 0L);
2763 }
2764
ClearAllFilters()2765 int ClearAllFilters()
2766 {
2767 ATLASSERT(::IsWindow(this->m_hWnd));
2768 return (int)::SendMessage(this->m_hWnd, HDM_CLEARFILTER, (WPARAM)-1, 0L);
2769 }
2770 };
2771
2772 typedef CHeaderCtrlT<ATL::CWindow> CHeaderCtrl;
2773
2774
2775 ///////////////////////////////////////////////////////////////////////////////
2776 // CListViewCtrl
2777
2778 template <class TBase>
2779 class CListViewCtrlT : public TBase
2780 {
2781 public:
2782 // Constructors
TBase(hWnd)2783 CListViewCtrlT(HWND hWnd = NULL) : TBase(hWnd)
2784 { }
2785
2786 CListViewCtrlT< TBase >& operator =(HWND hWnd)
2787 {
2788 this->m_hWnd = hWnd;
2789 return *this;
2790 }
2791
2792 HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
2793 DWORD dwStyle = 0, DWORD dwExStyle = 0,
2794 ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
2795 {
2796 return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
2797 }
2798
2799 // Attributes
GetWndClassName()2800 static LPCTSTR GetWndClassName()
2801 {
2802 return WC_LISTVIEW;
2803 }
2804
GetBkColor()2805 COLORREF GetBkColor() const
2806 {
2807 ATLASSERT(::IsWindow(this->m_hWnd));
2808 return (COLORREF)::SendMessage(this->m_hWnd, LVM_GETBKCOLOR, 0, 0L);
2809 }
2810
SetBkColor(COLORREF cr)2811 BOOL SetBkColor(COLORREF cr)
2812 {
2813 ATLASSERT(::IsWindow(this->m_hWnd));
2814 return (BOOL)::SendMessage(this->m_hWnd, LVM_SETBKCOLOR, 0, cr);
2815 }
2816
GetImageList(int nImageListType)2817 CImageList GetImageList(int nImageListType) const
2818 {
2819 ATLASSERT(::IsWindow(this->m_hWnd));
2820 return CImageList((HIMAGELIST)::SendMessage(this->m_hWnd, LVM_GETIMAGELIST, nImageListType, 0L));
2821 }
2822
SetImageList(HIMAGELIST hImageList,int nImageList)2823 CImageList SetImageList(HIMAGELIST hImageList, int nImageList)
2824 {
2825 ATLASSERT(::IsWindow(this->m_hWnd));
2826 return CImageList((HIMAGELIST)::SendMessage(this->m_hWnd, LVM_SETIMAGELIST, nImageList, (LPARAM)hImageList));
2827 }
2828
GetItemCount()2829 int GetItemCount() const
2830 {
2831 ATLASSERT(::IsWindow(this->m_hWnd));
2832 return (int)::SendMessage(this->m_hWnd, LVM_GETITEMCOUNT, 0, 0L);
2833 }
2834
SetItemCount(int nItems)2835 BOOL SetItemCount(int nItems)
2836 {
2837 ATLASSERT(::IsWindow(this->m_hWnd));
2838 return (BOOL)::SendMessage(this->m_hWnd, LVM_SETITEMCOUNT, nItems, 0L);
2839 }
2840
GetItem(LPLVITEM pItem)2841 BOOL GetItem(LPLVITEM pItem) const
2842 {
2843 ATLASSERT(::IsWindow(this->m_hWnd));
2844 return (BOOL)::SendMessage(this->m_hWnd, LVM_GETITEM, 0, (LPARAM)pItem);
2845 }
2846
SetItem(const LVITEM * pItem)2847 BOOL SetItem(const LVITEM* pItem)
2848 {
2849 ATLASSERT(::IsWindow(this->m_hWnd));
2850 return (BOOL)::SendMessage(this->m_hWnd, LVM_SETITEM, 0, (LPARAM)pItem);
2851 }
2852
SetItem(int nItem,int nSubItem,UINT nMask,LPCTSTR lpszItem,int nImage,UINT nState,UINT nStateMask,LPARAM lParam)2853 BOOL SetItem(int nItem, int nSubItem, UINT nMask, LPCTSTR lpszItem,
2854 int nImage, UINT nState, UINT nStateMask, LPARAM lParam)
2855 {
2856 ATLASSERT(::IsWindow(this->m_hWnd));
2857 LVITEM lvi = {};
2858 lvi.mask = nMask;
2859 lvi.iItem = nItem;
2860 lvi.iSubItem = nSubItem;
2861 lvi.stateMask = nStateMask;
2862 lvi.state = nState;
2863 lvi.pszText = (LPTSTR) lpszItem;
2864 lvi.iImage = nImage;
2865 lvi.lParam = lParam;
2866 return (BOOL)::SendMessage(this->m_hWnd, LVM_SETITEM, 0, (LPARAM)&lvi);
2867 }
2868
GetItemState(int nItem,UINT nMask)2869 UINT GetItemState(int nItem, UINT nMask) const
2870 {
2871 ATLASSERT(::IsWindow(this->m_hWnd));
2872 return (UINT)::SendMessage(this->m_hWnd, LVM_GETITEMSTATE, nItem, nMask);
2873 }
2874
SetItemState(int nItem,UINT nState,UINT nStateMask)2875 BOOL SetItemState(int nItem, UINT nState, UINT nStateMask)
2876 {
2877 ATLASSERT(::IsWindow(this->m_hWnd));
2878 LVITEM lvi = {};
2879 lvi.state = nState;
2880 lvi.stateMask = nStateMask;
2881 return (BOOL)::SendMessage(this->m_hWnd, LVM_SETITEMSTATE, nItem, (LPARAM)&lvi);
2882 }
2883
SetItemState(int nItem,LPLVITEM pItem)2884 BOOL SetItemState(int nItem, LPLVITEM pItem)
2885 {
2886 ATLASSERT(::IsWindow(this->m_hWnd));
2887 return (BOOL)::SendMessage(this->m_hWnd, LVM_SETITEMSTATE, nItem, (LPARAM)pItem);
2888 }
2889
GetItemText(int nItem,int nSubItem,BSTR & bstrText)2890 BOOL GetItemText(int nItem, int nSubItem, BSTR& bstrText) const
2891 {
2892 USES_CONVERSION;
2893 ATLASSERT(::IsWindow(this->m_hWnd));
2894 ATLASSERT(bstrText == NULL);
2895 LVITEM lvi = {};
2896 lvi.iSubItem = nSubItem;
2897
2898 LPTSTR lpstrText = NULL;
2899 int nRes = 0;
2900 for(int nLen = 256; ; nLen *= 2)
2901 {
2902 ATLTRY(lpstrText = new TCHAR[nLen]);
2903 if(lpstrText == NULL)
2904 break;
2905 lpstrText[0] = NULL;
2906 lvi.cchTextMax = nLen;
2907 lvi.pszText = lpstrText;
2908 nRes = (int)::SendMessage(this->m_hWnd, LVM_GETITEMTEXT, (WPARAM)nItem, (LPARAM)&lvi);
2909 if(nRes < nLen - 1)
2910 break;
2911 delete [] lpstrText;
2912 lpstrText = NULL;
2913 }
2914
2915 if(lpstrText != NULL)
2916 {
2917 if(nRes != 0)
2918 bstrText = ::SysAllocString(T2OLE(lpstrText));
2919 delete [] lpstrText;
2920 }
2921
2922 return (bstrText != NULL) ? TRUE : FALSE;
2923 }
2924
2925 #ifdef __ATLSTR_H__
GetItemText(int nItem,int nSubItem,ATL::CString & strText)2926 int GetItemText(int nItem, int nSubItem, ATL::CString& strText) const
2927 {
2928 ATLASSERT(::IsWindow(this->m_hWnd));
2929 LVITEM lvi = {};
2930 lvi.iSubItem = nSubItem;
2931
2932 strText.Empty();
2933 int nRes = 0;
2934 for(int nLen = 256; ; nLen *= 2)
2935 {
2936 lvi.cchTextMax = nLen;
2937 lvi.pszText = strText.GetBufferSetLength(nLen);
2938 if(lvi.pszText == NULL)
2939 {
2940 nRes = 0;
2941 break;
2942 }
2943 nRes = (int)::SendMessage(this->m_hWnd, LVM_GETITEMTEXT, (WPARAM)nItem, (LPARAM)&lvi);
2944 if(nRes < nLen - 1)
2945 break;
2946 }
2947 strText.ReleaseBuffer();
2948 return nRes;
2949 }
2950 #endif // __ATLSTR_H__
2951
GetItemText(int nItem,int nSubItem,LPTSTR lpszText,int nLen)2952 int GetItemText(int nItem, int nSubItem, LPTSTR lpszText, int nLen) const
2953 {
2954 ATLASSERT(::IsWindow(this->m_hWnd));
2955 LVITEM lvi = {};
2956 lvi.iSubItem = nSubItem;
2957 lvi.cchTextMax = nLen;
2958 lvi.pszText = lpszText;
2959 return (int)::SendMessage(this->m_hWnd, LVM_GETITEMTEXT, (WPARAM)nItem, (LPARAM)&lvi);
2960 }
2961
SetItemText(int nItem,int nSubItem,LPCTSTR lpszText)2962 BOOL SetItemText(int nItem, int nSubItem, LPCTSTR lpszText)
2963 {
2964 ATLASSERT(::IsWindow(this->m_hWnd));
2965 return SetItem(nItem, nSubItem, LVIF_TEXT, lpszText, 0, 0, 0, 0);
2966 }
2967
GetItemData(int nItem)2968 DWORD_PTR GetItemData(int nItem) const
2969 {
2970 ATLASSERT(::IsWindow(this->m_hWnd));
2971 LVITEM lvi = {};
2972 lvi.iItem = nItem;
2973 lvi.mask = LVIF_PARAM;
2974 BOOL bRet = (BOOL)::SendMessage(this->m_hWnd, LVM_GETITEM, 0, (LPARAM)&lvi);
2975 return (DWORD_PTR)(bRet ? lvi.lParam : NULL);
2976 }
2977
SetItemData(int nItem,DWORD_PTR dwData)2978 BOOL SetItemData(int nItem, DWORD_PTR dwData)
2979 {
2980 ATLASSERT(::IsWindow(this->m_hWnd));
2981 return SetItem(nItem, 0, LVIF_PARAM, NULL, 0, 0, 0, (LPARAM)dwData);
2982 }
2983
GetCallbackMask()2984 UINT GetCallbackMask() const
2985 {
2986 ATLASSERT(::IsWindow(this->m_hWnd));
2987 return (UINT)::SendMessage(this->m_hWnd, LVM_GETCALLBACKMASK, 0, 0L);
2988 }
2989
SetCallbackMask(UINT nMask)2990 BOOL SetCallbackMask(UINT nMask)
2991 {
2992 ATLASSERT(::IsWindow(this->m_hWnd));
2993 return (BOOL)::SendMessage(this->m_hWnd, LVM_SETCALLBACKMASK, nMask, 0L);
2994 }
2995
GetItemPosition(int nItem,LPPOINT lpPoint)2996 BOOL GetItemPosition(int nItem, LPPOINT lpPoint) const
2997 {
2998 ATLASSERT(::IsWindow(this->m_hWnd));
2999 return (BOOL)::SendMessage(this->m_hWnd, LVM_GETITEMPOSITION, nItem, (LPARAM)lpPoint);
3000 }
3001
SetItemPosition(int nItem,POINT pt)3002 BOOL SetItemPosition(int nItem, POINT pt)
3003 {
3004 ATLASSERT(::IsWindow(this->m_hWnd));
3005 ATLASSERT(((this->GetStyle() & LVS_TYPEMASK) == LVS_ICON) || ((this->GetStyle() & LVS_TYPEMASK) == LVS_SMALLICON));
3006 return (BOOL)::SendMessage(this->m_hWnd, LVM_SETITEMPOSITION32, nItem, (LPARAM)&pt);
3007 }
3008
SetItemPosition(int nItem,int x,int y)3009 BOOL SetItemPosition(int nItem, int x, int y)
3010 {
3011 ATLASSERT(::IsWindow(this->m_hWnd));
3012 ATLASSERT(((this->GetStyle() & LVS_TYPEMASK) == LVS_ICON) || ((this->GetStyle() & LVS_TYPEMASK) == LVS_SMALLICON));
3013 POINT pt = { x, y };
3014 return (BOOL)::SendMessage(this->m_hWnd, LVM_SETITEMPOSITION32, nItem, (LPARAM)&pt);
3015 }
3016
GetStringWidth(LPCTSTR lpsz)3017 int GetStringWidth(LPCTSTR lpsz) const
3018 {
3019 ATLASSERT(::IsWindow(this->m_hWnd));
3020 return (int)::SendMessage(this->m_hWnd, LVM_GETSTRINGWIDTH, 0, (LPARAM)lpsz);
3021 }
3022
GetEditControl()3023 CEdit GetEditControl() const
3024 {
3025 ATLASSERT(::IsWindow(this->m_hWnd));
3026 return CEdit((HWND)::SendMessage(this->m_hWnd, LVM_GETEDITCONTROL, 0, 0L));
3027 }
3028
GetColumn(int nCol,LVCOLUMN * pColumn)3029 BOOL GetColumn(int nCol, LVCOLUMN* pColumn) const
3030 {
3031 ATLASSERT(::IsWindow(this->m_hWnd));
3032 return (BOOL)::SendMessage(this->m_hWnd, LVM_GETCOLUMN, nCol, (LPARAM)pColumn);
3033 }
3034
SetColumn(int nCol,const LVCOLUMN * pColumn)3035 BOOL SetColumn(int nCol, const LVCOLUMN* pColumn)
3036 {
3037 ATLASSERT(::IsWindow(this->m_hWnd));
3038 return (BOOL)::SendMessage(this->m_hWnd, LVM_SETCOLUMN, nCol, (LPARAM)pColumn);
3039 }
3040
GetColumnWidth(int nCol)3041 int GetColumnWidth(int nCol) const
3042 {
3043 ATLASSERT(::IsWindow(this->m_hWnd));
3044 return (int)::SendMessage(this->m_hWnd, LVM_GETCOLUMNWIDTH, nCol, 0L);
3045 }
3046
SetColumnWidth(int nCol,int cx)3047 BOOL SetColumnWidth(int nCol, int cx)
3048 {
3049 ATLASSERT(::IsWindow(this->m_hWnd));
3050 return (BOOL)::SendMessage(this->m_hWnd, LVM_SETCOLUMNWIDTH, nCol, MAKELPARAM(cx, 0));
3051 }
3052
GetViewRect(LPRECT lpRect)3053 BOOL GetViewRect(LPRECT lpRect) const
3054 {
3055 ATLASSERT(::IsWindow(this->m_hWnd));
3056 return (BOOL)::SendMessage(this->m_hWnd, LVM_GETVIEWRECT, 0, (LPARAM)lpRect);
3057 }
3058
GetTextColor()3059 COLORREF GetTextColor() const
3060 {
3061 ATLASSERT(::IsWindow(this->m_hWnd));
3062 return (COLORREF)::SendMessage(this->m_hWnd, LVM_GETTEXTCOLOR, 0, 0L);
3063 }
3064
SetTextColor(COLORREF cr)3065 BOOL SetTextColor(COLORREF cr)
3066 {
3067 ATLASSERT(::IsWindow(this->m_hWnd));
3068 return (BOOL)::SendMessage(this->m_hWnd, LVM_SETTEXTCOLOR, 0, cr);
3069 }
3070
GetTextBkColor()3071 COLORREF GetTextBkColor() const
3072 {
3073 ATLASSERT(::IsWindow(this->m_hWnd));
3074 return (COLORREF)::SendMessage(this->m_hWnd, LVM_GETTEXTBKCOLOR, 0, 0L);
3075 }
3076
SetTextBkColor(COLORREF cr)3077 BOOL SetTextBkColor(COLORREF cr)
3078 {
3079 ATLASSERT(::IsWindow(this->m_hWnd));
3080 return (BOOL)::SendMessage(this->m_hWnd, LVM_SETTEXTBKCOLOR, 0, cr);
3081 }
3082
GetTopIndex()3083 int GetTopIndex() const
3084 {
3085 ATLASSERT(::IsWindow(this->m_hWnd));
3086 return (int)::SendMessage(this->m_hWnd, LVM_GETTOPINDEX, 0, 0L);
3087 }
3088
GetCountPerPage()3089 int GetCountPerPage() const
3090 {
3091 ATLASSERT(::IsWindow(this->m_hWnd));
3092 return (int)::SendMessage(this->m_hWnd, LVM_GETCOUNTPERPAGE, 0, 0L);
3093 }
3094
GetOrigin(LPPOINT lpPoint)3095 BOOL GetOrigin(LPPOINT lpPoint) const
3096 {
3097 ATLASSERT(::IsWindow(this->m_hWnd));
3098 return (BOOL)::SendMessage(this->m_hWnd, LVM_GETORIGIN, 0, (LPARAM)lpPoint);
3099 }
3100
GetSelectedCount()3101 UINT GetSelectedCount() const
3102 {
3103 ATLASSERT(::IsWindow(this->m_hWnd));
3104 return (UINT)::SendMessage(this->m_hWnd, LVM_GETSELECTEDCOUNT, 0, 0L);
3105 }
3106
GetItemRect(int nItem,LPRECT lpRect,UINT nCode)3107 BOOL GetItemRect(int nItem, LPRECT lpRect, UINT nCode) const
3108 {
3109 ATLASSERT(::IsWindow(this->m_hWnd));
3110 lpRect->left = nCode;
3111 return (BOOL)::SendMessage(this->m_hWnd, LVM_GETITEMRECT, (WPARAM)nItem, (LPARAM)lpRect);
3112 }
3113
GetHotCursor()3114 HCURSOR GetHotCursor() const
3115 {
3116 ATLASSERT(::IsWindow(this->m_hWnd));
3117 return (HCURSOR)::SendMessage(this->m_hWnd, LVM_GETHOTCURSOR, 0, 0L);
3118 }
3119
SetHotCursor(HCURSOR hHotCursor)3120 HCURSOR SetHotCursor(HCURSOR hHotCursor)
3121 {
3122 ATLASSERT(::IsWindow(this->m_hWnd));
3123 return (HCURSOR)::SendMessage(this->m_hWnd, LVM_SETHOTCURSOR, 0, (LPARAM)hHotCursor);
3124 }
3125
GetHotItem()3126 int GetHotItem() const
3127 {
3128 ATLASSERT(::IsWindow(this->m_hWnd));
3129 return (int)::SendMessage(this->m_hWnd, LVM_GETHOTITEM, 0, 0L);
3130 }
3131
SetHotItem(int nIndex)3132 int SetHotItem(int nIndex)
3133 {
3134 ATLASSERT(::IsWindow(this->m_hWnd));
3135 return (int)::SendMessage(this->m_hWnd, LVM_SETHOTITEM, nIndex, 0L);
3136 }
3137
GetColumnOrderArray(int nCount,int * lpnArray)3138 BOOL GetColumnOrderArray(int nCount, int* lpnArray) const
3139 {
3140 ATLASSERT(::IsWindow(this->m_hWnd));
3141 return (BOOL)::SendMessage(this->m_hWnd, LVM_GETCOLUMNORDERARRAY, nCount, (LPARAM)lpnArray);
3142 }
3143
SetColumnOrderArray(int nCount,int * lpnArray)3144 BOOL SetColumnOrderArray(int nCount, int* lpnArray)
3145 {
3146 ATLASSERT(::IsWindow(this->m_hWnd));
3147 return (BOOL)::SendMessage(this->m_hWnd, LVM_SETCOLUMNORDERARRAY, nCount, (LPARAM)lpnArray);
3148 }
3149
GetHeader()3150 CHeaderCtrl GetHeader() const
3151 {
3152 ATLASSERT(::IsWindow(this->m_hWnd));
3153 return CHeaderCtrl((HWND)::SendMessage(this->m_hWnd, LVM_GETHEADER, 0, 0L));
3154 }
3155
GetSubItemRect(int nItem,int nSubItem,int nFlag,LPRECT lpRect)3156 BOOL GetSubItemRect(int nItem, int nSubItem, int nFlag, LPRECT lpRect) const
3157 {
3158 ATLASSERT(::IsWindow(this->m_hWnd));
3159 ATLASSERT((this->GetStyle() & LVS_TYPEMASK) == LVS_REPORT);
3160 ATLASSERT(lpRect != NULL);
3161 lpRect->top = nSubItem;
3162 lpRect->left = nFlag;
3163 return (BOOL)::SendMessage(this->m_hWnd, LVM_GETSUBITEMRECT, nItem, (LPARAM)lpRect);
3164 }
3165
SetIconSpacing(int cx,int cy)3166 DWORD SetIconSpacing(int cx, int cy)
3167 {
3168 ATLASSERT(::IsWindow(this->m_hWnd));
3169 ATLASSERT((this->GetStyle() & LVS_TYPEMASK) == LVS_ICON);
3170 return (DWORD)::SendMessage(this->m_hWnd, LVM_SETICONSPACING, 0, MAKELPARAM(cx, cy));
3171 }
3172
GetISearchString(LPTSTR lpstr)3173 int GetISearchString(LPTSTR lpstr) const
3174 {
3175 ATLASSERT(::IsWindow(this->m_hWnd));
3176 return (int)::SendMessage(this->m_hWnd, LVM_GETISEARCHSTRING, 0, (LPARAM)lpstr);
3177 }
3178
3179 void GetItemSpacing(SIZE& sizeSpacing, BOOL bSmallIconView = FALSE) const
3180 {
3181 ATLASSERT(::IsWindow(this->m_hWnd));
3182 DWORD dwRet = (DWORD)::SendMessage(this->m_hWnd, LVM_GETITEMSPACING, bSmallIconView, 0L);
3183 sizeSpacing.cx = GET_X_LPARAM(dwRet);
3184 sizeSpacing.cy = GET_Y_LPARAM(dwRet);
3185 }
3186
3187 // single-selection only
GetSelectedIndex()3188 int GetSelectedIndex() const
3189 {
3190 ATLASSERT(::IsWindow(this->m_hWnd));
3191 ATLASSERT((this->GetStyle() & LVS_SINGLESEL) != 0);
3192 return (int)::SendMessage(this->m_hWnd, LVM_GETNEXTITEM, (WPARAM)-1, MAKELPARAM(LVNI_ALL | LVNI_SELECTED, 0));
3193 }
3194
GetSelectedItem(LPLVITEM pItem)3195 BOOL GetSelectedItem(LPLVITEM pItem) const
3196 {
3197 ATLASSERT(::IsWindow(this->m_hWnd));
3198 ATLASSERT((this->GetStyle() & LVS_SINGLESEL) != 0);
3199 ATLASSERT(pItem != NULL);
3200 pItem->iItem = (int)::SendMessage(this->m_hWnd, LVM_GETNEXTITEM, (WPARAM)-1, MAKELPARAM(LVNI_ALL | LVNI_SELECTED, 0));
3201 if(pItem->iItem == -1)
3202 return FALSE;
3203 return (BOOL)::SendMessage(this->m_hWnd, LVM_GETITEM, 0, (LPARAM)pItem);
3204 }
3205
3206 // extended list view styles
GetExtendedListViewStyle()3207 DWORD GetExtendedListViewStyle() const
3208 {
3209 ATLASSERT(::IsWindow(this->m_hWnd));
3210 return (DWORD)::SendMessage(this->m_hWnd, LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0L);
3211 }
3212
3213 // dwExMask = 0 means all styles
3214 DWORD SetExtendedListViewStyle(DWORD dwExStyle, DWORD dwExMask = 0)
3215 {
3216 ATLASSERT(::IsWindow(this->m_hWnd));
3217 return (DWORD)::SendMessage(this->m_hWnd, LVM_SETEXTENDEDLISTVIEWSTYLE, dwExMask, dwExStyle);
3218 }
3219
3220 // checkboxes only
GetCheckState(int nIndex)3221 BOOL GetCheckState(int nIndex) const
3222 {
3223 ATLASSERT(::IsWindow(this->m_hWnd));
3224 ATLASSERT((GetExtendedListViewStyle() & LVS_EX_CHECKBOXES) != 0);
3225 UINT uRet = GetItemState(nIndex, LVIS_STATEIMAGEMASK);
3226 return (uRet >> 12) - 1;
3227 }
3228
SetCheckState(int nItem,BOOL bCheck)3229 BOOL SetCheckState(int nItem, BOOL bCheck)
3230 {
3231 int nCheck = bCheck ? 2 : 1; // one based index
3232 return SetItemState(nItem, INDEXTOSTATEIMAGEMASK(nCheck), LVIS_STATEIMAGEMASK);
3233 }
3234
3235 // view type
GetViewType()3236 DWORD GetViewType() const
3237 {
3238 ATLASSERT(::IsWindow(this->m_hWnd));
3239 return (this->GetStyle() & LVS_TYPEMASK);
3240 }
3241
SetViewType(DWORD dwType)3242 DWORD SetViewType(DWORD dwType)
3243 {
3244 ATLASSERT(::IsWindow(this->m_hWnd));
3245 ATLASSERT((dwType == LVS_ICON) || (dwType == LVS_SMALLICON) || (dwType == LVS_LIST) || (dwType == LVS_REPORT));
3246 DWORD dwOldType = GetViewType();
3247 if(dwType != dwOldType)
3248 this->ModifyStyle(LVS_TYPEMASK, (dwType & LVS_TYPEMASK));
3249 return dwOldType;
3250 }
3251
GetBkImage(LPLVBKIMAGE plvbki)3252 BOOL GetBkImage(LPLVBKIMAGE plvbki) const
3253 {
3254 ATLASSERT(::IsWindow(this->m_hWnd));
3255 return (BOOL)::SendMessage(this->m_hWnd, LVM_GETBKIMAGE, 0, (LPARAM)plvbki);
3256 }
3257
SetBkImage(LPLVBKIMAGE plvbki)3258 BOOL SetBkImage(LPLVBKIMAGE plvbki)
3259 {
3260 ATLASSERT(::IsWindow(this->m_hWnd));
3261 return (BOOL)::SendMessage(this->m_hWnd, LVM_SETBKIMAGE, 0, (LPARAM)plvbki);
3262 }
3263
GetSelectionMark()3264 int GetSelectionMark() const
3265 {
3266 ATLASSERT(::IsWindow(this->m_hWnd));
3267 return (int)::SendMessage(this->m_hWnd, LVM_GETSELECTIONMARK, 0, 0L);
3268 }
3269
SetSelectionMark(int nIndex)3270 int SetSelectionMark(int nIndex)
3271 {
3272 ATLASSERT(::IsWindow(this->m_hWnd));
3273 return (int)::SendMessage(this->m_hWnd, LVM_SETSELECTIONMARK, 0, nIndex);
3274 }
3275
GetWorkAreas(int nWorkAreas,LPRECT lpRect)3276 BOOL GetWorkAreas(int nWorkAreas, LPRECT lpRect) const
3277 {
3278 ATLASSERT(::IsWindow(this->m_hWnd));
3279 return (BOOL)::SendMessage(this->m_hWnd, LVM_GETWORKAREAS, nWorkAreas, (LPARAM)lpRect);
3280 }
3281
SetWorkAreas(int nWorkAreas,LPRECT lpRect)3282 BOOL SetWorkAreas(int nWorkAreas, LPRECT lpRect)
3283 {
3284 ATLASSERT(::IsWindow(this->m_hWnd));
3285 return (BOOL)::SendMessage(this->m_hWnd, LVM_SETWORKAREAS, nWorkAreas, (LPARAM)lpRect);
3286 }
3287
GetHoverTime()3288 DWORD GetHoverTime() const
3289 {
3290 ATLASSERT(::IsWindow(this->m_hWnd));
3291 ATLASSERT((GetExtendedListViewStyle() & (LVS_EX_TRACKSELECT | LVS_EX_ONECLICKACTIVATE | LVS_EX_TWOCLICKACTIVATE)) != 0);
3292 return (DWORD)::SendMessage(this->m_hWnd, LVM_GETHOVERTIME, 0, 0L);
3293 }
3294
SetHoverTime(DWORD dwHoverTime)3295 DWORD SetHoverTime(DWORD dwHoverTime)
3296 {
3297 ATLASSERT(::IsWindow(this->m_hWnd));
3298 ATLASSERT((GetExtendedListViewStyle() & (LVS_EX_TRACKSELECT | LVS_EX_ONECLICKACTIVATE | LVS_EX_TWOCLICKACTIVATE)) != 0);
3299 return (DWORD)::SendMessage(this->m_hWnd, LVM_SETHOVERTIME, 0, dwHoverTime);
3300 }
3301
GetNumberOfWorkAreas(int * pnWorkAreas)3302 BOOL GetNumberOfWorkAreas(int* pnWorkAreas) const
3303 {
3304 ATLASSERT(::IsWindow(this->m_hWnd));
3305 return (BOOL)::SendMessage(this->m_hWnd, LVM_GETNUMBEROFWORKAREAS, 0, (LPARAM)pnWorkAreas);
3306 }
3307
SetItemCountEx(int nItems,DWORD dwFlags)3308 BOOL SetItemCountEx(int nItems, DWORD dwFlags)
3309 {
3310 ATLASSERT(::IsWindow(this->m_hWnd));
3311 ATLASSERT(((this->GetStyle() & LVS_OWNERDATA) != 0) && (((this->GetStyle() & LVS_TYPEMASK) == LVS_REPORT) || ((this->GetStyle() & LVS_TYPEMASK) == LVS_LIST)));
3312 return (BOOL)::SendMessage(this->m_hWnd, LVM_SETITEMCOUNT, nItems, dwFlags);
3313 }
3314
GetToolTips()3315 CToolTipCtrl GetToolTips() const
3316 {
3317 ATLASSERT(::IsWindow(this->m_hWnd));
3318 return CToolTipCtrl((HWND)::SendMessage(this->m_hWnd, LVM_GETTOOLTIPS, 0, 0L));
3319 }
3320
SetToolTips(HWND hWndTT)3321 CToolTipCtrl SetToolTips(HWND hWndTT)
3322 {
3323 ATLASSERT(::IsWindow(this->m_hWnd));
3324 return CToolTipCtrl((HWND)::SendMessage(this->m_hWnd, LVM_SETTOOLTIPS, (WPARAM)hWndTT, 0L));
3325 }
3326
GetUnicodeFormat()3327 BOOL GetUnicodeFormat() const
3328 {
3329 ATLASSERT(::IsWindow(this->m_hWnd));
3330 return (BOOL)::SendMessage(this->m_hWnd, LVM_GETUNICODEFORMAT, 0, 0L);
3331 }
3332
3333 BOOL SetUnicodeFormat(BOOL bUnicode = TRUE)
3334 {
3335 ATLASSERT(::IsWindow(this->m_hWnd));
3336 return (BOOL)::SendMessage(this->m_hWnd, LVM_SETUNICODEFORMAT, bUnicode, 0L);
3337 }
3338
GetSelectedColumn()3339 int GetSelectedColumn() const
3340 {
3341 ATLASSERT(::IsWindow(this->m_hWnd));
3342 return (int)::SendMessage(this->m_hWnd, LVM_GETSELECTEDCOLUMN, 0, 0L);
3343 }
3344
SetSelectedColumn(int nColumn)3345 void SetSelectedColumn(int nColumn)
3346 {
3347 ATLASSERT(::IsWindow(this->m_hWnd));
3348 ::SendMessage(this->m_hWnd, LVM_SETSELECTEDCOLUMN, nColumn, 0L);
3349 }
3350
GetView()3351 DWORD GetView() const
3352 {
3353 ATLASSERT(::IsWindow(this->m_hWnd));
3354 return (DWORD)::SendMessage(this->m_hWnd, LVM_GETVIEW, 0, 0L);
3355 }
3356
SetView(DWORD dwView)3357 int SetView(DWORD dwView)
3358 {
3359 ATLASSERT(::IsWindow(this->m_hWnd));
3360 return (int)::SendMessage(this->m_hWnd, LVM_SETVIEW, dwView, 0L);
3361 }
3362
IsGroupViewEnabled()3363 BOOL IsGroupViewEnabled() const
3364 {
3365 ATLASSERT(::IsWindow(this->m_hWnd));
3366 return (BOOL)::SendMessage(this->m_hWnd, LVM_ISGROUPVIEWENABLED, 0, 0L);
3367 }
3368
GetGroupInfo(int nGroupID,PLVGROUP pGroup)3369 int GetGroupInfo(int nGroupID, PLVGROUP pGroup) const
3370 {
3371 ATLASSERT(::IsWindow(this->m_hWnd));
3372 return (int)::SendMessage(this->m_hWnd, LVM_GETGROUPINFO, nGroupID, (LPARAM)pGroup);
3373 }
3374
SetGroupInfo(int nGroupID,PLVGROUP pGroup)3375 int SetGroupInfo(int nGroupID, PLVGROUP pGroup)
3376 {
3377 ATLASSERT(::IsWindow(this->m_hWnd));
3378 return (int)::SendMessage(this->m_hWnd, LVM_SETGROUPINFO, nGroupID, (LPARAM)pGroup);
3379 }
3380
GetGroupMetrics(PLVGROUPMETRICS pGroupMetrics)3381 void GetGroupMetrics(PLVGROUPMETRICS pGroupMetrics) const
3382 {
3383 ATLASSERT(::IsWindow(this->m_hWnd));
3384 ::SendMessage(this->m_hWnd, LVM_GETGROUPMETRICS, 0, (LPARAM)pGroupMetrics);
3385 }
3386
SetGroupMetrics(PLVGROUPMETRICS pGroupMetrics)3387 void SetGroupMetrics(PLVGROUPMETRICS pGroupMetrics)
3388 {
3389 ATLASSERT(::IsWindow(this->m_hWnd));
3390 ::SendMessage(this->m_hWnd, LVM_SETGROUPMETRICS, 0, (LPARAM)pGroupMetrics);
3391 }
3392
GetTileViewInfo(PLVTILEVIEWINFO pTileViewInfo)3393 void GetTileViewInfo(PLVTILEVIEWINFO pTileViewInfo) const
3394 {
3395 ATLASSERT(::IsWindow(this->m_hWnd));
3396 ::SendMessage(this->m_hWnd, LVM_GETTILEVIEWINFO, 0, (LPARAM)pTileViewInfo);
3397 }
3398
SetTileViewInfo(PLVTILEVIEWINFO pTileViewInfo)3399 BOOL SetTileViewInfo(PLVTILEVIEWINFO pTileViewInfo)
3400 {
3401 ATLASSERT(::IsWindow(this->m_hWnd));
3402 return (BOOL)::SendMessage(this->m_hWnd, LVM_SETTILEVIEWINFO, 0, (LPARAM)pTileViewInfo);
3403 }
3404
GetTileInfo(PLVTILEINFO pTileInfo)3405 void GetTileInfo(PLVTILEINFO pTileInfo) const
3406 {
3407 ATLASSERT(::IsWindow(this->m_hWnd));
3408 ::SendMessage(this->m_hWnd, LVM_GETTILEINFO, 0, (LPARAM)pTileInfo);
3409 }
3410
SetTileInfo(PLVTILEINFO pTileInfo)3411 BOOL SetTileInfo(PLVTILEINFO pTileInfo)
3412 {
3413 ATLASSERT(::IsWindow(this->m_hWnd));
3414 return (BOOL)::SendMessage(this->m_hWnd, LVM_SETTILEINFO, 0, (LPARAM)pTileInfo);
3415 }
3416
GetInsertMark(LPLVINSERTMARK pInsertMark)3417 BOOL GetInsertMark(LPLVINSERTMARK pInsertMark) const
3418 {
3419 ATLASSERT(::IsWindow(this->m_hWnd));
3420 return (BOOL)::SendMessage(this->m_hWnd, LVM_GETINSERTMARK, 0, (LPARAM)pInsertMark);
3421 }
3422
SetInsertMark(LPLVINSERTMARK pInsertMark)3423 BOOL SetInsertMark(LPLVINSERTMARK pInsertMark)
3424 {
3425 ATLASSERT(::IsWindow(this->m_hWnd));
3426 return (BOOL)::SendMessage(this->m_hWnd, LVM_SETINSERTMARK, 0, (LPARAM)pInsertMark);
3427 }
3428
GetInsertMarkRect(LPRECT lpRect)3429 int GetInsertMarkRect(LPRECT lpRect) const
3430 {
3431 ATLASSERT(::IsWindow(this->m_hWnd));
3432 return (int)::SendMessage(this->m_hWnd, LVM_GETINSERTMARKRECT, 0, (LPARAM)lpRect);
3433 }
3434
GetInsertMarkColor()3435 COLORREF GetInsertMarkColor() const
3436 {
3437 ATLASSERT(::IsWindow(this->m_hWnd));
3438 return (COLORREF)::SendMessage(this->m_hWnd, LVM_GETINSERTMARKCOLOR, 0, 0L);
3439 }
3440
SetInsertMarkColor(COLORREF clr)3441 COLORREF SetInsertMarkColor(COLORREF clr)
3442 {
3443 ATLASSERT(::IsWindow(this->m_hWnd));
3444 return (COLORREF)::SendMessage(this->m_hWnd, LVM_SETINSERTMARKCOLOR, 0, clr);
3445 }
3446
GetOutlineColor()3447 COLORREF GetOutlineColor() const
3448 {
3449 ATLASSERT(::IsWindow(this->m_hWnd));
3450 return (COLORREF)::SendMessage(this->m_hWnd, LVM_GETOUTLINECOLOR, 0, 0L);
3451 }
3452
SetOutlineColor(COLORREF clr)3453 COLORREF SetOutlineColor(COLORREF clr)
3454 {
3455 ATLASSERT(::IsWindow(this->m_hWnd));
3456 return (COLORREF)::SendMessage(this->m_hWnd, LVM_SETOUTLINECOLOR, 0, clr);
3457 }
3458
3459 #if (_WIN32_WINNT >= 0x0600)
GetGroupCount()3460 int GetGroupCount() const
3461 {
3462 ATLASSERT(::IsWindow(this->m_hWnd));
3463 return (int)::SendMessage(this->m_hWnd, LVM_GETGROUPCOUNT, 0, 0L);
3464 }
3465
GetGroupInfoByIndex(int nIndex,PLVGROUP pGroup)3466 BOOL GetGroupInfoByIndex(int nIndex, PLVGROUP pGroup) const
3467 {
3468 ATLASSERT(::IsWindow(this->m_hWnd));
3469 return (BOOL)::SendMessage(this->m_hWnd, LVM_GETGROUPINFOBYINDEX, nIndex, (LPARAM)pGroup);
3470 }
3471
GetGroupRect(int nGroupID,int nType,LPRECT lpRect)3472 BOOL GetGroupRect(int nGroupID, int nType, LPRECT lpRect) const
3473 {
3474 ATLASSERT(::IsWindow(this->m_hWnd));
3475 ATLASSERT(lpRect != NULL);
3476 if(lpRect != NULL)
3477 lpRect->top = nType;
3478 return (BOOL)::SendMessage(this->m_hWnd, LVM_GETGROUPRECT, nGroupID, (LPARAM)lpRect);
3479 }
3480
GetGroupState(int nGroupID,UINT uMask)3481 UINT GetGroupState(int nGroupID, UINT uMask) const
3482 {
3483 ATLASSERT(::IsWindow(this->m_hWnd));
3484 return (UINT)::SendMessage(this->m_hWnd, LVM_GETGROUPSTATE, nGroupID, (LPARAM)uMask);
3485 }
3486
GetFocusedGroup()3487 int GetFocusedGroup() const
3488 {
3489 ATLASSERT(::IsWindow(this->m_hWnd));
3490 return (int)::SendMessage(this->m_hWnd, LVM_GETFOCUSEDGROUP, 0, 0L);
3491 }
3492
GetEmptyText(LPWSTR lpstrText,int cchText)3493 BOOL GetEmptyText(LPWSTR lpstrText, int cchText) const
3494 {
3495 ATLASSERT(::IsWindow(this->m_hWnd));
3496 return (BOOL)::SendMessage(this->m_hWnd, LVM_GETEMPTYTEXT, cchText, (LPARAM)lpstrText);
3497 }
3498
GetFooterRect(LPRECT lpRect)3499 BOOL GetFooterRect(LPRECT lpRect) const
3500 {
3501 ATLASSERT(::IsWindow(this->m_hWnd));
3502 return (BOOL)::SendMessage(this->m_hWnd, LVM_GETFOOTERRECT, 0, (LPARAM)lpRect);
3503 }
3504
GetFooterInfo(LPLVFOOTERINFO lpFooterInfo)3505 BOOL GetFooterInfo(LPLVFOOTERINFO lpFooterInfo) const
3506 {
3507 ATLASSERT(::IsWindow(this->m_hWnd));
3508 return (BOOL)::SendMessage(this->m_hWnd, LVM_GETFOOTERINFO, 0, (LPARAM)lpFooterInfo);
3509 }
3510
GetFooterItemRect(int nItem,LPRECT lpRect)3511 BOOL GetFooterItemRect(int nItem, LPRECT lpRect) const
3512 {
3513 ATLASSERT(::IsWindow(this->m_hWnd));
3514 return (BOOL)::SendMessage(this->m_hWnd, LVM_GETFOOTERITEMRECT, nItem, (LPARAM)lpRect);
3515 }
3516
GetFooterItem(int nItem,LPLVFOOTERITEM lpFooterItem)3517 BOOL GetFooterItem(int nItem, LPLVFOOTERITEM lpFooterItem) const
3518 {
3519 ATLASSERT(::IsWindow(this->m_hWnd));
3520 return (BOOL)::SendMessage(this->m_hWnd, LVM_GETFOOTERITEM, nItem, (LPARAM)lpFooterItem);
3521 }
3522
GetItemIndexRect(PLVITEMINDEX pItemIndex,int nSubItem,int nType,LPRECT lpRect)3523 BOOL GetItemIndexRect(PLVITEMINDEX pItemIndex, int nSubItem, int nType, LPRECT lpRect) const
3524 {
3525 ATLASSERT(::IsWindow(this->m_hWnd));
3526 ATLASSERT(pItemIndex != NULL);
3527 ATLASSERT(lpRect != NULL);
3528 if(lpRect != NULL)
3529 {
3530 lpRect->top = nSubItem;
3531 lpRect->left = nType;
3532 }
3533 return (BOOL)::SendMessage(this->m_hWnd, LVM_GETITEMINDEXRECT, (WPARAM)pItemIndex, (LPARAM)lpRect);
3534 }
3535
SetItemIndexState(PLVITEMINDEX pItemIndex,UINT uState,UINT dwMask)3536 BOOL SetItemIndexState(PLVITEMINDEX pItemIndex, UINT uState, UINT dwMask)
3537 {
3538 ATLASSERT(::IsWindow(this->m_hWnd));
3539 LVITEM lvi = {};
3540 lvi.state = uState;
3541 lvi.stateMask = dwMask;
3542 return (BOOL)::SendMessage(this->m_hWnd, LVM_SETITEMINDEXSTATE, (WPARAM)pItemIndex, (LPARAM)&lvi);
3543 }
3544
GetNextItemIndex(PLVITEMINDEX pItemIndex,WORD wFlags)3545 BOOL GetNextItemIndex(PLVITEMINDEX pItemIndex, WORD wFlags) const
3546 {
3547 ATLASSERT(::IsWindow(this->m_hWnd));
3548 return (BOOL)::SendMessage(this->m_hWnd, LVM_GETNEXTITEMINDEX, (WPARAM)pItemIndex, MAKELPARAM(wFlags, 0));
3549 }
3550 #endif // (_WIN32_WINNT >= 0x0600)
3551
3552 // Operations
InsertColumn(int nCol,const LVCOLUMN * pColumn)3553 int InsertColumn(int nCol, const LVCOLUMN* pColumn)
3554 {
3555 ATLASSERT(::IsWindow(this->m_hWnd));
3556 return (int)::SendMessage(this->m_hWnd, LVM_INSERTCOLUMN, nCol, (LPARAM)pColumn);
3557 }
3558
3559 int InsertColumn(int nCol, LPCTSTR lpszColumnHeading, int nFormat = LVCFMT_LEFT,
3560 int nWidth = -1, int nSubItem = -1, int iImage = -1, int iOrder = -1)
3561 {
3562 LVCOLUMN column = {};
3563 column.mask = LVCF_TEXT | LVCF_FMT;
3564 column.pszText = (LPTSTR)lpszColumnHeading;
3565 column.fmt = nFormat;
3566 if (nWidth != -1)
3567 {
3568 column.mask |= LVCF_WIDTH;
3569 column.cx = nWidth;
3570 }
3571 if (nSubItem != -1)
3572 {
3573 column.mask |= LVCF_SUBITEM;
3574 column.iSubItem = nSubItem;
3575 }
3576 if (iImage != -1)
3577 {
3578 column.mask |= LVCF_IMAGE;
3579 column.iImage = iImage;
3580 }
3581 if (iOrder != -1)
3582 {
3583 column.mask |= LVCF_ORDER;
3584 column.iOrder = iOrder;
3585 }
3586 return InsertColumn(nCol, &column);
3587 }
3588
DeleteColumn(int nCol)3589 BOOL DeleteColumn(int nCol)
3590 {
3591 ATLASSERT(::IsWindow(this->m_hWnd));
3592 return (BOOL)::SendMessage(this->m_hWnd, LVM_DELETECOLUMN, nCol, 0L);
3593 }
3594
InsertItem(UINT nMask,int nItem,LPCTSTR lpszItem,UINT nState,UINT nStateMask,int nImage,LPARAM lParam)3595 int InsertItem(UINT nMask, int nItem, LPCTSTR lpszItem, UINT nState, UINT nStateMask, int nImage, LPARAM lParam)
3596 {
3597 ATLASSERT(::IsWindow(this->m_hWnd));
3598 LVITEM item = {};
3599 item.mask = nMask;
3600 item.iItem = nItem;
3601 item.iSubItem = 0;
3602 item.pszText = (LPTSTR)lpszItem;
3603 item.state = nState;
3604 item.stateMask = nStateMask;
3605 item.iImage = nImage;
3606 item.lParam = lParam;
3607 return InsertItem(&item);
3608 }
3609
InsertItem(const LVITEM * pItem)3610 int InsertItem(const LVITEM* pItem)
3611 {
3612 ATLASSERT(::IsWindow(this->m_hWnd));
3613 return (int)::SendMessage(this->m_hWnd, LVM_INSERTITEM, 0, (LPARAM)pItem);
3614 }
3615
InsertItem(int nItem,LPCTSTR lpszItem)3616 int InsertItem(int nItem, LPCTSTR lpszItem)
3617 {
3618 ATLASSERT(::IsWindow(this->m_hWnd));
3619 return InsertItem(LVIF_TEXT, nItem, lpszItem, 0, 0, 0, 0);
3620 }
3621
InsertItem(int nItem,LPCTSTR lpszItem,int nImage)3622 int InsertItem(int nItem, LPCTSTR lpszItem, int nImage)
3623 {
3624 ATLASSERT(::IsWindow(this->m_hWnd));
3625 return InsertItem(LVIF_TEXT|LVIF_IMAGE, nItem, lpszItem, 0, 0, nImage, 0);
3626 }
3627
GetNextItem(int nItem,int nFlags)3628 int GetNextItem(int nItem, int nFlags) const
3629 {
3630 ATLASSERT(::IsWindow(this->m_hWnd));
3631 return (int)::SendMessage(this->m_hWnd, LVM_GETNEXTITEM, nItem, MAKELPARAM(nFlags, 0));
3632 }
3633
DeleteItem(int nItem)3634 BOOL DeleteItem(int nItem)
3635 {
3636 ATLASSERT(::IsWindow(this->m_hWnd));
3637 return (BOOL)::SendMessage(this->m_hWnd, LVM_DELETEITEM, nItem, 0L);
3638 }
3639
DeleteAllItems()3640 BOOL DeleteAllItems()
3641 {
3642 ATLASSERT(::IsWindow(this->m_hWnd));
3643 return (BOOL)::SendMessage(this->m_hWnd, LVM_DELETEALLITEMS, 0, 0L);
3644 }
3645
3646 int FindItem(LVFINDINFO* pFindInfo, int nStart = -1) const
3647 {
3648 ATLASSERT(::IsWindow(this->m_hWnd));
3649 return (int)::SendMessage(this->m_hWnd, LVM_FINDITEM, nStart, (LPARAM)pFindInfo);
3650 }
3651
3652 int FindItem(LPCTSTR lpstrFind, bool bPartial = true, bool bWrap = false, int nStart = -1) const
3653 {
3654 ATLASSERT(::IsWindow(this->m_hWnd));
3655 LVFINDINFO lvfi = {};
3656 lvfi.flags = LVFI_STRING | (bWrap ? LVFI_WRAP : 0) | (bPartial ? LVFI_PARTIAL : 0);
3657 lvfi.psz = lpstrFind;
3658 return (int)::SendMessage(this->m_hWnd, LVM_FINDITEM, nStart, (LPARAM)&lvfi);
3659 }
3660
HitTest(LVHITTESTINFO * pHitTestInfo)3661 int HitTest(LVHITTESTINFO* pHitTestInfo) const
3662 {
3663 ATLASSERT(::IsWindow(this->m_hWnd));
3664 return (int)::SendMessage(this->m_hWnd, LVM_HITTEST, 0, (LPARAM)pHitTestInfo);
3665 }
3666
HitTest(POINT pt,UINT * pFlags)3667 int HitTest(POINT pt, UINT* pFlags) const
3668 {
3669 ATLASSERT(::IsWindow(this->m_hWnd));
3670 LVHITTESTINFO hti = {};
3671 hti.pt = pt;
3672 int nRes = (int)::SendMessage(this->m_hWnd, LVM_HITTEST, 0, (LPARAM)&hti);
3673 if (pFlags != NULL)
3674 *pFlags = hti.flags;
3675 return nRes;
3676 }
3677
EnsureVisible(int nItem,BOOL bPartialOK)3678 BOOL EnsureVisible(int nItem, BOOL bPartialOK)
3679 {
3680 ATLASSERT(::IsWindow(this->m_hWnd));
3681 return (BOOL)::SendMessage(this->m_hWnd, LVM_ENSUREVISIBLE, nItem, MAKELPARAM(bPartialOK, 0));
3682 }
3683
Scroll(SIZE size)3684 BOOL Scroll(SIZE size)
3685 {
3686 ATLASSERT(::IsWindow(this->m_hWnd));
3687 return (BOOL)::SendMessage(this->m_hWnd, LVM_SCROLL, size.cx, size.cy);
3688 }
3689
RedrawItems(int nFirst,int nLast)3690 BOOL RedrawItems(int nFirst, int nLast)
3691 {
3692 ATLASSERT(::IsWindow(this->m_hWnd));
3693 return (BOOL)::SendMessage(this->m_hWnd, LVM_REDRAWITEMS, nFirst, nLast);
3694 }
3695
Arrange(UINT nCode)3696 BOOL Arrange(UINT nCode)
3697 {
3698 ATLASSERT(::IsWindow(this->m_hWnd));
3699 return (BOOL)::SendMessage(this->m_hWnd, LVM_ARRANGE, nCode, 0L);
3700 }
3701
EditLabel(int nItem)3702 CEdit EditLabel(int nItem)
3703 {
3704 ATLASSERT(::IsWindow(this->m_hWnd));
3705 return CEdit((HWND)::SendMessage(this->m_hWnd, LVM_EDITLABEL, nItem, 0L));
3706 }
3707
Update(int nItem)3708 BOOL Update(int nItem)
3709 {
3710 ATLASSERT(::IsWindow(this->m_hWnd));
3711 return (BOOL)::SendMessage(this->m_hWnd, LVM_UPDATE, nItem, 0L);
3712 }
3713
SortItems(PFNLVCOMPARE pfnCompare,LPARAM lParamSort)3714 BOOL SortItems(PFNLVCOMPARE pfnCompare, LPARAM lParamSort)
3715 {
3716 ATLASSERT(::IsWindow(this->m_hWnd));
3717 return (BOOL)::SendMessage(this->m_hWnd, LVM_SORTITEMS, (WPARAM)lParamSort, (LPARAM)pfnCompare);
3718 }
3719
RemoveImageList(int nImageList)3720 CImageList RemoveImageList(int nImageList)
3721 {
3722 ATLASSERT(::IsWindow(this->m_hWnd));
3723 return CImageList((HIMAGELIST)::SendMessage(this->m_hWnd, LVM_SETIMAGELIST, (WPARAM)nImageList, NULL));
3724 }
3725
CreateDragImage(int nItem,LPPOINT lpPoint)3726 CImageList CreateDragImage(int nItem, LPPOINT lpPoint)
3727 {
3728 ATLASSERT(::IsWindow(this->m_hWnd));
3729 return CImageList((HIMAGELIST)::SendMessage(this->m_hWnd, LVM_CREATEDRAGIMAGE, nItem, (LPARAM)lpPoint));
3730 }
3731
3732 DWORD ApproximateViewRect(int cx = -1, int cy = -1, int nCount = -1)
3733 {
3734 ATLASSERT(::IsWindow(this->m_hWnd));
3735 return (DWORD)::SendMessage(this->m_hWnd, LVM_APPROXIMATEVIEWRECT, nCount, MAKELPARAM(cx, cy));
3736 }
3737
SubItemHitTest(LPLVHITTESTINFO lpInfo)3738 int SubItemHitTest(LPLVHITTESTINFO lpInfo) const
3739 {
3740 ATLASSERT(::IsWindow(this->m_hWnd));
3741 return (int)::SendMessage(this->m_hWnd, LVM_SUBITEMHITTEST, 0, (LPARAM)lpInfo);
3742 }
3743
3744 int AddColumn(LPCTSTR strColumn, int nItem, int nSubItem = -1,
3745 int nMask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM,
3746 int nFmt = LVCFMT_LEFT)
3747 {
3748 const int cxOffset = 15;
3749 ATLASSERT(::IsWindow(this->m_hWnd));
3750 LVCOLUMN lvc = {};
3751 lvc.mask = nMask;
3752 lvc.fmt = nFmt;
3753 lvc.pszText = (LPTSTR)strColumn;
3754 lvc.cx = GetStringWidth(lvc.pszText) + cxOffset;
3755 if(nMask & LVCF_SUBITEM)
3756 lvc.iSubItem = (nSubItem != -1) ? nSubItem : nItem;
3757 return InsertColumn(nItem, &lvc);
3758 }
3759
3760 int AddItem(int nItem, int nSubItem, LPCTSTR strItem, int nImageIndex = -3)
3761 {
3762 ATLASSERT(::IsWindow(this->m_hWnd));
3763 LVITEM lvItem = {};
3764 lvItem.mask = LVIF_TEXT;
3765 lvItem.iItem = nItem;
3766 lvItem.iSubItem = nSubItem;
3767 lvItem.pszText = (LPTSTR)strItem;
3768 if(nImageIndex != -3)
3769 {
3770 lvItem.mask |= LVIF_IMAGE;
3771 lvItem.iImage = nImageIndex;
3772 }
3773 if(nSubItem == 0)
3774 return InsertItem(&lvItem);
3775 return SetItem(&lvItem) ? nItem : -1;
3776 }
3777
SortItemsEx(PFNLVCOMPARE pfnCompare,LPARAM lParamSort)3778 BOOL SortItemsEx(PFNLVCOMPARE pfnCompare, LPARAM lParamSort)
3779 {
3780 ATLASSERT(::IsWindow(this->m_hWnd));
3781 return (BOOL)::SendMessage(this->m_hWnd, LVM_SORTITEMSEX, (WPARAM)lParamSort, (LPARAM)pfnCompare);
3782 }
3783
InsertGroup(int nItem,PLVGROUP pGroup)3784 int InsertGroup(int nItem, PLVGROUP pGroup)
3785 {
3786 ATLASSERT(::IsWindow(this->m_hWnd));
3787 return (int)::SendMessage(this->m_hWnd, LVM_INSERTGROUP, nItem, (LPARAM)pGroup);
3788 }
3789
AddGroup(PLVGROUP pGroup)3790 int AddGroup(PLVGROUP pGroup)
3791 {
3792 return InsertGroup(-1, pGroup);
3793 }
3794
RemoveGroup(int nGroupID)3795 int RemoveGroup(int nGroupID)
3796 {
3797 ATLASSERT(::IsWindow(this->m_hWnd));
3798 return (int)::SendMessage(this->m_hWnd, LVM_REMOVEGROUP, nGroupID, 0L);
3799 }
3800
MoveGroup(int nGroupID,int nItem)3801 void MoveGroup(int nGroupID, int nItem)
3802 {
3803 ATLASSERT(::IsWindow(this->m_hWnd));
3804 ::SendMessage(this->m_hWnd, LVM_MOVEGROUP, nGroupID, nItem);
3805 }
3806
MoveItemToGroup(int nItem,int nGroupID)3807 void MoveItemToGroup(int nItem, int nGroupID)
3808 {
3809 ATLASSERT(::IsWindow(this->m_hWnd));
3810 ::SendMessage(this->m_hWnd, LVM_MOVEITEMTOGROUP, nItem, nGroupID);
3811 }
3812
EnableGroupView(BOOL bEnable)3813 int EnableGroupView(BOOL bEnable)
3814 {
3815 ATLASSERT(::IsWindow(this->m_hWnd));
3816 return (int)::SendMessage(this->m_hWnd, LVM_ENABLEGROUPVIEW, bEnable, 0L);
3817 }
3818
3819 int SortGroups(PFNLVGROUPCOMPARE pCompareFunc, LPVOID lpVoid = NULL)
3820 {
3821 ATLASSERT(::IsWindow(this->m_hWnd));
3822 return (int)::SendMessage(this->m_hWnd, LVM_SORTGROUPS, (WPARAM)pCompareFunc, (LPARAM)lpVoid);
3823 }
3824
InsertGroupSorted(PLVINSERTGROUPSORTED pInsertGroupSorted)3825 void InsertGroupSorted(PLVINSERTGROUPSORTED pInsertGroupSorted)
3826 {
3827 ATLASSERT(::IsWindow(this->m_hWnd));
3828 ::SendMessage(this->m_hWnd, LVM_INSERTGROUPSORTED, (WPARAM)pInsertGroupSorted, 0L);
3829 }
3830
RemoveAllGroups()3831 void RemoveAllGroups()
3832 {
3833 ATLASSERT(::IsWindow(this->m_hWnd));
3834 ::SendMessage(this->m_hWnd, LVM_REMOVEALLGROUPS, 0, 0L);
3835 }
3836
HasGroup(int nGroupID)3837 BOOL HasGroup(int nGroupID)
3838 {
3839 ATLASSERT(::IsWindow(this->m_hWnd));
3840 return (BOOL)::SendMessage(this->m_hWnd, LVM_HASGROUP, nGroupID, 0L);
3841 }
3842
InsertMarkHitTest(LPPOINT lpPoint,LPLVINSERTMARK pInsertMark)3843 BOOL InsertMarkHitTest(LPPOINT lpPoint, LPLVINSERTMARK pInsertMark) const
3844 {
3845 ATLASSERT(::IsWindow(this->m_hWnd));
3846 return (BOOL)::SendMessage(this->m_hWnd, LVM_INSERTMARKHITTEST, (WPARAM)lpPoint, (LPARAM)pInsertMark);
3847 }
3848
SetInfoTip(PLVSETINFOTIP pSetInfoTip)3849 BOOL SetInfoTip(PLVSETINFOTIP pSetInfoTip)
3850 {
3851 ATLASSERT(::IsWindow(this->m_hWnd));
3852 return (BOOL)::SendMessage(this->m_hWnd, LVM_SETINFOTIP, 0, (LPARAM)pSetInfoTip);
3853 }
3854
CancelEditLabel()3855 void CancelEditLabel()
3856 {
3857 ATLASSERT(::IsWindow(this->m_hWnd));
3858 ::SendMessage(this->m_hWnd, LVM_CANCELEDITLABEL, 0, 0L);
3859 }
3860
MapIndexToID(int nIndex)3861 UINT MapIndexToID(int nIndex) const
3862 {
3863 ATLASSERT(::IsWindow(this->m_hWnd));
3864 return (UINT)::SendMessage(this->m_hWnd, LVM_MAPINDEXTOID, nIndex, 0L);
3865 }
3866
MapIDToIndex(UINT uID)3867 int MapIDToIndex(UINT uID) const
3868 {
3869 ATLASSERT(::IsWindow(this->m_hWnd));
3870 return (int)::SendMessage(this->m_hWnd, LVM_MAPIDTOINDEX, uID, 0L);
3871 }
3872
3873 #if (_WIN32_WINNT >= 0x0600)
HitTestEx(LPLVHITTESTINFO lpHitTestInfo)3874 int HitTestEx(LPLVHITTESTINFO lpHitTestInfo) const
3875 {
3876 ATLASSERT(::IsWindow(this->m_hWnd));
3877 return (int)::SendMessage(this->m_hWnd, LVM_HITTEST, (WPARAM)-1, (LPARAM)lpHitTestInfo);
3878 }
3879
HitTestEx(POINT pt,UINT * pFlags)3880 int HitTestEx(POINT pt, UINT* pFlags) const
3881 {
3882 ATLASSERT(::IsWindow(this->m_hWnd));
3883 LVHITTESTINFO hti = {};
3884 hti.pt = pt;
3885 int nRes = (int)::SendMessage(this->m_hWnd, LVM_HITTEST, (WPARAM)-1, (LPARAM)&hti);
3886 if (pFlags != NULL)
3887 *pFlags = hti.flags;
3888 return nRes;
3889 }
3890
SubItemHitTestEx(LPLVHITTESTINFO lpHitTestInfo)3891 int SubItemHitTestEx(LPLVHITTESTINFO lpHitTestInfo) const
3892 {
3893 ATLASSERT(::IsWindow(this->m_hWnd));
3894 return (int)::SendMessage(this->m_hWnd, LVM_SUBITEMHITTEST, (WPARAM)-1, (LPARAM)lpHitTestInfo);
3895 }
3896 #endif // (_WIN32_WINNT >= 0x0600)
3897
3898 // Note: selects only one item
SelectItem(int nIndex)3899 BOOL SelectItem(int nIndex)
3900 {
3901 ATLASSERT(::IsWindow(this->m_hWnd));
3902
3903 // multi-selection only: de-select all items
3904 if((this->GetStyle() & LVS_SINGLESEL) == 0)
3905 SetItemState(-1, 0, LVIS_SELECTED);
3906
3907 BOOL bRet = SetItemState(nIndex, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
3908 if(bRet)
3909 {
3910 SetSelectionMark(nIndex);
3911 bRet = EnsureVisible(nIndex, FALSE);
3912 }
3913
3914 return bRet;
3915 }
3916
3917 // multi-selection only
3918 BOOL SelectAllItems(bool bSelect = true)
3919 {
3920 ATLASSERT(::IsWindow(this->m_hWnd));
3921 ATLASSERT((this->GetStyle() & LVS_SINGLESEL) == 0);
3922
3923 return SetItemState(-1, bSelect ? LVIS_SELECTED : 0, LVIS_SELECTED);
3924 }
3925 };
3926
3927 typedef CListViewCtrlT<ATL::CWindow> CListViewCtrl;
3928
3929
3930 ///////////////////////////////////////////////////////////////////////////////
3931 // CTreeViewCtrl
3932
3933 template <class TBase>
3934 class CTreeViewCtrlT : public TBase
3935 {
3936 public:
3937 // Constructors
TBase(hWnd)3938 CTreeViewCtrlT(HWND hWnd = NULL) : TBase(hWnd)
3939 { }
3940
3941 CTreeViewCtrlT< TBase >& operator =(HWND hWnd)
3942 {
3943 this->m_hWnd = hWnd;
3944 return *this;
3945 }
3946
3947 HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
3948 DWORD dwStyle = 0, DWORD dwExStyle = 0,
3949 ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
3950 {
3951 return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
3952 }
3953
3954 // Attributes
GetWndClassName()3955 static LPCTSTR GetWndClassName()
3956 {
3957 return WC_TREEVIEW;
3958 }
3959
GetCount()3960 UINT GetCount() const
3961 {
3962 ATLASSERT(::IsWindow(this->m_hWnd));
3963 return (UINT)::SendMessage(this->m_hWnd, TVM_GETCOUNT, 0, 0L);
3964 }
3965
GetIndent()3966 UINT GetIndent() const
3967 {
3968 ATLASSERT(::IsWindow(this->m_hWnd));
3969 return (UINT)::SendMessage(this->m_hWnd, TVM_GETINDENT, 0, 0L);
3970 }
3971
SetIndent(UINT nIndent)3972 void SetIndent(UINT nIndent)
3973 {
3974 ATLASSERT(::IsWindow(this->m_hWnd));
3975 ::SendMessage(this->m_hWnd, TVM_SETINDENT, nIndent, 0L);
3976 }
3977
3978 CImageList GetImageList(int nImageListType = TVSIL_NORMAL) const
3979 {
3980 ATLASSERT(::IsWindow(this->m_hWnd));
3981 return CImageList((HIMAGELIST)::SendMessage(this->m_hWnd, TVM_GETIMAGELIST, (WPARAM)nImageListType, 0L));
3982 }
3983
3984 CImageList SetImageList(HIMAGELIST hImageList, int nImageListType = TVSIL_NORMAL)
3985 {
3986 ATLASSERT(::IsWindow(this->m_hWnd));
3987 return CImageList((HIMAGELIST)::SendMessage(this->m_hWnd, TVM_SETIMAGELIST, (WPARAM)nImageListType, (LPARAM)hImageList));
3988 }
3989
GetItem(LPTVITEM pItem)3990 BOOL GetItem(LPTVITEM pItem) const
3991 {
3992 ATLASSERT(::IsWindow(this->m_hWnd));
3993 return (BOOL)::SendMessage(this->m_hWnd, TVM_GETITEM, 0, (LPARAM)pItem);
3994 }
3995
SetItem(LPTVITEM pItem)3996 BOOL SetItem(LPTVITEM pItem)
3997 {
3998 ATLASSERT(::IsWindow(this->m_hWnd));
3999 return (BOOL)::SendMessage(this->m_hWnd, TVM_SETITEM, 0, (LPARAM)pItem);
4000 }
4001
SetItem(HTREEITEM hItem,UINT nMask,LPCTSTR lpszItem,int nImage,int nSelectedImage,UINT nState,UINT nStateMask,LPARAM lParam)4002 BOOL SetItem(HTREEITEM hItem, UINT nMask, LPCTSTR lpszItem, int nImage,
4003 int nSelectedImage, UINT nState, UINT nStateMask, LPARAM lParam)
4004 {
4005 ATLASSERT(::IsWindow(this->m_hWnd));
4006 TVITEM item = {};
4007 item.hItem = hItem;
4008 item.mask = nMask;
4009 item.pszText = (LPTSTR) lpszItem;
4010 item.iImage = nImage;
4011 item.iSelectedImage = nSelectedImage;
4012 item.state = nState;
4013 item.stateMask = nStateMask;
4014 item.lParam = lParam;
4015 return (BOOL)::SendMessage(this->m_hWnd, TVM_SETITEM, 0, (LPARAM)&item);
4016 }
4017
GetItemText(HTREEITEM hItem,LPTSTR lpstrText,int nLen)4018 BOOL GetItemText(HTREEITEM hItem, LPTSTR lpstrText, int nLen) const
4019 {
4020 ATLASSERT(::IsWindow(this->m_hWnd));
4021 ATLASSERT(lpstrText != NULL);
4022
4023 TVITEM item = {};
4024 item.hItem = hItem;
4025 item.mask = TVIF_TEXT;
4026 item.pszText = lpstrText;
4027 item.cchTextMax = nLen;
4028
4029 return (BOOL)::SendMessage(this->m_hWnd, TVM_GETITEM, 0, (LPARAM)&item);
4030 }
4031
GetItemText(HTREEITEM hItem,BSTR & bstrText)4032 BOOL GetItemText(HTREEITEM hItem, BSTR& bstrText) const
4033 {
4034 USES_CONVERSION;
4035 ATLASSERT(::IsWindow(this->m_hWnd));
4036 ATLASSERT(bstrText == NULL);
4037 TVITEM item = {};
4038 item.hItem = hItem;
4039 item.mask = TVIF_TEXT;
4040
4041 LPTSTR lpstrText = NULL;
4042 BOOL bRet = FALSE;
4043 for(int nLen = 256; ; nLen *= 2)
4044 {
4045 ATLTRY(lpstrText = new TCHAR[nLen]);
4046 if(lpstrText == NULL)
4047 break;
4048 lpstrText[0] = NULL;
4049 item.pszText = lpstrText;
4050 item.cchTextMax = nLen;
4051 bRet = (BOOL)::SendMessage(this->m_hWnd, TVM_GETITEM, 0, (LPARAM)&item);
4052 if(!bRet || (lstrlen(item.pszText) < (nLen - 1)))
4053 break;
4054 delete [] lpstrText;
4055 lpstrText = NULL;
4056 }
4057
4058 if(lpstrText != NULL)
4059 {
4060 if(bRet)
4061 bstrText = ::SysAllocString(T2OLE(lpstrText));
4062 delete [] lpstrText;
4063 }
4064
4065 return (bstrText != NULL) ? TRUE : FALSE;
4066 }
4067
4068 #ifdef __ATLSTR_H__
GetItemText(HTREEITEM hItem,ATL::CString & strText)4069 BOOL GetItemText(HTREEITEM hItem, ATL::CString& strText) const
4070 {
4071 ATLASSERT(::IsWindow(this->m_hWnd));
4072 TVITEM item = {};
4073 item.hItem = hItem;
4074 item.mask = TVIF_TEXT;
4075
4076 strText.Empty();
4077 BOOL bRet = FALSE;
4078 for(int nLen = 256; ; nLen *= 2)
4079 {
4080 item.pszText = strText.GetBufferSetLength(nLen);
4081 if(item.pszText == NULL)
4082 {
4083 bRet = FALSE;
4084 break;
4085 }
4086 item.cchTextMax = nLen;
4087 bRet = (BOOL)::SendMessage(this->m_hWnd, TVM_GETITEM, 0, (LPARAM)&item);
4088 if(!bRet || (lstrlen(item.pszText) < (nLen - 1)))
4089 break;
4090 }
4091 strText.ReleaseBuffer();
4092 return bRet;
4093 }
4094 #endif // __ATLSTR_H__
4095
SetItemText(HTREEITEM hItem,LPCTSTR lpszItem)4096 BOOL SetItemText(HTREEITEM hItem, LPCTSTR lpszItem)
4097 {
4098 ATLASSERT(::IsWindow(this->m_hWnd));
4099 return SetItem(hItem, TVIF_TEXT, lpszItem, 0, 0, 0, 0, NULL);
4100 }
4101
GetItemImage(HTREEITEM hItem,int & nImage,int & nSelectedImage)4102 BOOL GetItemImage(HTREEITEM hItem, int& nImage, int& nSelectedImage) const
4103 {
4104 ATLASSERT(::IsWindow(this->m_hWnd));
4105 TVITEM item = {};
4106 item.hItem = hItem;
4107 item.mask = TVIF_IMAGE|TVIF_SELECTEDIMAGE;
4108 BOOL bRes = (BOOL)::SendMessage(this->m_hWnd, TVM_GETITEM, 0, (LPARAM)&item);
4109 if (bRes)
4110 {
4111 nImage = item.iImage;
4112 nSelectedImage = item.iSelectedImage;
4113 }
4114 return bRes;
4115 }
4116
SetItemImage(HTREEITEM hItem,int nImage,int nSelectedImage)4117 BOOL SetItemImage(HTREEITEM hItem, int nImage, int nSelectedImage)
4118 {
4119 ATLASSERT(::IsWindow(this->m_hWnd));
4120 return SetItem(hItem, TVIF_IMAGE|TVIF_SELECTEDIMAGE, NULL, nImage, nSelectedImage, 0, 0, NULL);
4121 }
4122
GetItemState(HTREEITEM hItem,UINT nStateMask)4123 UINT GetItemState(HTREEITEM hItem, UINT nStateMask) const
4124 {
4125 ATLASSERT(::IsWindow(this->m_hWnd));
4126 return (((UINT)::SendMessage(this->m_hWnd, TVM_GETITEMSTATE, (WPARAM)hItem, (LPARAM)nStateMask)) & nStateMask);
4127 }
4128
SetItemState(HTREEITEM hItem,UINT nState,UINT nStateMask)4129 BOOL SetItemState(HTREEITEM hItem, UINT nState, UINT nStateMask)
4130 {
4131 ATLASSERT(::IsWindow(this->m_hWnd));
4132 return SetItem(hItem, TVIF_STATE, NULL, 0, 0, nState, nStateMask, NULL);
4133 }
4134
GetItemData(HTREEITEM hItem)4135 DWORD_PTR GetItemData(HTREEITEM hItem) const
4136 {
4137 ATLASSERT(::IsWindow(this->m_hWnd));
4138 TVITEM item = {};
4139 item.hItem = hItem;
4140 item.mask = TVIF_PARAM;
4141 BOOL bRet = (BOOL)::SendMessage(this->m_hWnd, TVM_GETITEM, 0, (LPARAM)&item);
4142 return (DWORD_PTR)(bRet ? item.lParam : NULL);
4143 }
4144
SetItemData(HTREEITEM hItem,DWORD_PTR dwData)4145 BOOL SetItemData(HTREEITEM hItem, DWORD_PTR dwData)
4146 {
4147 ATLASSERT(::IsWindow(this->m_hWnd));
4148 return SetItem(hItem, TVIF_PARAM, NULL, 0, 0, 0, 0, (LPARAM)dwData);
4149 }
4150
GetEditControl()4151 CEdit GetEditControl() const
4152 {
4153 ATLASSERT(::IsWindow(this->m_hWnd));
4154 return CEdit((HWND)::SendMessage(this->m_hWnd, TVM_GETEDITCONTROL, 0, 0L));
4155 }
4156
GetVisibleCount()4157 UINT GetVisibleCount() const
4158 {
4159 ATLASSERT(::IsWindow(this->m_hWnd));
4160 return (UINT)::SendMessage(this->m_hWnd, TVM_GETVISIBLECOUNT, 0, 0L);
4161 }
4162
GetItemRect(HTREEITEM hItem,LPRECT lpRect,BOOL bTextOnly)4163 BOOL GetItemRect(HTREEITEM hItem, LPRECT lpRect, BOOL bTextOnly) const
4164 {
4165 ATLASSERT(::IsWindow(this->m_hWnd));
4166 *(HTREEITEM*)lpRect = hItem;
4167 return (BOOL)::SendMessage(this->m_hWnd, TVM_GETITEMRECT, (WPARAM)bTextOnly, (LPARAM)lpRect);
4168 }
4169
ItemHasChildren(HTREEITEM hItem)4170 BOOL ItemHasChildren(HTREEITEM hItem) const
4171 {
4172 ATLASSERT(::IsWindow(this->m_hWnd));
4173 TVITEM item = {};
4174 item.hItem = hItem;
4175 item.mask = TVIF_CHILDREN;
4176 ::SendMessage(this->m_hWnd, TVM_GETITEM, 0, (LPARAM)&item);
4177 return item.cChildren;
4178 }
4179
GetToolTips()4180 CToolTipCtrl GetToolTips() const
4181 {
4182 ATLASSERT(::IsWindow(this->m_hWnd));
4183 return CToolTipCtrl((HWND)::SendMessage(this->m_hWnd, TVM_GETTOOLTIPS, 0, 0L));
4184 }
4185
SetToolTips(HWND hWndTT)4186 CToolTipCtrl SetToolTips(HWND hWndTT)
4187 {
4188 ATLASSERT(::IsWindow(this->m_hWnd));
4189 return CToolTipCtrl((HWND)::SendMessage(this->m_hWnd, TVM_SETTOOLTIPS, (WPARAM)hWndTT, 0L));
4190 }
4191
GetISearchString(LPTSTR lpstr)4192 int GetISearchString(LPTSTR lpstr) const
4193 {
4194 ATLASSERT(::IsWindow(this->m_hWnd));
4195 return (int)::SendMessage(this->m_hWnd, TVM_GETISEARCHSTRING, 0, (LPARAM)lpstr);
4196 }
4197
4198 // checkboxes only
GetCheckState(HTREEITEM hItem)4199 BOOL GetCheckState(HTREEITEM hItem) const
4200 {
4201 ATLASSERT(::IsWindow(this->m_hWnd));
4202 ATLASSERT((this->GetStyle() & TVS_CHECKBOXES) != 0);
4203 UINT uRet = GetItemState(hItem, TVIS_STATEIMAGEMASK);
4204 return (uRet >> 12) - 1;
4205 }
4206
SetCheckState(HTREEITEM hItem,BOOL bCheck)4207 BOOL SetCheckState(HTREEITEM hItem, BOOL bCheck)
4208 {
4209 int nCheck = bCheck ? 2 : 1; // one based index
4210 return SetItemState(hItem, INDEXTOSTATEIMAGEMASK(nCheck), TVIS_STATEIMAGEMASK);
4211 }
4212
GetBkColor()4213 COLORREF GetBkColor() const
4214 {
4215 ATLASSERT(::IsWindow(this->m_hWnd));
4216 return (COLORREF)::SendMessage(this->m_hWnd, TVM_GETBKCOLOR, 0, 0L);
4217 }
4218
SetBkColor(COLORREF clr)4219 COLORREF SetBkColor(COLORREF clr)
4220 {
4221 ATLASSERT(::IsWindow(this->m_hWnd));
4222 return (COLORREF)::SendMessage(this->m_hWnd, TVM_SETBKCOLOR, 0, (LPARAM)clr);
4223 }
4224
GetInsertMarkColor()4225 COLORREF GetInsertMarkColor() const
4226 {
4227 ATLASSERT(::IsWindow(this->m_hWnd));
4228 return (COLORREF)::SendMessage(this->m_hWnd, TVM_GETINSERTMARKCOLOR, 0, 0L);
4229 }
4230
SetInsertMarkColor(COLORREF clr)4231 COLORREF SetInsertMarkColor(COLORREF clr)
4232 {
4233 ATLASSERT(::IsWindow(this->m_hWnd));
4234 return (COLORREF)::SendMessage(this->m_hWnd, TVM_SETINSERTMARKCOLOR, 0, (LPARAM)clr);
4235 }
4236
GetItemHeight()4237 int GetItemHeight() const
4238 {
4239 ATLASSERT(::IsWindow(this->m_hWnd));
4240 return (int)::SendMessage(this->m_hWnd, TVM_GETITEMHEIGHT, 0, 0L);
4241 }
4242
SetItemHeight(int cyHeight)4243 int SetItemHeight(int cyHeight)
4244 {
4245 ATLASSERT(::IsWindow(this->m_hWnd));
4246 return (int)::SendMessage(this->m_hWnd, TVM_SETITEMHEIGHT, cyHeight, 0L);
4247 }
4248
GetScrollTime()4249 int GetScrollTime() const
4250 {
4251 ATLASSERT(::IsWindow(this->m_hWnd));
4252 return (int)::SendMessage(this->m_hWnd, TVM_GETSCROLLTIME, 0, 0L);
4253 }
4254
SetScrollTime(int nScrollTime)4255 int SetScrollTime(int nScrollTime)
4256 {
4257 ATLASSERT(::IsWindow(this->m_hWnd));
4258 return (int)::SendMessage(this->m_hWnd, TVM_SETSCROLLTIME, nScrollTime, 0L);
4259 }
4260
GetTextColor()4261 COLORREF GetTextColor() const
4262 {
4263 ATLASSERT(::IsWindow(this->m_hWnd));
4264 return (COLORREF)::SendMessage(this->m_hWnd, TVM_GETTEXTCOLOR, 0, 0L);
4265 }
4266
SetTextColor(COLORREF clr)4267 COLORREF SetTextColor(COLORREF clr)
4268 {
4269 ATLASSERT(::IsWindow(this->m_hWnd));
4270 return (COLORREF)::SendMessage(this->m_hWnd, TVM_SETTEXTCOLOR, 0, (LPARAM)clr);
4271 }
4272
GetUnicodeFormat()4273 BOOL GetUnicodeFormat() const
4274 {
4275 ATLASSERT(::IsWindow(this->m_hWnd));
4276 return (BOOL)::SendMessage(this->m_hWnd, TVM_GETUNICODEFORMAT, 0, 0L);
4277 }
4278
4279 BOOL SetUnicodeFormat(BOOL bUnicode = TRUE)
4280 {
4281 ATLASSERT(::IsWindow(this->m_hWnd));
4282 return (BOOL)::SendMessage(this->m_hWnd, TVM_SETUNICODEFORMAT, bUnicode, 0L);
4283 }
4284
GetLineColor()4285 COLORREF GetLineColor() const
4286 {
4287 ATLASSERT(::IsWindow(this->m_hWnd));
4288 return (COLORREF)::SendMessage(this->m_hWnd, TVM_GETLINECOLOR, 0, 0L);
4289 }
4290
SetLineColor(COLORREF clrNew)4291 COLORREF SetLineColor(COLORREF clrNew /*= CLR_DEFAULT*/)
4292 {
4293 ATLASSERT(::IsWindow(this->m_hWnd));
4294 return (COLORREF)::SendMessage(this->m_hWnd, TVM_SETLINECOLOR, 0, (LPARAM)clrNew);
4295 }
4296
GetItem(LPTVITEMEX pItem)4297 BOOL GetItem(LPTVITEMEX pItem) const
4298 {
4299 ATLASSERT(::IsWindow(this->m_hWnd));
4300 return (BOOL)::SendMessage(this->m_hWnd, TVM_GETITEM, 0, (LPARAM)pItem);
4301 }
4302
SetItem(LPTVITEMEX pItem)4303 BOOL SetItem(LPTVITEMEX pItem)
4304 {
4305 ATLASSERT(::IsWindow(this->m_hWnd));
4306 return (BOOL)::SendMessage(this->m_hWnd, TVM_SETITEM, 0, (LPARAM)pItem);
4307 }
4308
GetExtendedStyle()4309 DWORD GetExtendedStyle() const
4310 {
4311 ATLASSERT(::IsWindow(this->m_hWnd));
4312 return (DWORD)::SendMessage(this->m_hWnd, TVM_GETEXTENDEDSTYLE, 0, 0L);
4313 }
4314
SetExtendedStyle(DWORD dwStyle,DWORD dwMask)4315 DWORD SetExtendedStyle(DWORD dwStyle, DWORD dwMask)
4316 {
4317 ATLASSERT(::IsWindow(this->m_hWnd));
4318 return (DWORD)::SendMessage(this->m_hWnd, TVM_SETEXTENDEDSTYLE, dwMask, dwStyle);
4319 }
4320
4321 #if (_WIN32_WINNT >= 0x0600)
SetAutoScrollInfo(UINT uPixPerSec,UINT uUpdateTime)4322 BOOL SetAutoScrollInfo(UINT uPixPerSec, UINT uUpdateTime)
4323 {
4324 ATLASSERT(::IsWindow(this->m_hWnd));
4325 return (BOOL)::SendMessage(this->m_hWnd, TVM_SETAUTOSCROLLINFO, (WPARAM)uPixPerSec, (LPARAM)uUpdateTime);
4326 }
4327
GetSelectedCount()4328 DWORD GetSelectedCount() const
4329 {
4330 ATLASSERT(::IsWindow(this->m_hWnd));
4331 return (DWORD)::SendMessage(this->m_hWnd, TVM_GETSELECTEDCOUNT, 0, 0L);
4332 }
4333
GetItemPartRect(HTREEITEM hItem,TVITEMPART partID,LPRECT lpRect)4334 BOOL GetItemPartRect(HTREEITEM hItem, TVITEMPART partID, LPRECT lpRect) const
4335 {
4336 ATLASSERT(::IsWindow(this->m_hWnd));
4337 TVGETITEMPARTRECTINFO gipri = { hItem, lpRect, partID };
4338 return (BOOL)::SendMessage(this->m_hWnd, TVM_GETITEMPARTRECT, 0, (LPARAM)&gipri);
4339 }
4340 #endif // (_WIN32_WINNT >= 0x0600)
4341
4342 // Operations
InsertItem(LPTVINSERTSTRUCT lpInsertStruct)4343 HTREEITEM InsertItem(LPTVINSERTSTRUCT lpInsertStruct)
4344 {
4345 ATLASSERT(::IsWindow(this->m_hWnd));
4346 return (HTREEITEM)::SendMessage(this->m_hWnd, TVM_INSERTITEM, 0, (LPARAM)lpInsertStruct);
4347 }
4348
InsertItem(LPCTSTR lpszItem,int nImage,int nSelectedImage,HTREEITEM hParent,HTREEITEM hInsertAfter)4349 HTREEITEM InsertItem(LPCTSTR lpszItem, int nImage,
4350 int nSelectedImage, HTREEITEM hParent, HTREEITEM hInsertAfter)
4351 {
4352 ATLASSERT(::IsWindow(this->m_hWnd));
4353 return InsertItem(TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE, lpszItem, nImage, nSelectedImage, 0, 0, 0, hParent, hInsertAfter);
4354 }
4355
InsertItem(LPCTSTR lpszItem,HTREEITEM hParent,HTREEITEM hInsertAfter)4356 HTREEITEM InsertItem(LPCTSTR lpszItem, HTREEITEM hParent, HTREEITEM hInsertAfter)
4357 {
4358 ATLASSERT(::IsWindow(this->m_hWnd));
4359 return InsertItem(TVIF_TEXT, lpszItem, 0, 0, 0, 0, 0, hParent, hInsertAfter);
4360 }
4361
InsertItem(UINT nMask,LPCTSTR lpszItem,int nImage,int nSelectedImage,UINT nState,UINT nStateMask,LPARAM lParam,HTREEITEM hParent,HTREEITEM hInsertAfter)4362 HTREEITEM InsertItem(UINT nMask, LPCTSTR lpszItem, int nImage,
4363 int nSelectedImage, UINT nState, UINT nStateMask, LPARAM lParam,
4364 HTREEITEM hParent, HTREEITEM hInsertAfter)
4365 {
4366 ATLASSERT(::IsWindow(this->m_hWnd));
4367 TVINSERTSTRUCT tvis = {};
4368 tvis.hParent = hParent;
4369 tvis.hInsertAfter = hInsertAfter;
4370 tvis.item.mask = nMask;
4371 tvis.item.pszText = (LPTSTR) lpszItem;
4372 tvis.item.iImage = nImage;
4373 tvis.item.iSelectedImage = nSelectedImage;
4374 tvis.item.state = nState;
4375 tvis.item.stateMask = nStateMask;
4376 tvis.item.lParam = lParam;
4377 return (HTREEITEM)::SendMessage(this->m_hWnd, TVM_INSERTITEM, 0, (LPARAM)&tvis);
4378 }
4379
DeleteItem(HTREEITEM hItem)4380 BOOL DeleteItem(HTREEITEM hItem)
4381 {
4382 ATLASSERT(::IsWindow(this->m_hWnd));
4383 return (BOOL)::SendMessage(this->m_hWnd, TVM_DELETEITEM, 0, (LPARAM)hItem);
4384 }
4385
DeleteAllItems()4386 BOOL DeleteAllItems()
4387 {
4388 ATLASSERT(::IsWindow(this->m_hWnd));
4389 return (BOOL)::SendMessage(this->m_hWnd, TVM_DELETEITEM, 0, (LPARAM)TVI_ROOT);
4390 }
4391
4392 BOOL Expand(HTREEITEM hItem, UINT nCode = TVE_EXPAND)
4393 {
4394 ATLASSERT(::IsWindow(this->m_hWnd));
4395 return (BOOL)::SendMessage(this->m_hWnd, TVM_EXPAND, nCode, (LPARAM)hItem);
4396 }
4397
GetNextItem(HTREEITEM hItem,UINT nCode)4398 HTREEITEM GetNextItem(HTREEITEM hItem, UINT nCode) const
4399 {
4400 ATLASSERT(::IsWindow(this->m_hWnd));
4401 return (HTREEITEM)::SendMessage(this->m_hWnd, TVM_GETNEXTITEM, nCode, (LPARAM)hItem);
4402 }
4403
GetChildItem(HTREEITEM hItem)4404 HTREEITEM GetChildItem(HTREEITEM hItem) const
4405 {
4406 ATLASSERT(::IsWindow(this->m_hWnd));
4407 return (HTREEITEM)::SendMessage(this->m_hWnd, TVM_GETNEXTITEM, TVGN_CHILD, (LPARAM)hItem);
4408 }
4409
GetNextSiblingItem(HTREEITEM hItem)4410 HTREEITEM GetNextSiblingItem(HTREEITEM hItem) const
4411 {
4412 ATLASSERT(::IsWindow(this->m_hWnd));
4413 return (HTREEITEM)::SendMessage(this->m_hWnd, TVM_GETNEXTITEM, TVGN_NEXT, (LPARAM)hItem);
4414 }
4415
GetPrevSiblingItem(HTREEITEM hItem)4416 HTREEITEM GetPrevSiblingItem(HTREEITEM hItem) const
4417 {
4418 ATLASSERT(::IsWindow(this->m_hWnd));
4419 return (HTREEITEM)::SendMessage(this->m_hWnd, TVM_GETNEXTITEM, TVGN_PREVIOUS, (LPARAM)hItem);
4420 }
4421
GetParentItem(HTREEITEM hItem)4422 HTREEITEM GetParentItem(HTREEITEM hItem) const
4423 {
4424 ATLASSERT(::IsWindow(this->m_hWnd));
4425 return (HTREEITEM)::SendMessage(this->m_hWnd, TVM_GETNEXTITEM, TVGN_PARENT, (LPARAM)hItem);
4426 }
4427
GetFirstVisibleItem()4428 HTREEITEM GetFirstVisibleItem() const
4429 {
4430 ATLASSERT(::IsWindow(this->m_hWnd));
4431 return (HTREEITEM)::SendMessage(this->m_hWnd, TVM_GETNEXTITEM, TVGN_FIRSTVISIBLE, 0L);
4432 }
4433
GetNextVisibleItem(HTREEITEM hItem)4434 HTREEITEM GetNextVisibleItem(HTREEITEM hItem) const
4435 {
4436 ATLASSERT(::IsWindow(this->m_hWnd));
4437 return (HTREEITEM)::SendMessage(this->m_hWnd, TVM_GETNEXTITEM, TVGN_NEXTVISIBLE, (LPARAM)hItem);
4438 }
4439
GetPrevVisibleItem(HTREEITEM hItem)4440 HTREEITEM GetPrevVisibleItem(HTREEITEM hItem) const
4441 {
4442 ATLASSERT(::IsWindow(this->m_hWnd));
4443 return (HTREEITEM)::SendMessage(this->m_hWnd, TVM_GETNEXTITEM, TVGN_PREVIOUSVISIBLE, (LPARAM)hItem);
4444 }
4445
GetSelectedItem()4446 HTREEITEM GetSelectedItem() const
4447 {
4448 ATLASSERT(::IsWindow(this->m_hWnd));
4449 return (HTREEITEM)::SendMessage(this->m_hWnd, TVM_GETNEXTITEM, TVGN_CARET, 0L);
4450 }
4451
GetDropHilightItem()4452 HTREEITEM GetDropHilightItem() const
4453 {
4454 ATLASSERT(::IsWindow(this->m_hWnd));
4455 return (HTREEITEM)::SendMessage(this->m_hWnd, TVM_GETNEXTITEM, TVGN_DROPHILITE, 0L);
4456 }
4457
GetRootItem()4458 HTREEITEM GetRootItem() const
4459 {
4460 ATLASSERT(::IsWindow(this->m_hWnd));
4461 return (HTREEITEM)::SendMessage(this->m_hWnd, TVM_GETNEXTITEM, TVGN_ROOT, 0L);
4462 }
4463
GetLastVisibleItem()4464 HTREEITEM GetLastVisibleItem() const
4465 {
4466 ATLASSERT(::IsWindow(this->m_hWnd));
4467 return (HTREEITEM)::SendMessage(this->m_hWnd, TVM_GETNEXTITEM, TVGN_LASTVISIBLE, 0L);
4468 }
4469
GetNextSelectedItem()4470 HTREEITEM GetNextSelectedItem() const
4471 {
4472 ATLASSERT(::IsWindow(this->m_hWnd));
4473 return (HTREEITEM)::SendMessage(this->m_hWnd, TVM_GETNEXTITEM, TVGN_NEXTSELECTED, 0L);
4474 }
4475
Select(HTREEITEM hItem,UINT nCode)4476 BOOL Select(HTREEITEM hItem, UINT nCode)
4477 {
4478 ATLASSERT(::IsWindow(this->m_hWnd));
4479 return (BOOL)::SendMessage(this->m_hWnd, TVM_SELECTITEM, nCode, (LPARAM)hItem);
4480 }
4481
SelectItem(HTREEITEM hItem)4482 BOOL SelectItem(HTREEITEM hItem)
4483 {
4484 ATLASSERT(::IsWindow(this->m_hWnd));
4485 return (BOOL)::SendMessage(this->m_hWnd, TVM_SELECTITEM, TVGN_CARET, (LPARAM)hItem);
4486 }
4487
SelectDropTarget(HTREEITEM hItem)4488 BOOL SelectDropTarget(HTREEITEM hItem)
4489 {
4490 ATLASSERT(::IsWindow(this->m_hWnd));
4491 return (BOOL)::SendMessage(this->m_hWnd, TVM_SELECTITEM, TVGN_DROPHILITE, (LPARAM)hItem);
4492 }
4493
SelectSetFirstVisible(HTREEITEM hItem)4494 BOOL SelectSetFirstVisible(HTREEITEM hItem)
4495 {
4496 ATLASSERT(::IsWindow(this->m_hWnd));
4497 return (BOOL)::SendMessage(this->m_hWnd, TVM_SELECTITEM, TVGN_FIRSTVISIBLE, (LPARAM)hItem);
4498 }
4499
EditLabel(HTREEITEM hItem)4500 CEdit EditLabel(HTREEITEM hItem)
4501 {
4502 ATLASSERT(::IsWindow(this->m_hWnd));
4503 return CEdit((HWND)::SendMessage(this->m_hWnd, TVM_EDITLABEL, 0, (LPARAM)hItem));
4504 }
4505
EndEditLabelNow(BOOL bCancel)4506 BOOL EndEditLabelNow(BOOL bCancel)
4507 {
4508 ATLASSERT(::IsWindow(this->m_hWnd));
4509 return (BOOL)::SendMessage(this->m_hWnd, TVM_ENDEDITLABELNOW, bCancel, 0L);
4510 }
4511
HitTest(TVHITTESTINFO * pHitTestInfo)4512 HTREEITEM HitTest(TVHITTESTINFO* pHitTestInfo) const
4513 {
4514 ATLASSERT(::IsWindow(this->m_hWnd));
4515 return (HTREEITEM)::SendMessage(this->m_hWnd, TVM_HITTEST, 0, (LPARAM)pHitTestInfo);
4516 }
4517
HitTest(POINT pt,UINT * pFlags)4518 HTREEITEM HitTest(POINT pt, UINT* pFlags) const
4519 {
4520 ATLASSERT(::IsWindow(this->m_hWnd));
4521 TVHITTESTINFO hti = {};
4522 hti.pt = pt;
4523 HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(this->m_hWnd, TVM_HITTEST, 0, (LPARAM)&hti);
4524 if (pFlags != NULL)
4525 *pFlags = hti.flags;
4526 return hTreeItem;
4527 }
4528
4529 BOOL SortChildren(HTREEITEM hItem, BOOL bRecurse = FALSE)
4530 {
4531 ATLASSERT(::IsWindow(this->m_hWnd));
4532 return (BOOL)::SendMessage(this->m_hWnd, TVM_SORTCHILDREN, (WPARAM)bRecurse, (LPARAM)hItem);
4533 }
4534
EnsureVisible(HTREEITEM hItem)4535 BOOL EnsureVisible(HTREEITEM hItem)
4536 {
4537 ATLASSERT(::IsWindow(this->m_hWnd));
4538 return (BOOL)::SendMessage(this->m_hWnd, TVM_ENSUREVISIBLE, 0, (LPARAM)hItem);
4539 }
4540
4541 BOOL SortChildrenCB(LPTVSORTCB pSort, BOOL bRecurse = FALSE)
4542 {
4543 ATLASSERT(::IsWindow(this->m_hWnd));
4544 return (BOOL)::SendMessage(this->m_hWnd, TVM_SORTCHILDRENCB, (WPARAM)bRecurse, (LPARAM)pSort);
4545 }
4546
RemoveImageList(int nImageList)4547 CImageList RemoveImageList(int nImageList)
4548 {
4549 ATLASSERT(::IsWindow(this->m_hWnd));
4550 return CImageList((HIMAGELIST)::SendMessage(this->m_hWnd, TVM_SETIMAGELIST, (WPARAM)nImageList, NULL));
4551 }
4552
CreateDragImage(HTREEITEM hItem)4553 CImageList CreateDragImage(HTREEITEM hItem)
4554 {
4555 ATLASSERT(::IsWindow(this->m_hWnd));
4556 return CImageList((HIMAGELIST)::SendMessage(this->m_hWnd, TVM_CREATEDRAGIMAGE, 0, (LPARAM)hItem));
4557 }
4558
SetInsertMark(HTREEITEM hTreeItem,BOOL bAfter)4559 BOOL SetInsertMark(HTREEITEM hTreeItem, BOOL bAfter)
4560 {
4561 ATLASSERT(::IsWindow(this->m_hWnd));
4562 return (BOOL)::SendMessage(this->m_hWnd, TVM_SETINSERTMARK, bAfter, (LPARAM)hTreeItem);
4563 }
4564
RemoveInsertMark()4565 BOOL RemoveInsertMark()
4566 {
4567 ATLASSERT(::IsWindow(this->m_hWnd));
4568 return (BOOL)::SendMessage(this->m_hWnd, TVM_SETINSERTMARK, 0, 0L);
4569 }
4570
MapAccIDToHTREEITEM(UINT uID)4571 HTREEITEM MapAccIDToHTREEITEM(UINT uID) const
4572 {
4573 ATLASSERT(::IsWindow(this->m_hWnd));
4574 return (HTREEITEM)::SendMessage(this->m_hWnd, TVM_MAPACCIDTOHTREEITEM, uID, 0L);
4575 }
4576
MapHTREEITEMToAccID(HTREEITEM hTreeItem)4577 UINT MapHTREEITEMToAccID(HTREEITEM hTreeItem) const
4578 {
4579 ATLASSERT(::IsWindow(this->m_hWnd));
4580 return (UINT)::SendMessage(this->m_hWnd, TVM_MAPHTREEITEMTOACCID, (WPARAM)hTreeItem, 0L);
4581 }
4582
4583 #if (_WIN32_WINNT >= 0x0600)
ShowInfoTip(HTREEITEM hItem)4584 void ShowInfoTip(HTREEITEM hItem)
4585 {
4586 ATLASSERT(::IsWindow(this->m_hWnd));
4587 ::SendMessage(this->m_hWnd, TVM_SHOWINFOTIP, 0, (LPARAM)hItem);
4588 }
4589 #endif // (_WIN32_WINNT >= 0x0600)
4590 };
4591
4592 typedef CTreeViewCtrlT<ATL::CWindow> CTreeViewCtrl;
4593
4594
4595 ///////////////////////////////////////////////////////////////////////////////
4596 // CTreeViewCtrlEx
4597
4598 // forward declaration
4599 template <class TBase> class CTreeViewCtrlExT;
4600
4601 // Note: TBase here is for CTreeViewCtrlExT, and not for CTreeItemT itself
4602 template <class TBase>
4603 class CTreeItemT
4604 {
4605 public:
4606 HTREEITEM m_hTreeItem;
4607 CTreeViewCtrlExT<TBase>* m_pTreeView;
4608
4609 // Construction
m_hTreeItem(hTreeItem)4610 CTreeItemT(HTREEITEM hTreeItem = NULL, CTreeViewCtrlExT<TBase>* pTreeView = NULL) : m_hTreeItem(hTreeItem), m_pTreeView(pTreeView)
4611 { }
4612
CTreeItemT(const CTreeItemT<TBase> & posSrc)4613 CTreeItemT(const CTreeItemT<TBase>& posSrc)
4614 {
4615 *this = posSrc;
4616 }
4617
HTREEITEM()4618 operator HTREEITEM() { return m_hTreeItem; }
4619
4620 CTreeItemT<TBase>& operator =(const CTreeItemT<TBase>& itemSrc)
4621 {
4622 m_hTreeItem = itemSrc.m_hTreeItem;
4623 m_pTreeView = itemSrc.m_pTreeView;
4624 return *this;
4625 }
4626
4627 // Attributes
GetTreeView()4628 CTreeViewCtrlExT<TBase>* GetTreeView() const { return m_pTreeView; }
4629
4630 BOOL operator !() const { return m_hTreeItem == NULL; }
4631
IsNull()4632 BOOL IsNull() const { return m_hTreeItem == NULL; }
4633
4634 BOOL GetRect(LPRECT lpRect, BOOL bTextOnly) const;
4635 BOOL GetText(LPTSTR lpstrText, int nLen) const;
4636 BOOL GetText(BSTR& bstrText) const;
4637 #ifdef __ATLSTR_H__
4638 BOOL GetText(ATL::CString& strText) const;
4639 #endif // __ATLSTR_H__
4640 BOOL SetText(LPCTSTR lpszItem);
4641 BOOL GetImage(int& nImage, int& nSelectedImage) const;
4642 BOOL SetImage(int nImage, int nSelectedImage);
4643 UINT GetState(UINT nStateMask) const;
4644 BOOL SetState(UINT nState, UINT nStateMask);
4645 DWORD_PTR GetData() const;
4646 BOOL SetData(DWORD_PTR dwData);
4647 BOOL SetItem(UINT nMask, LPCTSTR lpszItem, int nImage, int nSelectedImage, UINT nState, UINT nStateMask, LPARAM lParam);
4648
4649 // Operations
InsertAfter(LPCTSTR lpstrItem,HTREEITEM hItemAfter,int nImageIndex)4650 CTreeItemT<TBase> InsertAfter(LPCTSTR lpstrItem, HTREEITEM hItemAfter, int nImageIndex)
4651 {
4652 return _Insert(lpstrItem, nImageIndex, hItemAfter);
4653 }
4654
AddHead(LPCTSTR lpstrItem,int nImageIndex)4655 CTreeItemT<TBase> AddHead(LPCTSTR lpstrItem, int nImageIndex)
4656 {
4657 return _Insert(lpstrItem, nImageIndex, TVI_FIRST);
4658 }
4659
AddTail(LPCTSTR lpstrItem,int nImageIndex)4660 CTreeItemT<TBase> AddTail(LPCTSTR lpstrItem, int nImageIndex)
4661 {
4662 return _Insert(lpstrItem, nImageIndex, TVI_LAST);
4663 }
4664
4665 CTreeItemT<TBase> GetChild() const;
4666 CTreeItemT<TBase> GetNext(UINT nCode) const;
4667 CTreeItemT<TBase> GetNextSibling() const;
4668 CTreeItemT<TBase> GetPrevSibling() const;
4669 CTreeItemT<TBase> GetParent() const;
4670 CTreeItemT<TBase> GetFirstVisible() const;
4671 CTreeItemT<TBase> GetNextVisible() const;
4672 CTreeItemT<TBase> GetPrevVisible() const;
4673 CTreeItemT<TBase> GetSelected() const;
4674 CTreeItemT<TBase> GetDropHilight() const;
4675 CTreeItemT<TBase> GetRoot() const;
4676 CTreeItemT<TBase> GetLastVisible() const;
4677 CTreeItemT<TBase> GetNextSelected() const;
4678 BOOL HasChildren() const;
4679 BOOL Delete();
4680 BOOL Expand(UINT nCode = TVE_EXPAND);
4681 BOOL Select(UINT nCode);
4682 BOOL Select();
4683 BOOL SelectDropTarget();
4684 BOOL SelectSetFirstVisible();
4685 HWND EditLabel();
4686 HIMAGELIST CreateDragImage();
4687 BOOL SortChildren(BOOL bRecurse = FALSE);
4688 BOOL EnsureVisible();
4689 CTreeItemT<TBase> _Insert(LPCTSTR lpstrItem, int nImageIndex, HTREEITEM hItemAfter);
4690 int GetImageIndex() const;
4691 BOOL SetInsertMark(BOOL bAfter);
4692 UINT MapHTREEITEMToAccID() const;
4693 #if (_WIN32_WINNT >= 0x0600)
4694 void ShowInfoTip();
4695 BOOL GetPartRect(TVITEMPART partID, LPRECT lpRect) const;
4696 #endif // (_WIN32_WINNT >= 0x0600)
4697 };
4698
4699 typedef CTreeItemT<ATL::CWindow> CTreeItem;
4700
4701
4702 template <class TBase>
4703 class CTreeViewCtrlExT : public CTreeViewCtrlT< TBase >
4704 {
4705 public:
4706 // Constructors
4707 CTreeViewCtrlExT(HWND hWnd = NULL) : CTreeViewCtrlT< TBase >(hWnd)
4708 { }
4709
4710 CTreeViewCtrlExT< TBase >& operator =(HWND hWnd)
4711 {
4712 this->m_hWnd = hWnd;
4713 return *this;
4714 }
4715
4716 // Operations (overides that return CTreeItem)
InsertItem(LPTVINSERTSTRUCT lpInsertStruct)4717 CTreeItemT<TBase> InsertItem(LPTVINSERTSTRUCT lpInsertStruct)
4718 {
4719 ATLASSERT(::IsWindow(this->m_hWnd));
4720 HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(this->m_hWnd, TVM_INSERTITEM, 0, (LPARAM)lpInsertStruct);
4721 return CTreeItemT<TBase>(hTreeItem, this);
4722 }
4723
InsertItem(LPCTSTR lpszItem,int nImage,int nSelectedImage,HTREEITEM hParent,HTREEITEM hInsertAfter)4724 CTreeItemT<TBase> InsertItem(LPCTSTR lpszItem, int nImage,
4725 int nSelectedImage, HTREEITEM hParent, HTREEITEM hInsertAfter)
4726 {
4727 ATLASSERT(::IsWindow(this->m_hWnd));
4728 return InsertItem(TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE, lpszItem, nImage, nSelectedImage, 0, 0, 0, hParent, hInsertAfter);
4729 }
4730
InsertItem(LPCTSTR lpszItem,HTREEITEM hParent,HTREEITEM hInsertAfter)4731 CTreeItemT<TBase> InsertItem(LPCTSTR lpszItem, HTREEITEM hParent, HTREEITEM hInsertAfter)
4732 {
4733 ATLASSERT(::IsWindow(this->m_hWnd));
4734 return InsertItem(TVIF_TEXT, lpszItem, 0, 0, 0, 0, 0, hParent, hInsertAfter);
4735 }
4736
GetNextItem(HTREEITEM hItem,UINT nCode)4737 CTreeItemT<TBase> GetNextItem(HTREEITEM hItem, UINT nCode) const
4738 {
4739 ATLASSERT(::IsWindow(this->m_hWnd));
4740 HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(this->m_hWnd, TVM_GETNEXTITEM, nCode, (LPARAM)hItem);
4741 return CTreeItemT<TBase>(hTreeItem, (CTreeViewCtrlExT<TBase>*)this);
4742 }
4743
GetChildItem(HTREEITEM hItem)4744 CTreeItemT<TBase> GetChildItem(HTREEITEM hItem) const
4745 {
4746 ATLASSERT(::IsWindow(this->m_hWnd));
4747 HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(this->m_hWnd, TVM_GETNEXTITEM, TVGN_CHILD, (LPARAM)hItem);
4748 return CTreeItemT<TBase>(hTreeItem, (CTreeViewCtrlExT<TBase>*)this);
4749 }
4750
GetNextSiblingItem(HTREEITEM hItem)4751 CTreeItemT<TBase> GetNextSiblingItem(HTREEITEM hItem) const
4752 {
4753 ATLASSERT(::IsWindow(this->m_hWnd));
4754 HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(this->m_hWnd, TVM_GETNEXTITEM, TVGN_NEXT, (LPARAM)hItem);
4755 return CTreeItemT<TBase>(hTreeItem, (CTreeViewCtrlExT<TBase>*)this);
4756 }
4757
GetPrevSiblingItem(HTREEITEM hItem)4758 CTreeItemT<TBase> GetPrevSiblingItem(HTREEITEM hItem) const
4759 {
4760 ATLASSERT(::IsWindow(this->m_hWnd));
4761 HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(this->m_hWnd, TVM_GETNEXTITEM, TVGN_PREVIOUS, (LPARAM)hItem);
4762 return CTreeItemT<TBase>(hTreeItem, (CTreeViewCtrlExT<TBase>*)this);
4763 }
4764
GetParentItem(HTREEITEM hItem)4765 CTreeItemT<TBase> GetParentItem(HTREEITEM hItem) const
4766 {
4767 ATLASSERT(::IsWindow(this->m_hWnd));
4768 HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(this->m_hWnd, TVM_GETNEXTITEM, TVGN_PARENT, (LPARAM)hItem);
4769 return CTreeItemT<TBase>(hTreeItem, (CTreeViewCtrlExT<TBase>*)this);
4770 }
4771
GetFirstVisibleItem()4772 CTreeItemT<TBase> GetFirstVisibleItem() const
4773 {
4774 ATLASSERT(::IsWindow(this->m_hWnd));
4775 HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(this->m_hWnd, TVM_GETNEXTITEM, TVGN_FIRSTVISIBLE, 0L);
4776 return CTreeItemT<TBase>(hTreeItem, (CTreeViewCtrlExT<TBase>*)this);
4777 }
4778
GetNextVisibleItem(HTREEITEM hItem)4779 CTreeItemT<TBase> GetNextVisibleItem(HTREEITEM hItem) const
4780 {
4781 ATLASSERT(::IsWindow(this->m_hWnd));
4782 HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(this->m_hWnd, TVM_GETNEXTITEM, TVGN_NEXTVISIBLE, (LPARAM)hItem);
4783 return CTreeItemT<TBase>(hTreeItem, (CTreeViewCtrlExT<TBase>*)this);
4784 }
4785
GetPrevVisibleItem(HTREEITEM hItem)4786 CTreeItemT<TBase> GetPrevVisibleItem(HTREEITEM hItem) const
4787 {
4788 ATLASSERT(::IsWindow(this->m_hWnd));
4789 HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(this->m_hWnd, TVM_GETNEXTITEM, TVGN_PREVIOUSVISIBLE, (LPARAM)hItem);
4790 return CTreeItemT<TBase>(hTreeItem, (CTreeViewCtrlExT<TBase>*)this);
4791 }
4792
GetSelectedItem()4793 CTreeItemT<TBase> GetSelectedItem() const
4794 {
4795 ATLASSERT(::IsWindow(this->m_hWnd));
4796 HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(this->m_hWnd, TVM_GETNEXTITEM, TVGN_CARET, 0L);
4797 return CTreeItemT<TBase>(hTreeItem, (CTreeViewCtrlExT<TBase>*)this);
4798 }
4799
GetDropHilightItem()4800 CTreeItemT<TBase> GetDropHilightItem() const
4801 {
4802 ATLASSERT(::IsWindow(this->m_hWnd));
4803 HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(this->m_hWnd, TVM_GETNEXTITEM, TVGN_DROPHILITE, 0L);
4804 return CTreeItemT<TBase>(hTreeItem, (CTreeViewCtrlExT<TBase>*)this);
4805 }
4806
GetRootItem()4807 CTreeItemT<TBase> GetRootItem() const
4808 {
4809 ATLASSERT(::IsWindow(this->m_hWnd));
4810 HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(this->m_hWnd, TVM_GETNEXTITEM, TVGN_ROOT, 0L);
4811 return CTreeItemT<TBase>(hTreeItem, (CTreeViewCtrlExT<TBase>*)this);
4812 }
4813
GetLastVisibleItem()4814 CTreeItemT<TBase> GetLastVisibleItem() const
4815 {
4816 ATLASSERT(::IsWindow(this->m_hWnd));
4817 HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(this->m_hWnd, TVM_GETNEXTITEM, TVGN_LASTVISIBLE, 0L);
4818 return CTreeItemT<TBase>(hTreeItem, (CTreeViewCtrlExT<TBase>*)this);
4819 }
4820
GetNextSelectedItem()4821 CTreeItemT<TBase> GetNextSelectedItem() const
4822 {
4823 ATLASSERT(::IsWindow(this->m_hWnd));
4824 HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(this->m_hWnd, TVM_GETNEXTITEM, TVGN_NEXTSELECTED, 0L);
4825 return CTreeItemT<TBase>(hTreeItem, (CTreeViewCtrlExT<TBase>*)this);
4826 }
4827
HitTest(TVHITTESTINFO * pHitTestInfo)4828 CTreeItemT<TBase> HitTest(TVHITTESTINFO* pHitTestInfo) const
4829 {
4830 ATLASSERT(::IsWindow(this->m_hWnd));
4831 HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(this->m_hWnd, TVM_HITTEST, 0, (LPARAM)pHitTestInfo);
4832 return CTreeItemT<TBase>(hTreeItem, (CTreeViewCtrlExT<TBase>*)this);
4833 }
4834
InsertItem(UINT nMask,LPCTSTR lpszItem,int nImage,int nSelectedImage,UINT nState,UINT nStateMask,LPARAM lParam,HTREEITEM hParent,HTREEITEM hInsertAfter)4835 CTreeItemT<TBase> InsertItem(UINT nMask, LPCTSTR lpszItem, int nImage,
4836 int nSelectedImage, UINT nState, UINT nStateMask, LPARAM lParam,
4837 HTREEITEM hParent, HTREEITEM hInsertAfter)
4838 {
4839 ATLASSERT(::IsWindow(this->m_hWnd));
4840 TVINSERTSTRUCT tvis = {};
4841 tvis.hParent = hParent;
4842 tvis.hInsertAfter = hInsertAfter;
4843 tvis.item.mask = nMask;
4844 tvis.item.pszText = (LPTSTR) lpszItem;
4845 tvis.item.iImage = nImage;
4846 tvis.item.iSelectedImage = nSelectedImage;
4847 tvis.item.state = nState;
4848 tvis.item.stateMask = nStateMask;
4849 tvis.item.lParam = lParam;
4850 HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(this->m_hWnd, TVM_INSERTITEM, 0, (LPARAM)&tvis);
4851 return CTreeItemT<TBase>(hTreeItem, this);
4852 }
4853
HitTest(POINT pt,UINT * pFlags)4854 CTreeItemT<TBase> HitTest(POINT pt, UINT* pFlags) const
4855 {
4856 ATLASSERT(::IsWindow(this->m_hWnd));
4857 TVHITTESTINFO hti = {};
4858 hti.pt = pt;
4859 HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(this->m_hWnd, TVM_HITTEST, 0, (LPARAM)&hti);
4860 if (pFlags != NULL)
4861 *pFlags = hti.flags;
4862 return CTreeItemT<TBase>(hTreeItem, (CTreeViewCtrlExT<TBase>*)this);
4863 }
4864
MapAccIDToHTREEITEM(UINT uID)4865 CTreeItemT<TBase> MapAccIDToHTREEITEM(UINT uID) const
4866 {
4867 ATLASSERT(::IsWindow(this->m_hWnd));
4868 HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(this->m_hWnd, TVM_MAPACCIDTOHTREEITEM, uID, 0L);
4869 return CTreeItemT<TBase>(hTreeItem, (CTreeViewCtrlExT<TBase>*)this);
4870 }
4871 };
4872
4873 typedef CTreeViewCtrlExT<ATL::CWindow> CTreeViewCtrlEx;
4874
4875
4876 // CTreeItem inline methods
4877 template <class TBase>
GetRect(LPRECT lpRect,BOOL bTextOnly)4878 inline BOOL CTreeItemT<TBase>::GetRect(LPRECT lpRect, BOOL bTextOnly) const
4879 {
4880 ATLASSERT(m_pTreeView != NULL);
4881 return m_pTreeView->GetItemRect(m_hTreeItem,lpRect,bTextOnly);
4882 }
4883
4884 template <class TBase>
GetNext(UINT nCode)4885 inline CTreeItemT<TBase> CTreeItemT<TBase>::GetNext(UINT nCode) const
4886 {
4887 ATLASSERT(m_pTreeView != NULL);
4888 return m_pTreeView->GetNextItem(m_hTreeItem,nCode);
4889 }
4890
4891 template <class TBase>
GetChild()4892 inline CTreeItemT<TBase> CTreeItemT<TBase>::GetChild() const
4893 {
4894 ATLASSERT(m_pTreeView != NULL);
4895 return m_pTreeView->GetChildItem(m_hTreeItem);
4896 }
4897
4898 template <class TBase>
GetNextSibling()4899 inline CTreeItemT<TBase> CTreeItemT<TBase>::GetNextSibling() const
4900 {
4901 ATLASSERT(m_pTreeView != NULL);
4902 return m_pTreeView->GetNextSiblingItem(m_hTreeItem);
4903 }
4904
4905 template <class TBase>
GetPrevSibling()4906 inline CTreeItemT<TBase> CTreeItemT<TBase>::GetPrevSibling() const
4907 {
4908 ATLASSERT(m_pTreeView != NULL);
4909 return m_pTreeView->GetPrevSiblingItem(m_hTreeItem);
4910 }
4911
4912 template <class TBase>
GetParent()4913 inline CTreeItemT<TBase> CTreeItemT<TBase>::GetParent() const
4914 {
4915 ATLASSERT(m_pTreeView != NULL);
4916 return m_pTreeView->GetParentItem(m_hTreeItem);
4917 }
4918
4919 template <class TBase>
GetFirstVisible()4920 inline CTreeItemT<TBase> CTreeItemT<TBase>::GetFirstVisible() const
4921 {
4922 ATLASSERT(m_pTreeView != NULL);
4923 return m_pTreeView->GetFirstVisibleItem();
4924 }
4925
4926 template <class TBase>
GetNextVisible()4927 inline CTreeItemT<TBase> CTreeItemT<TBase>::GetNextVisible() const
4928 {
4929 ATLASSERT(m_pTreeView != NULL);
4930 return m_pTreeView->GetNextVisibleItem(m_hTreeItem);
4931 }
4932
4933 template <class TBase>
GetPrevVisible()4934 inline CTreeItemT<TBase> CTreeItemT<TBase>::GetPrevVisible() const
4935 {
4936 ATLASSERT(m_pTreeView != NULL);
4937 return m_pTreeView->GetPrevVisibleItem(m_hTreeItem);
4938 }
4939
4940 template <class TBase>
GetSelected()4941 inline CTreeItemT<TBase> CTreeItemT<TBase>::GetSelected() const
4942 {
4943 ATLASSERT(m_pTreeView != NULL);
4944 return m_pTreeView->GetSelectedItem();
4945 }
4946
4947 template <class TBase>
GetDropHilight()4948 inline CTreeItemT<TBase> CTreeItemT<TBase>::GetDropHilight() const
4949 {
4950 ATLASSERT(m_pTreeView != NULL);
4951 return m_pTreeView->GetDropHilightItem();
4952 }
4953
4954 template <class TBase>
GetRoot()4955 inline CTreeItemT<TBase> CTreeItemT<TBase>::GetRoot() const
4956 {
4957 ATLASSERT(m_pTreeView != NULL);
4958 return m_pTreeView->GetRootItem();
4959 }
4960
4961 template <class TBase>
GetLastVisible()4962 inline CTreeItemT<TBase> CTreeItemT<TBase>::GetLastVisible() const
4963 {
4964 ATLASSERT(m_pTreeView != NULL);
4965 return m_pTreeView->GetLastVisibleItem();
4966 }
4967
4968 template <class TBase>
GetNextSelected()4969 inline CTreeItemT<TBase> CTreeItemT<TBase>::GetNextSelected() const
4970 {
4971 ATLASSERT(m_pTreeView != NULL);
4972 return m_pTreeView->GetNextSelectedItem();
4973 }
4974
4975 template <class TBase>
GetText(LPTSTR lpstrText,int nLen)4976 inline BOOL CTreeItemT<TBase>::GetText(LPTSTR lpstrText, int nLen) const
4977 {
4978 ATLASSERT(m_pTreeView != NULL);
4979 return m_pTreeView->GetItemText(m_hTreeItem, lpstrText, nLen);
4980 }
4981
4982 #ifdef _OLEAUTO_H_
4983 template <class TBase>
GetText(BSTR & bstrText)4984 inline BOOL CTreeItemT<TBase>::GetText(BSTR& bstrText) const
4985 {
4986 ATLASSERT(m_pTreeView != NULL);
4987 return m_pTreeView->GetItemText(m_hTreeItem, bstrText);
4988 }
4989 #endif // _OLEAUTO_H_
4990
4991 #ifdef __ATLSTR_H__
4992 template <class TBase>
GetText(ATL::CString & strText)4993 inline BOOL CTreeItemT<TBase>::GetText(ATL::CString& strText) const
4994 {
4995 ATLASSERT(m_pTreeView != NULL);
4996 return m_pTreeView->GetItemText(m_hTreeItem, strText);
4997 }
4998 #endif // __ATLSTR_H__
4999
5000 template <class TBase>
GetImage(int & nImage,int & nSelectedImage)5001 inline BOOL CTreeItemT<TBase>::GetImage(int& nImage, int& nSelectedImage) const
5002 {
5003 ATLASSERT(m_pTreeView != NULL);
5004 return m_pTreeView->GetItemImage(m_hTreeItem,nImage,nSelectedImage);
5005 }
5006
5007 template <class TBase>
GetState(UINT nStateMask)5008 inline UINT CTreeItemT<TBase>::GetState(UINT nStateMask) const
5009 {
5010 ATLASSERT(m_pTreeView != NULL);
5011 return m_pTreeView->GetItemState(m_hTreeItem,nStateMask);
5012 }
5013
5014 template <class TBase>
GetData()5015 inline DWORD_PTR CTreeItemT<TBase>::GetData() const
5016 {
5017 ATLASSERT(m_pTreeView != NULL);
5018 return m_pTreeView->GetItemData(m_hTreeItem);
5019 }
5020
5021 template <class TBase>
SetItem(UINT nMask,LPCTSTR lpszItem,int nImage,int nSelectedImage,UINT nState,UINT nStateMask,LPARAM lParam)5022 inline BOOL CTreeItemT<TBase>::SetItem(UINT nMask, LPCTSTR lpszItem, int nImage,
5023 int nSelectedImage, UINT nState, UINT nStateMask, LPARAM lParam)
5024 {
5025 ATLASSERT(m_pTreeView != NULL);
5026 return m_pTreeView->SetItem(m_hTreeItem, nMask, lpszItem, nImage, nSelectedImage, nState, nStateMask, lParam);
5027 }
5028
5029 template <class TBase>
SetText(LPCTSTR lpszItem)5030 inline BOOL CTreeItemT<TBase>::SetText(LPCTSTR lpszItem)
5031 {
5032 ATLASSERT(m_pTreeView != NULL);
5033 return m_pTreeView->SetItemText(m_hTreeItem,lpszItem);
5034 }
5035
5036 template <class TBase>
SetImage(int nImage,int nSelectedImage)5037 inline BOOL CTreeItemT<TBase>::SetImage(int nImage, int nSelectedImage)
5038 {
5039 ATLASSERT(m_pTreeView != NULL);
5040 return m_pTreeView->SetItemImage(m_hTreeItem,nImage,nSelectedImage);
5041 }
5042
5043 template <class TBase>
SetState(UINT nState,UINT nStateMask)5044 inline BOOL CTreeItemT<TBase>::SetState(UINT nState, UINT nStateMask)
5045 {
5046 ATLASSERT(m_pTreeView != NULL);
5047 return m_pTreeView->SetItemState(m_hTreeItem,nState,nStateMask);
5048 }
5049
5050 template <class TBase>
SetData(DWORD_PTR dwData)5051 inline BOOL CTreeItemT<TBase>::SetData(DWORD_PTR dwData)
5052 {
5053 ATLASSERT(m_pTreeView != NULL);
5054 return m_pTreeView->SetItemData(m_hTreeItem,dwData);
5055 }
5056
5057 template <class TBase>
HasChildren()5058 inline BOOL CTreeItemT<TBase>::HasChildren() const
5059 {
5060 ATLASSERT(m_pTreeView != NULL);
5061 return m_pTreeView->ItemHasChildren(m_hTreeItem);
5062 }
5063
5064 template <class TBase>
Delete()5065 inline BOOL CTreeItemT<TBase>::Delete()
5066 {
5067 ATLASSERT(m_pTreeView != NULL);
5068 return m_pTreeView->DeleteItem(m_hTreeItem);
5069 }
5070
5071 template <class TBase>
Expand(UINT nCode)5072 inline BOOL CTreeItemT<TBase>::Expand(UINT nCode /*= TVE_EXPAND*/)
5073 {
5074 ATLASSERT(m_pTreeView != NULL);
5075 return m_pTreeView->Expand(m_hTreeItem,nCode);
5076 }
5077
5078 template <class TBase>
Select(UINT nCode)5079 inline BOOL CTreeItemT<TBase>::Select(UINT nCode)
5080 {
5081 ATLASSERT(m_pTreeView != NULL);
5082 return m_pTreeView->Select(m_hTreeItem,nCode);
5083 }
5084
5085 template <class TBase>
Select()5086 inline BOOL CTreeItemT<TBase>::Select()
5087 {
5088 ATLASSERT(m_pTreeView != NULL);
5089 return m_pTreeView->SelectItem(m_hTreeItem);
5090 }
5091
5092 template <class TBase>
SelectDropTarget()5093 inline BOOL CTreeItemT<TBase>::SelectDropTarget()
5094 {
5095 ATLASSERT(m_pTreeView != NULL);
5096 return m_pTreeView->SelectDropTarget(m_hTreeItem);
5097 }
5098
5099 template <class TBase>
SelectSetFirstVisible()5100 inline BOOL CTreeItemT<TBase>::SelectSetFirstVisible()
5101 {
5102 ATLASSERT(m_pTreeView != NULL);
5103 return m_pTreeView->SelectSetFirstVisible(m_hTreeItem);
5104 }
5105
5106 template <class TBase>
EditLabel()5107 inline HWND CTreeItemT<TBase>::EditLabel()
5108 {
5109 ATLASSERT(m_pTreeView != NULL);
5110 return m_pTreeView->EditLabel(m_hTreeItem);
5111 }
5112
5113 template <class TBase>
CreateDragImage()5114 inline HIMAGELIST CTreeItemT<TBase>::CreateDragImage()
5115 {
5116 ATLASSERT(m_pTreeView != NULL);
5117 return m_pTreeView->CreateDragImage(m_hTreeItem);
5118 }
5119
5120 template <class TBase>
SortChildren(BOOL bRecurse)5121 inline BOOL CTreeItemT<TBase>::SortChildren(BOOL bRecurse /*= FALSE*/)
5122 {
5123 ATLASSERT(m_pTreeView != NULL);
5124 return m_pTreeView->SortChildren(m_hTreeItem, bRecurse);
5125 }
5126
5127 template <class TBase>
EnsureVisible()5128 inline BOOL CTreeItemT<TBase>::EnsureVisible()
5129 {
5130 ATLASSERT(m_pTreeView != NULL);
5131 return m_pTreeView->EnsureVisible(m_hTreeItem);
5132 }
5133
5134 template <class TBase>
_Insert(LPCTSTR lpstrItem,int nImageIndex,HTREEITEM hItemAfter)5135 inline CTreeItemT<TBase> CTreeItemT<TBase>::_Insert(LPCTSTR lpstrItem, int nImageIndex, HTREEITEM hItemAfter)
5136 {
5137 ATLASSERT(m_pTreeView != NULL);
5138 TVINSERTSTRUCT ins = {};
5139 ins.hParent = m_hTreeItem;
5140 ins.hInsertAfter = hItemAfter;
5141 ins.item.mask = TVIF_TEXT;
5142 ins.item.pszText = (LPTSTR)lpstrItem;
5143 if(nImageIndex != -1)
5144 {
5145 ins.item.mask |= TVIF_IMAGE | TVIF_SELECTEDIMAGE;
5146 ins.item.iImage = nImageIndex;
5147 ins.item.iSelectedImage = nImageIndex;
5148 }
5149 return CTreeItemT<TBase>(m_pTreeView->InsertItem(&ins), m_pTreeView);
5150 }
5151
5152 template <class TBase>
GetImageIndex()5153 inline int CTreeItemT<TBase>::GetImageIndex() const
5154 {
5155 ATLASSERT(m_pTreeView != NULL);
5156 TVITEM item = {};
5157 item.mask = TVIF_HANDLE | TVIF_IMAGE;
5158 item.hItem = m_hTreeItem;
5159 m_pTreeView->GetItem(&item);
5160 return item.iImage;
5161 }
5162
5163 template <class TBase>
SetInsertMark(BOOL bAfter)5164 inline BOOL CTreeItemT<TBase>::SetInsertMark(BOOL bAfter)
5165 {
5166 ATLASSERT(m_pTreeView != NULL);
5167 return m_pTreeView->SetInsertMark(m_hTreeItem, bAfter);
5168 }
5169
5170 template <class TBase>
MapHTREEITEMToAccID()5171 inline UINT CTreeItemT<TBase>::MapHTREEITEMToAccID() const
5172 {
5173 ATLASSERT(m_pTreeView != NULL);
5174 return m_pTreeView->MapHTREEITEMToAccID(m_hTreeItem);
5175 }
5176
5177 #if (_WIN32_WINNT >= 0x0600)
5178 template <class TBase>
ShowInfoTip()5179 inline void CTreeItemT<TBase>::ShowInfoTip()
5180 {
5181 ATLASSERT(m_pTreeView != NULL);
5182 m_pTreeView->ShowInfoTip(m_hTreeItem);
5183 }
5184
5185 template <class TBase>
GetPartRect(TVITEMPART partID,LPRECT lpRect)5186 inline BOOL CTreeItemT<TBase>::GetPartRect(TVITEMPART partID, LPRECT lpRect) const
5187 {
5188 ATLASSERT(m_pTreeView != NULL);
5189 return m_pTreeView->GetItemPartRect(m_hTreeItem, partID, lpRect);
5190 }
5191 #endif // (_WIN32_WINNT >= 0x0600)
5192
5193
5194 ///////////////////////////////////////////////////////////////////////////////
5195 // CToolBarCtrl
5196
5197 template <class TBase>
5198 class CToolBarCtrlT : public TBase
5199 {
5200 public:
5201 // Construction
TBase(hWnd)5202 CToolBarCtrlT(HWND hWnd = NULL) : TBase(hWnd)
5203 { }
5204
5205 CToolBarCtrlT< TBase >& operator =(HWND hWnd)
5206 {
5207 this->m_hWnd = hWnd;
5208 return *this;
5209 }
5210
5211 HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
5212 DWORD dwStyle = 0, DWORD dwExStyle = 0,
5213 ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
5214 {
5215 return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
5216 }
5217
5218 // Attributes
GetWndClassName()5219 static LPCTSTR GetWndClassName()
5220 {
5221 return TOOLBARCLASSNAME;
5222 }
5223
IsButtonEnabled(int nID)5224 BOOL IsButtonEnabled(int nID) const
5225 {
5226 ATLASSERT(::IsWindow(this->m_hWnd));
5227 return (BOOL)::SendMessage(this->m_hWnd, TB_ISBUTTONENABLED, nID, 0L);
5228 }
5229
IsButtonChecked(int nID)5230 BOOL IsButtonChecked(int nID) const
5231 {
5232 ATLASSERT(::IsWindow(this->m_hWnd));
5233 return (BOOL)::SendMessage(this->m_hWnd, TB_ISBUTTONCHECKED, nID, 0L);
5234 }
5235
IsButtonPressed(int nID)5236 BOOL IsButtonPressed(int nID) const
5237 {
5238 ATLASSERT(::IsWindow(this->m_hWnd));
5239 return (BOOL)::SendMessage(this->m_hWnd, TB_ISBUTTONPRESSED, nID, 0L);
5240 }
5241
IsButtonHidden(int nID)5242 BOOL IsButtonHidden(int nID) const
5243 {
5244 ATLASSERT(::IsWindow(this->m_hWnd));
5245 return(BOOL) ::SendMessage(this->m_hWnd, TB_ISBUTTONHIDDEN, nID, 0L);
5246 }
5247
IsButtonIndeterminate(int nID)5248 BOOL IsButtonIndeterminate(int nID) const
5249 {
5250 ATLASSERT(::IsWindow(this->m_hWnd));
5251 return (BOOL)::SendMessage(this->m_hWnd, TB_ISBUTTONINDETERMINATE, nID, 0L);
5252 }
5253
GetState(int nID)5254 int GetState(int nID) const
5255 {
5256 ATLASSERT(::IsWindow(this->m_hWnd));
5257 return (int)::SendMessage(this->m_hWnd, TB_GETSTATE, nID, 0L);
5258 }
5259
SetState(int nID,UINT nState)5260 BOOL SetState(int nID, UINT nState)
5261 {
5262 ATLASSERT(::IsWindow(this->m_hWnd));
5263 return (BOOL)::SendMessage(this->m_hWnd, TB_SETSTATE, nID, MAKELPARAM(nState, 0));
5264 }
5265
GetButton(int nIndex,LPTBBUTTON lpButton)5266 BOOL GetButton(int nIndex, LPTBBUTTON lpButton) const
5267 {
5268 ATLASSERT(::IsWindow(this->m_hWnd));
5269 return (BOOL)::SendMessage(this->m_hWnd, TB_GETBUTTON, nIndex, (LPARAM)lpButton);
5270 }
5271
GetButtonCount()5272 int GetButtonCount() const
5273 {
5274 ATLASSERT(::IsWindow(this->m_hWnd));
5275 return (int)::SendMessage(this->m_hWnd, TB_BUTTONCOUNT, 0, 0L);
5276 }
5277
GetItemRect(int nIndex,LPRECT lpRect)5278 BOOL GetItemRect(int nIndex, LPRECT lpRect) const
5279 {
5280 ATLASSERT(::IsWindow(this->m_hWnd));
5281 return (BOOL)::SendMessage(this->m_hWnd, TB_GETITEMRECT, nIndex, (LPARAM)lpRect);
5282 }
5283
5284 void SetButtonStructSize(int nSize = sizeof(TBBUTTON))
5285 {
5286 ATLASSERT(::IsWindow(this->m_hWnd));
5287 ::SendMessage(this->m_hWnd, TB_BUTTONSTRUCTSIZE, nSize, 0L);
5288 }
5289
SetButtonSize(SIZE size)5290 BOOL SetButtonSize(SIZE size)
5291 {
5292 ATLASSERT(::IsWindow(this->m_hWnd));
5293 return (BOOL)::SendMessage(this->m_hWnd, TB_SETBUTTONSIZE, 0, MAKELPARAM(size.cx, size.cy));
5294 }
5295
SetButtonSize(int cx,int cy)5296 BOOL SetButtonSize(int cx, int cy)
5297 {
5298 ATLASSERT(::IsWindow(this->m_hWnd));
5299 return (BOOL)::SendMessage(this->m_hWnd, TB_SETBUTTONSIZE, 0, MAKELPARAM(cx, cy));
5300 }
5301
SetBitmapSize(SIZE size)5302 BOOL SetBitmapSize(SIZE size)
5303 {
5304 ATLASSERT(::IsWindow(this->m_hWnd));
5305 return (BOOL)::SendMessage(this->m_hWnd, TB_SETBITMAPSIZE, 0, MAKELPARAM(size.cx, size.cy));
5306 }
5307
SetBitmapSize(int cx,int cy)5308 BOOL SetBitmapSize(int cx, int cy)
5309 {
5310 ATLASSERT(::IsWindow(this->m_hWnd));
5311 return (BOOL)::SendMessage(this->m_hWnd, TB_SETBITMAPSIZE, 0, MAKELPARAM(cx, cy));
5312 }
5313
GetToolTips()5314 CToolTipCtrl GetToolTips() const
5315 {
5316 ATLASSERT(::IsWindow(this->m_hWnd));
5317 return CToolTipCtrl((HWND)::SendMessage(this->m_hWnd, TB_GETTOOLTIPS, 0, 0L));
5318 }
5319
SetToolTips(HWND hWndToolTip)5320 void SetToolTips(HWND hWndToolTip)
5321 {
5322 ATLASSERT(::IsWindow(this->m_hWnd));
5323 ::SendMessage(this->m_hWnd, TB_SETTOOLTIPS, (WPARAM)hWndToolTip, 0L);
5324 }
5325
SetNotifyWnd(HWND hWnd)5326 void SetNotifyWnd(HWND hWnd)
5327 {
5328 ATLASSERT(::IsWindow(this->m_hWnd));
5329 ::SendMessage(this->m_hWnd, TB_SETPARENT, (WPARAM)hWnd, 0L);
5330 }
5331
GetRows()5332 int GetRows() const
5333 {
5334 ATLASSERT(::IsWindow(this->m_hWnd));
5335 return (int)::SendMessage(this->m_hWnd, TB_GETROWS, 0, 0L);
5336 }
5337
SetRows(int nRows,BOOL bLarger,LPRECT lpRect)5338 void SetRows(int nRows, BOOL bLarger, LPRECT lpRect)
5339 {
5340 ATLASSERT(::IsWindow(this->m_hWnd));
5341 ::SendMessage(this->m_hWnd, TB_SETROWS, MAKELPARAM(nRows, bLarger), (LPARAM)lpRect);
5342 }
5343
SetCmdID(int nIndex,UINT nID)5344 BOOL SetCmdID(int nIndex, UINT nID)
5345 {
5346 ATLASSERT(::IsWindow(this->m_hWnd));
5347 return (BOOL)::SendMessage(this->m_hWnd, TB_SETCMDID, nIndex, nID);
5348 }
5349
GetBitmapFlags()5350 DWORD GetBitmapFlags() const
5351 {
5352 ATLASSERT(::IsWindow(this->m_hWnd));
5353 return (DWORD)::SendMessage(this->m_hWnd, TB_GETBITMAPFLAGS, 0, 0L);
5354 }
5355
GetBitmap(int nID)5356 int GetBitmap(int nID) const
5357 {
5358 ATLASSERT(::IsWindow(this->m_hWnd));
5359 return (int)::SendMessage(this->m_hWnd, TB_GETBITMAP, nID, 0L);
5360 }
5361
GetButtonText(int nID,LPTSTR lpstrText)5362 int GetButtonText(int nID, LPTSTR lpstrText) const
5363 {
5364 ATLASSERT(::IsWindow(this->m_hWnd));
5365 return (int)::SendMessage(this->m_hWnd, TB_GETBUTTONTEXT, nID, (LPARAM)lpstrText);
5366 }
5367
5368 // nIndex - IE5 or higher only
5369 CImageList GetImageList(int nIndex = 0) const
5370 {
5371 ATLASSERT(::IsWindow(this->m_hWnd));
5372 return CImageList((HIMAGELIST)::SendMessage(this->m_hWnd, TB_GETIMAGELIST, nIndex, 0L));
5373 }
5374
5375 // nIndex - IE5 or higher only
5376 CImageList SetImageList(HIMAGELIST hImageList, int nIndex = 0)
5377 {
5378 ATLASSERT(::IsWindow(this->m_hWnd));
5379 return CImageList((HIMAGELIST)::SendMessage(this->m_hWnd, TB_SETIMAGELIST, nIndex, (LPARAM)hImageList));
5380 }
5381
5382 // nIndex - IE5 or higher only
5383 CImageList GetDisabledImageList(int nIndex = 0) const
5384 {
5385 ATLASSERT(::IsWindow(this->m_hWnd));
5386 return CImageList((HIMAGELIST)::SendMessage(this->m_hWnd, TB_GETDISABLEDIMAGELIST, nIndex, 0L));
5387 }
5388
5389 // nIndex - IE5 or higher only
5390 CImageList SetDisabledImageList(HIMAGELIST hImageList, int nIndex = 0)
5391 {
5392 ATLASSERT(::IsWindow(this->m_hWnd));
5393 return CImageList((HIMAGELIST)::SendMessage(this->m_hWnd, TB_SETDISABLEDIMAGELIST, nIndex, (LPARAM)hImageList));
5394 }
5395
5396 // nIndex - IE5 or higher only
5397 CImageList GetHotImageList(int nIndex = 0) const
5398 {
5399 ATLASSERT(::IsWindow(this->m_hWnd));
5400 return CImageList((HIMAGELIST)::SendMessage(this->m_hWnd, TB_GETHOTIMAGELIST, nIndex, 0L));
5401 }
5402
5403 // nIndex - IE5 or higher only
5404 CImageList SetHotImageList(HIMAGELIST hImageList, int nIndex = 0)
5405 {
5406 ATLASSERT(::IsWindow(this->m_hWnd));
5407 return CImageList((HIMAGELIST)::SendMessage(this->m_hWnd, TB_SETHOTIMAGELIST, nIndex, (LPARAM)hImageList));
5408 }
5409
GetStyle()5410 DWORD GetStyle() const
5411 {
5412 ATLASSERT(::IsWindow(this->m_hWnd));
5413 return (DWORD)::SendMessage(this->m_hWnd, TB_GETSTYLE, 0, 0L);
5414 }
5415
SetStyle(DWORD dwStyle)5416 void SetStyle(DWORD dwStyle)
5417 {
5418 ATLASSERT(::IsWindow(this->m_hWnd));
5419 ::SendMessage(this->m_hWnd, TB_SETSTYLE, 0, dwStyle);
5420 }
5421
GetButtonSize()5422 DWORD GetButtonSize() const
5423 {
5424 ATLASSERT(::IsWindow(this->m_hWnd));
5425 return (DWORD)::SendMessage(this->m_hWnd, TB_GETBUTTONSIZE, 0, 0L);
5426 }
5427
GetButtonSize(SIZE & size)5428 void GetButtonSize(SIZE& size) const
5429 {
5430 ATLASSERT(::IsWindow(this->m_hWnd));
5431 DWORD dwRet = (DWORD)::SendMessage(this->m_hWnd, TB_GETBUTTONSIZE, 0, 0L);
5432 size.cx = LOWORD(dwRet);
5433 size.cy = HIWORD(dwRet);
5434 }
5435
GetRect(int nID,LPRECT lpRect)5436 BOOL GetRect(int nID, LPRECT lpRect) const
5437 {
5438 ATLASSERT(::IsWindow(this->m_hWnd));
5439 return (BOOL)::SendMessage(this->m_hWnd, TB_GETRECT, nID, (LPARAM)lpRect);
5440 }
5441
GetTextRows()5442 int GetTextRows() const
5443 {
5444 ATLASSERT(::IsWindow(this->m_hWnd));
5445 return (int)::SendMessage(this->m_hWnd, TB_GETTEXTROWS, 0, 0L);
5446 }
5447
SetButtonWidth(int cxMin,int cxMax)5448 BOOL SetButtonWidth(int cxMin, int cxMax)
5449 {
5450 ATLASSERT(::IsWindow(this->m_hWnd));
5451 return (BOOL)::SendMessage(this->m_hWnd, TB_SETBUTTONWIDTH, 0, MAKELPARAM(cxMin, cxMax));
5452 }
5453
SetIndent(int nIndent)5454 BOOL SetIndent(int nIndent)
5455 {
5456 ATLASSERT(::IsWindow(this->m_hWnd));
5457 return (BOOL)::SendMessage(this->m_hWnd, TB_SETINDENT, nIndent, 0L);
5458 }
5459
SetMaxTextRows(int nMaxTextRows)5460 BOOL SetMaxTextRows(int nMaxTextRows)
5461 {
5462 ATLASSERT(::IsWindow(this->m_hWnd));
5463 return (BOOL)::SendMessage(this->m_hWnd, TB_SETMAXTEXTROWS, nMaxTextRows, 0L);
5464 }
5465
GetAnchorHighlight()5466 BOOL GetAnchorHighlight() const
5467 {
5468 ATLASSERT(::IsWindow(this->m_hWnd));
5469 return (BOOL)::SendMessage(this->m_hWnd, TB_GETANCHORHIGHLIGHT, 0, 0L);
5470 }
5471
5472 BOOL SetAnchorHighlight(BOOL bEnable = TRUE)
5473 {
5474 ATLASSERT(::IsWindow(this->m_hWnd));
5475 return (BOOL)::SendMessage(this->m_hWnd, TB_SETANCHORHIGHLIGHT, bEnable, 0L);
5476 }
5477
GetButtonInfo(int nID,LPTBBUTTONINFO lptbbi)5478 int GetButtonInfo(int nID, LPTBBUTTONINFO lptbbi) const
5479 {
5480 ATLASSERT(::IsWindow(this->m_hWnd));
5481 return (int)::SendMessage(this->m_hWnd, TB_GETBUTTONINFO, nID, (LPARAM)lptbbi);
5482 }
5483
SetButtonInfo(int nID,LPTBBUTTONINFO lptbbi)5484 BOOL SetButtonInfo(int nID, LPTBBUTTONINFO lptbbi)
5485 {
5486 ATLASSERT(::IsWindow(this->m_hWnd));
5487 return (BOOL)::SendMessage(this->m_hWnd, TB_SETBUTTONINFO, nID, (LPARAM)lptbbi);
5488 }
5489
SetButtonInfo(int nID,DWORD dwMask,BYTE Style,BYTE State,LPCTSTR lpszItem,int iImage,WORD cx,int iCommand,DWORD_PTR lParam)5490 BOOL SetButtonInfo(int nID, DWORD dwMask, BYTE Style, BYTE State, LPCTSTR lpszItem,
5491 int iImage, WORD cx, int iCommand, DWORD_PTR lParam)
5492 {
5493 ATLASSERT(::IsWindow(this->m_hWnd));
5494 TBBUTTONINFO tbbi = {};
5495 tbbi.cbSize = sizeof(TBBUTTONINFO);
5496 tbbi.dwMask = dwMask;
5497 tbbi.idCommand = iCommand;
5498 tbbi.iImage = iImage;
5499 tbbi.fsState = State;
5500 tbbi.fsStyle = Style;
5501 tbbi.cx = cx;
5502 tbbi.pszText = (LPTSTR) lpszItem;
5503 tbbi.lParam = lParam;
5504 return (BOOL)::SendMessage(this->m_hWnd, TB_SETBUTTONINFO, nID, (LPARAM)&tbbi);
5505 }
5506
GetHotItem()5507 int GetHotItem() const
5508 {
5509 ATLASSERT(::IsWindow(this->m_hWnd));
5510 return (int)::SendMessage(this->m_hWnd, TB_GETHOTITEM, 0, 0L);
5511 }
5512
SetHotItem(int nItem)5513 int SetHotItem(int nItem)
5514 {
5515 ATLASSERT(::IsWindow(this->m_hWnd));
5516 return (int)::SendMessage(this->m_hWnd, TB_SETHOTITEM, nItem, 0L);
5517 }
5518
IsButtonHighlighted(int nButtonID)5519 BOOL IsButtonHighlighted(int nButtonID) const
5520 {
5521 ATLASSERT(::IsWindow(this->m_hWnd));
5522 return (BOOL)::SendMessage(this->m_hWnd, TB_ISBUTTONHIGHLIGHTED, nButtonID, 0L);
5523 }
5524
SetDrawTextFlags(DWORD dwMask,DWORD dwFlags)5525 DWORD SetDrawTextFlags(DWORD dwMask, DWORD dwFlags)
5526 {
5527 ATLASSERT(::IsWindow(this->m_hWnd));
5528 return (DWORD)::SendMessage(this->m_hWnd, TB_SETDRAWTEXTFLAGS, dwMask, dwFlags);
5529 }
5530
GetColorScheme(LPCOLORSCHEME lpcs)5531 BOOL GetColorScheme(LPCOLORSCHEME lpcs) const
5532 {
5533 ATLASSERT(::IsWindow(this->m_hWnd));
5534 return (BOOL)::SendMessage(this->m_hWnd, TB_GETCOLORSCHEME, 0, (LPARAM)lpcs);
5535 }
5536
SetColorScheme(LPCOLORSCHEME lpcs)5537 void SetColorScheme(LPCOLORSCHEME lpcs)
5538 {
5539 ATLASSERT(::IsWindow(this->m_hWnd));
5540 ::SendMessage(this->m_hWnd, TB_SETCOLORSCHEME, 0, (LPARAM)lpcs);
5541 }
5542
GetExtendedStyle()5543 DWORD GetExtendedStyle() const
5544 {
5545 ATLASSERT(::IsWindow(this->m_hWnd));
5546 return (DWORD)::SendMessage(this->m_hWnd, TB_GETEXTENDEDSTYLE, 0, 0L);
5547 }
5548
SetExtendedStyle(DWORD dwStyle)5549 DWORD SetExtendedStyle(DWORD dwStyle)
5550 {
5551 ATLASSERT(::IsWindow(this->m_hWnd));
5552 return (DWORD)::SendMessage(this->m_hWnd, TB_SETEXTENDEDSTYLE, 0, dwStyle);
5553 }
5554
GetInsertMark(LPTBINSERTMARK lptbim)5555 void GetInsertMark(LPTBINSERTMARK lptbim) const
5556 {
5557 ATLASSERT(::IsWindow(this->m_hWnd));
5558 ::SendMessage(this->m_hWnd, TB_GETINSERTMARK, 0, (LPARAM)lptbim);
5559 }
5560
SetInsertMark(LPTBINSERTMARK lptbim)5561 void SetInsertMark(LPTBINSERTMARK lptbim)
5562 {
5563 ATLASSERT(::IsWindow(this->m_hWnd));
5564 ::SendMessage(this->m_hWnd, TB_SETINSERTMARK, 0, (LPARAM)lptbim);
5565 }
5566
GetInsertMarkColor()5567 COLORREF GetInsertMarkColor() const
5568 {
5569 ATLASSERT(::IsWindow(this->m_hWnd));
5570 return (COLORREF)::SendMessage(this->m_hWnd, TB_GETINSERTMARKCOLOR, 0, 0L);
5571 }
5572
SetInsertMarkColor(COLORREF clr)5573 COLORREF SetInsertMarkColor(COLORREF clr)
5574 {
5575 ATLASSERT(::IsWindow(this->m_hWnd));
5576 return (COLORREF)::SendMessage(this->m_hWnd, TB_SETINSERTMARKCOLOR, 0, (LPARAM)clr);
5577 }
5578
GetMaxSize(LPSIZE lpSize)5579 BOOL GetMaxSize(LPSIZE lpSize) const
5580 {
5581 ATLASSERT(::IsWindow(this->m_hWnd));
5582 return (BOOL)::SendMessage(this->m_hWnd, TB_GETMAXSIZE, 0, (LPARAM)lpSize);
5583 }
5584
GetPadding(LPSIZE lpSizePadding)5585 void GetPadding(LPSIZE lpSizePadding) const
5586 {
5587 ATLASSERT(::IsWindow(this->m_hWnd));
5588 ATLASSERT(lpSizePadding != NULL);
5589 DWORD dwRet = (DWORD)::SendMessage(this->m_hWnd, TB_GETPADDING, 0, 0L);
5590 lpSizePadding->cx = GET_X_LPARAM(dwRet);
5591 lpSizePadding->cy = GET_Y_LPARAM(dwRet);
5592 }
5593
5594 void SetPadding(int cx, int cy, LPSIZE lpSizePadding = NULL)
5595 {
5596 ATLASSERT(::IsWindow(this->m_hWnd));
5597 DWORD dwRet = (DWORD)::SendMessage(this->m_hWnd, TB_SETPADDING, 0, MAKELPARAM(cx, cy));
5598 if(lpSizePadding != NULL)
5599 {
5600 lpSizePadding->cx = GET_X_LPARAM(dwRet);
5601 lpSizePadding->cy = GET_Y_LPARAM(dwRet);
5602 }
5603 }
5604
GetUnicodeFormat()5605 BOOL GetUnicodeFormat() const
5606 {
5607 ATLASSERT(::IsWindow(this->m_hWnd));
5608 return (BOOL)::SendMessage(this->m_hWnd, TB_GETUNICODEFORMAT, 0, 0L);
5609 }
5610
5611 BOOL SetUnicodeFormat(BOOL bUnicode = TRUE)
5612 {
5613 ATLASSERT(::IsWindow(this->m_hWnd));
5614 return (BOOL)::SendMessage(this->m_hWnd, TB_SETUNICODEFORMAT, bUnicode, 0L);
5615 }
5616
GetString(int nString,LPTSTR lpstrString,int cchMaxLen)5617 int GetString(int nString, LPTSTR lpstrString, int cchMaxLen) const
5618 {
5619 ATLASSERT(::IsWindow(this->m_hWnd));
5620 return (int)::SendMessage(this->m_hWnd, TB_GETSTRING, MAKEWPARAM(cchMaxLen, nString), (LPARAM)lpstrString);
5621 }
5622
GetStringBSTR(int nString,BSTR & bstrString)5623 int GetStringBSTR(int nString, BSTR& bstrString) const
5624 {
5625 USES_CONVERSION;
5626 ATLASSERT(::IsWindow(this->m_hWnd));
5627 ATLASSERT(bstrString == NULL);
5628 int nLength = (int)(short)LOWORD(::SendMessage(this->m_hWnd, TB_GETSTRING, MAKEWPARAM(0, nString), NULL));
5629 if(nLength != -1)
5630 {
5631 ATL::CTempBuffer<TCHAR, _WTL_STACK_ALLOC_THRESHOLD> buff;
5632 LPTSTR lpstrText = buff.Allocate(nLength + 1);
5633 if(lpstrText != NULL)
5634 {
5635 nLength = (int)::SendMessage(this->m_hWnd, TB_GETSTRING, MAKEWPARAM(nLength + 1, nString), (LPARAM)lpstrText);
5636 if(nLength != -1)
5637 bstrString = ::SysAllocString(T2OLE(lpstrText));
5638 }
5639 else
5640 {
5641 nLength = -1;
5642 }
5643 }
5644
5645 return nLength;
5646 }
5647
5648 #ifdef __ATLSTR_H__
GetString(int nString,ATL::CString & str)5649 int GetString(int nString, ATL::CString& str) const
5650 {
5651 ATLASSERT(::IsWindow(this->m_hWnd));
5652 int nLength = (int)(short)LOWORD(::SendMessage(this->m_hWnd, TB_GETSTRING, MAKEWPARAM(0, nString), NULL));
5653 if(nLength != -1)
5654 {
5655 LPTSTR lpstr = str.GetBufferSetLength(nLength + 1);
5656 if(lpstr != NULL)
5657 nLength = (int)::SendMessage(this->m_hWnd, TB_GETSTRING, MAKEWPARAM(nLength + 1, nString), (LPARAM)lpstr);
5658 else
5659 nLength = -1;
5660 str.ReleaseBuffer();
5661 }
5662 return nLength;
5663 }
5664 #endif // __ATLSTR_H__
5665
GetMetrics(LPTBMETRICS lptbm)5666 void GetMetrics(LPTBMETRICS lptbm) const
5667 {
5668 ATLASSERT(::IsWindow(this->m_hWnd));
5669 ::SendMessage(this->m_hWnd, TB_GETMETRICS, 0, (LPARAM)lptbm);
5670 }
5671
SetMetrics(LPTBMETRICS lptbm)5672 void SetMetrics(LPTBMETRICS lptbm)
5673 {
5674 ATLASSERT(::IsWindow(this->m_hWnd));
5675 ::SendMessage(this->m_hWnd, TB_SETMETRICS, 0, (LPARAM)lptbm);
5676 }
5677
SetWindowTheme(LPCWSTR lpstrTheme)5678 void SetWindowTheme(LPCWSTR lpstrTheme)
5679 {
5680 ATLASSERT(::IsWindow(this->m_hWnd));
5681 ::SendMessage(this->m_hWnd, TB_SETWINDOWTHEME, 0, (LPARAM)lpstrTheme);
5682 }
5683
5684 #if (_WIN32_WINNT >= 0x0600)
5685 CImageList GetPressedImageList(int nIndex = 0) const
5686 {
5687 ATLASSERT(::IsWindow(this->m_hWnd));
5688 return CImageList((HIMAGELIST)::SendMessage(this->m_hWnd, TB_GETPRESSEDIMAGELIST, nIndex, 0L));
5689 }
5690
5691 CImageList SetPressedImageList(HIMAGELIST hImageList, int nIndex = 0)
5692 {
5693 ATLASSERT(::IsWindow(this->m_hWnd));
5694 return CImageList((HIMAGELIST)::SendMessage(this->m_hWnd, TB_SETPRESSEDIMAGELIST, nIndex, (LPARAM)hImageList));
5695 }
5696
GetItemDropDownRect(int nIndex,LPRECT lpRect)5697 void GetItemDropDownRect(int nIndex, LPRECT lpRect) const
5698 {
5699 #ifndef TB_GETITEMDROPDOWNRECT
5700 const int TB_GETITEMDROPDOWNRECT = WM_USER + 103;
5701 #endif
5702 ATLASSERT(::IsWindow(this->m_hWnd));
5703 BOOL bRet = (BOOL)::SendMessage(this->m_hWnd, TB_GETITEMDROPDOWNRECT, nIndex, (LPARAM)lpRect);
5704 (void)bRet; // avoid level 4 warning
5705 ATLASSERT(bRet != FALSE);
5706 }
5707 #endif // (_WIN32_WINNT >= 0x0600)
5708
5709 // Operations
5710 BOOL EnableButton(int nID, BOOL bEnable = TRUE)
5711 {
5712 ATLASSERT(::IsWindow(this->m_hWnd));
5713 return (BOOL)::SendMessage(this->m_hWnd, TB_ENABLEBUTTON, nID, MAKELPARAM(bEnable, 0));
5714 }
5715
5716 BOOL CheckButton(int nID, BOOL bCheck = TRUE)
5717 {
5718 ATLASSERT(::IsWindow(this->m_hWnd));
5719 return (BOOL)::SendMessage(this->m_hWnd, TB_CHECKBUTTON, nID, MAKELPARAM(bCheck, 0));
5720 }
5721
5722 BOOL PressButton(int nID, BOOL bPress = TRUE)
5723 {
5724 ATLASSERT(::IsWindow(this->m_hWnd));
5725 return (BOOL)::SendMessage(this->m_hWnd, TB_PRESSBUTTON, nID, MAKELPARAM(bPress, 0));
5726 }
5727
5728 BOOL HideButton(int nID, BOOL bHide = TRUE)
5729 {
5730 ATLASSERT(::IsWindow(this->m_hWnd));
5731 return (BOOL)::SendMessage(this->m_hWnd, TB_HIDEBUTTON, nID, MAKELPARAM(bHide, 0));
5732 }
5733
5734 BOOL Indeterminate(int nID, BOOL bIndeterminate = TRUE)
5735 {
5736 ATLASSERT(::IsWindow(this->m_hWnd));
5737 return (BOOL)::SendMessage(this->m_hWnd, TB_INDETERMINATE, nID, MAKELPARAM(bIndeterminate, 0));
5738 }
5739
AddBitmap(int nNumButtons,UINT nBitmapID)5740 int AddBitmap(int nNumButtons, UINT nBitmapID)
5741 {
5742 ATLASSERT(::IsWindow(this->m_hWnd));
5743 TBADDBITMAP tbab = {};
5744 tbab.hInst = ModuleHelper::GetResourceInstance();
5745 ATLASSERT(tbab.hInst != NULL);
5746 tbab.nID = nBitmapID;
5747 return (int)::SendMessage(this->m_hWnd, TB_ADDBITMAP, (WPARAM)nNumButtons, (LPARAM)&tbab);
5748 }
5749
AddBitmap(int nNumButtons,HBITMAP hBitmap)5750 int AddBitmap(int nNumButtons, HBITMAP hBitmap)
5751 {
5752 ATLASSERT(::IsWindow(this->m_hWnd));
5753 TBADDBITMAP tbab = {};
5754 tbab.hInst = NULL;
5755 tbab.nID = (UINT_PTR)hBitmap;
5756 return (int)::SendMessage(this->m_hWnd, TB_ADDBITMAP, (WPARAM)nNumButtons, (LPARAM)&tbab);
5757 }
5758
AddButtons(int nNumButtons,LPCTBBUTTON lpButtons)5759 BOOL AddButtons(int nNumButtons, LPCTBBUTTON lpButtons)
5760 {
5761 ATLASSERT(::IsWindow(this->m_hWnd));
5762 return (BOOL)::SendMessage(this->m_hWnd, TB_ADDBUTTONS, nNumButtons, (LPARAM)lpButtons);
5763 }
5764
InsertButton(int nIndex,LPCTBBUTTON lpButton)5765 BOOL InsertButton(int nIndex, LPCTBBUTTON lpButton)
5766 {
5767 ATLASSERT(::IsWindow(this->m_hWnd));
5768 return (BOOL)::SendMessage(this->m_hWnd, TB_INSERTBUTTON, nIndex, (LPARAM)lpButton);
5769 }
5770
InsertButton(int nIndex,int iCommand,BYTE Style,BYTE State,int iBitmap,INT_PTR iString,DWORD_PTR lParam)5771 BOOL InsertButton(int nIndex, int iCommand, BYTE Style, BYTE State, int iBitmap,
5772 INT_PTR iString, DWORD_PTR lParam)
5773 {
5774 ATLASSERT(::IsWindow(this->m_hWnd));
5775 TBBUTTON tbb = {};
5776 tbb.fsStyle = Style;
5777 tbb.fsState = State;
5778 tbb.idCommand = iCommand;
5779 tbb.iBitmap = iBitmap;
5780 tbb.iString = iString;
5781 tbb.dwData = lParam;
5782 return (BOOL)::SendMessage(this->m_hWnd, TB_INSERTBUTTON, nIndex, (LPARAM)&tbb);
5783 }
5784
InsertButton(int nIndex,int iCommand,BYTE Style,BYTE State,int iBitmap,LPCTSTR lpszItem,DWORD_PTR lParam)5785 BOOL InsertButton(int nIndex, int iCommand, BYTE Style, BYTE State, int iBitmap,
5786 LPCTSTR lpszItem, DWORD_PTR lParam)
5787 {
5788 return InsertButton(nIndex, iCommand, Style, State, iBitmap, (INT_PTR)lpszItem, lParam);
5789 }
5790
AddButton(LPTBBUTTON lpButton)5791 BOOL AddButton(LPTBBUTTON lpButton)
5792 {
5793 return InsertButton(-1, lpButton);
5794 }
5795
AddButton(int iCommand,BYTE Style,BYTE State,int iBitmap,INT_PTR iString,DWORD_PTR lParam)5796 BOOL AddButton(int iCommand, BYTE Style, BYTE State, int iBitmap, INT_PTR iString, DWORD_PTR lParam)
5797 {
5798 return InsertButton(-1, iCommand, Style, State, iBitmap, iString, lParam);
5799 }
5800
AddButton(int iCommand,BYTE Style,BYTE State,int iBitmap,LPCTSTR lpszItem,DWORD_PTR lParam)5801 BOOL AddButton(int iCommand, BYTE Style, BYTE State, int iBitmap, LPCTSTR lpszItem, DWORD_PTR lParam)
5802 {
5803 return InsertButton(-1, iCommand, Style, State, iBitmap, lpszItem, lParam);
5804 }
5805
DeleteButton(int nIndex)5806 BOOL DeleteButton(int nIndex)
5807 {
5808 ATLASSERT(::IsWindow(this->m_hWnd));
5809 return (BOOL)::SendMessage(this->m_hWnd, TB_DELETEBUTTON, nIndex, 0L);
5810 }
5811
5812 BOOL InsertSeparator(int nIndex, int cxWidth = 8)
5813 {
5814 return InsertButton(nIndex, 0, BTNS_SEP, 0, cxWidth, (INT_PTR)0, 0);
5815 }
5816
5817 BOOL AddSeparator(int cxWidth = 8)
5818 {
5819 return AddButton(0, BTNS_SEP, 0, cxWidth, (INT_PTR)0, 0);
5820 }
5821
CommandToIndex(UINT nID)5822 int CommandToIndex(UINT nID) const
5823 {
5824 ATLASSERT(::IsWindow(this->m_hWnd));
5825 return (int)::SendMessage(this->m_hWnd, TB_COMMANDTOINDEX, nID, 0L);
5826 }
5827
SaveState(HKEY hKeyRoot,LPCTSTR lpszSubKey,LPCTSTR lpszValueName)5828 void SaveState(HKEY hKeyRoot, LPCTSTR lpszSubKey, LPCTSTR lpszValueName)
5829 {
5830 ATLASSERT(::IsWindow(this->m_hWnd));
5831 TBSAVEPARAMS tbs = {};
5832 tbs.hkr = hKeyRoot;
5833 tbs.pszSubKey = lpszSubKey;
5834 tbs.pszValueName = lpszValueName;
5835 ::SendMessage(this->m_hWnd, TB_SAVERESTORE, (WPARAM)TRUE, (LPARAM)&tbs);
5836 }
5837
RestoreState(HKEY hKeyRoot,LPCTSTR lpszSubKey,LPCTSTR lpszValueName)5838 void RestoreState(HKEY hKeyRoot, LPCTSTR lpszSubKey, LPCTSTR lpszValueName)
5839 {
5840 ATLASSERT(::IsWindow(this->m_hWnd));
5841 TBSAVEPARAMS tbs = {};
5842 tbs.hkr = hKeyRoot;
5843 tbs.pszSubKey = lpszSubKey;
5844 tbs.pszValueName = lpszValueName;
5845 ::SendMessage(this->m_hWnd, TB_SAVERESTORE, (WPARAM)FALSE, (LPARAM)&tbs);
5846 }
5847
Customize()5848 void Customize()
5849 {
5850 ATLASSERT(::IsWindow(this->m_hWnd));
5851 ::SendMessage(this->m_hWnd, TB_CUSTOMIZE, 0, 0L);
5852 }
5853
AddString(UINT nStringID)5854 int AddString(UINT nStringID)
5855 {
5856 ATLASSERT(::IsWindow(this->m_hWnd));
5857 return (int)::SendMessage(this->m_hWnd, TB_ADDSTRING, (WPARAM)ModuleHelper::GetResourceInstance(), (LPARAM)nStringID);
5858 }
5859
AddStrings(LPCTSTR lpszStrings)5860 int AddStrings(LPCTSTR lpszStrings)
5861 {
5862 ATLASSERT(::IsWindow(this->m_hWnd));
5863 return (int)::SendMessage(this->m_hWnd, TB_ADDSTRING, 0, (LPARAM)lpszStrings);
5864 }
5865
AutoSize()5866 void AutoSize()
5867 {
5868 ATLASSERT(::IsWindow(this->m_hWnd));
5869 ::SendMessage(this->m_hWnd, TB_AUTOSIZE, 0, 0L);
5870 }
5871
ChangeBitmap(int nID,int nBitmap)5872 BOOL ChangeBitmap(int nID, int nBitmap)
5873 {
5874 ATLASSERT(::IsWindow(this->m_hWnd));
5875 return (BOOL)::SendMessage(this->m_hWnd, TB_CHANGEBITMAP, nID, MAKELPARAM(nBitmap, 0));
5876 }
5877
LoadImages(int nBitmapID)5878 int LoadImages(int nBitmapID)
5879 {
5880 ATLASSERT(::IsWindow(this->m_hWnd));
5881 return (int)::SendMessage(this->m_hWnd, TB_LOADIMAGES, nBitmapID, (LPARAM)ModuleHelper::GetResourceInstance());
5882 }
5883
LoadStdImages(int nBitmapID)5884 int LoadStdImages(int nBitmapID)
5885 {
5886 ATLASSERT(::IsWindow(this->m_hWnd));
5887 return (int)::SendMessage(this->m_hWnd, TB_LOADIMAGES, nBitmapID, (LPARAM)HINST_COMMCTRL);
5888 }
5889
ReplaceBitmap(LPTBREPLACEBITMAP ptbrb)5890 BOOL ReplaceBitmap(LPTBREPLACEBITMAP ptbrb)
5891 {
5892 ATLASSERT(::IsWindow(this->m_hWnd));
5893 return (BOOL)::SendMessage(this->m_hWnd, TB_REPLACEBITMAP, 0, (LPARAM)ptbrb);
5894 }
5895
HitTest(LPPOINT lpPoint)5896 int HitTest(LPPOINT lpPoint) const
5897 {
5898 ATLASSERT(::IsWindow(this->m_hWnd));
5899 return (int)::SendMessage(this->m_hWnd, TB_HITTEST, 0, (LPARAM)lpPoint);
5900 }
5901
InsertMarkHitTest(LPPOINT lpPoint,LPTBINSERTMARK lptbim)5902 BOOL InsertMarkHitTest(LPPOINT lpPoint, LPTBINSERTMARK lptbim) const
5903 {
5904 ATLASSERT(::IsWindow(this->m_hWnd));
5905 return (BOOL)::SendMessage(this->m_hWnd, TB_INSERTMARKHITTEST, (WPARAM)lpPoint, (LPARAM)lptbim);
5906 }
5907
InsertMarkHitTest(int x,int y,LPTBINSERTMARK lptbim)5908 BOOL InsertMarkHitTest(int x, int y, LPTBINSERTMARK lptbim) const
5909 {
5910 ATLASSERT(::IsWindow(this->m_hWnd));
5911 POINT pt = { x, y };
5912 return (BOOL)::SendMessage(this->m_hWnd, TB_INSERTMARKHITTEST, (WPARAM)&pt, (LPARAM)lptbim);
5913 }
5914
MapAccelerator(TCHAR chAccel,int & nID)5915 BOOL MapAccelerator(TCHAR chAccel, int& nID) const
5916 {
5917 ATLASSERT(::IsWindow(this->m_hWnd));
5918 return (BOOL)::SendMessage(this->m_hWnd, TB_MAPACCELERATOR, (WPARAM)chAccel, (LPARAM)&nID);
5919 }
5920
5921 BOOL MarkButton(int nID, BOOL bHighlight = TRUE)
5922 {
5923 ATLASSERT(::IsWindow(this->m_hWnd));
5924 return (BOOL)::SendMessage(this->m_hWnd, TB_MARKBUTTON, nID, MAKELPARAM(bHighlight, 0));
5925 }
5926
MoveButton(int nOldPos,int nNewPos)5927 BOOL MoveButton(int nOldPos, int nNewPos)
5928 {
5929 ATLASSERT(::IsWindow(this->m_hWnd));
5930 return (BOOL)::SendMessage(this->m_hWnd, TB_MOVEBUTTON, nOldPos, nNewPos);
5931 }
5932
GetObject(REFIID iid,LPVOID * ppvObject)5933 HRESULT GetObject(REFIID iid, LPVOID* ppvObject)
5934 {
5935 ATLASSERT(::IsWindow(this->m_hWnd));
5936 return (HRESULT)::SendMessage(this->m_hWnd, TB_GETOBJECT, (WPARAM)&iid, (LPARAM)ppvObject);
5937 }
5938 };
5939
5940 typedef CToolBarCtrlT<ATL::CWindow> CToolBarCtrl;
5941
5942
5943 ///////////////////////////////////////////////////////////////////////////////
5944 // CStatusBarCtrl
5945
5946 template <class TBase>
5947 class CStatusBarCtrlT : public TBase
5948 {
5949 public:
5950 // Constructors
TBase(hWnd)5951 CStatusBarCtrlT(HWND hWnd = NULL) : TBase(hWnd)
5952 { }
5953
5954 CStatusBarCtrlT< TBase >& operator =(HWND hWnd)
5955 {
5956 this->m_hWnd = hWnd;
5957 return *this;
5958 }
5959
5960 HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
5961 DWORD dwStyle = 0, DWORD dwExStyle = 0,
5962 ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
5963 {
5964 return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
5965 }
5966
5967 // Methods
GetWndClassName()5968 static LPCTSTR GetWndClassName()
5969 {
5970 return STATUSCLASSNAME;
5971 }
5972
GetParts(int nParts,int * pParts)5973 int GetParts(int nParts, int* pParts) const
5974 {
5975 ATLASSERT(::IsWindow(this->m_hWnd));
5976 return (int)::SendMessage(this->m_hWnd, SB_GETPARTS, nParts, (LPARAM)pParts);
5977 }
5978
SetParts(int nParts,int * pWidths)5979 BOOL SetParts(int nParts, int* pWidths)
5980 {
5981 ATLASSERT(::IsWindow(this->m_hWnd));
5982 return (BOOL)::SendMessage(this->m_hWnd, SB_SETPARTS, nParts, (LPARAM)pWidths);
5983 }
5984
5985 int GetTextLength(int nPane, int* pType = NULL) const
5986 {
5987 ATLASSERT(::IsWindow(this->m_hWnd));
5988 ATLASSERT(nPane < 256);
5989 DWORD dwRet = (DWORD)::SendMessage(this->m_hWnd, SB_GETTEXTLENGTH, (WPARAM)nPane, 0L);
5990 if (pType != NULL)
5991 *pType = (int)(short)HIWORD(dwRet);
5992 return (int)(short)LOWORD(dwRet);
5993 }
5994
5995 int GetText(int nPane, LPTSTR lpszText, int* pType = NULL) const
5996 {
5997 ATLASSERT(::IsWindow(this->m_hWnd));
5998 ATLASSERT(nPane < 256);
5999 DWORD dwRet = (DWORD)::SendMessage(this->m_hWnd, SB_GETTEXT, (WPARAM)nPane, (LPARAM)lpszText);
6000 if(pType != NULL)
6001 *pType = (int)(short)HIWORD(dwRet);
6002 return (int)(short)LOWORD(dwRet);
6003 }
6004
6005 BOOL GetTextBSTR(int nPane, BSTR& bstrText, int* pType = NULL) const
6006 {
6007 USES_CONVERSION;
6008 ATLASSERT(::IsWindow(this->m_hWnd));
6009 ATLASSERT(nPane < 256);
6010 ATLASSERT(bstrText == NULL);
6011 int nLength = (int)(short)LOWORD(::SendMessage(this->m_hWnd, SB_GETTEXTLENGTH, (WPARAM)nPane, 0L));
6012 if(nLength == 0)
6013 return FALSE;
6014
6015 ATL::CTempBuffer<TCHAR, _WTL_STACK_ALLOC_THRESHOLD> buff;
6016 LPTSTR lpstrText = buff.Allocate(nLength + 1);
6017 if(lpstrText == NULL)
6018 return FALSE;
6019
6020 if(!GetText(nPane, lpstrText, pType))
6021 return FALSE;
6022
6023 bstrText = ::SysAllocString(T2OLE(lpstrText));
6024 return (bstrText != NULL) ? TRUE : FALSE;
6025 }
6026
6027 #ifdef __ATLSTR_H__
6028 int GetText(int nPane, ATL::CString& strText, int* pType = NULL) const
6029 {
6030 ATLASSERT(::IsWindow(this->m_hWnd));
6031 ATLASSERT(nPane < 256);
6032 int nLength = (int)(short)LOWORD(::SendMessage(this->m_hWnd, SB_GETTEXTLENGTH, (WPARAM)nPane, 0L));
6033 if(nLength == 0)
6034 return 0;
6035
6036 LPTSTR lpstr = strText.GetBufferSetLength(nLength);
6037 if(lpstr == NULL)
6038 return 0;
6039 return GetText(nPane, lpstr, pType);
6040 }
6041 #endif // __ATLSTR_H__
6042
6043 BOOL SetText(int nPane, LPCTSTR lpszText, int nType = 0)
6044 {
6045 ATLASSERT(::IsWindow(this->m_hWnd));
6046 ATLASSERT(nPane < 256);
6047 return (BOOL)::SendMessage(this->m_hWnd, SB_SETTEXT, (nPane | nType), (LPARAM)lpszText);
6048 }
6049
GetRect(int nPane,LPRECT lpRect)6050 BOOL GetRect(int nPane, LPRECT lpRect) const
6051 {
6052 ATLASSERT(::IsWindow(this->m_hWnd));
6053 ATLASSERT(nPane < 256);
6054 return (BOOL)::SendMessage(this->m_hWnd, SB_GETRECT, nPane, (LPARAM)lpRect);
6055 }
6056
GetBorders(int * pBorders)6057 BOOL GetBorders(int* pBorders) const
6058 {
6059 ATLASSERT(::IsWindow(this->m_hWnd));
6060 return (BOOL)::SendMessage(this->m_hWnd, SB_GETBORDERS, 0, (LPARAM)pBorders);
6061 }
6062
GetBorders(int & nHorz,int & nVert,int & nSpacing)6063 BOOL GetBorders(int& nHorz, int& nVert, int& nSpacing) const
6064 {
6065 ATLASSERT(::IsWindow(this->m_hWnd));
6066 int borders[3] = {};
6067 BOOL bResult = (BOOL)::SendMessage(this->m_hWnd, SB_GETBORDERS, 0, (LPARAM)&borders);
6068 if(bResult)
6069 {
6070 nHorz = borders[0];
6071 nVert = borders[1];
6072 nSpacing = borders[2];
6073 }
6074 return bResult;
6075 }
6076
SetMinHeight(int nMin)6077 void SetMinHeight(int nMin)
6078 {
6079 ATLASSERT(::IsWindow(this->m_hWnd));
6080 ::SendMessage(this->m_hWnd, SB_SETMINHEIGHT, nMin, 0L);
6081 }
6082
6083 BOOL SetSimple(BOOL bSimple = TRUE)
6084 {
6085 ATLASSERT(::IsWindow(this->m_hWnd));
6086 return (BOOL)::SendMessage(this->m_hWnd, SB_SIMPLE, bSimple, 0L);
6087 }
6088
IsSimple()6089 BOOL IsSimple() const
6090 {
6091 ATLASSERT(::IsWindow(this->m_hWnd));
6092 return (BOOL)::SendMessage(this->m_hWnd, SB_ISSIMPLE, 0, 0L);
6093 }
6094
GetUnicodeFormat()6095 BOOL GetUnicodeFormat() const
6096 {
6097 ATLASSERT(::IsWindow(this->m_hWnd));
6098 return (BOOL)::SendMessage(this->m_hWnd, SB_GETUNICODEFORMAT, 0, 0L);
6099 }
6100
6101 BOOL SetUnicodeFormat(BOOL bUnicode = TRUE)
6102 {
6103 ATLASSERT(::IsWindow(this->m_hWnd));
6104 return (BOOL)::SendMessage(this->m_hWnd, SB_SETUNICODEFORMAT, bUnicode, 0L);
6105 }
6106
GetTipText(int nPane,LPTSTR lpstrText,int nSize)6107 void GetTipText(int nPane, LPTSTR lpstrText, int nSize) const
6108 {
6109 ATLASSERT(::IsWindow(this->m_hWnd));
6110 ATLASSERT(nPane < 256);
6111 ::SendMessage(this->m_hWnd, SB_GETTIPTEXT, MAKEWPARAM(nPane, nSize), (LPARAM)lpstrText);
6112 }
6113
SetTipText(int nPane,LPCTSTR lpstrText)6114 void SetTipText(int nPane, LPCTSTR lpstrText)
6115 {
6116 ATLASSERT(::IsWindow(this->m_hWnd));
6117 ATLASSERT(nPane < 256);
6118 ::SendMessage(this->m_hWnd, SB_SETTIPTEXT, nPane, (LPARAM)lpstrText);
6119 }
6120
SetBkColor(COLORREF clrBk)6121 COLORREF SetBkColor(COLORREF clrBk)
6122 {
6123 ATLASSERT(::IsWindow(this->m_hWnd));
6124 return (COLORREF)::SendMessage(this->m_hWnd, SB_SETBKCOLOR, 0, (LPARAM)clrBk);
6125 }
6126
GetIcon(int nPane)6127 HICON GetIcon(int nPane) const
6128 {
6129 ATLASSERT(::IsWindow(this->m_hWnd));
6130 ATLASSERT(nPane < 256);
6131 return (HICON)::SendMessage(this->m_hWnd, SB_GETICON, nPane, 0L);
6132 }
6133
SetIcon(int nPane,HICON hIcon)6134 BOOL SetIcon(int nPane, HICON hIcon)
6135 {
6136 ATLASSERT(::IsWindow(this->m_hWnd));
6137 ATLASSERT(nPane < 256);
6138 return (BOOL)::SendMessage(this->m_hWnd, SB_SETICON, nPane, (LPARAM)hIcon);
6139 }
6140 };
6141
6142 typedef CStatusBarCtrlT<ATL::CWindow> CStatusBarCtrl;
6143
6144
6145 ///////////////////////////////////////////////////////////////////////////////
6146 // CTabCtrl
6147
6148 template <class TBase>
6149 class CTabCtrlT : public TBase
6150 {
6151 public:
6152 // Constructors
TBase(hWnd)6153 CTabCtrlT(HWND hWnd = NULL) : TBase(hWnd)
6154 { }
6155
6156 CTabCtrlT< TBase >& operator =(HWND hWnd)
6157 {
6158 this->m_hWnd = hWnd;
6159 return *this;
6160 }
6161
6162 HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
6163 DWORD dwStyle = 0, DWORD dwExStyle = 0,
6164 ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
6165 {
6166 return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
6167 }
6168
6169 // Attributes
GetWndClassName()6170 static LPCTSTR GetWndClassName()
6171 {
6172 return WC_TABCONTROL;
6173 }
6174
GetImageList()6175 CImageList GetImageList() const
6176 {
6177 ATLASSERT(::IsWindow(this->m_hWnd));
6178 return CImageList((HIMAGELIST)::SendMessage(this->m_hWnd, TCM_GETIMAGELIST, 0, 0L));
6179 }
6180
SetImageList(HIMAGELIST hImageList)6181 CImageList SetImageList(HIMAGELIST hImageList)
6182 {
6183 ATLASSERT(::IsWindow(this->m_hWnd));
6184 return CImageList((HIMAGELIST)::SendMessage(this->m_hWnd, TCM_SETIMAGELIST, 0, (LPARAM)hImageList));
6185 }
6186
GetItemCount()6187 int GetItemCount() const
6188 {
6189 ATLASSERT(::IsWindow(this->m_hWnd));
6190 return (int)::SendMessage(this->m_hWnd, TCM_GETITEMCOUNT, 0, 0L);
6191 }
6192
GetItem(int nItem,LPTCITEM pTabCtrlItem)6193 BOOL GetItem(int nItem, LPTCITEM pTabCtrlItem) const
6194 {
6195 ATLASSERT(::IsWindow(this->m_hWnd));
6196 return (BOOL)::SendMessage(this->m_hWnd, TCM_GETITEM, nItem, (LPARAM)pTabCtrlItem);
6197 }
6198
SetItem(int nItem,LPTCITEM pTabCtrlItem)6199 BOOL SetItem(int nItem, LPTCITEM pTabCtrlItem)
6200 {
6201 ATLASSERT(::IsWindow(this->m_hWnd));
6202 return (BOOL)::SendMessage(this->m_hWnd, TCM_SETITEM, nItem, (LPARAM)pTabCtrlItem);
6203 }
6204
SetItem(int nItem,UINT mask,LPCTSTR lpszItem,DWORD dwState,DWORD dwStateMask,int iImage,LPARAM lParam)6205 int SetItem(int nItem, UINT mask, LPCTSTR lpszItem, DWORD dwState, DWORD dwStateMask, int iImage, LPARAM lParam)
6206 {
6207 ATLASSERT(::IsWindow(this->m_hWnd));
6208 TCITEM tci = {};
6209 tci.mask = mask;
6210 tci.pszText = (LPTSTR) lpszItem;
6211 tci.dwState = dwState;
6212 tci.dwStateMask = dwStateMask;
6213 tci.iImage = iImage;
6214 tci.lParam = lParam;
6215 return (int)::SendMessage(this->m_hWnd, TCM_SETITEM, nItem, (LPARAM)&tci);
6216 }
6217
GetItemRect(int nItem,LPRECT lpRect)6218 BOOL GetItemRect(int nItem, LPRECT lpRect) const
6219 {
6220 ATLASSERT(::IsWindow(this->m_hWnd));
6221 return (BOOL)::SendMessage(this->m_hWnd, TCM_GETITEMRECT, nItem, (LPARAM)lpRect);
6222 }
6223
GetCurSel()6224 int GetCurSel() const
6225 {
6226 ATLASSERT(::IsWindow(this->m_hWnd));
6227 return (int)::SendMessage(this->m_hWnd, TCM_GETCURSEL, 0, 0L);
6228 }
6229
SetCurSel(int nItem)6230 int SetCurSel(int nItem)
6231 {
6232 ATLASSERT(::IsWindow(this->m_hWnd));
6233 return (int)::SendMessage(this->m_hWnd, TCM_SETCURSEL, nItem, 0L);
6234 }
6235
SetItemSize(SIZE size)6236 SIZE SetItemSize(SIZE size)
6237 {
6238 ATLASSERT(::IsWindow(this->m_hWnd));
6239 DWORD dwSize = (DWORD)::SendMessage(this->m_hWnd, TCM_SETITEMSIZE, 0, MAKELPARAM(size.cx, size.cy));
6240 SIZE sizeRet = { GET_X_LPARAM(dwSize), GET_Y_LPARAM(dwSize) };
6241 return sizeRet;
6242 }
6243
SetItemSize(int cx,int cy)6244 void SetItemSize(int cx, int cy)
6245 {
6246 ATLASSERT(::IsWindow(this->m_hWnd));
6247 ::SendMessage(this->m_hWnd, TCM_SETITEMSIZE, 0, MAKELPARAM(cx, cy));
6248 }
6249
SetPadding(SIZE size)6250 void SetPadding(SIZE size)
6251 {
6252 ATLASSERT(::IsWindow(this->m_hWnd));
6253 ::SendMessage(this->m_hWnd, TCM_SETPADDING, 0, MAKELPARAM(size.cx, size.cy));
6254 }
6255
GetRowCount()6256 int GetRowCount() const
6257 {
6258 ATLASSERT(::IsWindow(this->m_hWnd));
6259 return (int)::SendMessage(this->m_hWnd, TCM_GETROWCOUNT, 0, 0L);
6260 }
6261
GetToolTips()6262 CToolTipCtrl GetToolTips() const
6263 {
6264 ATLASSERT(::IsWindow(this->m_hWnd));
6265 return CToolTipCtrl((HWND)::SendMessage(this->m_hWnd, TCM_GETTOOLTIPS, 0, 0L));
6266 }
6267
6268 // this method is deprecated, please use GetToolTips
GetTooltips()6269 CToolTipCtrl GetTooltips() const { return GetToolTips(); }
6270
SetToolTips(HWND hWndToolTip)6271 void SetToolTips(HWND hWndToolTip)
6272 {
6273 ATLASSERT(::IsWindow(this->m_hWnd));
6274 ::SendMessage(this->m_hWnd, TCM_SETTOOLTIPS, (WPARAM)hWndToolTip, 0L);
6275 }
6276
6277 // this method is deprecated, please use SetToolTips
SetTooltips(HWND hWndToolTip)6278 void SetTooltips(HWND hWndToolTip) { SetToolTips(hWndToolTip); }
6279
GetCurFocus()6280 int GetCurFocus() const
6281 {
6282 ATLASSERT(::IsWindow(this->m_hWnd));
6283 return (int)::SendMessage(this->m_hWnd, TCM_GETCURFOCUS, 0, 0L);
6284 }
6285
SetCurFocus(int nItem)6286 void SetCurFocus(int nItem)
6287 {
6288 ATLASSERT(::IsWindow(this->m_hWnd));
6289 ::SendMessage(this->m_hWnd, TCM_SETCURFOCUS, nItem, 0L);
6290 }
6291
SetItemExtra(int cbExtra)6292 BOOL SetItemExtra(int cbExtra)
6293 {
6294 ATLASSERT(::IsWindow(this->m_hWnd));
6295 ATLASSERT(GetItemCount() == 0); // must be empty
6296 return (BOOL)::SendMessage(this->m_hWnd, TCM_SETITEMEXTRA, cbExtra, 0L);
6297 }
6298
6299 int SetMinTabWidth(int nWidth = -1)
6300 {
6301 ATLASSERT(::IsWindow(this->m_hWnd));
6302 return (int)::SendMessage(this->m_hWnd, TCM_SETMINTABWIDTH, 0, nWidth);
6303 }
6304
GetExtendedStyle()6305 DWORD GetExtendedStyle() const
6306 {
6307 ATLASSERT(::IsWindow(this->m_hWnd));
6308 return (DWORD)::SendMessage(this->m_hWnd, TCM_GETEXTENDEDSTYLE, 0, 0L);
6309 }
6310
SetExtendedStyle(DWORD dwExMask,DWORD dwExStyle)6311 DWORD SetExtendedStyle(DWORD dwExMask, DWORD dwExStyle)
6312 {
6313 ATLASSERT(::IsWindow(this->m_hWnd));
6314 return (DWORD)::SendMessage(this->m_hWnd, TCM_SETEXTENDEDSTYLE, dwExMask, dwExStyle);
6315 }
6316
GetUnicodeFormat()6317 BOOL GetUnicodeFormat() const
6318 {
6319 ATLASSERT(::IsWindow(this->m_hWnd));
6320 return (BOOL)::SendMessage(this->m_hWnd, TCM_GETUNICODEFORMAT, 0, 0L);
6321 }
6322
6323 BOOL SetUnicodeFormat(BOOL bUnicode = TRUE)
6324 {
6325 ATLASSERT(::IsWindow(this->m_hWnd));
6326 return (BOOL)::SendMessage(this->m_hWnd, TCM_SETUNICODEFORMAT, bUnicode, 0L);
6327 }
6328
6329 // Operations
InsertItem(int nItem,LPTCITEM pTabCtrlItem)6330 int InsertItem(int nItem, LPTCITEM pTabCtrlItem)
6331 {
6332 ATLASSERT(::IsWindow(this->m_hWnd));
6333 return (int)::SendMessage(this->m_hWnd, TCM_INSERTITEM, nItem, (LPARAM)pTabCtrlItem);
6334 }
6335
InsertItem(int nItem,UINT mask,LPCTSTR lpszItem,int iImage,LPARAM lParam)6336 int InsertItem(int nItem, UINT mask, LPCTSTR lpszItem, int iImage, LPARAM lParam)
6337 {
6338 ATLASSERT(::IsWindow(this->m_hWnd));
6339 TCITEM tci = {};
6340 tci.mask = mask;
6341 tci.pszText = (LPTSTR) lpszItem;
6342 tci.iImage = iImage;
6343 tci.lParam = lParam;
6344 return (int)::SendMessage(this->m_hWnd, TCM_INSERTITEM, nItem, (LPARAM)&tci);
6345 }
6346
InsertItem(int nItem,LPCTSTR lpszItem)6347 int InsertItem(int nItem, LPCTSTR lpszItem)
6348 {
6349 ATLASSERT(::IsWindow(this->m_hWnd));
6350 TCITEM tci = {};
6351 tci.mask = TCIF_TEXT;
6352 tci.pszText = (LPTSTR) lpszItem;
6353 return (int)::SendMessage(this->m_hWnd, TCM_INSERTITEM, nItem, (LPARAM)&tci);
6354 }
6355
AddItem(LPTCITEM pTabCtrlItem)6356 int AddItem(LPTCITEM pTabCtrlItem)
6357 {
6358 return InsertItem(GetItemCount(), pTabCtrlItem);
6359 }
6360
AddItem(UINT mask,LPCTSTR lpszItem,int iImage,LPARAM lParam)6361 int AddItem(UINT mask, LPCTSTR lpszItem, int iImage, LPARAM lParam)
6362 {
6363 return InsertItem(GetItemCount(), mask, lpszItem, iImage, lParam);
6364 }
6365
AddItem(LPCTSTR lpszItem)6366 int AddItem(LPCTSTR lpszItem)
6367 {
6368 return InsertItem(GetItemCount(), lpszItem);
6369 }
6370
DeleteItem(int nItem)6371 BOOL DeleteItem(int nItem)
6372 {
6373 ATLASSERT(::IsWindow(this->m_hWnd));
6374 return (BOOL)::SendMessage(this->m_hWnd, TCM_DELETEITEM, nItem, 0L);
6375 }
6376
DeleteAllItems()6377 BOOL DeleteAllItems()
6378 {
6379 ATLASSERT(::IsWindow(this->m_hWnd));
6380 return (BOOL)::SendMessage(this->m_hWnd, TCM_DELETEALLITEMS, 0, 0L);
6381 }
6382
AdjustRect(BOOL bLarger,LPRECT lpRect)6383 void AdjustRect(BOOL bLarger, LPRECT lpRect)
6384 {
6385 ATLASSERT(::IsWindow(this->m_hWnd));
6386 ::SendMessage(this->m_hWnd, TCM_ADJUSTRECT, bLarger, (LPARAM)lpRect);
6387 }
6388
RemoveImage(int nImage)6389 void RemoveImage(int nImage)
6390 {
6391 ATLASSERT(::IsWindow(this->m_hWnd));
6392 ::SendMessage(this->m_hWnd, TCM_REMOVEIMAGE, nImage, 0L);
6393 }
6394
HitTest(TC_HITTESTINFO * pHitTestInfo)6395 int HitTest(TC_HITTESTINFO* pHitTestInfo) const
6396 {
6397 ATLASSERT(::IsWindow(this->m_hWnd));
6398 return (int)::SendMessage(this->m_hWnd, TCM_HITTEST, 0, (LPARAM)pHitTestInfo);
6399 }
6400
6401 void DeselectAll(BOOL bExcludeFocus = TRUE)
6402 {
6403 ATLASSERT(::IsWindow(this->m_hWnd));
6404 ::SendMessage(this->m_hWnd, TCM_DESELECTALL, bExcludeFocus, 0L);
6405 }
6406
6407 BOOL HighlightItem(int nIndex, BOOL bHighlight = TRUE)
6408 {
6409 ATLASSERT(::IsWindow(this->m_hWnd));
6410 return (BOOL)::SendMessage(this->m_hWnd, TCM_HIGHLIGHTITEM, nIndex, MAKELPARAM(bHighlight, 0));
6411 }
6412 };
6413
6414 typedef CTabCtrlT<ATL::CWindow> CTabCtrl;
6415
6416
6417 ///////////////////////////////////////////////////////////////////////////////
6418 // CTrackBarCtrl
6419
6420 template <class TBase>
6421 class CTrackBarCtrlT : public TBase
6422 {
6423 public:
6424 // Constructors
TBase(hWnd)6425 CTrackBarCtrlT(HWND hWnd = NULL) : TBase(hWnd)
6426 { }
6427
6428 CTrackBarCtrlT< TBase >& operator =(HWND hWnd)
6429 {
6430 this->m_hWnd = hWnd;
6431 return *this;
6432 }
6433
6434 HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
6435 DWORD dwStyle = 0, DWORD dwExStyle = 0,
6436 ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
6437 {
6438 return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
6439 }
6440
6441 // Attributes
GetWndClassName()6442 static LPCTSTR GetWndClassName()
6443 {
6444 return TRACKBAR_CLASS;
6445 }
6446
GetLineSize()6447 int GetLineSize() const
6448 {
6449 ATLASSERT(::IsWindow(this->m_hWnd));
6450 return (int)::SendMessage(this->m_hWnd, TBM_GETLINESIZE, 0, 0L);
6451 }
6452
SetLineSize(int nSize)6453 int SetLineSize(int nSize)
6454 {
6455 ATLASSERT(::IsWindow(this->m_hWnd));
6456 return (int)::SendMessage(this->m_hWnd, TBM_SETLINESIZE, 0, nSize);
6457 }
6458
GetPageSize()6459 int GetPageSize() const
6460 {
6461 ATLASSERT(::IsWindow(this->m_hWnd));
6462 return (int)::SendMessage(this->m_hWnd, TBM_GETPAGESIZE, 0, 0L);
6463 }
6464
SetPageSize(int nSize)6465 int SetPageSize(int nSize)
6466 {
6467 ATLASSERT(::IsWindow(this->m_hWnd));
6468 return (int)::SendMessage(this->m_hWnd, TBM_SETPAGESIZE, 0, nSize);
6469 }
6470
GetRangeMin()6471 int GetRangeMin() const
6472 {
6473 ATLASSERT(::IsWindow(this->m_hWnd));
6474 return (int)::SendMessage(this->m_hWnd, TBM_GETRANGEMIN, 0, 0L);
6475 }
6476
6477 void SetRangeMin(int nMin, BOOL bRedraw = FALSE)
6478 {
6479 ATLASSERT(::IsWindow(this->m_hWnd));
6480 ::SendMessage(this->m_hWnd, TBM_SETRANGEMIN, bRedraw, nMin);
6481 }
6482
GetRangeMax()6483 int GetRangeMax() const
6484 {
6485 ATLASSERT(::IsWindow(this->m_hWnd));
6486 return (int)::SendMessage(this->m_hWnd, TBM_GETRANGEMAX, 0, 0L);
6487 }
6488
6489 void SetRangeMax(int nMax, BOOL bRedraw = FALSE)
6490 {
6491 ATLASSERT(::IsWindow(this->m_hWnd));
6492 ::SendMessage(this->m_hWnd, TBM_SETRANGEMAX, bRedraw, nMax);
6493 }
6494
GetRange(int & nMin,int & nMax)6495 void GetRange(int& nMin, int& nMax) const
6496 {
6497 nMin = GetRangeMin();
6498 nMax = GetRangeMax();
6499 }
6500
6501 void SetRange(int nMin, int nMax, BOOL bRedraw = TRUE)
6502 {
6503 ATLASSERT(::IsWindow(this->m_hWnd));
6504 ::SendMessage(this->m_hWnd, TBM_SETRANGE, bRedraw, MAKELPARAM(nMin, nMax));
6505 }
6506
GetSelStart()6507 int GetSelStart() const
6508 {
6509 ATLASSERT(::IsWindow(this->m_hWnd));
6510 return (int)::SendMessage(this->m_hWnd, TBM_GETSELSTART, 0, 0L);
6511 }
6512
6513 void SetSelStart(int nMin, BOOL bRedraw = FALSE)
6514 {
6515 ATLASSERT(::IsWindow(this->m_hWnd));
6516 ::SendMessage(this->m_hWnd, TBM_SETSELSTART, bRedraw, (LPARAM)nMin);
6517 }
6518
GetSelEnd()6519 int GetSelEnd() const
6520 {
6521 ATLASSERT(::IsWindow(this->m_hWnd));
6522 return (int)::SendMessage(this->m_hWnd, TBM_GETSELEND, 0, 0L);
6523 }
6524
6525 void SetSelEnd(int nMax, BOOL bRedraw = FALSE)
6526 {
6527 ATLASSERT(::IsWindow(this->m_hWnd));
6528 ::SendMessage(this->m_hWnd, TBM_SETSELEND, bRedraw, (LPARAM)nMax);
6529 }
6530
GetSelection(int & nMin,int & nMax)6531 void GetSelection(int& nMin, int& nMax) const
6532 {
6533 nMin = GetSelStart();
6534 nMax = GetSelEnd();
6535 }
6536
6537 void SetSelection(int nMin, int nMax, BOOL bRedraw = TRUE)
6538 {
6539 SetSelStart(nMin, FALSE);
6540 SetSelEnd(nMax, bRedraw);
6541 }
6542
GetChannelRect(LPRECT lprc)6543 void GetChannelRect(LPRECT lprc) const
6544 {
6545 ATLASSERT(::IsWindow(this->m_hWnd));
6546 ::SendMessage(this->m_hWnd, TBM_GETCHANNELRECT, 0, (LPARAM)lprc);
6547 }
6548
GetThumbRect(LPRECT lprc)6549 void GetThumbRect(LPRECT lprc) const
6550 {
6551 ATLASSERT(::IsWindow(this->m_hWnd));
6552 ::SendMessage(this->m_hWnd, TBM_GETTHUMBRECT, 0, (LPARAM)lprc);
6553 }
6554
GetPos()6555 int GetPos() const
6556 {
6557 ATLASSERT(::IsWindow(this->m_hWnd));
6558 return (int)::SendMessage(this->m_hWnd, TBM_GETPOS, 0, 0L);
6559 }
6560
SetPos(int nPos)6561 void SetPos(int nPos)
6562 {
6563 ATLASSERT(::IsWindow(this->m_hWnd));
6564 ::SendMessage(this->m_hWnd, TBM_SETPOS, TRUE, nPos);
6565 }
6566
GetNumTics()6567 UINT GetNumTics() const
6568 {
6569 ATLASSERT(::IsWindow(this->m_hWnd));
6570 return (UINT)::SendMessage(this->m_hWnd, TBM_GETNUMTICS, 0, 0L);
6571 }
6572
GetTicArray()6573 DWORD* GetTicArray() const
6574 {
6575 ATLASSERT(::IsWindow(this->m_hWnd));
6576 return (DWORD*)::SendMessage(this->m_hWnd, TBM_GETPTICS, 0, 0L);
6577 }
6578
GetTic(int nTic)6579 int GetTic(int nTic) const
6580 {
6581 ATLASSERT(::IsWindow(this->m_hWnd));
6582 return (int)::SendMessage(this->m_hWnd, TBM_GETTIC, nTic, 0L);
6583 }
6584
SetTic(int nTic)6585 BOOL SetTic(int nTic)
6586 {
6587 ATLASSERT(::IsWindow(this->m_hWnd));
6588 return (BOOL)::SendMessage(this->m_hWnd, TBM_SETTIC, 0, nTic);
6589 }
6590
GetTicPos(int nTic)6591 int GetTicPos(int nTic) const
6592 {
6593 ATLASSERT(::IsWindow(this->m_hWnd));
6594 return (int)::SendMessage(this->m_hWnd, TBM_GETTICPOS, nTic, 0L);
6595 }
6596
SetTicFreq(int nFreq)6597 void SetTicFreq(int nFreq)
6598 {
6599 ATLASSERT(::IsWindow(this->m_hWnd));
6600 ::SendMessage(this->m_hWnd, TBM_SETTICFREQ, nFreq, 0L);
6601 }
6602
GetThumbLength()6603 int GetThumbLength() const
6604 {
6605 ATLASSERT(::IsWindow(this->m_hWnd));
6606 return (int)::SendMessage(this->m_hWnd, TBM_GETTHUMBLENGTH, 0, 0L);
6607 }
6608
SetThumbLength(int nLength)6609 void SetThumbLength(int nLength)
6610 {
6611 ATLASSERT(::IsWindow(this->m_hWnd));
6612 ::SendMessage(this->m_hWnd, TBM_SETTHUMBLENGTH, nLength, 0L);
6613 }
6614
6615 void SetSel(int nStart, int nEnd, BOOL bRedraw = TRUE)
6616 {
6617 ATLASSERT(::IsWindow(this->m_hWnd));
6618 ATLASSERT((this->GetStyle() & TBS_ENABLESELRANGE) != 0);
6619 ::SendMessage(this->m_hWnd, TBM_SETSEL, bRedraw, MAKELPARAM(nStart, nEnd));
6620 }
6621
6622 ATL::CWindow GetBuddy(BOOL bLeft = TRUE) const
6623 {
6624 ATLASSERT(::IsWindow(this->m_hWnd));
6625 return ATL::CWindow((HWND)::SendMessage(this->m_hWnd, TBM_GETBUDDY, bLeft, 0L));
6626 }
6627
6628 ATL::CWindow SetBuddy(HWND hWndBuddy, BOOL bLeft = TRUE)
6629 {
6630 ATLASSERT(::IsWindow(this->m_hWnd));
6631 return ATL::CWindow((HWND)::SendMessage(this->m_hWnd, TBM_SETBUDDY, bLeft, (LPARAM)hWndBuddy));
6632 }
6633
GetToolTips()6634 CToolTipCtrl GetToolTips() const
6635 {
6636 ATLASSERT(::IsWindow(this->m_hWnd));
6637 return CToolTipCtrl((HWND)::SendMessage(this->m_hWnd, TBM_GETTOOLTIPS, 0, 0L));
6638 }
6639
SetToolTips(HWND hWndTT)6640 void SetToolTips(HWND hWndTT)
6641 {
6642 ATLASSERT(::IsWindow(this->m_hWnd));
6643 ::SendMessage(this->m_hWnd, TBM_SETTOOLTIPS, (WPARAM)hWndTT, 0L);
6644 }
6645
SetTipSide(int nSide)6646 int SetTipSide(int nSide)
6647 {
6648 ATLASSERT(::IsWindow(this->m_hWnd));
6649 return (int)::SendMessage(this->m_hWnd, TBM_SETTIPSIDE, nSide, 0L);
6650 }
6651
GetUnicodeFormat()6652 BOOL GetUnicodeFormat() const
6653 {
6654 ATLASSERT(::IsWindow(this->m_hWnd));
6655 return (BOOL)::SendMessage(this->m_hWnd, TBM_GETUNICODEFORMAT, 0, 0L);
6656 }
6657
6658 BOOL SetUnicodeFormat(BOOL bUnicode = TRUE)
6659 {
6660 ATLASSERT(::IsWindow(this->m_hWnd));
6661 return (BOOL)::SendMessage(this->m_hWnd, TBM_SETUNICODEFORMAT, bUnicode, 0L);
6662 }
6663
6664 // Operations
6665 void ClearSel(BOOL bRedraw = FALSE)
6666 {
6667 ATLASSERT(::IsWindow(this->m_hWnd));
6668 ::SendMessage(this->m_hWnd, TBM_CLEARSEL, bRedraw, 0L);
6669 }
6670
VerifyPos()6671 void VerifyPos()
6672 {
6673 ATLASSERT(::IsWindow(this->m_hWnd));
6674 ::SendMessage(this->m_hWnd, TBM_SETPOS, FALSE, 0L);
6675 }
6676
6677 void ClearTics(BOOL bRedraw = FALSE)
6678 {
6679 ATLASSERT(::IsWindow(this->m_hWnd));
6680 ::SendMessage(this->m_hWnd, TBM_CLEARTICS, bRedraw, 0L);
6681 }
6682 };
6683
6684 typedef CTrackBarCtrlT<ATL::CWindow> CTrackBarCtrl;
6685
6686
6687 ///////////////////////////////////////////////////////////////////////////////
6688 // CUpDownCtrl
6689
6690 template <class TBase>
6691 class CUpDownCtrlT : public TBase
6692 {
6693 public:
6694 // Constructors
TBase(hWnd)6695 CUpDownCtrlT(HWND hWnd = NULL) : TBase(hWnd)
6696 { }
6697
6698 CUpDownCtrlT< TBase >& operator =(HWND hWnd)
6699 {
6700 this->m_hWnd = hWnd;
6701 return *this;
6702 }
6703
6704 HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
6705 DWORD dwStyle = 0, DWORD dwExStyle = 0,
6706 ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
6707 {
6708 return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
6709 }
6710
6711 // Attributes
GetWndClassName()6712 static LPCTSTR GetWndClassName()
6713 {
6714 return UPDOWN_CLASS;
6715 }
6716
GetAccel(int nAccel,UDACCEL * pAccel)6717 UINT GetAccel(int nAccel, UDACCEL* pAccel) const
6718 {
6719 ATLASSERT(::IsWindow(this->m_hWnd));
6720 return (UINT)LOWORD(::SendMessage(this->m_hWnd, UDM_GETACCEL, nAccel, (LPARAM)pAccel));
6721 }
6722
SetAccel(int nAccel,UDACCEL * pAccel)6723 BOOL SetAccel(int nAccel, UDACCEL* pAccel)
6724 {
6725 ATLASSERT(::IsWindow(this->m_hWnd));
6726 return (BOOL)LOWORD(::SendMessage(this->m_hWnd, UDM_SETACCEL, nAccel, (LPARAM)pAccel));
6727 }
6728
GetBase()6729 UINT GetBase() const
6730 {
6731 ATLASSERT(::IsWindow(this->m_hWnd));
6732 return (UINT)LOWORD(::SendMessage(this->m_hWnd, UDM_GETBASE, 0, 0L));
6733 }
6734
SetBase(int nBase)6735 int SetBase(int nBase)
6736 {
6737 ATLASSERT(::IsWindow(this->m_hWnd));
6738 return (int)::SendMessage(this->m_hWnd, UDM_SETBASE, nBase, 0L);
6739 }
6740
GetBuddy()6741 ATL::CWindow GetBuddy() const
6742 {
6743 ATLASSERT(::IsWindow(this->m_hWnd));
6744 return ATL::CWindow((HWND)::SendMessage(this->m_hWnd, UDM_GETBUDDY, 0, 0L));
6745 }
6746
SetBuddy(HWND hWndBuddy)6747 ATL::CWindow SetBuddy(HWND hWndBuddy)
6748 {
6749 ATLASSERT(::IsWindow(this->m_hWnd));
6750 return ATL::CWindow((HWND)::SendMessage(this->m_hWnd, UDM_SETBUDDY, (WPARAM)hWndBuddy, 0L));
6751 }
6752
6753 int GetPos(LPBOOL lpbError = NULL) const
6754 {
6755 ATLASSERT(::IsWindow(this->m_hWnd));
6756 DWORD dwRet = (DWORD)::SendMessage(this->m_hWnd, UDM_GETPOS, 0, 0L);
6757 // Note: Seems that Windows always sets error to TRUE if
6758 // UDS_SETBUDDYINT style is not used
6759 if(lpbError != NULL)
6760 *lpbError = (HIWORD(dwRet) != 0) ? TRUE : FALSE;
6761 return (int)(short)LOWORD(dwRet);
6762 }
6763
SetPos(int nPos)6764 int SetPos(int nPos)
6765 {
6766 ATLASSERT(::IsWindow(this->m_hWnd));
6767 return (int)(short)LOWORD(::SendMessage(this->m_hWnd, UDM_SETPOS, 0, MAKELPARAM(nPos, 0)));
6768 }
6769
GetRange()6770 DWORD GetRange() const
6771 {
6772 ATLASSERT(::IsWindow(this->m_hWnd));
6773 return (DWORD)::SendMessage(this->m_hWnd, UDM_GETRANGE, 0, 0L);
6774 }
6775
GetRange(int & nLower,int & nUpper)6776 void GetRange(int& nLower, int& nUpper) const
6777 {
6778 ATLASSERT(::IsWindow(this->m_hWnd));
6779 DWORD dwRet = (DWORD)::SendMessage(this->m_hWnd, UDM_GETRANGE, 0, 0L);
6780 nLower = (int)(short)HIWORD(dwRet);
6781 nUpper = (int)(short)LOWORD(dwRet);
6782 }
6783
SetRange(int nLower,int nUpper)6784 void SetRange(int nLower, int nUpper)
6785 {
6786 ATLASSERT(::IsWindow(this->m_hWnd));
6787 ::SendMessage(this->m_hWnd, UDM_SETRANGE, 0, MAKELPARAM(nUpper, nLower));
6788 }
6789
SetRange32(int nLower,int nUpper)6790 void SetRange32(int nLower, int nUpper)
6791 {
6792 ATLASSERT(::IsWindow(this->m_hWnd));
6793 ::SendMessage(this->m_hWnd, UDM_SETRANGE32, nLower, nUpper);
6794 }
6795
GetRange32(int & nLower,int & nUpper)6796 void GetRange32(int& nLower, int& nUpper) const
6797 {
6798 ATLASSERT(::IsWindow(this->m_hWnd));
6799 ::SendMessage(this->m_hWnd, UDM_GETRANGE32, (WPARAM)&nLower, (LPARAM)&nUpper);
6800 }
6801
GetUnicodeFormat()6802 BOOL GetUnicodeFormat() const
6803 {
6804 ATLASSERT(::IsWindow(this->m_hWnd));
6805 return (BOOL)::SendMessage(this->m_hWnd, UDM_GETUNICODEFORMAT, 0, 0L);
6806 }
6807
6808 BOOL SetUnicodeFormat(BOOL bUnicode = TRUE)
6809 {
6810 ATLASSERT(::IsWindow(this->m_hWnd));
6811 return (BOOL)::SendMessage(this->m_hWnd, UDM_SETUNICODEFORMAT, bUnicode, 0L);
6812 }
6813
6814 int GetPos32(LPBOOL lpbError = NULL) const
6815 {
6816 ATLASSERT(::IsWindow(this->m_hWnd));
6817 // Note: Seems that Windows always sets error to TRUE if
6818 // UDS_SETBUDDYINT style is not used
6819 return (int)::SendMessage(this->m_hWnd, UDM_GETPOS32, 0, (LPARAM)lpbError);
6820 }
6821
SetPos32(int nPos)6822 int SetPos32(int nPos)
6823 {
6824 ATLASSERT(::IsWindow(this->m_hWnd));
6825 return (int)::SendMessage(this->m_hWnd, UDM_SETPOS32, 0, (LPARAM)nPos);
6826 }
6827 };
6828
6829 typedef CUpDownCtrlT<ATL::CWindow> CUpDownCtrl;
6830
6831
6832 ///////////////////////////////////////////////////////////////////////////////
6833 // CProgressBarCtrl
6834
6835 template <class TBase>
6836 class CProgressBarCtrlT : public TBase
6837 {
6838 public:
6839 // Constructors
TBase(hWnd)6840 CProgressBarCtrlT(HWND hWnd = NULL) : TBase(hWnd)
6841 { }
6842
6843 CProgressBarCtrlT< TBase >& operator =(HWND hWnd)
6844 {
6845 this->m_hWnd = hWnd;
6846 return *this;
6847 }
6848
6849 HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
6850 DWORD dwStyle = 0, DWORD dwExStyle = 0,
6851 ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
6852 {
6853 return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
6854 }
6855
6856 // Attributes
GetWndClassName()6857 static LPCTSTR GetWndClassName()
6858 {
6859 return PROGRESS_CLASS;
6860 }
6861
SetRange(int nLower,int nUpper)6862 DWORD SetRange(int nLower, int nUpper)
6863 {
6864 ATLASSERT(::IsWindow(this->m_hWnd));
6865 return (DWORD)::SendMessage(this->m_hWnd, PBM_SETRANGE, 0, MAKELPARAM(nLower, nUpper));
6866 }
6867
SetPos(int nPos)6868 int SetPos(int nPos)
6869 {
6870 ATLASSERT(::IsWindow(this->m_hWnd));
6871 return (int)(short)LOWORD(::SendMessage(this->m_hWnd, PBM_SETPOS, nPos, 0L));
6872 }
6873
OffsetPos(int nPos)6874 int OffsetPos(int nPos)
6875 {
6876 ATLASSERT(::IsWindow(this->m_hWnd));
6877 return (int)(short)LOWORD(::SendMessage(this->m_hWnd, PBM_DELTAPOS, nPos, 0L));
6878 }
6879
SetStep(int nStep)6880 int SetStep(int nStep)
6881 {
6882 ATLASSERT(::IsWindow(this->m_hWnd));
6883 return (int)(short)LOWORD(::SendMessage(this->m_hWnd, PBM_SETSTEP, nStep, 0L));
6884 }
6885
GetPos()6886 UINT GetPos() const
6887 {
6888 ATLASSERT(::IsWindow(this->m_hWnd));
6889 return (UINT)::SendMessage(this->m_hWnd, PBM_GETPOS, 0, 0L);
6890 }
6891
GetRange(PPBRANGE pPBRange)6892 void GetRange(PPBRANGE pPBRange) const
6893 {
6894 ATLASSERT(::IsWindow(this->m_hWnd));
6895 ATLASSERT(pPBRange != NULL);
6896 ::SendMessage(this->m_hWnd, PBM_GETRANGE, TRUE, (LPARAM)pPBRange);
6897 }
6898
GetRange(int & nLower,int & nUpper)6899 void GetRange(int& nLower, int& nUpper) const
6900 {
6901 ATLASSERT(::IsWindow(this->m_hWnd));
6902 PBRANGE range = {};
6903 ::SendMessage(this->m_hWnd, PBM_GETRANGE, TRUE, (LPARAM)&range);
6904 nLower = range.iLow;
6905 nUpper = range.iHigh;
6906 }
6907
GetRangeLimit(BOOL bLowLimit)6908 int GetRangeLimit(BOOL bLowLimit) const
6909 {
6910 ATLASSERT(::IsWindow(this->m_hWnd));
6911 return (int)::SendMessage(this->m_hWnd, PBM_GETRANGE, bLowLimit, (LPARAM)NULL);
6912 }
6913
SetRange32(int nMin,int nMax)6914 DWORD SetRange32(int nMin, int nMax)
6915 {
6916 ATLASSERT(::IsWindow(this->m_hWnd));
6917 return (DWORD)::SendMessage(this->m_hWnd, PBM_SETRANGE32, nMin, nMax);
6918 }
6919
SetBarColor(COLORREF clr)6920 COLORREF SetBarColor(COLORREF clr)
6921 {
6922 ATLASSERT(::IsWindow(this->m_hWnd));
6923 return (COLORREF)::SendMessage(this->m_hWnd, PBM_SETBARCOLOR, 0, (LPARAM)clr);
6924 }
6925
SetBkColor(COLORREF clr)6926 COLORREF SetBkColor(COLORREF clr)
6927 {
6928 ATLASSERT(::IsWindow(this->m_hWnd));
6929 return (COLORREF)::SendMessage(this->m_hWnd, PBM_SETBKCOLOR, 0, (LPARAM)clr);
6930 }
6931
6932 #ifdef PBM_SETMARQUEE
6933 BOOL SetMarquee(BOOL bMarquee, UINT uUpdateTime = 0U)
6934 {
6935 ATLASSERT(::IsWindow(this->m_hWnd));
6936 return (BOOL)::SendMessage(this->m_hWnd, PBM_SETMARQUEE, (WPARAM)bMarquee, (LPARAM)uUpdateTime);
6937 }
6938 #endif
6939
6940 #if (_WIN32_WINNT >= 0x0600)
GetStep()6941 int GetStep() const
6942 {
6943 ATLASSERT(::IsWindow(this->m_hWnd));
6944 return (int)::SendMessage(this->m_hWnd, PBM_GETSTEP, 0, 0L);
6945 }
6946
GetBkColor()6947 COLORREF GetBkColor() const
6948 {
6949 ATLASSERT(::IsWindow(this->m_hWnd));
6950 return (COLORREF)::SendMessage(this->m_hWnd, PBM_GETBKCOLOR, 0, 0L);
6951 }
6952
GetBarColor()6953 COLORREF GetBarColor() const
6954 {
6955 ATLASSERT(::IsWindow(this->m_hWnd));
6956 return (COLORREF)::SendMessage(this->m_hWnd, PBM_GETBARCOLOR, 0, 0L);
6957 }
6958
GetState()6959 int GetState() const
6960 {
6961 ATLASSERT(::IsWindow(this->m_hWnd));
6962 return (int)::SendMessage(this->m_hWnd, PBM_GETSTATE, 0, 0L);
6963 }
6964
SetState(int nState)6965 int SetState(int nState)
6966 {
6967 ATLASSERT(::IsWindow(this->m_hWnd));
6968 return (int)::SendMessage(this->m_hWnd, PBM_SETSTATE, nState, 0L);
6969 }
6970 #endif // (_WIN32_WINNT >= 0x0600)
6971
6972 // Operations
StepIt()6973 int StepIt()
6974 {
6975 ATLASSERT(::IsWindow(this->m_hWnd));
6976 return (int)(short)LOWORD(::SendMessage(this->m_hWnd, PBM_STEPIT, 0, 0L));
6977 }
6978 };
6979
6980 typedef CProgressBarCtrlT<ATL::CWindow> CProgressBarCtrl;
6981
6982
6983 ///////////////////////////////////////////////////////////////////////////////
6984 // CHotKeyCtrl
6985
6986 template <class TBase>
6987 class CHotKeyCtrlT : public TBase
6988 {
6989 public:
6990 // Constructors
TBase(hWnd)6991 CHotKeyCtrlT(HWND hWnd = NULL) : TBase(hWnd)
6992 { }
6993
6994 CHotKeyCtrlT< TBase >& operator =(HWND hWnd)
6995 {
6996 this->m_hWnd = hWnd;
6997 return *this;
6998 }
6999
7000 HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
7001 DWORD dwStyle = 0, DWORD dwExStyle = 0,
7002 ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
7003 {
7004 return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
7005 }
7006
7007 // Attributes
GetWndClassName()7008 static LPCTSTR GetWndClassName()
7009 {
7010 return HOTKEY_CLASS;
7011 }
7012
GetHotKey()7013 DWORD GetHotKey() const
7014 {
7015 ATLASSERT(::IsWindow(this->m_hWnd));
7016 return (DWORD)::SendMessage(this->m_hWnd, HKM_GETHOTKEY, 0, 0L);
7017 }
7018
GetHotKey(WORD & wVirtualKeyCode,WORD & wModifiers)7019 void GetHotKey(WORD &wVirtualKeyCode, WORD &wModifiers) const
7020 {
7021 ATLASSERT(::IsWindow(this->m_hWnd));
7022 DWORD dw = (DWORD)::SendMessage(this->m_hWnd, HKM_GETHOTKEY, 0, 0L);
7023 wVirtualKeyCode = LOBYTE(LOWORD(dw));
7024 wModifiers = HIBYTE(LOWORD(dw));
7025 }
7026
SetHotKey(WORD wVirtualKeyCode,WORD wModifiers)7027 void SetHotKey(WORD wVirtualKeyCode, WORD wModifiers)
7028 {
7029 ATLASSERT(::IsWindow(this->m_hWnd));
7030 ::SendMessage(this->m_hWnd, HKM_SETHOTKEY, MAKEWORD(wVirtualKeyCode, wModifiers), 0L);
7031 }
7032
SetRules(WORD wInvalidComb,WORD wModifiers)7033 void SetRules(WORD wInvalidComb, WORD wModifiers)
7034 {
7035 ATLASSERT(::IsWindow(this->m_hWnd));
7036 ::SendMessage(this->m_hWnd, HKM_SETRULES, wInvalidComb, MAKELPARAM(wModifiers, 0));
7037 }
7038 };
7039
7040 typedef CHotKeyCtrlT<ATL::CWindow> CHotKeyCtrl;
7041
7042
7043 ///////////////////////////////////////////////////////////////////////////////
7044 // CAnimateCtrl
7045
7046 template <class TBase>
7047 class CAnimateCtrlT : public TBase
7048 {
7049 public:
7050 // Constructors
TBase(hWnd)7051 CAnimateCtrlT(HWND hWnd = NULL) : TBase(hWnd)
7052 { }
7053
7054 CAnimateCtrlT< TBase >& operator =(HWND hWnd)
7055 {
7056 this->m_hWnd = hWnd;
7057 return *this;
7058 }
7059
7060 HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
7061 DWORD dwStyle = 0, DWORD dwExStyle = 0,
7062 ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
7063 {
7064 return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
7065 }
7066
7067 // Attributes
GetWndClassName()7068 static LPCTSTR GetWndClassName()
7069 {
7070 return ANIMATE_CLASS;
7071 }
7072
7073 // Operations
Open(ATL::_U_STRINGorID FileName)7074 BOOL Open(ATL::_U_STRINGorID FileName)
7075 {
7076 ATLASSERT(::IsWindow(this->m_hWnd));
7077 return (BOOL)::SendMessage(this->m_hWnd, ACM_OPEN, 0, (LPARAM)FileName.m_lpstr);
7078 }
7079
Play(UINT nFrom,UINT nTo,UINT nRep)7080 BOOL Play(UINT nFrom, UINT nTo, UINT nRep)
7081 {
7082 ATLASSERT(::IsWindow(this->m_hWnd));
7083 return (BOOL)::SendMessage(this->m_hWnd, ACM_PLAY, nRep, MAKELPARAM(nFrom, nTo));
7084 }
7085
Stop()7086 BOOL Stop()
7087 {
7088 ATLASSERT(::IsWindow(this->m_hWnd));
7089 return (BOOL)::SendMessage(this->m_hWnd, ACM_STOP, 0, 0L);
7090 }
7091
Close()7092 BOOL Close()
7093 {
7094 ATLASSERT(::IsWindow(this->m_hWnd));
7095 return (BOOL)::SendMessage(this->m_hWnd, ACM_OPEN, 0, 0L);
7096 }
7097
Seek(UINT nTo)7098 BOOL Seek(UINT nTo)
7099 {
7100 ATLASSERT(::IsWindow(this->m_hWnd));
7101 return (BOOL)::SendMessage(this->m_hWnd, ACM_PLAY, 0, MAKELPARAM(nTo, nTo));
7102 }
7103
7104 // Vista only
IsPlaying()7105 BOOL IsPlaying() const
7106 {
7107 ATLASSERT(::IsWindow(this->m_hWnd));
7108 return (BOOL)::SendMessage(this->m_hWnd, ACM_ISPLAYING, 0, 0L);
7109 }
7110 };
7111
7112 typedef CAnimateCtrlT<ATL::CWindow> CAnimateCtrl;
7113
7114
7115 ///////////////////////////////////////////////////////////////////////////////
7116 // CRichEditCtrl
7117
7118 #if !defined(_UNICODE) && (_RICHEDIT_VER >= 0x0500)
7119 #undef MSFTEDIT_CLASS
7120 #define MSFTEDIT_CLASS "RICHEDIT50W"
7121 #endif
7122
7123 template <class TBase>
7124 class CRichEditCtrlT : public TBase
7125 {
7126 public:
7127 // Constructors
TBase(hWnd)7128 CRichEditCtrlT(HWND hWnd = NULL) : TBase(hWnd)
7129 { }
7130
7131 CRichEditCtrlT< TBase >& operator =(HWND hWnd)
7132 {
7133 this->m_hWnd = hWnd;
7134 return *this;
7135 }
7136
7137 HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
7138 DWORD dwStyle = 0, DWORD dwExStyle = 0,
7139 ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
7140 {
7141 return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
7142 }
7143
7144 // Attributes
GetWndClassName()7145 static LPCTSTR GetWndClassName()
7146 {
7147 #if (_RICHEDIT_VER >= 0x0500)
7148 return MSFTEDIT_CLASS;
7149 #else
7150 return RICHEDIT_CLASS;
7151 #endif
7152 }
7153
GetLibraryName()7154 static LPCTSTR GetLibraryName()
7155 {
7156 #if (_RICHEDIT_VER >= 0x0500)
7157 return _T("MSFTEDIT.DLL");
7158 #else
7159 return _T("RICHED20.DLL");
7160 #endif
7161 }
7162
GetLineCount()7163 int GetLineCount() const
7164 {
7165 ATLASSERT(::IsWindow(this->m_hWnd));
7166 return (int)::SendMessage(this->m_hWnd, EM_GETLINECOUNT, 0, 0L);
7167 }
7168
GetModify()7169 BOOL GetModify() const
7170 {
7171 ATLASSERT(::IsWindow(this->m_hWnd));
7172 return (BOOL)::SendMessage(this->m_hWnd, EM_GETMODIFY, 0, 0L);
7173 }
7174
7175 void SetModify(BOOL bModified = TRUE)
7176 {
7177 ATLASSERT(::IsWindow(this->m_hWnd));
7178 ::SendMessage(this->m_hWnd, EM_SETMODIFY, bModified, 0L);
7179 }
7180
GetRect(LPRECT lpRect)7181 void GetRect(LPRECT lpRect) const
7182 {
7183 ATLASSERT(::IsWindow(this->m_hWnd));
7184 ::SendMessage(this->m_hWnd, EM_GETRECT, 0, (LPARAM)lpRect);
7185 }
7186
GetOptions()7187 DWORD GetOptions() const
7188 {
7189 ATLASSERT(::IsWindow(this->m_hWnd));
7190 return (DWORD)::SendMessage(this->m_hWnd, EM_GETOPTIONS, 0, 0L);
7191 }
7192
SetOptions(WORD wOperation,DWORD dwOptions)7193 DWORD SetOptions(WORD wOperation, DWORD dwOptions)
7194 {
7195 ATLASSERT(::IsWindow(this->m_hWnd));
7196 return (DWORD)::SendMessage(this->m_hWnd, EM_SETOPTIONS, wOperation, dwOptions);
7197 }
7198
7199 // NOTE: first word in lpszBuffer must contain the size of the buffer!
GetLine(int nIndex,LPTSTR lpszBuffer)7200 int GetLine(int nIndex, LPTSTR lpszBuffer) const
7201 {
7202 ATLASSERT(::IsWindow(this->m_hWnd));
7203 return (int)::SendMessage(this->m_hWnd, EM_GETLINE, nIndex, (LPARAM)lpszBuffer);
7204 }
7205
GetLine(int nIndex,LPTSTR lpszBuffer,int nMaxLength)7206 int GetLine(int nIndex, LPTSTR lpszBuffer, int nMaxLength) const
7207 {
7208 ATLASSERT(::IsWindow(this->m_hWnd));
7209 *(LPWORD)lpszBuffer = (WORD)nMaxLength;
7210 return (int)::SendMessage(this->m_hWnd, EM_GETLINE, nIndex, (LPARAM)lpszBuffer);
7211 }
7212
CanUndo()7213 BOOL CanUndo() const
7214 {
7215 ATLASSERT(::IsWindow(this->m_hWnd));
7216 return (BOOL)::SendMessage(this->m_hWnd, EM_CANUNDO, 0, 0L);
7217 }
7218
7219 BOOL CanPaste(UINT nFormat = 0) const
7220 {
7221 ATLASSERT(::IsWindow(this->m_hWnd));
7222 return (BOOL)::SendMessage(this->m_hWnd, EM_CANPASTE, nFormat, 0L);
7223 }
7224
GetSel(LONG & nStartChar,LONG & nEndChar)7225 void GetSel(LONG& nStartChar, LONG& nEndChar) const
7226 {
7227 ATLASSERT(::IsWindow(this->m_hWnd));
7228 CHARRANGE cr = {};
7229 ::SendMessage(this->m_hWnd, EM_EXGETSEL, 0, (LPARAM)&cr);
7230 nStartChar = cr.cpMin;
7231 nEndChar = cr.cpMax;
7232 }
7233
GetSel(CHARRANGE & cr)7234 void GetSel(CHARRANGE &cr) const
7235 {
7236 ATLASSERT(::IsWindow(this->m_hWnd));
7237 ::SendMessage(this->m_hWnd, EM_EXGETSEL, 0, (LPARAM)&cr);
7238 }
7239
SetSel(LONG nStartChar,LONG nEndChar)7240 int SetSel(LONG nStartChar, LONG nEndChar)
7241 {
7242 ATLASSERT(::IsWindow(this->m_hWnd));
7243 CHARRANGE cr = { nStartChar, nEndChar };
7244 return (int)::SendMessage(this->m_hWnd, EM_EXSETSEL, 0, (LPARAM)&cr);
7245 }
7246
SetSel(CHARRANGE & cr)7247 int SetSel(CHARRANGE &cr)
7248 {
7249 ATLASSERT(::IsWindow(this->m_hWnd));
7250 return (int)::SendMessage(this->m_hWnd, EM_EXSETSEL, 0, (LPARAM)&cr);
7251 }
7252
SetSelAll()7253 int SetSelAll()
7254 {
7255 return SetSel(0, -1);
7256 }
7257
SetSelNone()7258 int SetSelNone()
7259 {
7260 return SetSel(-1, 0);
7261 }
7262
GetDefaultCharFormat(CHARFORMAT & cf)7263 DWORD GetDefaultCharFormat(CHARFORMAT& cf) const
7264 {
7265 ATLASSERT(::IsWindow(this->m_hWnd));
7266 cf.cbSize = sizeof(CHARFORMAT);
7267 return (DWORD)::SendMessage(this->m_hWnd, EM_GETCHARFORMAT, 0, (LPARAM)&cf);
7268 }
7269
GetSelectionCharFormat(CHARFORMAT & cf)7270 DWORD GetSelectionCharFormat(CHARFORMAT& cf) const
7271 {
7272 ATLASSERT(::IsWindow(this->m_hWnd));
7273 cf.cbSize = sizeof(CHARFORMAT);
7274 return (DWORD)::SendMessage(this->m_hWnd, EM_GETCHARFORMAT, 1, (LPARAM)&cf);
7275 }
7276
GetEventMask()7277 DWORD GetEventMask() const
7278 {
7279 ATLASSERT(::IsWindow(this->m_hWnd));
7280 return (DWORD)::SendMessage(this->m_hWnd, EM_GETEVENTMASK, 0, 0L);
7281 }
7282
GetLimitText()7283 LONG GetLimitText() const
7284 {
7285 ATLASSERT(::IsWindow(this->m_hWnd));
7286 return (LONG)::SendMessage(this->m_hWnd, EM_GETLIMITTEXT, 0, 0L);
7287 }
7288
GetParaFormat(PARAFORMAT & pf)7289 DWORD GetParaFormat(PARAFORMAT& pf) const
7290 {
7291 ATLASSERT(::IsWindow(this->m_hWnd));
7292 pf.cbSize = sizeof(PARAFORMAT);
7293 return (DWORD)::SendMessage(this->m_hWnd, EM_GETPARAFORMAT, 0, (LPARAM)&pf);
7294 }
7295
GetSelText(LPTSTR lpstrBuff)7296 LONG GetSelText(LPTSTR lpstrBuff) const
7297 {
7298 ATLASSERT(::IsWindow(this->m_hWnd));
7299 return (LONG)::SendMessage(this->m_hWnd, EM_GETSELTEXT, 0, (LPARAM)lpstrBuff);
7300 }
7301
GetSelTextBSTR(BSTR & bstrText)7302 BOOL GetSelTextBSTR(BSTR& bstrText) const
7303 {
7304 USES_CONVERSION;
7305 ATLASSERT(::IsWindow(this->m_hWnd));
7306 ATLASSERT(bstrText == NULL);
7307
7308 CHARRANGE cr = {};
7309 ::SendMessage(this->m_hWnd, EM_EXGETSEL, 0, (LPARAM)&cr);
7310
7311 ATL::CTempBuffer<TCHAR, _WTL_STACK_ALLOC_THRESHOLD> buff;
7312 LPTSTR lpstrText = buff.Allocate(cr.cpMax - cr.cpMin + 1);
7313 if(lpstrText == NULL)
7314 return FALSE;
7315 if(::SendMessage(this->m_hWnd, EM_GETSELTEXT, 0, (LPARAM)lpstrText) == 0)
7316 return FALSE;
7317
7318 bstrText = ::SysAllocString(T2W(lpstrText));
7319
7320 return (bstrText != NULL) ? TRUE : FALSE;
7321 }
7322
7323 #ifdef __ATLSTR_H__
GetSelText(ATL::CString & strText)7324 LONG GetSelText(ATL::CString& strText) const
7325 {
7326 ATLASSERT(::IsWindow(this->m_hWnd));
7327
7328 CHARRANGE cr = {};
7329 ::SendMessage(this->m_hWnd, EM_EXGETSEL, 0, (LPARAM)&cr);
7330
7331 LONG lLen = 0;
7332 LPTSTR lpstrText = strText.GetBufferSetLength(cr.cpMax - cr.cpMin);
7333 if(lpstrText != NULL)
7334 {
7335 lLen = (LONG)::SendMessage(this->m_hWnd, EM_GETSELTEXT, 0, (LPARAM)lpstrText);
7336 strText.ReleaseBuffer();
7337 }
7338
7339 return lLen;
7340 }
7341 #endif // __ATLSTR_H__
7342
GetSelectionType()7343 WORD GetSelectionType() const
7344 {
7345 ATLASSERT(::IsWindow(this->m_hWnd));
7346 return (WORD)::SendMessage(this->m_hWnd, EM_SELECTIONTYPE, 0, 0L);
7347 }
7348
SetBackgroundColor(COLORREF cr)7349 COLORREF SetBackgroundColor(COLORREF cr)
7350 {
7351 ATLASSERT(::IsWindow(this->m_hWnd));
7352 return (COLORREF)::SendMessage(this->m_hWnd, EM_SETBKGNDCOLOR, 0, cr);
7353 }
7354
SetBackgroundColor()7355 COLORREF SetBackgroundColor() // sets to system background
7356 {
7357 ATLASSERT(::IsWindow(this->m_hWnd));
7358 return (COLORREF)::SendMessage(this->m_hWnd, EM_SETBKGNDCOLOR, 1, 0);
7359 }
7360
SetCharFormat(CHARFORMAT & cf,WORD wFlags)7361 BOOL SetCharFormat(CHARFORMAT& cf, WORD wFlags)
7362 {
7363 ATLASSERT(::IsWindow(this->m_hWnd));
7364 cf.cbSize = sizeof(CHARFORMAT);
7365 return (BOOL)::SendMessage(this->m_hWnd, EM_SETCHARFORMAT, (WPARAM)wFlags, (LPARAM)&cf);
7366 }
7367
SetDefaultCharFormat(CHARFORMAT & cf)7368 BOOL SetDefaultCharFormat(CHARFORMAT& cf)
7369 {
7370 ATLASSERT(::IsWindow(this->m_hWnd));
7371 cf.cbSize = sizeof(CHARFORMAT);
7372 return (BOOL)::SendMessage(this->m_hWnd, EM_SETCHARFORMAT, 0, (LPARAM)&cf);
7373 }
7374
SetSelectionCharFormat(CHARFORMAT & cf)7375 BOOL SetSelectionCharFormat(CHARFORMAT& cf)
7376 {
7377 ATLASSERT(::IsWindow(this->m_hWnd));
7378 cf.cbSize = sizeof(CHARFORMAT);
7379 return (BOOL)::SendMessage(this->m_hWnd, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf);
7380 }
7381
SetWordCharFormat(CHARFORMAT & cf)7382 BOOL SetWordCharFormat(CHARFORMAT& cf)
7383 {
7384 ATLASSERT(::IsWindow(this->m_hWnd));
7385 cf.cbSize = sizeof(CHARFORMAT);
7386 return (BOOL)::SendMessage(this->m_hWnd, EM_SETCHARFORMAT, SCF_SELECTION | SCF_WORD, (LPARAM)&cf);
7387 }
7388
SetEventMask(DWORD dwEventMask)7389 DWORD SetEventMask(DWORD dwEventMask)
7390 {
7391 ATLASSERT(::IsWindow(this->m_hWnd));
7392 return (DWORD)::SendMessage(this->m_hWnd, EM_SETEVENTMASK, 0, dwEventMask);
7393 }
7394
SetParaFormat(PARAFORMAT & pf)7395 BOOL SetParaFormat(PARAFORMAT& pf)
7396 {
7397 ATLASSERT(::IsWindow(this->m_hWnd));
7398 pf.cbSize = sizeof(PARAFORMAT);
7399 return (BOOL)::SendMessage(this->m_hWnd, EM_SETPARAFORMAT, 0, (LPARAM)&pf);
7400 }
7401
SetTargetDevice(HDC hDC,int cxLineWidth)7402 BOOL SetTargetDevice(HDC hDC, int cxLineWidth)
7403 {
7404 ATLASSERT(::IsWindow(this->m_hWnd));
7405 return (BOOL)::SendMessage(this->m_hWnd, EM_SETTARGETDEVICE, (WPARAM)hDC, cxLineWidth);
7406 }
7407
GetTextLength()7408 int GetTextLength() const
7409 {
7410 ATLASSERT(::IsWindow(this->m_hWnd));
7411 return (int)::SendMessage(this->m_hWnd, WM_GETTEXTLENGTH, 0, 0L);
7412 }
7413
7414 BOOL SetReadOnly(BOOL bReadOnly = TRUE)
7415 {
7416 ATLASSERT(::IsWindow(this->m_hWnd));
7417 return (BOOL)::SendMessage(this->m_hWnd, EM_SETREADONLY, bReadOnly, 0L);
7418 }
7419
GetFirstVisibleLine()7420 int GetFirstVisibleLine() const
7421 {
7422 ATLASSERT(::IsWindow(this->m_hWnd));
7423 return (int)::SendMessage(this->m_hWnd, EM_GETFIRSTVISIBLELINE, 0, 0L);
7424 }
7425
GetTextRange(TEXTRANGE * pTextRange)7426 int GetTextRange(TEXTRANGE* pTextRange) const
7427 {
7428 ATLASSERT(::IsWindow(this->m_hWnd));
7429 return (int)::SendMessage(this->m_hWnd, EM_GETTEXTRANGE, 0, (LPARAM)pTextRange);
7430 }
7431
GetTextRange(LONG nStartChar,LONG nEndChar,LPTSTR lpstrText)7432 int GetTextRange(LONG nStartChar, LONG nEndChar, LPTSTR lpstrText) const
7433 {
7434 ATLASSERT(::IsWindow(this->m_hWnd));
7435 TEXTRANGE tr = {};
7436 tr.chrg.cpMin = nStartChar;
7437 tr.chrg.cpMax = nEndChar;
7438 tr.lpstrText = lpstrText;
7439 return (int)::SendMessage(this->m_hWnd, EM_GETTEXTRANGE, 0, (LPARAM)&tr);
7440 }
7441
GetDefaultCharFormat(CHARFORMAT2 & cf)7442 DWORD GetDefaultCharFormat(CHARFORMAT2& cf) const
7443 {
7444 ATLASSERT(::IsWindow(this->m_hWnd));
7445 cf.cbSize = sizeof(CHARFORMAT2);
7446 return (DWORD)::SendMessage(this->m_hWnd, EM_GETCHARFORMAT, 0, (LPARAM)&cf);
7447 }
7448
SetCharFormat(CHARFORMAT2 & cf,WORD wFlags)7449 BOOL SetCharFormat(CHARFORMAT2& cf, WORD wFlags)
7450 {
7451 ATLASSERT(::IsWindow(this->m_hWnd));
7452 cf.cbSize = sizeof(CHARFORMAT2);
7453 return (BOOL)::SendMessage(this->m_hWnd, EM_SETCHARFORMAT, (WPARAM)wFlags, (LPARAM)&cf);
7454 }
7455
SetDefaultCharFormat(CHARFORMAT2 & cf)7456 BOOL SetDefaultCharFormat(CHARFORMAT2& cf)
7457 {
7458 ATLASSERT(::IsWindow(this->m_hWnd));
7459 cf.cbSize = sizeof(CHARFORMAT2);
7460 return (BOOL)::SendMessage(this->m_hWnd, EM_SETCHARFORMAT, 0, (LPARAM)&cf);
7461 }
7462
GetSelectionCharFormat(CHARFORMAT2 & cf)7463 DWORD GetSelectionCharFormat(CHARFORMAT2& cf) const
7464 {
7465 ATLASSERT(::IsWindow(this->m_hWnd));
7466 cf.cbSize = sizeof(CHARFORMAT2);
7467 return (DWORD)::SendMessage(this->m_hWnd, EM_GETCHARFORMAT, 1, (LPARAM)&cf);
7468 }
7469
SetSelectionCharFormat(CHARFORMAT2 & cf)7470 BOOL SetSelectionCharFormat(CHARFORMAT2& cf)
7471 {
7472 ATLASSERT(::IsWindow(this->m_hWnd));
7473 cf.cbSize = sizeof(CHARFORMAT2);
7474 return (BOOL)::SendMessage(this->m_hWnd, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf);
7475 }
7476
SetWordCharFormat(CHARFORMAT2 & cf)7477 BOOL SetWordCharFormat(CHARFORMAT2& cf)
7478 {
7479 ATLASSERT(::IsWindow(this->m_hWnd));
7480 cf.cbSize = sizeof(CHARFORMAT2);
7481 return (BOOL)::SendMessage(this->m_hWnd, EM_SETCHARFORMAT, SCF_SELECTION | SCF_WORD, (LPARAM)&cf);
7482 }
7483
GetParaFormat(PARAFORMAT2 & pf)7484 DWORD GetParaFormat(PARAFORMAT2& pf) const
7485 {
7486 ATLASSERT(::IsWindow(this->m_hWnd));
7487 pf.cbSize = sizeof(PARAFORMAT2);
7488 return (DWORD)::SendMessage(this->m_hWnd, EM_GETPARAFORMAT, 0, (LPARAM)&pf);
7489 }
7490
SetParaFormat(PARAFORMAT2 & pf)7491 BOOL SetParaFormat(PARAFORMAT2& pf)
7492 {
7493 ATLASSERT(::IsWindow(this->m_hWnd));
7494 pf.cbSize = sizeof(PARAFORMAT2);
7495 return (BOOL)::SendMessage(this->m_hWnd, EM_SETPARAFORMAT, 0, (LPARAM)&pf);
7496 }
7497
GetTextMode()7498 TEXTMODE GetTextMode() const
7499 {
7500 ATLASSERT(::IsWindow(this->m_hWnd));
7501 return (TEXTMODE)::SendMessage(this->m_hWnd, EM_GETTEXTMODE, 0, 0L);
7502 }
7503
SetTextMode(TEXTMODE enumTextMode)7504 BOOL SetTextMode(TEXTMODE enumTextMode)
7505 {
7506 ATLASSERT(::IsWindow(this->m_hWnd));
7507 return !(BOOL)::SendMessage(this->m_hWnd, EM_SETTEXTMODE, enumTextMode, 0L);
7508 }
7509
GetUndoName()7510 UNDONAMEID GetUndoName() const
7511 {
7512 ATLASSERT(::IsWindow(this->m_hWnd));
7513 return (UNDONAMEID)::SendMessage(this->m_hWnd, EM_GETUNDONAME, 0, 0L);
7514 }
7515
GetRedoName()7516 UNDONAMEID GetRedoName() const
7517 {
7518 ATLASSERT(::IsWindow(this->m_hWnd));
7519 return (UNDONAMEID)::SendMessage(this->m_hWnd, EM_GETREDONAME, 0, 0L);
7520 }
7521
CanRedo()7522 BOOL CanRedo() const
7523 {
7524 ATLASSERT(::IsWindow(this->m_hWnd));
7525 return (BOOL)::SendMessage(this->m_hWnd, EM_CANREDO, 0, 0L);
7526 }
7527
GetAutoURLDetect()7528 BOOL GetAutoURLDetect() const
7529 {
7530 ATLASSERT(::IsWindow(this->m_hWnd));
7531 return (BOOL)::SendMessage(this->m_hWnd, EM_GETAUTOURLDETECT, 0, 0L);
7532 }
7533
7534 BOOL SetAutoURLDetect(BOOL bAutoDetect = TRUE)
7535 {
7536 ATLASSERT(::IsWindow(this->m_hWnd));
7537 return !(BOOL)::SendMessage(this->m_hWnd, EM_AUTOURLDETECT, bAutoDetect, 0L);
7538 }
7539
7540 // this method is deprecated, please use SetAutoURLDetect
7541 BOOL EnableAutoURLDetect(BOOL bEnable = TRUE) { return SetAutoURLDetect(bEnable); }
7542
SetUndoLimit(UINT uUndoLimit)7543 UINT SetUndoLimit(UINT uUndoLimit)
7544 {
7545 ATLASSERT(::IsWindow(this->m_hWnd));
7546 return (UINT)::SendMessage(this->m_hWnd, EM_SETUNDOLIMIT, uUndoLimit, 0L);
7547 }
7548
SetPalette(HPALETTE hPalette)7549 void SetPalette(HPALETTE hPalette)
7550 {
7551 ATLASSERT(::IsWindow(this->m_hWnd));
7552 ::SendMessage(this->m_hWnd, EM_SETPALETTE, (WPARAM)hPalette, 0L);
7553 }
7554
GetTextEx(GETTEXTEX * pGetTextEx,LPTSTR lpstrText)7555 int GetTextEx(GETTEXTEX* pGetTextEx, LPTSTR lpstrText) const
7556 {
7557 ATLASSERT(::IsWindow(this->m_hWnd));
7558 return (int)::SendMessage(this->m_hWnd, EM_GETTEXTEX, (WPARAM)pGetTextEx, (LPARAM)lpstrText);
7559 }
7560
7561 int GetTextEx(LPTSTR lpstrText, int nTextLen, DWORD dwFlags = GT_DEFAULT, UINT uCodePage = CP_ACP, LPCSTR lpDefaultChar = NULL, LPBOOL lpUsedDefChar = NULL) const
7562 {
7563 ATLASSERT(::IsWindow(this->m_hWnd));
7564 GETTEXTEX gte = {};
7565 gte.cb = nTextLen * sizeof(TCHAR);
7566 gte.codepage = uCodePage;
7567 gte.flags = dwFlags;
7568 gte.lpDefaultChar = lpDefaultChar;
7569 gte.lpUsedDefChar = lpUsedDefChar;
7570 return (int)::SendMessage(this->m_hWnd, EM_GETTEXTEX, (WPARAM)>e, (LPARAM)lpstrText);
7571 }
7572
GetTextLengthEx(GETTEXTLENGTHEX * pGetTextLengthEx)7573 int GetTextLengthEx(GETTEXTLENGTHEX* pGetTextLengthEx) const
7574 {
7575 ATLASSERT(::IsWindow(this->m_hWnd));
7576 return (int)::SendMessage(this->m_hWnd, EM_GETTEXTLENGTHEX, (WPARAM)pGetTextLengthEx, 0L);
7577 }
7578
7579 int GetTextLengthEx(DWORD dwFlags = GTL_DEFAULT, UINT uCodePage = CP_ACP) const
7580 {
7581 ATLASSERT(::IsWindow(this->m_hWnd));
7582 GETTEXTLENGTHEX gtle = {};
7583 gtle.codepage = uCodePage;
7584 gtle.flags = dwFlags;
7585 return (int)::SendMessage(this->m_hWnd, EM_GETTEXTLENGTHEX, (WPARAM)>le, 0L);
7586 }
7587
GetWordBreakProc()7588 EDITWORDBREAKPROC GetWordBreakProc() const
7589 {
7590 ATLASSERT(::IsWindow(this->m_hWnd));
7591 return (EDITWORDBREAKPROC)::SendMessage(this->m_hWnd, EM_GETWORDBREAKPROC, 0, 0L);
7592 }
7593
SetWordBreakProc(EDITWORDBREAKPROC ewbprc)7594 void SetWordBreakProc(EDITWORDBREAKPROC ewbprc)
7595 {
7596 ATLASSERT(::IsWindow(this->m_hWnd));
7597 ::SendMessage(this->m_hWnd, EM_SETWORDBREAKPROC, 0, (LPARAM)ewbprc);
7598 }
7599
SetTextEx(SETTEXTEX * pSetTextEx,LPCTSTR lpstrText)7600 int SetTextEx(SETTEXTEX* pSetTextEx, LPCTSTR lpstrText)
7601 {
7602 ATLASSERT(::IsWindow(this->m_hWnd));
7603 return (int)::SendMessage(this->m_hWnd, EM_SETTEXTEX, (WPARAM)pSetTextEx, (LPARAM)lpstrText);
7604 }
7605
7606 int SetTextEx(LPCTSTR lpstrText, DWORD dwFlags = ST_DEFAULT, UINT uCodePage = CP_ACP)
7607 {
7608 ATLASSERT(::IsWindow(this->m_hWnd));
7609 SETTEXTEX ste = {};
7610 ste.flags = dwFlags;
7611 ste.codepage = uCodePage;
7612 return (int)::SendMessage(this->m_hWnd, EM_SETTEXTEX, (WPARAM)&ste, (LPARAM)lpstrText);
7613 }
7614
GetEditStyle()7615 int GetEditStyle() const
7616 {
7617 ATLASSERT(::IsWindow(this->m_hWnd));
7618 return (int)::SendMessage(this->m_hWnd, EM_GETEDITSTYLE, 0, 0L);
7619 }
7620
7621 int SetEditStyle(int nStyle, int nMask = -1)
7622 {
7623 ATLASSERT(::IsWindow(this->m_hWnd));
7624 if(nMask == -1)
7625 nMask = nStyle; // set everything specified
7626 return (int)::SendMessage(this->m_hWnd, EM_SETEDITSTYLE, nStyle, nMask);
7627 }
7628
SetFontSize(int nFontSizeDelta)7629 BOOL SetFontSize(int nFontSizeDelta)
7630 {
7631 ATLASSERT(::IsWindow(this->m_hWnd));
7632 ATLASSERT((nFontSizeDelta >= -1637) && (nFontSizeDelta <= 1638));
7633 return (BOOL)::SendMessage(this->m_hWnd, EM_SETFONTSIZE, nFontSizeDelta, 0L);
7634 }
7635
GetScrollPos(LPPOINT lpPoint)7636 void GetScrollPos(LPPOINT lpPoint) const
7637 {
7638 ATLASSERT(::IsWindow(this->m_hWnd));
7639 ATLASSERT(lpPoint != NULL);
7640 ::SendMessage(this->m_hWnd, EM_GETSCROLLPOS, 0, (LPARAM)lpPoint);
7641 }
7642
SetScrollPos(LPPOINT lpPoint)7643 void SetScrollPos(LPPOINT lpPoint)
7644 {
7645 ATLASSERT(::IsWindow(this->m_hWnd));
7646 ATLASSERT(lpPoint != NULL);
7647 ::SendMessage(this->m_hWnd, EM_SETSCROLLPOS, 0, (LPARAM)lpPoint);
7648 }
7649
GetZoom(int & nNum,int & nDen)7650 BOOL GetZoom(int& nNum, int& nDen) const
7651 {
7652 ATLASSERT(::IsWindow(this->m_hWnd));
7653 return (BOOL)::SendMessage(this->m_hWnd, EM_GETZOOM, (WPARAM)&nNum, (LPARAM)&nDen);
7654 }
7655
SetZoom(int nNum,int nDen)7656 BOOL SetZoom(int nNum, int nDen)
7657 {
7658 ATLASSERT(::IsWindow(this->m_hWnd));
7659 ATLASSERT((nNum >= 0) && (nNum <= 64));
7660 ATLASSERT((nDen >= 0) && (nDen <= 64));
7661 return (BOOL)::SendMessage(this->m_hWnd, EM_SETZOOM, nNum, nDen);
7662 }
7663
SetZoomOff()7664 BOOL SetZoomOff()
7665 {
7666 ATLASSERT(::IsWindow(this->m_hWnd));
7667 return (BOOL)::SendMessage(this->m_hWnd, EM_SETZOOM, 0, 0L);
7668 }
7669
7670 void SetMargins(UINT nLeft, UINT nRight, WORD wFlags = EC_LEFTMARGIN | EC_RIGHTMARGIN)
7671 {
7672 ATLASSERT(::IsWindow(this->m_hWnd));
7673 ::SendMessage(this->m_hWnd, EM_SETMARGINS, wFlags, MAKELONG(nLeft, nRight));
7674 }
7675
GetTypographyOptions()7676 WORD GetTypographyOptions() const
7677 {
7678 ATLASSERT(::IsWindow(this->m_hWnd));
7679 return (WORD)::SendMessage(this->m_hWnd, EM_GETTYPOGRAPHYOPTIONS, 0, 0L);
7680 }
7681
SetTypographyOptions(WORD wOptions,WORD wMask)7682 BOOL SetTypographyOptions(WORD wOptions, WORD wMask) const
7683 {
7684 ATLASSERT(::IsWindow(this->m_hWnd));
7685 return (BOOL)::SendMessage(this->m_hWnd, EM_SETTYPOGRAPHYOPTIONS, wOptions, wMask);
7686 }
7687
7688 // Operations
7689 void LimitText(LONG nChars = 0)
7690 {
7691 ATLASSERT(::IsWindow(this->m_hWnd));
7692 ::SendMessage(this->m_hWnd, EM_EXLIMITTEXT, 0, nChars);
7693 }
7694
LineFromChar(LONG nIndex)7695 int LineFromChar(LONG nIndex) const
7696 {
7697 ATLASSERT(::IsWindow(this->m_hWnd));
7698 return (int)::SendMessage(this->m_hWnd, EM_EXLINEFROMCHAR, 0, nIndex);
7699 }
7700
PosFromChar(LONG nChar)7701 POINT PosFromChar(LONG nChar) const
7702 {
7703 ATLASSERT(::IsWindow(this->m_hWnd));
7704 POINT point = {};
7705 ::SendMessage(this->m_hWnd, EM_POSFROMCHAR, (WPARAM)&point, nChar);
7706 return point;
7707 }
7708
CharFromPos(POINT pt)7709 int CharFromPos(POINT pt) const
7710 {
7711 ATLASSERT(::IsWindow(this->m_hWnd));
7712 POINTL ptl = { pt.x, pt.y };
7713 return (int)::SendMessage(this->m_hWnd, EM_CHARFROMPOS, 0, (LPARAM)&ptl);
7714 }
7715
EmptyUndoBuffer()7716 void EmptyUndoBuffer()
7717 {
7718 ATLASSERT(::IsWindow(this->m_hWnd));
7719 ::SendMessage(this->m_hWnd, EM_EMPTYUNDOBUFFER, 0, 0L);
7720 }
7721
7722 int LineIndex(int nLine = -1) const
7723 {
7724 ATLASSERT(::IsWindow(this->m_hWnd));
7725 return (int)::SendMessage(this->m_hWnd, EM_LINEINDEX, nLine, 0L);
7726 }
7727
7728 int LineLength(int nLine = -1) const
7729 {
7730 ATLASSERT(::IsWindow(this->m_hWnd));
7731 return (int)::SendMessage(this->m_hWnd, EM_LINELENGTH, nLine, 0L);
7732 }
7733
LineScroll(int nLines)7734 BOOL LineScroll(int nLines)
7735 {
7736 ATLASSERT(::IsWindow(this->m_hWnd));
7737 return (BOOL)::SendMessage(this->m_hWnd, EM_LINESCROLL, 0, nLines);
7738 }
7739
7740 void ReplaceSel(LPCTSTR lpszNewText, BOOL bCanUndo = FALSE)
7741 {
7742 ATLASSERT(::IsWindow(this->m_hWnd));
7743 ::SendMessage(this->m_hWnd, EM_REPLACESEL, (WPARAM) bCanUndo, (LPARAM)lpszNewText);
7744 }
7745
SetRect(LPCRECT lpRect)7746 void SetRect(LPCRECT lpRect)
7747 {
7748 ATLASSERT(::IsWindow(this->m_hWnd));
7749 ::SendMessage(this->m_hWnd, EM_SETRECT, 0, (LPARAM)lpRect);
7750 }
7751
DisplayBand(LPRECT pDisplayRect)7752 BOOL DisplayBand(LPRECT pDisplayRect)
7753 {
7754 ATLASSERT(::IsWindow(this->m_hWnd));
7755 return (BOOL)::SendMessage(this->m_hWnd, EM_DISPLAYBAND, 0, (LPARAM)pDisplayRect);
7756 }
7757
FindText(DWORD dwFlags,FINDTEXT & ft)7758 LONG FindText(DWORD dwFlags, FINDTEXT& ft) const
7759 {
7760 ATLASSERT(::IsWindow(this->m_hWnd));
7761 #ifdef _UNICODE
7762 return (LONG)::SendMessage(this->m_hWnd, EM_FINDTEXTW, dwFlags, (LPARAM)&ft);
7763 #else
7764 return (LONG)::SendMessage(this->m_hWnd, EM_FINDTEXT, dwFlags, (LPARAM)&ft);
7765 #endif
7766 }
7767
FindText(DWORD dwFlags,FINDTEXTEX & ft)7768 LONG FindText(DWORD dwFlags, FINDTEXTEX& ft) const
7769 {
7770 ATLASSERT(::IsWindow(this->m_hWnd));
7771 #ifdef _UNICODE
7772 return (LONG)::SendMessage(this->m_hWnd, EM_FINDTEXTEXW, dwFlags, (LPARAM)&ft);
7773 #else
7774 return (LONG)::SendMessage(this->m_hWnd, EM_FINDTEXTEX, dwFlags, (LPARAM)&ft);
7775 #endif
7776 }
7777
7778 LONG FormatRange(FORMATRANGE& fr, BOOL bDisplay = TRUE)
7779 {
7780 ATLASSERT(::IsWindow(this->m_hWnd));
7781 return (LONG)::SendMessage(this->m_hWnd, EM_FORMATRANGE, bDisplay, (LPARAM)&fr);
7782 }
7783
7784 LONG FormatRange(FORMATRANGE* pFormatRange, BOOL bDisplay = TRUE)
7785 {
7786 ATLASSERT(::IsWindow(this->m_hWnd));
7787 return (LONG)::SendMessage(this->m_hWnd, EM_FORMATRANGE, bDisplay, (LPARAM)pFormatRange);
7788 }
7789
7790 void HideSelection(BOOL bHide = TRUE, BOOL bChangeStyle = FALSE)
7791 {
7792 ATLASSERT(::IsWindow(this->m_hWnd));
7793 ::SendMessage(this->m_hWnd, EM_HIDESELECTION, bHide, bChangeStyle);
7794 }
7795
7796 void PasteSpecial(UINT uClipFormat, DWORD dwAspect = 0, HMETAFILE hMF = 0)
7797 {
7798 ATLASSERT(::IsWindow(this->m_hWnd));
7799 REPASTESPECIAL reps = { dwAspect, (DWORD_PTR)hMF };
7800 ::SendMessage(this->m_hWnd, EM_PASTESPECIAL, uClipFormat, (LPARAM)&reps);
7801 }
7802
RequestResize()7803 void RequestResize()
7804 {
7805 ATLASSERT(::IsWindow(this->m_hWnd));
7806 ::SendMessage(this->m_hWnd, EM_REQUESTRESIZE, 0, 0L);
7807 }
7808
StreamIn(UINT uFormat,EDITSTREAM & es)7809 LONG StreamIn(UINT uFormat, EDITSTREAM& es)
7810 {
7811 ATLASSERT(::IsWindow(this->m_hWnd));
7812 return (LONG)::SendMessage(this->m_hWnd, EM_STREAMIN, uFormat, (LPARAM)&es);
7813 }
7814
StreamOut(UINT uFormat,EDITSTREAM & es)7815 LONG StreamOut(UINT uFormat, EDITSTREAM& es)
7816 {
7817 ATLASSERT(::IsWindow(this->m_hWnd));
7818 return (LONG)::SendMessage(this->m_hWnd, EM_STREAMOUT, uFormat, (LPARAM)&es);
7819 }
7820
FindWordBreak(int nCode,LONG nStartChar)7821 DWORD FindWordBreak(int nCode, LONG nStartChar)
7822 {
7823 ATLASSERT(::IsWindow(this->m_hWnd));
7824 return (DWORD)::SendMessage(this->m_hWnd, EM_FINDWORDBREAK, nCode, nStartChar);
7825 }
7826
7827 // Additional operations
ScrollCaret()7828 void ScrollCaret()
7829 {
7830 ATLASSERT(::IsWindow(this->m_hWnd));
7831 ::SendMessage(this->m_hWnd, EM_SCROLLCARET, 0, 0L);
7832 }
7833
7834 int InsertText(long nInsertAfterChar, LPCTSTR lpstrText, BOOL bCanUndo = FALSE)
7835 {
7836 int nRet = SetSel(nInsertAfterChar, nInsertAfterChar);
7837 ReplaceSel(lpstrText, bCanUndo);
7838 return nRet;
7839 }
7840
7841 int AppendText(LPCTSTR lpstrText, BOOL bCanUndo = FALSE)
7842 {
7843 return InsertText(this->GetWindowTextLength(), lpstrText, bCanUndo);
7844 }
7845
7846 // Clipboard operations
Undo()7847 BOOL Undo()
7848 {
7849 ATLASSERT(::IsWindow(this->m_hWnd));
7850 return (BOOL)::SendMessage(this->m_hWnd, EM_UNDO, 0, 0L);
7851 }
7852
Clear()7853 void Clear()
7854 {
7855 ATLASSERT(::IsWindow(this->m_hWnd));
7856 ::SendMessage(this->m_hWnd, WM_CLEAR, 0, 0L);
7857 }
7858
Copy()7859 void Copy()
7860 {
7861 ATLASSERT(::IsWindow(this->m_hWnd));
7862 ::SendMessage(this->m_hWnd, WM_COPY, 0, 0L);
7863 }
7864
Cut()7865 void Cut()
7866 {
7867 ATLASSERT(::IsWindow(this->m_hWnd));
7868 ::SendMessage(this->m_hWnd, WM_CUT, 0, 0L);
7869 }
7870
Paste()7871 void Paste()
7872 {
7873 ATLASSERT(::IsWindow(this->m_hWnd));
7874 ::SendMessage(this->m_hWnd, WM_PASTE, 0, 0L);
7875 }
7876
7877 // OLE support
GetOleInterface()7878 IRichEditOle* GetOleInterface() const
7879 {
7880 ATLASSERT(::IsWindow(this->m_hWnd));
7881 IRichEditOle *pRichEditOle = NULL;
7882 ::SendMessage(this->m_hWnd, EM_GETOLEINTERFACE, 0, (LPARAM)&pRichEditOle);
7883 return pRichEditOle;
7884 }
7885
SetOleCallback(IRichEditOleCallback * pCallback)7886 BOOL SetOleCallback(IRichEditOleCallback* pCallback)
7887 {
7888 ATLASSERT(::IsWindow(this->m_hWnd));
7889 return (BOOL)::SendMessage(this->m_hWnd, EM_SETOLECALLBACK, 0, (LPARAM)pCallback);
7890 }
7891
Redo()7892 BOOL Redo()
7893 {
7894 ATLASSERT(::IsWindow(this->m_hWnd));
7895 return (BOOL)::SendMessage(this->m_hWnd, EM_REDO, 0, 0L);
7896 }
7897
StopGroupTyping()7898 void StopGroupTyping()
7899 {
7900 ATLASSERT(::IsWindow(this->m_hWnd));
7901 ::SendMessage(this->m_hWnd, EM_STOPGROUPTYPING, 0, 0L);
7902 }
7903
7904 void ShowScrollBar(int nBarType, BOOL bVisible = TRUE)
7905 {
7906 ATLASSERT(::IsWindow(this->m_hWnd));
7907 ::SendMessage(this->m_hWnd, EM_SHOWSCROLLBAR, nBarType, bVisible);
7908 }
7909
SetTabStops(int nTabStops,LPINT rgTabStops)7910 BOOL SetTabStops(int nTabStops, LPINT rgTabStops)
7911 {
7912 ATLASSERT(::IsWindow(this->m_hWnd));
7913 return (BOOL)::SendMessage(this->m_hWnd, EM_SETTABSTOPS, nTabStops, (LPARAM)rgTabStops);
7914 }
7915
SetTabStops()7916 BOOL SetTabStops()
7917 {
7918 ATLASSERT(::IsWindow(this->m_hWnd));
7919 return (BOOL)::SendMessage(this->m_hWnd, EM_SETTABSTOPS, 0, 0L);
7920 }
7921
SetTabStops(const int & cxEachStop)7922 BOOL SetTabStops(const int& cxEachStop) // takes an 'int'
7923 {
7924 ATLASSERT(::IsWindow(this->m_hWnd));
7925 return (BOOL)::SendMessage(this->m_hWnd, EM_SETTABSTOPS, 1, (LPARAM)(LPINT)&cxEachStop);
7926 }
7927
7928 #if (_RICHEDIT_VER >= 0x0800)
GetAutoCorrectProc()7929 AutoCorrectProc GetAutoCorrectProc() const
7930 {
7931 ATLASSERT(::IsWindow(this->m_hWnd));
7932 return (AutoCorrectProc)::SendMessage(this->m_hWnd, EM_GETAUTOCORRECTPROC, 0, 0L);
7933 }
7934
SetAutoCorrectProc(AutoCorrectProc pfn)7935 BOOL SetAutoCorrectProc(AutoCorrectProc pfn)
7936 {
7937 ATLASSERT(::IsWindow(this->m_hWnd));
7938 return (BOOL)::SendMessage(this->m_hWnd, EM_SETAUTOCORRECTPROC, (WPARAM)pfn, 0L);
7939 }
7940
CallAutoCorrectProc(WCHAR ch)7941 BOOL CallAutoCorrectProc(WCHAR ch)
7942 {
7943 ATLASSERT(::IsWindow(this->m_hWnd));
7944 return (BOOL)::SendMessage(this->m_hWnd, EM_CALLAUTOCORRECTPROC, (WPARAM)ch, 0L);
7945 }
7946
GetEditStyleEx()7947 DWORD GetEditStyleEx() const
7948 {
7949 ATLASSERT(::IsWindow(this->m_hWnd));
7950 return (DWORD)::SendMessage(this->m_hWnd, EM_GETEDITSTYLEEX, 0, 0L);
7951 }
7952
SetEditStyleEx(DWORD dwStyleEx,DWORD dwMask)7953 DWORD SetEditStyleEx(DWORD dwStyleEx, DWORD dwMask)
7954 {
7955 ATLASSERT(::IsWindow(this->m_hWnd));
7956 return (DWORD)::SendMessage(this->m_hWnd, EM_SETEDITSTYLEEX, dwStyleEx, dwMask);
7957 }
7958
GetStoryType(int nStoryIndex)7959 DWORD GetStoryType(int nStoryIndex) const
7960 {
7961 ATLASSERT(::IsWindow(this->m_hWnd));
7962 return (DWORD)::SendMessage(this->m_hWnd, EM_GETSTORYTYPE, nStoryIndex, 0L);
7963 }
7964
SetStoryType(int nStoryIndex,DWORD dwStoryType)7965 DWORD SetStoryType(int nStoryIndex, DWORD dwStoryType)
7966 {
7967 ATLASSERT(::IsWindow(this->m_hWnd));
7968 return (DWORD)::SendMessage(this->m_hWnd, EM_SETSTORYTYPE, nStoryIndex, dwStoryType);
7969 }
7970
GetEllipsisMode()7971 DWORD GetEllipsisMode() const
7972 {
7973 ATLASSERT(::IsWindow(this->m_hWnd));
7974
7975 DWORD dwMode = 0;
7976 BOOL bRet = (BOOL)::SendMessage(this->m_hWnd, EM_GETELLIPSISMODE, 0, (LPARAM)&dwMode);
7977 (void)bRet; // avoid level 4 warning
7978 ATLASSERT(bRet != FALSE);
7979
7980 return dwMode;
7981 }
7982
SetEllipsisMode(DWORD dwEllipsisMode)7983 BOOL SetEllipsisMode(DWORD dwEllipsisMode)
7984 {
7985 ATLASSERT(::IsWindow(this->m_hWnd));
7986 return (BOOL)::SendMessage(this->m_hWnd, EM_SETELLIPSISMODE, 0, dwEllipsisMode);
7987 }
7988
GetEllipsisState()7989 BOOL GetEllipsisState() const
7990 {
7991 ATLASSERT(::IsWindow(this->m_hWnd));
7992 return (BOOL)::SendMessage(this->m_hWnd, EM_GETELLIPSISSTATE, 0, 0L);
7993 }
7994
GetTouchOptions(int nTouchOptions)7995 BOOL GetTouchOptions(int nTouchOptions) const
7996 {
7997 ATLASSERT(::IsWindow(this->m_hWnd));
7998 return (BOOL)::SendMessage(this->m_hWnd, EM_GETTOUCHOPTIONS, nTouchOptions, 0L);
7999 }
8000
SetTouchOptions(int nTouchOptions,BOOL bEnable)8001 void SetTouchOptions(int nTouchOptions, BOOL bEnable)
8002 {
8003 ATLASSERT(::IsWindow(this->m_hWnd));
8004 ::SendMessage(this->m_hWnd, EM_SETTOUCHOPTIONS, nTouchOptions, bEnable);
8005 }
8006
InsertTable(TABLEROWPARMS * pRowParams,TABLECELLPARMS * pCellParams)8007 HRESULT InsertTable(TABLEROWPARMS* pRowParams, TABLECELLPARMS* pCellParams)
8008 {
8009 ATLASSERT(::IsWindow(this->m_hWnd));
8010 return (HRESULT)::SendMessage(this->m_hWnd, EM_INSERTTABLE, (WPARAM)pRowParams, (LPARAM)pCellParams);
8011 }
8012
GetTableParams(TABLEROWPARMS * pRowParams,TABLECELLPARMS * pCellParams)8013 HRESULT GetTableParams(TABLEROWPARMS* pRowParams, TABLECELLPARMS* pCellParams) const
8014 {
8015 ATLASSERT(::IsWindow(this->m_hWnd));
8016 return (HRESULT)::SendMessage(this->m_hWnd, EM_GETTABLEPARMS, (WPARAM)pRowParams, (LPARAM)pCellParams);
8017 }
8018
SetTableParams(TABLEROWPARMS * pRowParams,TABLECELLPARMS * pCellParams)8019 HRESULT SetTableParams(TABLEROWPARMS* pRowParams, TABLECELLPARMS* pCellParams)
8020 {
8021 ATLASSERT(::IsWindow(this->m_hWnd));
8022 return (HRESULT)::SendMessage(this->m_hWnd, EM_SETTABLEPARMS, (WPARAM)pRowParams, (LPARAM)pCellParams);
8023 }
8024
InsertImage(RICHEDIT_IMAGE_PARAMETERS * pParams)8025 HRESULT InsertImage(RICHEDIT_IMAGE_PARAMETERS* pParams)
8026 {
8027 ATLASSERT(::IsWindow(this->m_hWnd));
8028 return (HRESULT)::SendMessage(this->m_hWnd, EM_INSERTIMAGE, 0, (LPARAM)pParams);
8029 }
8030
SetUiaName(LPCTSTR lpstrName)8031 BOOL SetUiaName(LPCTSTR lpstrName)
8032 {
8033 ATLASSERT(::IsWindow(this->m_hWnd));
8034 return (BOOL)::SendMessage(this->m_hWnd, EM_SETUIANAME, 0, (LPARAM)lpstrName);
8035 }
8036 #endif // (_RICHEDIT_VER >= 0x0800)
8037 };
8038
8039 typedef CRichEditCtrlT<ATL::CWindow> CRichEditCtrl;
8040
8041
8042 ///////////////////////////////////////////////////////////////////////////////
8043 // CRichEditCommands - message handlers for standard EDIT commands
8044
8045 // Chain to CRichEditCommands message map. Your class must also derive from CRichEditCtrl.
8046 // Example:
8047 // class CMyRichEdit : public CWindowImpl<CMyRichEdit, CRichEditCtrl>,
8048 // public CRichEditCommands<CMyRichEdit>
8049 // {
8050 // public:
8051 // BEGIN_MSG_MAP(CMyRichEdit)
8052 // // your handlers...
8053 // CHAIN_MSG_MAP_ALT(CRichEditCommands<CMyRichEdit>, 1)
8054 // END_MSG_MAP()
8055 // // other stuff...
8056 // };
8057
8058 template <class T>
8059 class CRichEditCommands : public CEditCommands< T >
8060 {
8061 public:
BEGIN_MSG_MAP(CRichEditCommands<T>)8062 BEGIN_MSG_MAP(CRichEditCommands< T >)
8063 ALT_MSG_MAP(1)
8064 COMMAND_ID_HANDLER(ID_EDIT_CLEAR, CEditCommands< T >::OnEditClear)
8065 COMMAND_ID_HANDLER(ID_EDIT_CLEAR_ALL, CEditCommands< T >::OnEditClearAll)
8066 COMMAND_ID_HANDLER(ID_EDIT_COPY, CEditCommands< T >::OnEditCopy)
8067 COMMAND_ID_HANDLER(ID_EDIT_CUT, CEditCommands< T >::OnEditCut)
8068 COMMAND_ID_HANDLER(ID_EDIT_PASTE, CEditCommands< T >::OnEditPaste)
8069 COMMAND_ID_HANDLER(ID_EDIT_SELECT_ALL, CEditCommands< T >::OnEditSelectAll)
8070 COMMAND_ID_HANDLER(ID_EDIT_UNDO, CEditCommands< T >::OnEditUndo)
8071 COMMAND_ID_HANDLER(ID_EDIT_REDO, OnEditRedo)
8072 END_MSG_MAP()
8073
8074 LRESULT OnEditRedo(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
8075 {
8076 T* pT = static_cast<T*>(this);
8077 pT->Redo();
8078 return 0;
8079 }
8080
8081 // State (update UI) helpers
CanCut()8082 BOOL CanCut() const
8083 { return HasSelection(); }
8084
CanCopy()8085 BOOL CanCopy() const
8086 { return HasSelection(); }
8087
CanClear()8088 BOOL CanClear() const
8089 { return HasSelection(); }
8090
8091 // Implementation
HasSelection()8092 BOOL HasSelection() const
8093 {
8094 const T* pT = static_cast<const T*>(this);
8095 return (pT->GetSelectionType() != SEL_EMPTY);
8096 }
8097 };
8098
8099
8100 ///////////////////////////////////////////////////////////////////////////////
8101 // CDragListBox
8102
8103 template <class TBase>
8104 class CDragListBoxT : public CListBoxT< TBase >
8105 {
8106 public:
8107 // Constructors
8108 CDragListBoxT(HWND hWnd = NULL) : CListBoxT< TBase >(hWnd)
8109 { }
8110
8111 CDragListBoxT< TBase >& operator =(HWND hWnd)
8112 {
8113 this->m_hWnd = hWnd;
8114 return *this;
8115 }
8116
8117 HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
8118 DWORD dwStyle = 0, DWORD dwExStyle = 0,
8119 ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
8120 {
8121 HWND hWnd = TBase::Create(TBase::GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
8122 if(hWnd != NULL)
8123 MakeDragList();
8124 return hWnd;
8125 }
8126
8127 // Operations
MakeDragList()8128 BOOL MakeDragList()
8129 {
8130 ATLASSERT(::IsWindow(this->m_hWnd));
8131 ATLASSERT((this->GetStyle() & (LBS_MULTIPLESEL | LBS_EXTENDEDSEL)) == 0);
8132 return ::MakeDragList(this->m_hWnd);
8133 }
8134
8135 int LBItemFromPt(POINT pt, BOOL bAutoScroll = TRUE)
8136 {
8137 ATLASSERT(::IsWindow(this->m_hWnd));
8138 return ::LBItemFromPt(this->m_hWnd, pt, bAutoScroll);
8139 }
8140
DrawInsert(int nItem)8141 void DrawInsert(int nItem)
8142 {
8143 ATLASSERT(::IsWindow(this->m_hWnd));
8144 ::DrawInsert(this->GetParent(), this->m_hWnd, nItem);
8145 }
8146
GetDragListMessage()8147 static UINT GetDragListMessage()
8148 {
8149 static UINT uDragListMessage = 0;
8150 if(uDragListMessage == 0)
8151 {
8152 CStaticDataInitCriticalSectionLock lock;
8153 if(FAILED(lock.Lock()))
8154 {
8155 ATLTRACE2(atlTraceUI, 0, _T("ERROR : Unable to lock critical section in CDragListBox::GetDragListMessage.\n"));
8156 ATLASSERT(FALSE);
8157 return 0;
8158 }
8159
8160 if(uDragListMessage == 0)
8161 uDragListMessage = ::RegisterWindowMessage(DRAGLISTMSGSTRING);
8162
8163 lock.Unlock();
8164 }
8165 ATLASSERT(uDragListMessage != 0);
8166 return uDragListMessage;
8167 }
8168 };
8169
8170 typedef CDragListBoxT<ATL::CWindow> CDragListBox;
8171
8172 template <class T>
8173 class CDragListNotifyImpl
8174 {
8175 public:
BEGIN_MSG_MAP(CDragListNotifyImpl<T>)8176 BEGIN_MSG_MAP(CDragListNotifyImpl< T >)
8177 MESSAGE_HANDLER(CDragListBox::GetDragListMessage(), OnDragListNotify)
8178 END_MSG_MAP()
8179
8180 LRESULT OnDragListNotify(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
8181 {
8182 (void)uMsg; // avoid level 4 warning
8183 ATLASSERT(uMsg == CDragListBox::GetDragListMessage());
8184 T* pT = static_cast<T*>(this);
8185 LPDRAGLISTINFO lpDragListInfo = (LPDRAGLISTINFO)lParam;
8186 LRESULT lRet = 0;
8187 switch(lpDragListInfo->uNotification)
8188 {
8189 case DL_BEGINDRAG:
8190 lRet = (LPARAM)pT->OnBeginDrag((int)wParam, lpDragListInfo->hWnd, lpDragListInfo->ptCursor);
8191 break;
8192 case DL_CANCELDRAG:
8193 pT->OnCancelDrag((int)wParam, lpDragListInfo->hWnd, lpDragListInfo->ptCursor);
8194 break;
8195 case DL_DRAGGING:
8196 lRet = (LPARAM)pT->OnDragging((int)wParam, lpDragListInfo->hWnd, lpDragListInfo->ptCursor);
8197 break;
8198 case DL_DROPPED:
8199 pT->OnDropped((int)wParam, lpDragListInfo->hWnd, lpDragListInfo->ptCursor);
8200 break;
8201 default:
8202 ATLTRACE2(atlTraceUI, 0, _T("Unknown DragListBox notification\n"));
8203 bHandled = FALSE; // don't handle it
8204 break;
8205 }
8206 return lRet;
8207 }
8208
8209 // Overrideables
OnBeginDrag(int,HWND,POINT)8210 BOOL OnBeginDrag(int /*nCtlID*/, HWND /*hWndDragList*/, POINT /*ptCursor*/)
8211 {
8212 return TRUE; // allow dragging
8213 }
8214
OnCancelDrag(int,HWND,POINT)8215 void OnCancelDrag(int /*nCtlID*/, HWND /*hWndDragList*/, POINT /*ptCursor*/)
8216 {
8217 // nothing to do
8218 }
8219
OnDragging(int,HWND,POINT)8220 int OnDragging(int /*nCtlID*/, HWND /*hWndDragList*/, POINT /*ptCursor*/)
8221 {
8222 return 0; // don't change cursor
8223 }
8224
OnDropped(int,HWND,POINT)8225 void OnDropped(int /*nCtlID*/, HWND /*hWndDragList*/, POINT /*ptCursor*/)
8226 {
8227 // nothing to do
8228 }
8229 };
8230
8231
8232 ///////////////////////////////////////////////////////////////////////////////
8233 // CReBarCtrl
8234
8235 template <class TBase>
8236 class CReBarCtrlT : public TBase
8237 {
8238 public:
8239 // Constructors
TBase(hWnd)8240 CReBarCtrlT(HWND hWnd = NULL) : TBase(hWnd)
8241 { }
8242
8243 CReBarCtrlT< TBase >& operator =(HWND hWnd)
8244 {
8245 this->m_hWnd = hWnd;
8246 return *this;
8247 }
8248
8249 HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
8250 DWORD dwStyle = 0, DWORD dwExStyle = 0,
8251 ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
8252 {
8253 return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
8254 }
8255
8256 // Attributes
GetWndClassName()8257 static LPCTSTR GetWndClassName()
8258 {
8259 return REBARCLASSNAME;
8260 }
8261
GetBandCount()8262 UINT GetBandCount() const
8263 {
8264 ATLASSERT(::IsWindow(this->m_hWnd));
8265 return (UINT)::SendMessage(this->m_hWnd, RB_GETBANDCOUNT, 0, 0L);
8266 }
8267
GetBandInfo(int nBand,LPREBARBANDINFO lprbbi)8268 BOOL GetBandInfo(int nBand, LPREBARBANDINFO lprbbi) const
8269 {
8270 ATLASSERT(::IsWindow(this->m_hWnd));
8271 return (BOOL)::SendMessage(this->m_hWnd, RB_GETBANDINFO, nBand, (LPARAM)lprbbi);
8272 }
8273
SetBandInfo(int nBand,LPREBARBANDINFO lprbbi)8274 BOOL SetBandInfo(int nBand, LPREBARBANDINFO lprbbi)
8275 {
8276 ATLASSERT(::IsWindow(this->m_hWnd));
8277 return (BOOL)::SendMessage(this->m_hWnd, RB_SETBANDINFO, nBand, (LPARAM)lprbbi);
8278 }
8279
GetBarInfo(LPREBARINFO lprbi)8280 BOOL GetBarInfo(LPREBARINFO lprbi) const
8281 {
8282 ATLASSERT(::IsWindow(this->m_hWnd));
8283 return (BOOL)::SendMessage(this->m_hWnd, RB_GETBARINFO, 0, (LPARAM)lprbi);
8284 }
8285
SetBarInfo(LPREBARINFO lprbi)8286 BOOL SetBarInfo(LPREBARINFO lprbi)
8287 {
8288 ATLASSERT(::IsWindow(this->m_hWnd));
8289 return (BOOL)::SendMessage(this->m_hWnd, RB_SETBARINFO, 0, (LPARAM)lprbi);
8290 }
8291
GetImageList()8292 CImageList GetImageList() const
8293 {
8294 ATLASSERT(::IsWindow(this->m_hWnd));
8295 REBARINFO rbi = {};
8296 rbi.cbSize = sizeof(REBARINFO);
8297 rbi.fMask = RBIM_IMAGELIST;
8298 BOOL bRet = (BOOL)::SendMessage(this->m_hWnd, RB_GETBARINFO, 0, (LPARAM)&rbi);
8299 return CImageList((bRet != FALSE) ? rbi.himl : NULL);
8300 }
8301
SetImageList(HIMAGELIST hImageList)8302 BOOL SetImageList(HIMAGELIST hImageList)
8303 {
8304 ATLASSERT(::IsWindow(this->m_hWnd));
8305 REBARINFO rbi = {};
8306 rbi.cbSize = sizeof(REBARINFO);
8307 rbi.fMask = RBIM_IMAGELIST;
8308 rbi.himl = hImageList;
8309 return (BOOL)::SendMessage(this->m_hWnd, RB_SETBARINFO, 0, (LPARAM)&rbi);
8310 }
8311
GetRowCount()8312 UINT GetRowCount() const
8313 {
8314 ATLASSERT(::IsWindow(this->m_hWnd));
8315 return (UINT)::SendMessage(this->m_hWnd, RB_GETROWCOUNT, 0, 0L);
8316 }
8317
GetRowHeight(int nBand)8318 UINT GetRowHeight(int nBand) const
8319 {
8320 ATLASSERT(::IsWindow(this->m_hWnd));
8321 return (UINT)::SendMessage(this->m_hWnd, RB_GETROWHEIGHT, nBand, 0L);
8322 }
8323
GetTextColor()8324 COLORREF GetTextColor() const
8325 {
8326 ATLASSERT(::IsWindow(this->m_hWnd));
8327 return (COLORREF)::SendMessage(this->m_hWnd, RB_GETTEXTCOLOR, 0, 0L);
8328 }
8329
SetTextColor(COLORREF clr)8330 COLORREF SetTextColor(COLORREF clr)
8331 {
8332 ATLASSERT(::IsWindow(this->m_hWnd));
8333 return (COLORREF)::SendMessage(this->m_hWnd, RB_SETTEXTCOLOR, 0, (LPARAM)clr);
8334 }
8335
GetBkColor()8336 COLORREF GetBkColor() const
8337 {
8338 ATLASSERT(::IsWindow(this->m_hWnd));
8339 return (COLORREF)::SendMessage(this->m_hWnd, RB_GETBKCOLOR, 0, 0L);
8340 }
8341
SetBkColor(COLORREF clr)8342 COLORREF SetBkColor(COLORREF clr)
8343 {
8344 ATLASSERT(::IsWindow(this->m_hWnd));
8345 return (COLORREF)::SendMessage(this->m_hWnd, RB_SETBKCOLOR, 0, (LPARAM)clr);
8346 }
8347
GetBarHeight()8348 UINT GetBarHeight() const
8349 {
8350 ATLASSERT(::IsWindow(this->m_hWnd));
8351 return (UINT)::SendMessage(this->m_hWnd, RB_GETBARHEIGHT, 0, 0L);
8352 }
8353
GetRect(int nBand,LPRECT lpRect)8354 BOOL GetRect(int nBand, LPRECT lpRect) const
8355 {
8356 ATLASSERT(::IsWindow(this->m_hWnd));
8357 return (BOOL)::SendMessage(this->m_hWnd, RB_GETRECT, nBand, (LPARAM)lpRect);
8358 }
8359
GetToolTips()8360 CToolTipCtrl GetToolTips() const
8361 {
8362 ATLASSERT(::IsWindow(this->m_hWnd));
8363 return CToolTipCtrl((HWND)::SendMessage(this->m_hWnd, RB_GETTOOLTIPS, 0, 0L));
8364 }
8365
SetToolTips(HWND hwndToolTip)8366 void SetToolTips(HWND hwndToolTip)
8367 {
8368 ATLASSERT(::IsWindow(this->m_hWnd));
8369 ::SendMessage(this->m_hWnd, RB_SETTOOLTIPS, (WPARAM)hwndToolTip, 0L);
8370 }
8371
GetBandBorders(int nBand,LPRECT lpRect)8372 void GetBandBorders(int nBand, LPRECT lpRect) const
8373 {
8374 ATLASSERT(::IsWindow(this->m_hWnd));
8375 ATLASSERT(lpRect != NULL);
8376 ::SendMessage(this->m_hWnd, RB_GETBANDBORDERS, nBand, (LPARAM)lpRect);
8377 }
8378
GetColorScheme(LPCOLORSCHEME lpColorScheme)8379 BOOL GetColorScheme(LPCOLORSCHEME lpColorScheme) const
8380 {
8381 ATLASSERT(::IsWindow(this->m_hWnd));
8382 ATLASSERT(lpColorScheme != NULL);
8383 return (BOOL)::SendMessage(this->m_hWnd, RB_GETCOLORSCHEME, 0, (LPARAM)lpColorScheme);
8384 }
8385
SetColorScheme(LPCOLORSCHEME lpColorScheme)8386 void SetColorScheme(LPCOLORSCHEME lpColorScheme)
8387 {
8388 ATLASSERT(::IsWindow(this->m_hWnd));
8389 ATLASSERT(lpColorScheme != NULL);
8390 ::SendMessage(this->m_hWnd, RB_SETCOLORSCHEME, 0, (LPARAM)lpColorScheme);
8391 }
8392
GetPalette()8393 HPALETTE GetPalette() const
8394 {
8395 ATLASSERT(::IsWindow(this->m_hWnd));
8396 return (HPALETTE)::SendMessage(this->m_hWnd, RB_GETPALETTE, 0, 0L);
8397 }
8398
SetPalette(HPALETTE hPalette)8399 HPALETTE SetPalette(HPALETTE hPalette)
8400 {
8401 ATLASSERT(::IsWindow(this->m_hWnd));
8402 return (HPALETTE)::SendMessage(this->m_hWnd, RB_SETPALETTE, 0, (LPARAM)hPalette);
8403 }
8404
GetUnicodeFormat()8405 BOOL GetUnicodeFormat() const
8406 {
8407 ATLASSERT(::IsWindow(this->m_hWnd));
8408 return (BOOL)::SendMessage(this->m_hWnd, RB_GETUNICODEFORMAT, 0, 0L);
8409 }
8410
8411 BOOL SetUnicodeFormat(BOOL bUnicode = TRUE)
8412 {
8413 ATLASSERT(::IsWindow(this->m_hWnd));
8414 return (BOOL)::SendMessage(this->m_hWnd, RB_SETUNICODEFORMAT, bUnicode, 0L);
8415 }
8416
8417 // requires uxtheme.h to be included to use MARGINS struct
8418 #ifndef _UXTHEME_H_
8419 typedef struct _MARGINS* PMARGINS;
8420 #endif // !_UXTHEME_H_
GetBandMargins(PMARGINS pMargins)8421 void GetBandMargins(PMARGINS pMargins) const
8422 {
8423 ATLASSERT(::IsWindow(this->m_hWnd));
8424 ::SendMessage(this->m_hWnd, RB_GETBANDMARGINS, 0, (LPARAM)pMargins);
8425 }
8426
SetWindowTheme(LPCWSTR lpstrTheme)8427 void SetWindowTheme(LPCWSTR lpstrTheme)
8428 {
8429 ATLASSERT(::IsWindow(this->m_hWnd));
8430 ::SendMessage(this->m_hWnd, RB_SETWINDOWTHEME, 0, (LPARAM)lpstrTheme);
8431 }
8432
GetExtendedStyle()8433 DWORD GetExtendedStyle() const
8434 {
8435 ATLASSERT(::IsWindow(this->m_hWnd));
8436 return (DWORD)::SendMessage(this->m_hWnd, RB_GETEXTENDEDSTYLE, 0, 0L);
8437 }
8438
SetExtendedStyle(DWORD dwStyle,DWORD dwMask)8439 DWORD SetExtendedStyle(DWORD dwStyle, DWORD dwMask)
8440 {
8441 ATLASSERT(::IsWindow(this->m_hWnd));
8442 return (DWORD)::SendMessage(this->m_hWnd, RB_SETEXTENDEDSTYLE, dwMask, dwStyle);
8443 }
8444
8445 // Operations
InsertBand(int nBand,LPREBARBANDINFO lprbbi)8446 BOOL InsertBand(int nBand, LPREBARBANDINFO lprbbi)
8447 {
8448 ATLASSERT(::IsWindow(this->m_hWnd));
8449 return (BOOL)::SendMessage(this->m_hWnd, RB_INSERTBAND, nBand, (LPARAM)lprbbi);
8450 }
8451
AddBand(LPREBARBANDINFO lprbbi)8452 BOOL AddBand(LPREBARBANDINFO lprbbi)
8453 {
8454 return InsertBand(-1, lprbbi);
8455 }
8456
DeleteBand(int nBand)8457 BOOL DeleteBand(int nBand)
8458 {
8459 ATLASSERT(::IsWindow(this->m_hWnd));
8460 return (BOOL)::SendMessage(this->m_hWnd, RB_DELETEBAND, nBand, 0L);
8461 }
8462
SetNotifyWnd(HWND hWnd)8463 ATL::CWindow SetNotifyWnd(HWND hWnd)
8464 {
8465 ATLASSERT(::IsWindow(this->m_hWnd));
8466 return ATL::CWindow((HWND)::SendMessage(this->m_hWnd, RB_SETPARENT, (WPARAM)hWnd, 0L));
8467 }
8468
BeginDrag(int nBand,DWORD dwPos)8469 void BeginDrag(int nBand, DWORD dwPos)
8470 {
8471 ATLASSERT(::IsWindow(this->m_hWnd));
8472 ::SendMessage(this->m_hWnd, RB_BEGINDRAG, nBand, dwPos);
8473 }
8474
BeginDrag(int nBand,int xPos,int yPos)8475 void BeginDrag(int nBand, int xPos, int yPos)
8476 {
8477 ATLASSERT(::IsWindow(this->m_hWnd));
8478 ::SendMessage(this->m_hWnd, RB_BEGINDRAG, nBand, MAKELPARAM(xPos, yPos));
8479 }
8480
EndDrag()8481 void EndDrag()
8482 {
8483 ATLASSERT(::IsWindow(this->m_hWnd));
8484 ::SendMessage(this->m_hWnd, RB_ENDDRAG, 0, 0L);
8485 }
8486
DragMove(DWORD dwPos)8487 void DragMove(DWORD dwPos)
8488 {
8489 ATLASSERT(::IsWindow(this->m_hWnd));
8490 ::SendMessage(this->m_hWnd, RB_DRAGMOVE, 0, dwPos);
8491 }
8492
DragMove(int xPos,int yPos)8493 void DragMove(int xPos, int yPos)
8494 {
8495 ATLASSERT(::IsWindow(this->m_hWnd));
8496 ::SendMessage(this->m_hWnd, RB_DRAGMOVE, 0, MAKELPARAM(xPos, yPos));
8497 }
8498
GetDropTarget(IDropTarget ** ppDropTarget)8499 void GetDropTarget(IDropTarget** ppDropTarget) const
8500 {
8501 ATLASSERT(::IsWindow(this->m_hWnd));
8502 ::SendMessage(this->m_hWnd, RB_GETDROPTARGET, 0, (LPARAM)ppDropTarget);
8503 }
8504
8505 void MaximizeBand(int nBand, BOOL bIdeal = FALSE)
8506 {
8507 ATLASSERT(::IsWindow(this->m_hWnd));
8508 ::SendMessage(this->m_hWnd, RB_MAXIMIZEBAND, nBand, bIdeal);
8509 }
8510
MinimizeBand(int nBand)8511 void MinimizeBand(int nBand)
8512 {
8513 ATLASSERT(::IsWindow(this->m_hWnd));
8514 ::SendMessage(this->m_hWnd, RB_MINIMIZEBAND, nBand, 0L);
8515 }
8516
SizeToRect(LPRECT lpRect)8517 BOOL SizeToRect(LPRECT lpRect)
8518 {
8519 ATLASSERT(::IsWindow(this->m_hWnd));
8520 return (BOOL)::SendMessage(this->m_hWnd, RB_SIZETORECT, 0, (LPARAM)lpRect);
8521 }
8522
IdToIndex(UINT uBandID)8523 int IdToIndex(UINT uBandID) const
8524 {
8525 ATLASSERT(::IsWindow(this->m_hWnd));
8526 return (int)::SendMessage(this->m_hWnd, RB_IDTOINDEX, uBandID, 0L);
8527 }
8528
HitTest(LPRBHITTESTINFO lprbht)8529 int HitTest(LPRBHITTESTINFO lprbht) const
8530 {
8531 ATLASSERT(::IsWindow(this->m_hWnd));
8532 return (int)::SendMessage(this->m_hWnd, RB_HITTEST, 0, (LPARAM)lprbht);
8533 }
8534
ShowBand(int nBand,BOOL bShow)8535 BOOL ShowBand(int nBand, BOOL bShow)
8536 {
8537 ATLASSERT(::IsWindow(this->m_hWnd));
8538 return (BOOL)::SendMessage(this->m_hWnd, RB_SHOWBAND, nBand, bShow);
8539 }
8540
MoveBand(int nBand,int nNewPos)8541 BOOL MoveBand(int nBand, int nNewPos)
8542 {
8543 ATLASSERT(::IsWindow(this->m_hWnd));
8544 ATLASSERT((nNewPos >= 0) && (nNewPos <= ((int)GetBandCount() - 1)));
8545 return (BOOL)::SendMessage(this->m_hWnd, RB_MOVEBAND, nBand, nNewPos);
8546 }
8547
PushChevron(int nBand,LPARAM lAppValue)8548 void PushChevron(int nBand, LPARAM lAppValue)
8549 {
8550 ATLASSERT(::IsWindow(this->m_hWnd));
8551 ::SendMessage(this->m_hWnd, RB_PUSHCHEVRON, nBand, lAppValue);
8552 }
8553
8554 // Extra operations
LockBands(bool bLock)8555 void LockBands(bool bLock)
8556 {
8557 int nBandCount = GetBandCount();
8558 for(int i =0; i < nBandCount; i++)
8559 {
8560 REBARBANDINFO rbbi = { RunTimeHelper::SizeOf_REBARBANDINFO() };
8561 rbbi.fMask = RBBIM_STYLE;
8562 BOOL bRet = GetBandInfo(i, &rbbi);
8563 ATLASSERT(bRet);
8564
8565 if((rbbi.fStyle & RBBS_GRIPPERALWAYS) == 0)
8566 {
8567 rbbi.fStyle |= RBBS_GRIPPERALWAYS;
8568 bRet = SetBandInfo(i, &rbbi);
8569 ATLASSERT(bRet);
8570 rbbi.fStyle &= ~RBBS_GRIPPERALWAYS;
8571 }
8572
8573 if(bLock)
8574 rbbi.fStyle |= RBBS_NOGRIPPER;
8575 else
8576 rbbi.fStyle &= ~RBBS_NOGRIPPER;
8577
8578 bRet = SetBandInfo(i, &rbbi);
8579 ATLASSERT(bRet);
8580 }
8581 }
8582
8583 #if (_WIN32_WINNT >= 0x0600)
SetBandWidth(int nBand,int cxWidth)8584 BOOL SetBandWidth(int nBand, int cxWidth)
8585 {
8586 ATLASSERT(::IsWindow(this->m_hWnd));
8587 return (BOOL)::SendMessage(this->m_hWnd, RB_SETBANDWIDTH, nBand, cxWidth);
8588 }
8589 #endif // (_WIN32_WINNT >= 0x0600)
8590 };
8591
8592 typedef CReBarCtrlT<ATL::CWindow> CReBarCtrl;
8593
8594
8595 ///////////////////////////////////////////////////////////////////////////////
8596 // CComboBoxEx
8597
8598 template <class TBase>
8599 class CComboBoxExT : public CComboBoxT< TBase >
8600 {
8601 public:
8602 // Constructors
8603 CComboBoxExT(HWND hWnd = NULL) : CComboBoxT< TBase >(hWnd)
8604 { }
8605
8606 CComboBoxExT< TBase >& operator =(HWND hWnd)
8607 {
8608 this->m_hWnd = hWnd;
8609 return *this;
8610 }
8611
8612 HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
8613 DWORD dwStyle = 0, DWORD dwExStyle = 0,
8614 ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
8615 {
8616 return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
8617 }
8618
8619 // Attributes
GetWndClassName()8620 static LPCTSTR GetWndClassName()
8621 {
8622 return WC_COMBOBOXEX;
8623 }
8624
GetImageList()8625 CImageList GetImageList() const
8626 {
8627 ATLASSERT(::IsWindow(this->m_hWnd));
8628 return CImageList((HIMAGELIST)::SendMessage(this->m_hWnd, CBEM_GETIMAGELIST, 0, 0L));
8629 }
8630
SetImageList(HIMAGELIST hImageList)8631 CImageList SetImageList(HIMAGELIST hImageList)
8632 {
8633 ATLASSERT(::IsWindow(this->m_hWnd));
8634 return CImageList((HIMAGELIST)::SendMessage(this->m_hWnd, CBEM_SETIMAGELIST, 0, (LPARAM)hImageList));
8635 }
8636
GetExtendedStyle()8637 DWORD GetExtendedStyle() const
8638 {
8639 ATLASSERT(::IsWindow(this->m_hWnd));
8640 return (DWORD)::SendMessage(this->m_hWnd, CBEM_GETEXTENDEDSTYLE, 0, 0L);
8641 }
8642
SetExtendedStyle(DWORD dwExMask,DWORD dwExStyle)8643 DWORD SetExtendedStyle(DWORD dwExMask, DWORD dwExStyle)
8644 {
8645 ATLASSERT(::IsWindow(this->m_hWnd));
8646 return (DWORD)::SendMessage(this->m_hWnd, CBEM_SETEXTENDEDSTYLE, dwExMask, dwExStyle);
8647 }
8648
GetUnicodeFormat()8649 BOOL GetUnicodeFormat() const
8650 {
8651 ATLASSERT(::IsWindow(this->m_hWnd));
8652 return (BOOL)::SendMessage(this->m_hWnd, CBEM_GETUNICODEFORMAT, 0, 0L);
8653 }
8654
8655 BOOL SetUnicodeFormat(BOOL bUnicode = TRUE)
8656 {
8657 ATLASSERT(::IsWindow(this->m_hWnd));
8658 return (BOOL)::SendMessage(this->m_hWnd, CBEM_SETUNICODEFORMAT, bUnicode, 0L);
8659 }
8660
SetWindowTheme(LPCWSTR lpstrTheme)8661 void SetWindowTheme(LPCWSTR lpstrTheme)
8662 {
8663 ATLASSERT(::IsWindow(this->m_hWnd));
8664 ::SendMessage(this->m_hWnd, CBEM_SETWINDOWTHEME, 0, (LPARAM)lpstrTheme);
8665 }
8666
8667 // Operations
InsertItem(const COMBOBOXEXITEM * lpcCBItem)8668 int InsertItem(const COMBOBOXEXITEM* lpcCBItem)
8669 {
8670 ATLASSERT(::IsWindow(this->m_hWnd));
8671 return (int)::SendMessage(this->m_hWnd, CBEM_INSERTITEM, 0, (LPARAM)lpcCBItem);
8672 }
8673
InsertItem(UINT nMask,int nIndex,LPCTSTR lpszItem,int nImage,int nSelImage,int iIndent,int iOverlay,LPARAM lParam)8674 int InsertItem(UINT nMask, int nIndex, LPCTSTR lpszItem, int nImage, int nSelImage,
8675 int iIndent, int iOverlay, LPARAM lParam)
8676 {
8677 ATLASSERT(::IsWindow(this->m_hWnd));
8678 COMBOBOXEXITEM cbex = {};
8679 cbex.mask = nMask;
8680 cbex.iItem = nIndex;
8681 cbex.pszText = (LPTSTR) lpszItem;
8682 cbex.iImage = nImage;
8683 cbex.iSelectedImage = nSelImage;
8684 cbex.iIndent = iIndent;
8685 cbex.iOverlay = iOverlay;
8686 cbex.lParam = lParam;
8687 return (int)::SendMessage(this->m_hWnd, CBEM_INSERTITEM, 0, (LPARAM)&cbex);
8688 }
8689
8690 int InsertItem(int nIndex, LPCTSTR lpszItem, int nImage, int nSelImage, int iIndent, LPARAM lParam = 0)
8691 {
8692 ATLASSERT(::IsWindow(this->m_hWnd));
8693 COMBOBOXEXITEM cbex = {};
8694 cbex.mask = CBEIF_TEXT | CBEIF_IMAGE | CBEIF_SELECTEDIMAGE | CBEIF_INDENT | CBEIF_LPARAM;
8695 cbex.iItem = nIndex;
8696 cbex.pszText = (LPTSTR) lpszItem;
8697 cbex.iImage = nImage;
8698 cbex.iSelectedImage = nSelImage;
8699 cbex.iIndent = iIndent;
8700 cbex.lParam = lParam;
8701 return (int)::SendMessage(this->m_hWnd, CBEM_INSERTITEM, 0, (LPARAM)&cbex);
8702 }
8703
AddItem(UINT nMask,LPCTSTR lpszItem,int nImage,int nSelImage,int iIndent,int iOverlay,LPARAM lParam)8704 int AddItem(UINT nMask, LPCTSTR lpszItem, int nImage, int nSelImage, int iIndent, int iOverlay, LPARAM lParam)
8705 {
8706 return InsertItem(nMask, -1, lpszItem, nImage, nSelImage, iIndent, iOverlay, lParam);
8707 }
8708
8709 int AddItem(LPCTSTR lpszItem, int nImage, int nSelImage, int iIndent, LPARAM lParam = 0)
8710 {
8711 return InsertItem(-1, lpszItem, nImage, nSelImage, iIndent, lParam);
8712 }
8713
DeleteItem(int nIndex)8714 int DeleteItem(int nIndex)
8715 {
8716 ATLASSERT(::IsWindow(this->m_hWnd));
8717 return (int)::SendMessage(this->m_hWnd, CBEM_DELETEITEM, nIndex, 0L);
8718 }
8719
GetItem(PCOMBOBOXEXITEM pCBItem)8720 BOOL GetItem(PCOMBOBOXEXITEM pCBItem) const
8721 {
8722 ATLASSERT(::IsWindow(this->m_hWnd));
8723 return (BOOL)::SendMessage(this->m_hWnd, CBEM_GETITEM, 0, (LPARAM)pCBItem);
8724 }
8725
SetItem(const COMBOBOXEXITEM * lpcCBItem)8726 BOOL SetItem(const COMBOBOXEXITEM* lpcCBItem)
8727 {
8728 ATLASSERT(::IsWindow(this->m_hWnd));
8729 return (BOOL)::SendMessage(this->m_hWnd, CBEM_SETITEM, 0, (LPARAM)lpcCBItem);
8730 }
8731
SetItem(int nIndex,UINT nMask,LPCTSTR lpszItem,int nImage,int nSelImage,int iIndent,int iOverlay,LPARAM lParam)8732 int SetItem(int nIndex, UINT nMask, LPCTSTR lpszItem, int nImage, int nSelImage,
8733 int iIndent, int iOverlay, LPARAM lParam)
8734 {
8735 ATLASSERT(::IsWindow(this->m_hWnd));
8736 COMBOBOXEXITEM cbex = {};
8737 cbex.mask = nMask;
8738 cbex.iItem = nIndex;
8739 cbex.pszText = (LPTSTR) lpszItem;
8740 cbex.iImage = nImage;
8741 cbex.iSelectedImage = nSelImage;
8742 cbex.iIndent = iIndent;
8743 cbex.iOverlay = iOverlay;
8744 cbex.lParam = lParam;
8745 return (int)::SendMessage(this->m_hWnd, CBEM_SETITEM, 0, (LPARAM)&cbex);
8746 }
8747
GetItemText(int nIndex,LPTSTR lpszItem,int nLen)8748 BOOL GetItemText(int nIndex, LPTSTR lpszItem, int nLen) const
8749 {
8750 ATLASSERT(::IsWindow(this->m_hWnd));
8751 ATLASSERT(lpszItem != NULL);
8752
8753 COMBOBOXEXITEM cbex = {};
8754 cbex.mask = CBEIF_TEXT;
8755 cbex.iItem = nIndex;
8756 cbex.pszText = lpszItem;
8757 cbex.cchTextMax = nLen;
8758
8759 return (BOOL)::SendMessage(this->m_hWnd, CBEM_GETITEM, 0, (LPARAM)&cbex);
8760 }
8761
GetItemText(int nIndex,BSTR & bstrText)8762 BOOL GetItemText(int nIndex, BSTR& bstrText) const
8763 {
8764 USES_CONVERSION;
8765 ATLASSERT(::IsWindow(this->m_hWnd));
8766 ATLASSERT(bstrText == NULL);
8767
8768 COMBOBOXEXITEM cbex = {};
8769 cbex.mask = CBEIF_TEXT;
8770 cbex.iItem = nIndex;
8771
8772 LPTSTR lpstrText = NULL;
8773 BOOL bRet = FALSE;
8774 for(int nLen = 256; ; nLen *= 2)
8775 {
8776 ATLTRY(lpstrText = new TCHAR[nLen]);
8777 if(lpstrText == NULL)
8778 break;
8779 lpstrText[0] = NULL;
8780 cbex.pszText = lpstrText;
8781 cbex.cchTextMax = nLen;
8782 bRet = (BOOL)::SendMessage(this->m_hWnd, CBEM_GETITEM, 0, (LPARAM)&cbex);
8783 if(!bRet || (lstrlen(cbex.pszText) < (nLen - 1)))
8784 break;
8785 delete [] lpstrText;
8786 lpstrText = NULL;
8787 }
8788
8789 if(lpstrText != NULL)
8790 {
8791 if(bRet)
8792 bstrText = ::SysAllocString(T2OLE(lpstrText));
8793 delete [] lpstrText;
8794 }
8795
8796 return (bstrText != NULL) ? TRUE : FALSE;
8797 }
8798
8799 #ifdef __ATLSTR_H__
GetItemText(int nIndex,ATL::CString & strText)8800 BOOL GetItemText(int nIndex, ATL::CString& strText) const
8801 {
8802 ATLASSERT(::IsWindow(this->m_hWnd));
8803
8804 COMBOBOXEXITEM cbex = {};
8805 cbex.mask = CBEIF_TEXT;
8806 cbex.iItem = nIndex;
8807
8808 strText.Empty();
8809 BOOL bRet = FALSE;
8810 for(int nLen = 256; ; nLen *= 2)
8811 {
8812 cbex.pszText = strText.GetBufferSetLength(nLen);
8813 if(cbex.pszText == NULL)
8814 {
8815 bRet = FALSE;
8816 break;
8817 }
8818 cbex.cchTextMax = nLen;
8819 bRet = (BOOL)::SendMessage(this->m_hWnd, CBEM_GETITEM, 0, (LPARAM)&cbex);
8820 if(!bRet || (lstrlen(cbex.pszText) < (nLen - 1)))
8821 break;
8822 }
8823 strText.ReleaseBuffer();
8824 return bRet;
8825 }
8826 #endif // __ATLSTR_H__
8827
SetItemText(int nIndex,LPCTSTR lpszItem)8828 BOOL SetItemText(int nIndex, LPCTSTR lpszItem)
8829 {
8830 ATLASSERT(::IsWindow(this->m_hWnd));
8831 return SetItem(nIndex, CBEIF_TEXT, lpszItem, 0, 0, 0, 0, 0);
8832 }
8833
GetComboCtrl()8834 CComboBox GetComboCtrl() const
8835 {
8836 ATLASSERT(::IsWindow(this->m_hWnd));
8837 return CComboBox((HWND)::SendMessage(this->m_hWnd, CBEM_GETCOMBOCONTROL, 0, 0L));
8838 }
8839
GetEditCtrl()8840 CEdit GetEditCtrl() const
8841 {
8842 ATLASSERT(::IsWindow(this->m_hWnd));
8843 return CEdit((HWND)::SendMessage(this->m_hWnd, CBEM_GETEDITCONTROL, 0, 0L));
8844 }
8845
HasEditChanged()8846 BOOL HasEditChanged() const
8847 {
8848 ATLASSERT(::IsWindow(this->m_hWnd));
8849 return (BOOL)::SendMessage(this->m_hWnd, CBEM_HASEDITCHANGED, 0, 0L);
8850 }
8851
8852 // Non-functional
AddString(LPCTSTR)8853 int AddString(LPCTSTR /*lpszItem*/)
8854 {
8855 ATLASSERT(FALSE); // Not available in CComboBoxEx; use InsertItem
8856 return 0;
8857 }
8858
InsertString(int,LPCTSTR)8859 int InsertString(int /*nIndex*/, LPCTSTR /*lpszString*/)
8860 {
8861 ATLASSERT(FALSE); // Not available in CComboBoxEx; use InsertItem
8862 return 0;
8863 }
8864
Dir(UINT,LPCTSTR)8865 int Dir(UINT /*attr*/, LPCTSTR /*lpszWildCard*/)
8866 {
8867 ATLASSERT(FALSE); // Not available in CComboBoxEx
8868 return 0;
8869 }
8870
FindString(int,LPCTSTR)8871 int FindString(int /*nStartAfter*/, LPCTSTR /*lpszString*/) const
8872 {
8873 ATLASSERT(FALSE); // Not available in CComboBoxEx; try FindStringExact
8874 return 0;
8875 }
8876 };
8877
8878 typedef CComboBoxExT<ATL::CWindow> CComboBoxEx;
8879
8880
8881 ///////////////////////////////////////////////////////////////////////////////
8882 // CMonthCalendarCtrl
8883
8884 template <class TBase>
8885 class CMonthCalendarCtrlT : public TBase
8886 {
8887 public:
8888 // Constructors
TBase(hWnd)8889 CMonthCalendarCtrlT(HWND hWnd = NULL) : TBase(hWnd)
8890 { }
8891
8892 CMonthCalendarCtrlT< TBase >& operator =(HWND hWnd)
8893 {
8894 this->m_hWnd = hWnd;
8895 return *this;
8896 }
8897
8898 HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
8899 DWORD dwStyle = 0, DWORD dwExStyle = 0,
8900 ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
8901 {
8902 return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
8903 }
8904
8905 // Attributes
GetWndClassName()8906 static LPCTSTR GetWndClassName()
8907 {
8908 return MONTHCAL_CLASS;
8909 }
8910
GetColor(int nColorType)8911 COLORREF GetColor(int nColorType) const
8912 {
8913 ATLASSERT(::IsWindow(this->m_hWnd));
8914 return (COLORREF)::SendMessage(this->m_hWnd, MCM_GETCOLOR, nColorType, 0L);
8915 }
8916
SetColor(int nColorType,COLORREF clr)8917 COLORREF SetColor(int nColorType, COLORREF clr)
8918 {
8919 ATLASSERT(::IsWindow(this->m_hWnd));
8920 return (COLORREF)::SendMessage(this->m_hWnd, MCM_SETCOLOR, nColorType, clr);
8921 }
8922
GetCurSel(LPSYSTEMTIME lpSysTime)8923 BOOL GetCurSel(LPSYSTEMTIME lpSysTime) const
8924 {
8925 ATLASSERT(::IsWindow(this->m_hWnd));
8926 return (BOOL)::SendMessage(this->m_hWnd, MCM_GETCURSEL, 0, (LPARAM)lpSysTime);
8927 }
8928
SetCurSel(LPSYSTEMTIME lpSysTime)8929 BOOL SetCurSel(LPSYSTEMTIME lpSysTime)
8930 {
8931 ATLASSERT(::IsWindow(this->m_hWnd));
8932 return (BOOL)::SendMessage(this->m_hWnd, MCM_SETCURSEL, 0, (LPARAM)lpSysTime);
8933 }
8934
8935 int GetFirstDayOfWeek(BOOL* pbLocaleVal = NULL) const
8936 {
8937 ATLASSERT(::IsWindow(this->m_hWnd));
8938 DWORD dwRet = (DWORD)::SendMessage(this->m_hWnd, MCM_GETFIRSTDAYOFWEEK, 0, 0L);
8939 if(pbLocaleVal != NULL)
8940 *pbLocaleVal = (BOOL)HIWORD(dwRet);
8941 return (int)(short)LOWORD(dwRet);
8942 }
8943
8944 int SetFirstDayOfWeek(int nDay, BOOL* pbLocaleVal = NULL)
8945 {
8946 ATLASSERT(::IsWindow(this->m_hWnd));
8947 DWORD dwRet = (DWORD)::SendMessage(this->m_hWnd, MCM_SETFIRSTDAYOFWEEK, 0, nDay);
8948 if(pbLocaleVal != NULL)
8949 *pbLocaleVal = (BOOL)HIWORD(dwRet);
8950 return (int)(short)LOWORD(dwRet);
8951 }
8952
GetMaxSelCount()8953 int GetMaxSelCount() const
8954 {
8955 ATLASSERT(::IsWindow(this->m_hWnd));
8956 return (int)::SendMessage(this->m_hWnd, MCM_GETMAXSELCOUNT, 0, 0L);
8957 }
8958
SetMaxSelCount(int nMax)8959 BOOL SetMaxSelCount(int nMax)
8960 {
8961 ATLASSERT(::IsWindow(this->m_hWnd));
8962 return (BOOL)::SendMessage(this->m_hWnd, MCM_SETMAXSELCOUNT, nMax, 0L);
8963 }
8964
GetMonthDelta()8965 int GetMonthDelta() const
8966 {
8967 ATLASSERT(::IsWindow(this->m_hWnd));
8968 return (int)::SendMessage(this->m_hWnd, MCM_GETMONTHDELTA, 0, 0L);
8969 }
8970
SetMonthDelta(int nDelta)8971 int SetMonthDelta(int nDelta)
8972 {
8973 ATLASSERT(::IsWindow(this->m_hWnd));
8974 return (int)::SendMessage(this->m_hWnd, MCM_SETMONTHDELTA, nDelta, 0L);
8975 }
8976
GetRange(LPSYSTEMTIME lprgSysTimeArray)8977 DWORD GetRange(LPSYSTEMTIME lprgSysTimeArray) const
8978 {
8979 ATLASSERT(::IsWindow(this->m_hWnd));
8980 return (DWORD)::SendMessage(this->m_hWnd, MCM_GETRANGE, 0, (LPARAM)lprgSysTimeArray);
8981 }
8982
SetRange(DWORD dwFlags,LPSYSTEMTIME lprgSysTimeArray)8983 BOOL SetRange(DWORD dwFlags, LPSYSTEMTIME lprgSysTimeArray)
8984 {
8985 ATLASSERT(::IsWindow(this->m_hWnd));
8986 return (BOOL)::SendMessage(this->m_hWnd, MCM_SETRANGE, dwFlags, (LPARAM)lprgSysTimeArray);
8987 }
8988
GetSelRange(LPSYSTEMTIME lprgSysTimeArray)8989 BOOL GetSelRange(LPSYSTEMTIME lprgSysTimeArray) const
8990 {
8991 ATLASSERT(::IsWindow(this->m_hWnd));
8992 return (BOOL)::SendMessage(this->m_hWnd, MCM_GETSELRANGE, 0, (LPARAM)lprgSysTimeArray);
8993 }
8994
SetSelRange(LPSYSTEMTIME lprgSysTimeArray)8995 BOOL SetSelRange(LPSYSTEMTIME lprgSysTimeArray)
8996 {
8997 ATLASSERT(::IsWindow(this->m_hWnd));
8998 return (BOOL)::SendMessage(this->m_hWnd, MCM_SETSELRANGE, 0, (LPARAM)lprgSysTimeArray);
8999 }
9000
GetToday(LPSYSTEMTIME lpSysTime)9001 BOOL GetToday(LPSYSTEMTIME lpSysTime) const
9002 {
9003 ATLASSERT(::IsWindow(this->m_hWnd));
9004 return (BOOL)::SendMessage(this->m_hWnd, MCM_GETTODAY, 0, (LPARAM)lpSysTime);
9005 }
9006
SetToday(LPSYSTEMTIME lpSysTime)9007 void SetToday(LPSYSTEMTIME lpSysTime)
9008 {
9009 ATLASSERT(::IsWindow(this->m_hWnd));
9010 ::SendMessage(this->m_hWnd, MCM_SETTODAY, 0, (LPARAM)lpSysTime);
9011 }
9012
GetMinReqRect(LPRECT lpRectInfo)9013 BOOL GetMinReqRect(LPRECT lpRectInfo) const
9014 {
9015 ATLASSERT(::IsWindow(this->m_hWnd));
9016 return (BOOL)::SendMessage(this->m_hWnd, MCM_GETMINREQRECT, 0, (LPARAM)lpRectInfo);
9017 }
9018
GetMaxTodayWidth()9019 int GetMaxTodayWidth() const
9020 {
9021 ATLASSERT(::IsWindow(this->m_hWnd));
9022 return (int)::SendMessage(this->m_hWnd, MCM_GETMAXTODAYWIDTH, 0, 0L);
9023 }
9024
GetUnicodeFormat()9025 BOOL GetUnicodeFormat() const
9026 {
9027 ATLASSERT(::IsWindow(this->m_hWnd));
9028 return (BOOL)::SendMessage(this->m_hWnd, MCM_GETUNICODEFORMAT, 0, 0L);
9029 }
9030
9031 BOOL SetUnicodeFormat(BOOL bUnicode = TRUE)
9032 {
9033 ATLASSERT(::IsWindow(this->m_hWnd));
9034 return (BOOL)::SendMessage(this->m_hWnd, MCM_SETUNICODEFORMAT, bUnicode, 0L);
9035 }
9036
9037 #if defined(NTDDI_VERSION) && (NTDDI_VERSION >= NTDDI_LONGHORN)
GetCurrentView()9038 DWORD GetCurrentView() const
9039 {
9040 ATLASSERT(::IsWindow(this->m_hWnd));
9041 return (DWORD)::SendMessage(this->m_hWnd, MCM_GETCURRENTVIEW, 0, 0L);
9042 }
9043
SetCurrentView(DWORD dwView)9044 BOOL SetCurrentView(DWORD dwView)
9045 {
9046 ATLASSERT(::IsWindow(this->m_hWnd));
9047 return (BOOL)::SendMessage(this->m_hWnd, MCM_SETCURRENTVIEW, 0, dwView);
9048 }
9049
GetCalendarCount()9050 DWORD GetCalendarCount() const
9051 {
9052 ATLASSERT(::IsWindow(this->m_hWnd));
9053 return (DWORD)::SendMessage(this->m_hWnd, MCM_GETCALENDARCOUNT, 0, 0L);
9054 }
9055
GetCalendarGridInfo(PMCGRIDINFO pGridInfo)9056 BOOL GetCalendarGridInfo(PMCGRIDINFO pGridInfo) const
9057 {
9058 ATLASSERT(::IsWindow(this->m_hWnd));
9059 return (BOOL)::SendMessage(this->m_hWnd, MCM_GETCALENDARGRIDINFO, 0, (LPARAM)pGridInfo);
9060 }
9061
GetCALID()9062 CALID GetCALID() const
9063 {
9064 ATLASSERT(::IsWindow(this->m_hWnd));
9065 return (CALID)::SendMessage(this->m_hWnd, MCM_GETCALID, 0, 0L);
9066 }
9067
SetCALID(CALID calid)9068 void SetCALID(CALID calid)
9069 {
9070 ATLASSERT(::IsWindow(this->m_hWnd));
9071 ::SendMessage(this->m_hWnd, MCM_SETCALID, (LPARAM)calid, 0L);
9072 }
9073
GetCalendarBorder()9074 int GetCalendarBorder() const
9075 {
9076 ATLASSERT(::IsWindow(this->m_hWnd));
9077 return (int)::SendMessage(this->m_hWnd, MCM_GETCALENDARBORDER, 0, 0L);
9078 }
9079
9080 void SetCalendarBorder(int cxyBorder, BOOL bSet = TRUE)
9081 {
9082 ATLASSERT(::IsWindow(this->m_hWnd));
9083 ::SendMessage(this->m_hWnd, MCM_SETCALENDARBORDER, (WPARAM)bSet, (LPARAM)cxyBorder);
9084 }
9085 #endif // defined(NTDDI_VERSION) && (NTDDI_VERSION >= NTDDI_LONGHORN)
9086
9087 // Operations
GetMonthRange(DWORD dwFlags,LPSYSTEMTIME lprgSysTimeArray)9088 int GetMonthRange(DWORD dwFlags, LPSYSTEMTIME lprgSysTimeArray) const
9089 {
9090 ATLASSERT(::IsWindow(this->m_hWnd));
9091 return (int)::SendMessage(this->m_hWnd, MCM_GETMONTHRANGE, dwFlags, (LPARAM)lprgSysTimeArray);
9092 }
9093
SetDayState(int nMonths,LPMONTHDAYSTATE lpDayStateArray)9094 BOOL SetDayState(int nMonths, LPMONTHDAYSTATE lpDayStateArray)
9095 {
9096 ATLASSERT(::IsWindow(this->m_hWnd));
9097 return (BOOL)::SendMessage(this->m_hWnd, MCM_SETDAYSTATE, nMonths, (LPARAM)lpDayStateArray);
9098 }
9099
HitTest(PMCHITTESTINFO pMCHitTest)9100 DWORD HitTest(PMCHITTESTINFO pMCHitTest) const
9101 {
9102 ATLASSERT(::IsWindow(this->m_hWnd));
9103 return (DWORD)::SendMessage(this->m_hWnd, MCM_HITTEST, 0, (LPARAM)pMCHitTest);
9104 }
9105
9106 #if defined(NTDDI_VERSION) && (NTDDI_VERSION >= NTDDI_LONGHORN)
SizeRectToMin(LPRECT lpRect)9107 void SizeRectToMin(LPRECT lpRect)
9108 {
9109 ATLASSERT(::IsWindow(this->m_hWnd));
9110 ::SendMessage(this->m_hWnd, MCM_SIZERECTTOMIN, 0, (LPARAM)lpRect);
9111 }
9112 #endif // defined(NTDDI_VERSION) && (NTDDI_VERSION >= NTDDI_LONGHORN)
9113 };
9114
9115 typedef CMonthCalendarCtrlT<ATL::CWindow> CMonthCalendarCtrl;
9116
9117
9118 ///////////////////////////////////////////////////////////////////////////////
9119 // CDateTimePickerCtrl
9120
9121 template <class TBase>
9122 class CDateTimePickerCtrlT : public TBase
9123 {
9124 public:
9125 // Constructors
TBase(hWnd)9126 CDateTimePickerCtrlT(HWND hWnd = NULL) : TBase(hWnd)
9127 { }
9128
9129 CDateTimePickerCtrlT< TBase >& operator =(HWND hWnd)
9130 {
9131 this->m_hWnd = hWnd;
9132 return *this;
9133 }
9134
9135 HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
9136 DWORD dwStyle = 0, DWORD dwExStyle = 0,
9137 ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
9138 {
9139 return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
9140 }
9141
9142 // Operations
GetWndClassName()9143 static LPCTSTR GetWndClassName()
9144 {
9145 return DATETIMEPICK_CLASS;
9146 }
9147
SetFormat(LPCTSTR lpszFormat)9148 BOOL SetFormat(LPCTSTR lpszFormat)
9149 {
9150 ATLASSERT(::IsWindow(this->m_hWnd));
9151 return (BOOL)::SendMessage(this->m_hWnd, DTM_SETFORMAT, 0, (LPARAM)lpszFormat);
9152 }
9153
GetMonthCalColor(int nColorType)9154 COLORREF GetMonthCalColor(int nColorType) const
9155 {
9156 ATLASSERT(::IsWindow(this->m_hWnd));
9157 return (COLORREF)::SendMessage(this->m_hWnd, DTM_GETMCCOLOR, nColorType, 0L);
9158 }
9159
SetMonthCalColor(int nColorType,COLORREF clr)9160 COLORREF SetMonthCalColor(int nColorType, COLORREF clr)
9161 {
9162 ATLASSERT(::IsWindow(this->m_hWnd));
9163 return (COLORREF)::SendMessage(this->m_hWnd, DTM_SETMCCOLOR, nColorType, clr);
9164 }
9165
GetRange(LPSYSTEMTIME lpSysTimeArray)9166 DWORD GetRange(LPSYSTEMTIME lpSysTimeArray) const
9167 {
9168 ATLASSERT(::IsWindow(this->m_hWnd));
9169 return (DWORD)::SendMessage(this->m_hWnd, DTM_GETRANGE, 0, (LPARAM)lpSysTimeArray);
9170 }
9171
SetRange(DWORD dwFlags,LPSYSTEMTIME lpSysTimeArray)9172 BOOL SetRange(DWORD dwFlags, LPSYSTEMTIME lpSysTimeArray)
9173 {
9174 ATLASSERT(::IsWindow(this->m_hWnd));
9175 return (BOOL)::SendMessage(this->m_hWnd, DTM_SETRANGE, dwFlags, (LPARAM)lpSysTimeArray);
9176 }
9177
GetSystemTime(LPSYSTEMTIME lpSysTime)9178 DWORD GetSystemTime(LPSYSTEMTIME lpSysTime) const
9179 {
9180 ATLASSERT(::IsWindow(this->m_hWnd));
9181 return (DWORD)::SendMessage(this->m_hWnd, DTM_GETSYSTEMTIME, 0, (LPARAM)lpSysTime);
9182 }
9183
SetSystemTime(DWORD dwFlags,LPSYSTEMTIME lpSysTime)9184 BOOL SetSystemTime(DWORD dwFlags, LPSYSTEMTIME lpSysTime)
9185 {
9186 ATLASSERT(::IsWindow(this->m_hWnd));
9187 return (BOOL)::SendMessage(this->m_hWnd, DTM_SETSYSTEMTIME, dwFlags, (LPARAM)lpSysTime);
9188 }
9189
GetMonthCal()9190 CMonthCalendarCtrl GetMonthCal() const
9191 {
9192 ATLASSERT(::IsWindow(this->m_hWnd));
9193 return CMonthCalendarCtrl((HWND)::SendMessage(this->m_hWnd, DTM_GETMONTHCAL, 0, 0L));
9194 }
9195
GetMonthCalFont()9196 CFontHandle GetMonthCalFont() const
9197 {
9198 ATLASSERT(::IsWindow(this->m_hWnd));
9199 return CFontHandle((HFONT)::SendMessage(this->m_hWnd, DTM_GETMCFONT, 0, 0L));
9200 }
9201
9202 void SetMonthCalFont(HFONT hFont, BOOL bRedraw = TRUE)
9203 {
9204 ATLASSERT(::IsWindow(this->m_hWnd));
9205 ::SendMessage(this->m_hWnd, DTM_SETMCFONT, (WPARAM)hFont, MAKELPARAM(bRedraw, 0));
9206 }
9207
9208 #if defined(NTDDI_VERSION) && (NTDDI_VERSION >= NTDDI_LONGHORN)
GetMonthCalStyle()9209 DWORD GetMonthCalStyle() const
9210 {
9211 ATLASSERT(::IsWindow(this->m_hWnd));
9212 return (DWORD)::SendMessage(this->m_hWnd, DTM_GETMCSTYLE, 0, 0L);
9213 }
9214
SetMonthCalStyle(DWORD dwStyle)9215 DWORD SetMonthCalStyle(DWORD dwStyle)
9216 {
9217 ATLASSERT(::IsWindow(this->m_hWnd));
9218 return (DWORD)::SendMessage(this->m_hWnd, DTM_SETMCSTYLE, 0, (LPARAM)dwStyle);
9219 }
9220
GetDateTimePickerInfo(LPDATETIMEPICKERINFO lpPickerInfo)9221 void GetDateTimePickerInfo(LPDATETIMEPICKERINFO lpPickerInfo) const
9222 {
9223 ATLASSERT(::IsWindow(this->m_hWnd));
9224 ::SendMessage(this->m_hWnd, DTM_GETDATETIMEPICKERINFO, 0, (LPARAM)lpPickerInfo);
9225 }
9226
GetIdealSize(LPSIZE lpSize)9227 BOOL GetIdealSize(LPSIZE lpSize) const
9228 {
9229 ATLASSERT(::IsWindow(this->m_hWnd));
9230 return (BOOL)::SendMessage(this->m_hWnd, DTM_GETIDEALSIZE, 0, (LPARAM)lpSize);
9231 }
9232
CloseMonthCal()9233 void CloseMonthCal()
9234 {
9235 ATLASSERT(::IsWindow(this->m_hWnd));
9236 ::SendMessage(this->m_hWnd, DTM_CLOSEMONTHCAL, 0, 0L);
9237 }
9238 #endif // defined(NTDDI_VERSION) && (NTDDI_VERSION >= NTDDI_LONGHORN)
9239 };
9240
9241 typedef CDateTimePickerCtrlT<ATL::CWindow> CDateTimePickerCtrl;
9242
9243
9244 ///////////////////////////////////////////////////////////////////////////////
9245 // CFlatScrollBarImpl - support for flat scroll bars
9246
9247 template <class T>
9248 class CFlatScrollBarImpl
9249 {
9250 public:
9251 // Initialization
FlatSB_Initialize()9252 BOOL FlatSB_Initialize()
9253 {
9254 T* pT = static_cast<T*>(this);
9255 ATLASSERT(::IsWindow(pT->m_hWnd));
9256 return ::InitializeFlatSB(pT->m_hWnd);
9257 }
9258
FlatSB_Uninitialize()9259 HRESULT FlatSB_Uninitialize()
9260 {
9261 T* pT = static_cast<T*>(this);
9262 ATLASSERT(::IsWindow(pT->m_hWnd));
9263 return ::UninitializeFlatSB(pT->m_hWnd);
9264 }
9265
9266 // Flat scroll bar properties
FlatSB_GetScrollProp(UINT uIndex,LPINT lpnValue)9267 BOOL FlatSB_GetScrollProp(UINT uIndex, LPINT lpnValue) const
9268 {
9269 const T* pT = static_cast<const T*>(this);
9270 ATLASSERT(::IsWindow(pT->m_hWnd));
9271 return ::FlatSB_GetScrollProp(pT->m_hWnd, uIndex, lpnValue);
9272 }
9273
9274 BOOL FlatSB_SetScrollProp(UINT uIndex, int nValue, BOOL bRedraw = TRUE)
9275 {
9276 T* pT = static_cast<T*>(this);
9277 ATLASSERT(::IsWindow(pT->m_hWnd));
9278 return ::FlatSB_SetScrollProp(pT->m_hWnd, uIndex, nValue, bRedraw);
9279 }
9280
9281 // Attributes
FlatSB_GetScrollPos(int nBar)9282 int FlatSB_GetScrollPos(int nBar) const
9283 {
9284 const T* pT = static_cast<const T*>(this);
9285 ATLASSERT(::IsWindow(pT->m_hWnd));
9286 return ::FlatSB_GetScrollPos(pT->m_hWnd, nBar);
9287 }
9288
9289 int FlatSB_SetScrollPos(int nBar, int nPos, BOOL bRedraw = TRUE)
9290 {
9291 T* pT = static_cast<T*>(this);
9292 ATLASSERT(::IsWindow(pT->m_hWnd));
9293 return ::FlatSB_SetScrollPos(pT->m_hWnd, nBar, nPos, bRedraw);
9294 }
9295
FlatSB_GetScrollRange(int nBar,LPINT lpMinPos,LPINT lpMaxPos)9296 BOOL FlatSB_GetScrollRange(int nBar, LPINT lpMinPos, LPINT lpMaxPos) const
9297 {
9298 const T* pT = static_cast<const T*>(this);
9299 ATLASSERT(::IsWindow(pT->m_hWnd));
9300 return ::FlatSB_GetScrollRange(pT->m_hWnd, nBar, lpMinPos, lpMaxPos);
9301 }
9302
9303 BOOL FlatSB_SetScrollRange(int nBar, int nMinPos, int nMaxPos, BOOL bRedraw = TRUE)
9304 {
9305 T* pT = static_cast<T*>(this);
9306 ATLASSERT(::IsWindow(pT->m_hWnd));
9307 return ::FlatSB_SetScrollRange(pT->m_hWnd, nBar, nMinPos, nMaxPos, bRedraw);
9308 }
9309
FlatSB_GetScrollInfo(int nBar,LPSCROLLINFO lpScrollInfo)9310 BOOL FlatSB_GetScrollInfo(int nBar, LPSCROLLINFO lpScrollInfo) const
9311 {
9312 const T* pT = static_cast<const T*>(this);
9313 ATLASSERT(::IsWindow(pT->m_hWnd));
9314 return ::FlatSB_GetScrollInfo(pT->m_hWnd, nBar, lpScrollInfo);
9315 }
9316
9317 int FlatSB_SetScrollInfo(int nBar, LPSCROLLINFO lpScrollInfo, BOOL bRedraw = TRUE)
9318 {
9319 T* pT = static_cast<T*>(this);
9320 ATLASSERT(::IsWindow(pT->m_hWnd));
9321 return ::FlatSB_SetScrollInfo(pT->m_hWnd, nBar, lpScrollInfo, bRedraw);
9322 }
9323
9324 // Operations
9325 BOOL FlatSB_ShowScrollBar(UINT nBar, BOOL bShow = TRUE)
9326 {
9327 T* pT = static_cast<T*>(this);
9328 ATLASSERT(::IsWindow(pT->m_hWnd));
9329 return ::FlatSB_ShowScrollBar(pT->m_hWnd, nBar, bShow);
9330 }
9331
9332 BOOL FlatSB_EnableScrollBar(UINT uSBFlags, UINT uArrowFlags = ESB_ENABLE_BOTH)
9333 {
9334 T* pT = static_cast<T*>(this);
9335 ATLASSERT(::IsWindow(pT->m_hWnd));
9336 return ::FlatSB_EnableScrollBar(pT->m_hWnd, uSBFlags, uArrowFlags);
9337 }
9338 };
9339
9340 template <class TBase>
9341 class CFlatScrollBarT : public TBase, public CFlatScrollBarImpl<CFlatScrollBarT< TBase > >
9342 {
9343 public:
TBase(hWnd)9344 CFlatScrollBarT(HWND hWnd = NULL) : TBase(hWnd)
9345 { }
9346
9347 CFlatScrollBarT< TBase >& operator =(HWND hWnd)
9348 {
9349 this->m_hWnd = hWnd;
9350 return *this;
9351 }
9352 };
9353
9354 typedef CFlatScrollBarT<ATL::CWindow> CFlatScrollBar;
9355
9356
9357 ///////////////////////////////////////////////////////////////////////////////
9358 // CIPAddressCtrl
9359
9360 template <class TBase>
9361 class CIPAddressCtrlT : public TBase
9362 {
9363 public:
9364 // Constructors
TBase(hWnd)9365 CIPAddressCtrlT(HWND hWnd = NULL) : TBase(hWnd)
9366 { }
9367
9368 CIPAddressCtrlT< TBase >& operator =(HWND hWnd)
9369 {
9370 this->m_hWnd = hWnd;
9371 return *this;
9372 }
9373
9374 HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
9375 DWORD dwStyle = 0, DWORD dwExStyle = 0,
9376 ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
9377 {
9378 return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
9379 }
9380
9381 // Atteributes
GetWndClassName()9382 static LPCTSTR GetWndClassName()
9383 {
9384 return WC_IPADDRESS;
9385 }
9386
IsBlank()9387 BOOL IsBlank() const
9388 {
9389 ATLASSERT(::IsWindow(this->m_hWnd));
9390 return (BOOL)::SendMessage(this->m_hWnd, IPM_ISBLANK, 0, 0L);
9391 }
9392
GetAddress(LPDWORD lpdwAddress)9393 int GetAddress(LPDWORD lpdwAddress) const
9394 {
9395 ATLASSERT(::IsWindow(this->m_hWnd));
9396 return (int)::SendMessage(this->m_hWnd, IPM_GETADDRESS, 0, (LPARAM)lpdwAddress);
9397 }
9398
SetAddress(DWORD dwAddress)9399 void SetAddress(DWORD dwAddress)
9400 {
9401 ATLASSERT(::IsWindow(this->m_hWnd));
9402 ::SendMessage(this->m_hWnd, IPM_SETADDRESS, 0, dwAddress);
9403 }
9404
ClearAddress()9405 void ClearAddress()
9406 {
9407 ATLASSERT(::IsWindow(this->m_hWnd));
9408 ::SendMessage(this->m_hWnd, IPM_CLEARADDRESS, 0, 0L);
9409 }
9410
SetRange(int nField,WORD wRange)9411 void SetRange(int nField, WORD wRange)
9412 {
9413 ATLASSERT(::IsWindow(this->m_hWnd));
9414 ::SendMessage(this->m_hWnd, IPM_SETRANGE, nField, wRange);
9415 }
9416
SetRange(int nField,BYTE nMin,BYTE nMax)9417 void SetRange(int nField, BYTE nMin, BYTE nMax)
9418 {
9419 ATLASSERT(::IsWindow(this->m_hWnd));
9420 ::SendMessage(this->m_hWnd, IPM_SETRANGE, nField, MAKEIPRANGE(nMin, nMax));
9421 }
9422
SetFocus(int nField)9423 void SetFocus(int nField)
9424 {
9425 ATLASSERT(::IsWindow(this->m_hWnd));
9426 ::SendMessage(this->m_hWnd, IPM_SETFOCUS, nField, 0L);
9427 }
9428 };
9429
9430 typedef CIPAddressCtrlT<ATL::CWindow> CIPAddressCtrl;
9431
9432
9433 ///////////////////////////////////////////////////////////////////////////////
9434 // CPagerCtrl
9435
9436 template <class TBase>
9437 class CPagerCtrlT : public TBase
9438 {
9439 public:
9440 // Constructors
TBase(hWnd)9441 CPagerCtrlT(HWND hWnd = NULL) : TBase(hWnd)
9442 { }
9443
9444 CPagerCtrlT< TBase >& operator =(HWND hWnd)
9445 {
9446 this->m_hWnd = hWnd;
9447 return *this;
9448 }
9449
9450 HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
9451 DWORD dwStyle = 0, DWORD dwExStyle = 0,
9452 ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
9453 {
9454 return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
9455 }
9456
9457 // Attributes
GetWndClassName()9458 static LPCTSTR GetWndClassName()
9459 {
9460 return WC_PAGESCROLLER;
9461 }
9462
GetButtonSize()9463 int GetButtonSize() const
9464 {
9465 ATLASSERT(::IsWindow(this->m_hWnd));
9466 return (int)::SendMessage(this->m_hWnd, PGM_GETBUTTONSIZE, 0, 0L);
9467 }
9468
SetButtonSize(int nButtonSize)9469 int SetButtonSize(int nButtonSize)
9470 {
9471 ATLASSERT(::IsWindow(this->m_hWnd));
9472 return (int)::SendMessage(this->m_hWnd, PGM_SETBUTTONSIZE, 0, nButtonSize);
9473 }
9474
GetButtonState(int nButton)9475 DWORD GetButtonState(int nButton) const
9476 {
9477 ATLASSERT(::IsWindow(this->m_hWnd));
9478 ATLASSERT((nButton == PGB_TOPORLEFT) || (nButton == PGB_BOTTOMORRIGHT));
9479 return (DWORD)::SendMessage(this->m_hWnd, PGM_GETBUTTONSTATE, 0, nButton);
9480 }
9481
GetBkColor()9482 COLORREF GetBkColor() const
9483 {
9484 ATLASSERT(::IsWindow(this->m_hWnd));
9485 return (COLORREF)::SendMessage(this->m_hWnd, PGM_GETBKCOLOR, 0, 0L);
9486 }
9487
SetBkColor(COLORREF clrBk)9488 COLORREF SetBkColor(COLORREF clrBk)
9489 {
9490 ATLASSERT(::IsWindow(this->m_hWnd));
9491 return (COLORREF)::SendMessage(this->m_hWnd, PGM_SETBKCOLOR, 0, (LPARAM)clrBk);
9492 }
9493
GetBorder()9494 int GetBorder() const
9495 {
9496 ATLASSERT(::IsWindow(this->m_hWnd));
9497 return (int)::SendMessage(this->m_hWnd, PGM_GETBORDER, 0, 0L);
9498 }
9499
SetBorder(int nBorderSize)9500 int SetBorder(int nBorderSize)
9501 {
9502 ATLASSERT(::IsWindow(this->m_hWnd));
9503 return (int)::SendMessage(this->m_hWnd, PGM_SETBORDER, 0, nBorderSize);
9504 }
9505
GetPos()9506 int GetPos() const
9507 {
9508 ATLASSERT(::IsWindow(this->m_hWnd));
9509 return (int)::SendMessage(this->m_hWnd, PGM_GETPOS, 0, 0L);
9510 }
9511
SetPos(int nPos)9512 int SetPos(int nPos)
9513 {
9514 ATLASSERT(::IsWindow(this->m_hWnd));
9515 return (int)::SendMessage(this->m_hWnd, PGM_SETPOS, 0, nPos);
9516 }
9517
9518 // Operations
SetChild(HWND hWndChild)9519 void SetChild(HWND hWndChild)
9520 {
9521 ATLASSERT(::IsWindow(this->m_hWnd));
9522 ::SendMessage(this->m_hWnd, PGM_SETCHILD, 0, (LPARAM)hWndChild);
9523 }
9524
9525 void ForwardMouse(BOOL bForward = TRUE)
9526 {
9527 ATLASSERT(::IsWindow(this->m_hWnd));
9528 ::SendMessage(this->m_hWnd, PGM_FORWARDMOUSE, bForward, 0L);
9529 }
9530
RecalcSize()9531 void RecalcSize()
9532 {
9533 ATLASSERT(::IsWindow(this->m_hWnd));
9534 ::SendMessage(this->m_hWnd, PGM_RECALCSIZE, 0, 0L);
9535 }
9536
GetDropTarget(IDropTarget ** ppDropTarget)9537 void GetDropTarget(IDropTarget** ppDropTarget)
9538 {
9539 ATLASSERT(::IsWindow(this->m_hWnd));
9540 ATLASSERT(ppDropTarget != NULL);
9541 ::SendMessage(this->m_hWnd, PGM_GETDROPTARGET, 0, (LPARAM)ppDropTarget);
9542 }
9543 };
9544
9545 typedef CPagerCtrlT<ATL::CWindow> CPagerCtrl;
9546
9547
9548 ///////////////////////////////////////////////////////////////////////////////
9549 // CLinkCtrl - Windows SYSLINK control
9550
9551 template <class TBase>
9552 class CLinkCtrlT : public TBase
9553 {
9554 public:
9555 // Constructors
TBase(hWnd)9556 CLinkCtrlT(HWND hWnd = NULL) : TBase(hWnd)
9557 { }
9558
9559 CLinkCtrlT< TBase >& operator =(HWND hWnd)
9560 {
9561 this->m_hWnd = hWnd;
9562 return *this;
9563 }
9564
9565 HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
9566 DWORD dwStyle = 0, DWORD dwExStyle = 0,
9567 ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
9568 {
9569 return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
9570 }
9571
9572 // Attributes
GetWndClassName()9573 static LPCTSTR GetWndClassName()
9574 {
9575 #ifdef _UNICODE
9576 return WC_LINK;
9577 #else // !_UNICODE
9578 return "SysLink";
9579 #endif // !_UNICODE
9580 }
9581
9582 int GetIdealHeight(int cxMaxWidth = 0) const
9583 {
9584 ATLASSERT(::IsWindow(this->m_hWnd));
9585 return (int)::SendMessage(this->m_hWnd, LM_GETIDEALHEIGHT, cxMaxWidth, 0L);
9586 }
9587
GetItem(PLITEM pLItem)9588 BOOL GetItem(PLITEM pLItem) const
9589 {
9590 ATLASSERT(::IsWindow(this->m_hWnd));
9591 return (BOOL)::SendMessage(this->m_hWnd, LM_GETITEM, 0, (LPARAM)pLItem);
9592 }
9593
SetItem(PLITEM pLItem)9594 BOOL SetItem(PLITEM pLItem)
9595 {
9596 ATLASSERT(::IsWindow(this->m_hWnd));
9597 return (BOOL)::SendMessage(this->m_hWnd, LM_SETITEM, 0, (LPARAM)pLItem);
9598 }
9599
9600 // Vista only
9601 int GetIdealSize(SIZE& size, int cxMaxWidth = 0) const
9602 {
9603 ATLASSERT(::IsWindow(this->m_hWnd));
9604 return (int)::SendMessage(this->m_hWnd, LM_GETIDEALSIZE, cxMaxWidth, (LPARAM)&size);
9605 }
9606
9607 // Operations
HitTest(PLHITTESTINFO pLHitTestInfo)9608 BOOL HitTest(PLHITTESTINFO pLHitTestInfo) const
9609 {
9610 ATLASSERT(::IsWindow(this->m_hWnd));
9611 return (BOOL)::SendMessage(this->m_hWnd, LM_HITTEST, 0, (LPARAM)pLHitTestInfo);
9612 }
9613 };
9614
9615 typedef CLinkCtrlT<ATL::CWindow> CLinkCtrl;
9616
9617
9618 ///////////////////////////////////////////////////////////////////////////////
9619 // CCustomDraw - MI class for custom-draw support
9620
9621 template <class T>
9622 class CCustomDraw
9623 {
9624 public:
9625 // Message map and handlers
BEGIN_MSG_MAP(CCustomDraw<T>)9626 BEGIN_MSG_MAP(CCustomDraw< T >)
9627 NOTIFY_CODE_HANDLER(NM_CUSTOMDRAW, OnCustomDraw)
9628 ALT_MSG_MAP(1)
9629 REFLECTED_NOTIFY_CODE_HANDLER(NM_CUSTOMDRAW, OnCustomDraw)
9630 END_MSG_MAP()
9631
9632 // message handler
9633 LRESULT OnCustomDraw(int idCtrl, LPNMHDR pnmh, BOOL& bHandled)
9634 {
9635 T* pT = static_cast<T*>(this);
9636 pT->SetMsgHandled(TRUE);
9637 LPNMCUSTOMDRAW lpNMCustomDraw = (LPNMCUSTOMDRAW)pnmh;
9638 DWORD dwRet = 0;
9639 switch(lpNMCustomDraw->dwDrawStage)
9640 {
9641 case CDDS_PREPAINT:
9642 dwRet = pT->OnPrePaint(idCtrl, lpNMCustomDraw);
9643 break;
9644 case CDDS_POSTPAINT:
9645 dwRet = pT->OnPostPaint(idCtrl, lpNMCustomDraw);
9646 break;
9647 case CDDS_PREERASE:
9648 dwRet = pT->OnPreErase(idCtrl, lpNMCustomDraw);
9649 break;
9650 case CDDS_POSTERASE:
9651 dwRet = pT->OnPostErase(idCtrl, lpNMCustomDraw);
9652 break;
9653 case CDDS_ITEMPREPAINT:
9654 dwRet = pT->OnItemPrePaint(idCtrl, lpNMCustomDraw);
9655 break;
9656 case CDDS_ITEMPOSTPAINT:
9657 dwRet = pT->OnItemPostPaint(idCtrl, lpNMCustomDraw);
9658 break;
9659 case CDDS_ITEMPREERASE:
9660 dwRet = pT->OnItemPreErase(idCtrl, lpNMCustomDraw);
9661 break;
9662 case CDDS_ITEMPOSTERASE:
9663 dwRet = pT->OnItemPostErase(idCtrl, lpNMCustomDraw);
9664 break;
9665 case (CDDS_ITEMPREPAINT | CDDS_SUBITEM):
9666 dwRet = pT->OnSubItemPrePaint(idCtrl, lpNMCustomDraw);
9667 break;
9668 default:
9669 pT->SetMsgHandled(FALSE);
9670 break;
9671 }
9672 bHandled = pT->IsMsgHandled();
9673 return dwRet;
9674 }
9675
9676 // Overrideables
OnPrePaint(int,LPNMCUSTOMDRAW)9677 DWORD OnPrePaint(int /*idCtrl*/, LPNMCUSTOMDRAW /*lpNMCustomDraw*/)
9678 {
9679 return CDRF_DODEFAULT;
9680 }
9681
OnPostPaint(int,LPNMCUSTOMDRAW)9682 DWORD OnPostPaint(int /*idCtrl*/, LPNMCUSTOMDRAW /*lpNMCustomDraw*/)
9683 {
9684 return CDRF_DODEFAULT;
9685 }
9686
OnPreErase(int,LPNMCUSTOMDRAW)9687 DWORD OnPreErase(int /*idCtrl*/, LPNMCUSTOMDRAW /*lpNMCustomDraw*/)
9688 {
9689 return CDRF_DODEFAULT;
9690 }
9691
OnPostErase(int,LPNMCUSTOMDRAW)9692 DWORD OnPostErase(int /*idCtrl*/, LPNMCUSTOMDRAW /*lpNMCustomDraw*/)
9693 {
9694 return CDRF_DODEFAULT;
9695 }
9696
OnItemPrePaint(int,LPNMCUSTOMDRAW)9697 DWORD OnItemPrePaint(int /*idCtrl*/, LPNMCUSTOMDRAW /*lpNMCustomDraw*/)
9698 {
9699 return CDRF_DODEFAULT;
9700 }
9701
OnItemPostPaint(int,LPNMCUSTOMDRAW)9702 DWORD OnItemPostPaint(int /*idCtrl*/, LPNMCUSTOMDRAW /*lpNMCustomDraw*/)
9703 {
9704 return CDRF_DODEFAULT;
9705 }
9706
OnItemPreErase(int,LPNMCUSTOMDRAW)9707 DWORD OnItemPreErase(int /*idCtrl*/, LPNMCUSTOMDRAW /*lpNMCustomDraw*/)
9708 {
9709 return CDRF_DODEFAULT;
9710 }
9711
OnItemPostErase(int,LPNMCUSTOMDRAW)9712 DWORD OnItemPostErase(int /*idCtrl*/, LPNMCUSTOMDRAW /*lpNMCustomDraw*/)
9713 {
9714 return CDRF_DODEFAULT;
9715 }
9716
OnSubItemPrePaint(int,LPNMCUSTOMDRAW)9717 DWORD OnSubItemPrePaint(int /*idCtrl*/, LPNMCUSTOMDRAW /*lpNMCustomDraw*/)
9718 {
9719 return CDRF_DODEFAULT;
9720 }
9721 };
9722
9723 } // namespace WTL
9724
9725 #endif // __ATLCTRLS_H__
9726