Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

7159 lines
204 KiB

  1. // WTL Version 3.1
  2. // Copyright (C) 1997-2000 Microsoft Corporation
  3. // All rights reserved.
  4. //
  5. // This file is a part of Windows Template Library.
  6. // The code and information is provided "as-is" without
  7. // warranty of any kind, either expressed or implied.
  8. #ifndef __ATLCTRLS_H__
  9. #define __ATLCTRLS_H__
  10. #pragma once
  11. #ifndef __cplusplus
  12. #error ATL requires C++ compilation (use a .cpp suffix)
  13. #endif
  14. #ifndef __ATLAPP_H__
  15. #error atlctrls.h requires atlapp.h to be included first
  16. #endif
  17. #ifndef __ATLWIN_H__
  18. #error atlctrls.h requires atlwin.h to be included first
  19. #endif
  20. #if (_WIN32_IE < 0x0300)
  21. #error atlctrls.h requires IE Version 3.0 or higher
  22. #endif
  23. #include <richedit.h>
  24. #include <richole.h>
  25. // protect template members from windowsx.h macros
  26. #ifdef _INC_WINDOWSX
  27. #undef GetNextSibling
  28. #undef GetPrevSibling
  29. #endif //_INC_WINDOWSX
  30. namespace WTL
  31. {
  32. // These are wrapper classes for Windows standard and common controls.
  33. // To implement a window based on a control, use following:
  34. // Example: Implementing a window based on a list box
  35. //
  36. // class CMyListBox : CWindowImpl<CMyListBox, CListBox>
  37. // {
  38. // public:
  39. // BEGIN_MSG_MAP(CMyListBox)
  40. // // put your message handler entries here
  41. // END_MSG_MAP()
  42. // };
  43. /////////////////////////////////////////////////////////////////////////////
  44. // Forward declarations
  45. template <class TBase> class CStaticT;
  46. template <class TBase> class CButtonT;
  47. template <class TBase> class CListBoxT;
  48. template <class TBase> class CComboBoxT;
  49. template <class TBase> class CEditT;
  50. template <class T> class CEditCommands;
  51. template <class TBase> class CScrollBarT;
  52. class CImageList;
  53. template <class TBase> class CListViewCtrlT;
  54. template <class TBase> class CTreeViewCtrlT;
  55. class CTreeItem;
  56. template <class TBase> class CTreeViewCtrlExT;
  57. template <class TBase> class CHeaderCtrlT;
  58. template <class TBase> class CToolBarCtrlT;
  59. template <class TBase> class CStatusBarCtrlT;
  60. template <class TBase> class CTabCtrlT;
  61. class CToolInfo;
  62. template <class TBase> class CToolTipCtrlT;
  63. template <class TBase> class CTrackBarCtrlT;
  64. template <class TBase> class CUpDownCtrlT;
  65. template <class TBase> class CProgressBarCtrlT;
  66. template <class TBase> class CHotKeyCtrlT;
  67. template <class TBase> class CAnimateCtrlT;
  68. template <class TBase> class CRichEditCtrlT;
  69. template <class T> class CRichEditCommands;
  70. template <class TBase> class CDragListBoxT;
  71. template <class T> class CDragListNotifyImpl;
  72. template <class TBase> class CReBarCtrlT;
  73. template <class TBase> class CComboBoxExT;
  74. template <class TBase> class CDateTimePickerCtrlT;
  75. template <class TBase> class CMonthCalendarCtrlT;
  76. #if (_WIN32_IE >= 0x0400)
  77. template <class T> class CFlatScrollBarImpl;
  78. template <class TBase> class CFlatScrollBarT;
  79. template <class TBase> class CIPAddressCtrlT;
  80. template <class TBase> class CPagerCtrlT;
  81. #endif //(_WIN32_IE >= 0x0400)
  82. template <class T> class CCustomDraw;
  83. // --- Standard Windows controls ---
  84. /////////////////////////////////////////////////////////////////////////////
  85. // CStatic - client side for a Windows STATIC control
  86. template <class TBase>
  87. class CStaticT : public TBase
  88. {
  89. public:
  90. // Constructors
  91. CStaticT(HWND hWnd = NULL) : TBase(hWnd) { }
  92. CStaticT< TBase >& operator=(HWND hWnd)
  93. {
  94. m_hWnd = hWnd;
  95. return *this;
  96. }
  97. HWND Create(HWND hWndParent, _U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
  98. DWORD dwStyle = 0, DWORD dwExStyle = 0,
  99. _U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
  100. {
  101. return CWindow::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
  102. }
  103. // Attributes
  104. static LPCTSTR GetWndClassName()
  105. {
  106. return _T("STATIC");
  107. }
  108. HICON GetIcon() const
  109. {
  110. ATLASSERT(::IsWindow(m_hWnd));
  111. return (HICON)::SendMessage(m_hWnd, STM_GETICON, 0, 0L);
  112. }
  113. HICON SetIcon(HICON hIcon)
  114. {
  115. ATLASSERT(::IsWindow(m_hWnd));
  116. return (HICON)::SendMessage(m_hWnd, STM_SETICON, (WPARAM)hIcon, 0L);
  117. }
  118. HENHMETAFILE GetEnhMetaFile() const
  119. {
  120. ATLASSERT(::IsWindow(m_hWnd));
  121. return (HENHMETAFILE)::SendMessage(m_hWnd, STM_GETIMAGE, IMAGE_ENHMETAFILE, 0L);
  122. }
  123. HENHMETAFILE SetEnhMetaFile(HENHMETAFILE hMetaFile)
  124. {
  125. ATLASSERT(::IsWindow(m_hWnd));
  126. return (HENHMETAFILE)::SendMessage(m_hWnd, STM_SETIMAGE, IMAGE_ENHMETAFILE, (LPARAM)hMetaFile);
  127. }
  128. CBitmapHandle GetBitmap() const
  129. {
  130. ATLASSERT(::IsWindow(m_hWnd));
  131. return CBitmapHandle((HBITMAP)::SendMessage(m_hWnd, STM_GETIMAGE, IMAGE_BITMAP, 0L));
  132. }
  133. CBitmapHandle SetBitmap(HBITMAP hBitmap)
  134. {
  135. ATLASSERT(::IsWindow(m_hWnd));
  136. return CBitmapHandle((HBITMAP)::SendMessage(m_hWnd, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBitmap));
  137. }
  138. HCURSOR GetCursor() const
  139. {
  140. ATLASSERT(::IsWindow(m_hWnd));
  141. return (HCURSOR)::SendMessage(m_hWnd, STM_GETIMAGE, IMAGE_CURSOR, 0L);
  142. }
  143. HCURSOR SetCursor(HCURSOR hCursor)
  144. {
  145. ATLASSERT(::IsWindow(m_hWnd));
  146. return (HCURSOR)::SendMessage(m_hWnd, STM_SETIMAGE, IMAGE_CURSOR, (LPARAM)hCursor);
  147. }
  148. };
  149. typedef CStaticT<CWindow> CStatic;
  150. /////////////////////////////////////////////////////////////////////////////
  151. // CButton - client side for a Windows BUTTON control
  152. template <class TBase>
  153. class CButtonT : public TBase
  154. {
  155. public:
  156. // Constructors
  157. CButtonT(HWND hWnd = NULL) : TBase(hWnd) { }
  158. CButtonT< TBase >& operator=(HWND hWnd)
  159. {
  160. m_hWnd = hWnd;
  161. return *this;
  162. }
  163. HWND Create(HWND hWndParent, _U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
  164. DWORD dwStyle = 0, DWORD dwExStyle = 0,
  165. _U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
  166. {
  167. return CWindow::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
  168. }
  169. // Attributes
  170. static LPCTSTR GetWndClassName()
  171. {
  172. return _T("BUTTON");
  173. }
  174. UINT GetState() const
  175. {
  176. ATLASSERT(::IsWindow(m_hWnd));
  177. return (UINT)::SendMessage(m_hWnd, BM_GETSTATE, 0, 0L);
  178. }
  179. void SetState(BOOL bHighlight)
  180. {
  181. ATLASSERT(::IsWindow(m_hWnd));
  182. ::SendMessage(m_hWnd, BM_SETSTATE, bHighlight, 0L);
  183. }
  184. int GetCheck() const
  185. {
  186. ATLASSERT(::IsWindow(m_hWnd));
  187. return (int)::SendMessage(m_hWnd, BM_GETCHECK, 0, 0L);
  188. }
  189. void SetCheck(int nCheck)
  190. {
  191. ATLASSERT(::IsWindow(m_hWnd));
  192. ::SendMessage(m_hWnd, BM_SETCHECK, nCheck, 0L);
  193. }
  194. UINT GetButtonStyle() const
  195. {
  196. ATLASSERT(::IsWindow(m_hWnd));
  197. return (UINT)::GetWindowLong(m_hWnd, GWL_STYLE) & 0xff;
  198. }
  199. void SetButtonStyle(UINT nStyle, BOOL bRedraw = TRUE)
  200. {
  201. ATLASSERT(::IsWindow(m_hWnd));
  202. ::SendMessage(m_hWnd, BM_SETSTYLE, nStyle, (LPARAM)bRedraw);
  203. }
  204. HICON GetIcon() const
  205. {
  206. ATLASSERT(::IsWindow(m_hWnd));
  207. return (HICON)::SendMessage(m_hWnd, BM_GETIMAGE, IMAGE_ICON, 0L);
  208. }
  209. HICON SetIcon(HICON hIcon)
  210. {
  211. ATLASSERT(::IsWindow(m_hWnd));
  212. return (HICON)::SendMessage(m_hWnd, BM_SETIMAGE, IMAGE_ICON, (LPARAM)hIcon);
  213. }
  214. CBitmapHandle GetBitmap() const
  215. {
  216. ATLASSERT(::IsWindow(m_hWnd));
  217. return CBitmapHandle((HBITMAP)::SendMessage(m_hWnd, BM_GETIMAGE, IMAGE_BITMAP, 0L));
  218. }
  219. CBitmapHandle SetBitmap(HBITMAP hBitmap)
  220. {
  221. ATLASSERT(::IsWindow(m_hWnd));
  222. return CBitmapHandle((HBITMAP)::SendMessage(m_hWnd, BM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBitmap));
  223. }
  224. // Operations
  225. void Click()
  226. {
  227. ATLASSERT(::IsWindow(m_hWnd));
  228. ::SendMessage(m_hWnd, BM_CLICK, 0, 0L);
  229. }
  230. };
  231. typedef CButtonT<CWindow> CButton;
  232. /////////////////////////////////////////////////////////////////////////////
  233. // CListBox - client side for a Windows LISTBOX control
  234. template <class TBase>
  235. class CListBoxT : public TBase
  236. {
  237. public:
  238. // Constructors
  239. CListBoxT(HWND hWnd = NULL) : TBase(hWnd) { }
  240. CListBoxT< TBase >& operator=(HWND hWnd)
  241. {
  242. m_hWnd = hWnd;
  243. return *this;
  244. }
  245. HWND Create(HWND hWndParent, _U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
  246. DWORD dwStyle = 0, DWORD dwExStyle = 0,
  247. _U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
  248. {
  249. return CWindow::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
  250. }
  251. // Attributes
  252. static LPCTSTR GetWndClassName()
  253. {
  254. return _T("LISTBOX");
  255. }
  256. // for entire listbox
  257. int GetCount() const
  258. {
  259. ATLASSERT(::IsWindow(m_hWnd));
  260. return (int)::SendMessage(m_hWnd, LB_GETCOUNT, 0, 0L);
  261. }
  262. int SetCount(int cItems)
  263. {
  264. ATLASSERT(::IsWindow(m_hWnd));
  265. ATLASSERT(((GetStyle() & LBS_NODATA) != 0) && ((GetStyle() & LBS_HASSTRINGS) == 0));
  266. return (int)::SendMessage(m_hWnd, LB_SETCOUNT, cItems, 0L);
  267. }
  268. int GetHorizontalExtent() const
  269. {
  270. ATLASSERT(::IsWindow(m_hWnd));
  271. return (int)::SendMessage(m_hWnd, LB_GETHORIZONTALEXTENT, 0, 0L);
  272. }
  273. void SetHorizontalExtent(int cxExtent)
  274. {
  275. ATLASSERT(::IsWindow(m_hWnd));
  276. ::SendMessage(m_hWnd, LB_SETHORIZONTALEXTENT, cxExtent, 0L);
  277. }
  278. int GetTopIndex() const
  279. {
  280. ATLASSERT(::IsWindow(m_hWnd));
  281. return (int)::SendMessage(m_hWnd, LB_GETTOPINDEX, 0, 0L);
  282. }
  283. int SetTopIndex(int nIndex)
  284. {
  285. ATLASSERT(::IsWindow(m_hWnd));
  286. return (int)::SendMessage(m_hWnd, LB_SETTOPINDEX, nIndex, 0L);
  287. }
  288. LCID GetLocale() const
  289. {
  290. ATLASSERT(::IsWindow(m_hWnd));
  291. return (LCID)::SendMessage(m_hWnd, LB_GETLOCALE, 0, 0L);
  292. }
  293. LCID SetLocale(LCID nNewLocale)
  294. {
  295. ATLASSERT(::IsWindow(m_hWnd));
  296. return (LCID)::SendMessage(m_hWnd, LB_SETLOCALE, (WPARAM)nNewLocale, 0L);
  297. }
  298. // for single-selection listboxes
  299. int GetCurSel() const
  300. {
  301. ATLASSERT(::IsWindow(m_hWnd));
  302. ATLASSERT((GetStyle() & (LBS_MULTIPLESEL | LBS_EXTENDEDSEL)) == 0);
  303. return (int)::SendMessage(m_hWnd, LB_GETCURSEL, 0, 0L);
  304. }
  305. int SetCurSel(int nSelect)
  306. {
  307. ATLASSERT(::IsWindow(m_hWnd));
  308. ATLASSERT((GetStyle() & (LBS_MULTIPLESEL | LBS_EXTENDEDSEL)) == 0);
  309. return (int)::SendMessage(m_hWnd, LB_SETCURSEL, nSelect, 0L);
  310. }
  311. // for multiple-selection listboxes
  312. int GetSel(int nIndex) const // also works for single-selection
  313. {
  314. ATLASSERT(::IsWindow(m_hWnd));
  315. return (int)::SendMessage(m_hWnd, LB_GETSEL, nIndex, 0L);
  316. }
  317. int SetSel(int nIndex, BOOL bSelect = TRUE)
  318. {
  319. ATLASSERT(::IsWindow(m_hWnd));
  320. ATLASSERT((GetStyle() & (LBS_MULTIPLESEL | LBS_EXTENDEDSEL)) != 0);
  321. return (int)::SendMessage(m_hWnd, LB_SETSEL, bSelect, nIndex);
  322. }
  323. int GetSelCount() const
  324. {
  325. ATLASSERT(::IsWindow(m_hWnd));
  326. ATLASSERT((GetStyle() & (LBS_MULTIPLESEL | LBS_EXTENDEDSEL)) != 0);
  327. return (int)::SendMessage(m_hWnd, LB_GETSELCOUNT, 0, 0L);
  328. }
  329. int GetSelItems(int nMaxItems, LPINT rgIndex) const
  330. {
  331. ATLASSERT(::IsWindow(m_hWnd));
  332. ATLASSERT((GetStyle() & (LBS_MULTIPLESEL | LBS_EXTENDEDSEL)) != 0);
  333. return (int)::SendMessage(m_hWnd, LB_GETSELITEMS, nMaxItems, (LPARAM)rgIndex);
  334. }
  335. int GetAnchorIndex() const
  336. {
  337. ATLASSERT(::IsWindow(m_hWnd));
  338. ATLASSERT((GetStyle() & (LBS_MULTIPLESEL | LBS_EXTENDEDSEL)) != 0);
  339. return (int)::SendMessage(m_hWnd, LB_GETANCHORINDEX, 0, 0L);
  340. }
  341. void SetAnchorIndex(int nIndex)
  342. {
  343. ATLASSERT(::IsWindow(m_hWnd));
  344. ATLASSERT((GetStyle() & (LBS_MULTIPLESEL | LBS_EXTENDEDSEL)) != 0);
  345. ::SendMessage(m_hWnd, LB_SETANCHORINDEX, nIndex, 0L);
  346. }
  347. int GetCaretIndex() const
  348. {
  349. ATLASSERT(::IsWindow(m_hWnd));
  350. return (int)::SendMessage(m_hWnd, LB_GETCARETINDEX, 0, 0);
  351. }
  352. int SetCaretIndex(int nIndex, BOOL bScroll = TRUE)
  353. {
  354. ATLASSERT(::IsWindow(m_hWnd));
  355. return (int)::SendMessage(m_hWnd, LB_SETCARETINDEX, nIndex, MAKELONG(bScroll, 0));
  356. }
  357. // for listbox items
  358. DWORD_PTR GetItemData(int nIndex) const
  359. {
  360. ATLASSERT(::IsWindow(m_hWnd));
  361. return (DWORD_PTR)::SendMessage(m_hWnd, LB_GETITEMDATA, nIndex, 0L);
  362. }
  363. int SetItemData(int nIndex, DWORD_PTR dwItemData)
  364. {
  365. ATLASSERT(::IsWindow(m_hWnd));
  366. return (int)::SendMessage(m_hWnd, LB_SETITEMDATA, nIndex, (LPARAM)dwItemData);
  367. }
  368. void* GetItemDataPtr(int nIndex) const
  369. {
  370. ATLASSERT(::IsWindow(m_hWnd));
  371. return (void*)::SendMessage(m_hWnd, LB_GETITEMDATA, nIndex, 0L);
  372. }
  373. int SetItemDataPtr(int nIndex, void* pData)
  374. {
  375. ATLASSERT(::IsWindow(m_hWnd));
  376. return SetItemData(nIndex, (DWORD_PTR)pData);
  377. }
  378. int GetItemRect(int nIndex, LPRECT lpRect) const
  379. {
  380. ATLASSERT(::IsWindow(m_hWnd));
  381. return (int)::SendMessage(m_hWnd, LB_GETITEMRECT, nIndex, (LPARAM)lpRect);
  382. }
  383. int GetText(int nIndex, LPTSTR lpszBuffer) const
  384. {
  385. ATLASSERT(::IsWindow(m_hWnd));
  386. return (int)::SendMessage(m_hWnd, LB_GETTEXT, nIndex, (LPARAM)lpszBuffer);
  387. }
  388. #ifndef _ATL_NO_COM
  389. #ifdef _OLEAUTO_H_
  390. BOOL GetTextBSTR(int nIndex, BSTR& bstrText) const
  391. {
  392. USES_CONVERSION;
  393. ATLASSERT(::IsWindow(m_hWnd));
  394. ATLASSERT(bstrText == NULL);
  395. int nLen = GetTextLen(nIndex);
  396. if(nLen == LB_ERR)
  397. return FALSE;
  398. LPTSTR lpszText = (LPTSTR)_alloca((nLen + 1) * sizeof(TCHAR));
  399. if(GetText(nIndex, lpszText) == LB_ERR)
  400. return FALSE;
  401. bstrText = ::SysAllocString(T2OLE(lpszText));
  402. return (bstrText != NULL) ? TRUE : FALSE;
  403. }
  404. #endif // _OLEAUTO_H_
  405. #endif //!_ATL_NO_COM
  406. #ifdef __ATLSTR_H__
  407. int GetText(int nIndex, CString& strText) const
  408. {
  409. ATLASSERT(::IsWindow(m_hWnd));
  410. int nRet = GetText(nIndex, strText.GetBufferSetLength(GetTextLen(nIndex)));
  411. strText.ReleaseBuffer();
  412. return nRet;
  413. }
  414. #endif //__ATLSTR_H__
  415. int GetTextLen(int nIndex) const
  416. {
  417. ATLASSERT(::IsWindow(m_hWnd));
  418. return (int)::SendMessage(m_hWnd, LB_GETTEXTLEN, nIndex, 0L);
  419. }
  420. int GetItemHeight(int nIndex) const
  421. {
  422. ATLASSERT(::IsWindow(m_hWnd));
  423. return (int)::SendMessage(m_hWnd, LB_GETITEMHEIGHT, nIndex, 0L);
  424. }
  425. int SetItemHeight(int nIndex, UINT cyItemHeight)
  426. {
  427. ATLASSERT(::IsWindow(m_hWnd));
  428. return (int)::SendMessage(m_hWnd, LB_SETITEMHEIGHT, nIndex, MAKELONG(cyItemHeight, 0));
  429. }
  430. // Settable only attributes
  431. void SetColumnWidth(int cxWidth)
  432. {
  433. ATLASSERT(::IsWindow(m_hWnd));
  434. ::SendMessage(m_hWnd, LB_SETCOLUMNWIDTH, cxWidth, 0L);
  435. }
  436. BOOL SetTabStops(int nTabStops, LPINT rgTabStops)
  437. {
  438. ATLASSERT(::IsWindow(m_hWnd));
  439. ATLASSERT((GetStyle() & LBS_USETABSTOPS) != 0);
  440. return (BOOL)::SendMessage(m_hWnd, LB_SETTABSTOPS, nTabStops, (LPARAM)rgTabStops);
  441. }
  442. BOOL SetTabStops()
  443. {
  444. ATLASSERT(::IsWindow(m_hWnd));
  445. ATLASSERT((GetStyle() & LBS_USETABSTOPS) != 0);
  446. return (BOOL)::SendMessage(m_hWnd, LB_SETTABSTOPS, 0, 0L);
  447. }
  448. BOOL SetTabStops(const int& cxEachStop) // takes an 'int'
  449. {
  450. ATLASSERT(::IsWindow(m_hWnd));
  451. ATLASSERT((GetStyle() & LBS_USETABSTOPS) != 0);
  452. return (BOOL)::SendMessage(m_hWnd, LB_SETTABSTOPS, 1, (LPARAM)(LPINT)&cxEachStop);
  453. }
  454. // Operations
  455. int InitStorage(int nItems, UINT nBytes)
  456. {
  457. ATLASSERT(::IsWindow(m_hWnd));
  458. return (int)::SendMessage(m_hWnd, LB_INITSTORAGE, (WPARAM)nItems, nBytes);
  459. }
  460. void ResetContent()
  461. {
  462. ATLASSERT(::IsWindow(m_hWnd));
  463. ::SendMessage(m_hWnd, LB_RESETCONTENT, 0, 0L);
  464. }
  465. UINT ItemFromPoint(POINT pt, BOOL& bOutside) const
  466. {
  467. ATLASSERT(::IsWindow(m_hWnd));
  468. DWORD dw = (DWORD)::SendMessage(m_hWnd, LB_ITEMFROMPOINT, 0, MAKELPARAM(pt.x, pt.y));
  469. bOutside = (BOOL)HIWORD(dw);
  470. return (UINT)LOWORD(dw);
  471. }
  472. // manipulating listbox items
  473. int AddString(LPCTSTR lpszItem)
  474. {
  475. ATLASSERT(::IsWindow(m_hWnd));
  476. return (int)::SendMessage(m_hWnd, LB_ADDSTRING, 0, (LPARAM)lpszItem);
  477. }
  478. int DeleteString(UINT nIndex)
  479. {
  480. ATLASSERT(::IsWindow(m_hWnd));
  481. return (int)::SendMessage(m_hWnd, LB_DELETESTRING, nIndex, 0L);
  482. }
  483. int InsertString(int nIndex, LPCTSTR lpszItem)
  484. {
  485. ATLASSERT(::IsWindow(m_hWnd));
  486. return (int)::SendMessage(m_hWnd, LB_INSERTSTRING, nIndex, (LPARAM)lpszItem);
  487. }
  488. int Dir(UINT attr, LPCTSTR lpszWildCard)
  489. {
  490. ATLASSERT(::IsWindow(m_hWnd));
  491. return (int)::SendMessage(m_hWnd, LB_DIR, attr, (LPARAM)lpszWildCard);
  492. }
  493. int AddFile(LPCTSTR lpstrFileName)
  494. {
  495. ATLASSERT(::IsWindow(m_hWnd));
  496. return (int)::SendMessage(m_hWnd, LB_ADDFILE, 0, (LPARAM)lpstrFileName);
  497. }
  498. // selection helpers
  499. int FindString(int nStartAfter, LPCTSTR lpszItem) const
  500. {
  501. ATLASSERT(::IsWindow(m_hWnd));
  502. return (int)::SendMessage(m_hWnd, LB_FINDSTRING, nStartAfter, (LPARAM)lpszItem);
  503. }
  504. int FindStringExact(int nIndexStart, LPCTSTR lpszFind) const
  505. {
  506. ATLASSERT(::IsWindow(m_hWnd));
  507. return (int)::SendMessage(m_hWnd, LB_FINDSTRINGEXACT, nIndexStart, (LPARAM)lpszFind);
  508. }
  509. int SelectString(int nStartAfter, LPCTSTR lpszItem)
  510. {
  511. ATLASSERT(::IsWindow(m_hWnd));
  512. return (int)::SendMessage(m_hWnd, LB_SELECTSTRING, nStartAfter, (LPARAM)lpszItem);
  513. }
  514. int SelItemRange(BOOL bSelect, int nFirstItem, int nLastItem)
  515. {
  516. ATLASSERT(::IsWindow(m_hWnd));
  517. ATLASSERT((GetStyle() & (LBS_MULTIPLESEL | LBS_EXTENDEDSEL)) != 0);
  518. ATLASSERT(nFirstItem <= nLastItem);
  519. return bSelect ? (int)::SendMessage(m_hWnd, LB_SELITEMRANGEEX, nFirstItem, nLastItem) : (int)::SendMessage(m_hWnd, LB_SELITEMRANGEEX, nLastItem, nFirstItem);
  520. }
  521. };
  522. typedef CListBoxT<CWindow> CListBox;
  523. /////////////////////////////////////////////////////////////////////////////
  524. // CComboBox - client side for a Windows COMBOBOX control
  525. template <class TBase>
  526. class CComboBoxT : public TBase
  527. {
  528. public:
  529. // Constructors
  530. CComboBoxT(HWND hWnd = NULL) : TBase(hWnd) { }
  531. CComboBoxT< TBase >& operator=(HWND hWnd)
  532. {
  533. m_hWnd = hWnd;
  534. return *this;
  535. }
  536. HWND Create(HWND hWndParent, _U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
  537. DWORD dwStyle = 0, DWORD dwExStyle = 0,
  538. _U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
  539. {
  540. return CWindow::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
  541. }
  542. // Attributes
  543. static LPCTSTR GetWndClassName()
  544. {
  545. return _T("COMBOBOX");
  546. }
  547. // for entire combo box
  548. int GetCount() const
  549. {
  550. ATLASSERT(::IsWindow(m_hWnd));
  551. return (int)::SendMessage(m_hWnd, CB_GETCOUNT, 0, 0L);
  552. }
  553. int GetCurSel() const
  554. {
  555. ATLASSERT(::IsWindow(m_hWnd));
  556. return (int)::SendMessage(m_hWnd, CB_GETCURSEL, 0, 0L);
  557. }
  558. int SetCurSel(int nSelect)
  559. {
  560. ATLASSERT(::IsWindow(m_hWnd));
  561. return (int)::SendMessage(m_hWnd, CB_SETCURSEL, nSelect, 0L);
  562. }
  563. LCID GetLocale() const
  564. {
  565. ATLASSERT(::IsWindow(m_hWnd));
  566. return (LCID)::SendMessage(m_hWnd, CB_GETLOCALE, 0, 0L);
  567. }
  568. LCID SetLocale(LCID nNewLocale)
  569. {
  570. ATLASSERT(::IsWindow(m_hWnd));
  571. return (LCID)::SendMessage(m_hWnd, CB_SETLOCALE, (WPARAM)nNewLocale, 0L);
  572. }
  573. int GetTopIndex() const
  574. {
  575. ATLASSERT(::IsWindow(m_hWnd));
  576. return (int)::SendMessage(m_hWnd, CB_GETTOPINDEX, 0, 0L);
  577. }
  578. int SetTopIndex(int nIndex)
  579. {
  580. ATLASSERT(::IsWindow(m_hWnd));
  581. return (int)::SendMessage(m_hWnd, CB_SETTOPINDEX, nIndex, 0L);
  582. }
  583. UINT GetHorizontalExtent() const
  584. {
  585. ATLASSERT(::IsWindow(m_hWnd));
  586. return (UINT)::SendMessage(m_hWnd, CB_GETHORIZONTALEXTENT, 0, 0L);
  587. }
  588. void SetHorizontalExtent(UINT nExtent)
  589. {
  590. ATLASSERT(::IsWindow(m_hWnd));
  591. ::SendMessage(m_hWnd, CB_SETHORIZONTALEXTENT, nExtent, 0L);
  592. }
  593. int GetDroppedWidth() const
  594. {
  595. ATLASSERT(::IsWindow(m_hWnd));
  596. return (int)::SendMessage(m_hWnd, CB_GETDROPPEDWIDTH, 0, 0L);
  597. }
  598. int SetDroppedWidth(UINT nWidth)
  599. {
  600. ATLASSERT(::IsWindow(m_hWnd));
  601. return (int)::SendMessage(m_hWnd, CB_SETDROPPEDWIDTH, nWidth, 0L);
  602. }
  603. // for edit control
  604. DWORD GetEditSel() const
  605. {
  606. ATLASSERT(::IsWindow(m_hWnd));
  607. return (DWORD)::SendMessage(m_hWnd, CB_GETEDITSEL, 0, 0L);
  608. }
  609. BOOL SetEditSel(int nStartChar, int nEndChar)
  610. {
  611. ATLASSERT(::IsWindow(m_hWnd));
  612. return (BOOL)::SendMessage(m_hWnd, CB_SETEDITSEL, 0, MAKELONG(nStartChar, nEndChar));
  613. }
  614. // for combobox item
  615. DWORD_PTR GetItemData(int nIndex) const
  616. {
  617. ATLASSERT(::IsWindow(m_hWnd));
  618. return (DWORD_PTR)::SendMessage(m_hWnd, CB_GETITEMDATA, nIndex, 0L);
  619. }
  620. int SetItemData(int nIndex, DWORD_PTR dwItemData)
  621. {
  622. ATLASSERT(::IsWindow(m_hWnd));
  623. return (int)::SendMessage(m_hWnd, CB_SETITEMDATA, nIndex, (LPARAM)dwItemData);
  624. }
  625. void* GetItemDataPtr(int nIndex) const
  626. {
  627. ATLASSERT(::IsWindow(m_hWnd));
  628. return (void*)GetItemData(nIndex);
  629. }
  630. int SetItemDataPtr(int nIndex, void* pData)
  631. {
  632. ATLASSERT(::IsWindow(m_hWnd));
  633. return SetItemData(nIndex, (DWORD_PTR)pData);
  634. }
  635. int GetLBText(int nIndex, LPTSTR lpszText) const
  636. {
  637. ATLASSERT(::IsWindow(m_hWnd));
  638. return (int)::SendMessage(m_hWnd, CB_GETLBTEXT, nIndex, (LPARAM)lpszText);
  639. }
  640. #ifndef _ATL_NO_COM
  641. BOOL GetLBTextBSTR(int nIndex, BSTR& bstrText) const
  642. {
  643. USES_CONVERSION;
  644. ATLASSERT(::IsWindow(m_hWnd));
  645. ATLASSERT(bstrText == NULL);
  646. int nLen = GetLBTextLen(nIndex);
  647. if(nLen == CB_ERR)
  648. return FALSE;
  649. LPTSTR lpszText = (LPTSTR)_alloca((nLen + 1) * sizeof(TCHAR));
  650. if(GetLBText(nIndex, lpszText) == CB_ERR)
  651. return FALSE;
  652. bstrText = ::SysAllocString(T2OLE(lpszText));
  653. return (bstrText != NULL) ? TRUE : FALSE;
  654. }
  655. #endif //!_ATL_NO_COM
  656. #ifdef __ATLSTR_H__
  657. int GetLBText(int nIndex, CString& strText) const
  658. {
  659. ATLASSERT(::IsWindow(m_hWnd));
  660. int nRet = GetLBText(nIndex, strText.GetBufferSetLength(GetLBTextLen(nIndex)));
  661. strText.ReleaseBuffer();
  662. return nRet;
  663. }
  664. #endif //__ATLSTR_H__
  665. int GetLBTextLen(int nIndex) const
  666. {
  667. ATLASSERT(::IsWindow(m_hWnd));
  668. return (int)::SendMessage(m_hWnd, CB_GETLBTEXTLEN, nIndex, 0L);
  669. }
  670. int GetItemHeight(int nIndex) const
  671. {
  672. ATLASSERT(::IsWindow(m_hWnd));
  673. return (int)::SendMessage(m_hWnd, CB_GETITEMHEIGHT, nIndex, 0L);
  674. }
  675. int SetItemHeight(int nIndex, UINT cyItemHeight)
  676. {
  677. ATLASSERT(::IsWindow(m_hWnd));
  678. return (int)::SendMessage(m_hWnd, CB_SETITEMHEIGHT, nIndex, MAKELONG(cyItemHeight, 0));
  679. }
  680. BOOL GetExtendedUI() const
  681. {
  682. ATLASSERT(::IsWindow(m_hWnd));
  683. return (BOOL)::SendMessage(m_hWnd, CB_GETEXTENDEDUI, 0, 0L);
  684. }
  685. int SetExtendedUI(BOOL bExtended = TRUE)
  686. {
  687. ATLASSERT(::IsWindow(m_hWnd));
  688. return (int)::SendMessage(m_hWnd, CB_SETEXTENDEDUI, bExtended, 0L);
  689. }
  690. void GetDroppedControlRect(LPRECT lprect) const
  691. {
  692. ATLASSERT(::IsWindow(m_hWnd));
  693. ::SendMessage(m_hWnd, CB_GETDROPPEDCONTROLRECT, 0, (LPARAM)lprect);
  694. }
  695. BOOL GetDroppedState() const
  696. {
  697. ATLASSERT(::IsWindow(m_hWnd));
  698. return (BOOL)::SendMessage(m_hWnd, CB_GETDROPPEDSTATE, 0, 0L);
  699. }
  700. // Operations
  701. int InitStorage(int nItems, UINT nBytes)
  702. {
  703. ATLASSERT(::IsWindow(m_hWnd));
  704. return (int)::SendMessage(m_hWnd, CB_INITSTORAGE, (WPARAM)nItems, nBytes);
  705. }
  706. void ResetContent()
  707. {
  708. ATLASSERT(::IsWindow(m_hWnd));
  709. ::SendMessage(m_hWnd, CB_RESETCONTENT, 0, 0L);
  710. }
  711. // for edit control
  712. BOOL LimitText(int nMaxChars)
  713. {
  714. ATLASSERT(::IsWindow(m_hWnd));
  715. return (BOOL)::SendMessage(m_hWnd, CB_LIMITTEXT, nMaxChars, 0L);
  716. }
  717. // for drop-down combo boxes
  718. void ShowDropDown(BOOL bShowIt = TRUE)
  719. {
  720. ATLASSERT(::IsWindow(m_hWnd));
  721. ::SendMessage(m_hWnd, CB_SHOWDROPDOWN, bShowIt, 0L);
  722. }
  723. // manipulating listbox items
  724. int AddString(LPCTSTR lpszString)
  725. {
  726. ATLASSERT(::IsWindow(m_hWnd));
  727. return (int)::SendMessage(m_hWnd, CB_ADDSTRING, 0, (LPARAM)lpszString);
  728. }
  729. int DeleteString(UINT nIndex)
  730. {
  731. ATLASSERT(::IsWindow(m_hWnd));
  732. return (int)::SendMessage(m_hWnd, CB_DELETESTRING, nIndex, 0L);
  733. }
  734. int InsertString(int nIndex, LPCTSTR lpszString)
  735. {
  736. ATLASSERT(::IsWindow(m_hWnd));
  737. return (int)::SendMessage(m_hWnd, CB_INSERTSTRING, nIndex, (LPARAM)lpszString);
  738. }
  739. int Dir(UINT attr, LPCTSTR lpszWildCard)
  740. {
  741. ATLASSERT(::IsWindow(m_hWnd));
  742. return (int)::SendMessage(m_hWnd, CB_DIR, attr, (LPARAM)lpszWildCard);
  743. }
  744. // selection helpers
  745. int FindString(int nStartAfter, LPCTSTR lpszString) const
  746. {
  747. ATLASSERT(::IsWindow(m_hWnd));
  748. return (int)::SendMessage(m_hWnd, CB_FINDSTRING, nStartAfter, (LPARAM)lpszString);
  749. }
  750. int FindStringExact(int nIndexStart, LPCTSTR lpszFind) const
  751. {
  752. ATLASSERT(::IsWindow(m_hWnd));
  753. return (int)::SendMessage(m_hWnd, CB_FINDSTRINGEXACT, nIndexStart, (LPARAM)lpszFind);
  754. }
  755. int SelectString(int nStartAfter, LPCTSTR lpszString)
  756. {
  757. ATLASSERT(::IsWindow(m_hWnd));
  758. return (int)::SendMessage(m_hWnd, CB_SELECTSTRING, nStartAfter, (LPARAM)lpszString);
  759. }
  760. // Clipboard operations
  761. void Clear()
  762. {
  763. ATLASSERT(::IsWindow(m_hWnd));
  764. ::SendMessage(m_hWnd, WM_CLEAR, 0, 0L);
  765. }
  766. void Copy()
  767. {
  768. ATLASSERT(::IsWindow(m_hWnd));
  769. ::SendMessage(m_hWnd, WM_COPY, 0, 0L);
  770. }
  771. void Cut()
  772. {
  773. ATLASSERT(::IsWindow(m_hWnd));
  774. ::SendMessage(m_hWnd, WM_CUT, 0, 0L);
  775. }
  776. void Paste()
  777. {
  778. ATLASSERT(::IsWindow(m_hWnd));
  779. ::SendMessage(m_hWnd, WM_PASTE, 0, 0L);
  780. }
  781. };
  782. typedef CComboBoxT<CWindow> CComboBox;
  783. /////////////////////////////////////////////////////////////////////////////
  784. // CEdit - client side for a Windows EDIT control
  785. template <class TBase>
  786. class CEditT : public TBase
  787. {
  788. public:
  789. // Constructors
  790. CEditT(HWND hWnd = NULL) : TBase(hWnd) { }
  791. CEditT< TBase >& operator=(HWND hWnd)
  792. {
  793. m_hWnd = hWnd;
  794. return *this;
  795. }
  796. HWND Create(HWND hWndParent, _U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
  797. DWORD dwStyle = 0, DWORD dwExStyle = 0,
  798. _U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
  799. {
  800. return CWindow::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
  801. }
  802. // Attributes
  803. static LPCTSTR GetWndClassName()
  804. {
  805. return _T("EDIT");
  806. }
  807. BOOL CanUndo() const
  808. {
  809. ATLASSERT(::IsWindow(m_hWnd));
  810. return (BOOL)::SendMessage(m_hWnd, EM_CANUNDO, 0, 0L);
  811. }
  812. int GetLineCount() const
  813. {
  814. ATLASSERT(::IsWindow(m_hWnd));
  815. return (int)::SendMessage(m_hWnd, EM_GETLINECOUNT, 0, 0L);
  816. }
  817. BOOL GetModify() const
  818. {
  819. ATLASSERT(::IsWindow(m_hWnd));
  820. return (BOOL)::SendMessage(m_hWnd, EM_GETMODIFY, 0, 0L);
  821. }
  822. void SetModify(BOOL bModified = TRUE)
  823. {
  824. ATLASSERT(::IsWindow(m_hWnd));
  825. ::SendMessage(m_hWnd, EM_SETMODIFY, bModified, 0L);
  826. }
  827. void GetRect(LPRECT lpRect) const
  828. {
  829. ATLASSERT(::IsWindow(m_hWnd));
  830. ::SendMessage(m_hWnd, EM_GETRECT, 0, (LPARAM)lpRect);
  831. }
  832. DWORD GetSel() const
  833. {
  834. ATLASSERT(::IsWindow(m_hWnd));
  835. return (DWORD)::SendMessage(m_hWnd, EM_GETSEL, 0, 0L);
  836. }
  837. void GetSel(int& nStartChar, int& nEndChar) const
  838. {
  839. ATLASSERT(::IsWindow(m_hWnd));
  840. ::SendMessage(m_hWnd, EM_GETSEL, (WPARAM)&nStartChar, (LPARAM)&nEndChar);
  841. }
  842. HLOCAL GetHandle() const
  843. {
  844. ATLASSERT(::IsWindow(m_hWnd));
  845. return (HLOCAL)::SendMessage(m_hWnd, EM_GETHANDLE, 0, 0L);
  846. }
  847. void SetHandle(HLOCAL hBuffer)
  848. {
  849. ATLASSERT(::IsWindow(m_hWnd));
  850. ::SendMessage(m_hWnd, EM_SETHANDLE, (WPARAM)hBuffer, 0L);
  851. }
  852. DWORD GetMargins() const
  853. {
  854. ATLASSERT(::IsWindow(m_hWnd));
  855. return (DWORD)::SendMessage(m_hWnd, EM_GETMARGINS, 0, 0L);
  856. }
  857. void SetMargins(UINT nLeft, UINT nRight)
  858. {
  859. ATLASSERT(::IsWindow(m_hWnd));
  860. ::SendMessage(m_hWnd, EM_SETMARGINS, EC_LEFTMARGIN|EC_RIGHTMARGIN, MAKELONG(nLeft, nRight));
  861. }
  862. UINT GetLimitText() const
  863. {
  864. ATLASSERT(::IsWindow(m_hWnd));
  865. return (UINT)::SendMessage(m_hWnd, EM_GETLIMITTEXT, 0, 0L);
  866. }
  867. void SetLimitText(UINT nMax)
  868. {
  869. ATLASSERT(::IsWindow(m_hWnd));
  870. ::SendMessage(m_hWnd, EM_SETLIMITTEXT, nMax, 0L);
  871. }
  872. POINT PosFromChar(UINT nChar) const
  873. {
  874. ATLASSERT(::IsWindow(m_hWnd));
  875. DWORD dwRet = (DWORD)::SendMessage(m_hWnd, EM_POSFROMCHAR, nChar, 0);
  876. POINT point = { GET_X_LPARAM(dwRet), GET_Y_LPARAM(dwRet) };
  877. return point;
  878. }
  879. int CharFromPos(POINT pt, int* pLine = NULL) const
  880. {
  881. ATLASSERT(::IsWindow(m_hWnd));
  882. DWORD dwRet = (DWORD)::SendMessage(m_hWnd, EM_CHARFROMPOS, 0, MAKELPARAM(pt.x, pt.y));
  883. if(pLine != NULL)
  884. *pLine = (int)(short)HIWORD(dwRet);
  885. return (int)(short)LOWORD(dwRet);
  886. }
  887. // NOTE: first word in lpszBuffer must contain the size of the buffer!
  888. int GetLine(int nIndex, LPTSTR lpszBuffer) const
  889. {
  890. ATLASSERT(::IsWindow(m_hWnd));
  891. return (int)::SendMessage(m_hWnd, EM_GETLINE, nIndex, (LPARAM)lpszBuffer);
  892. }
  893. int GetLine(int nIndex, LPTSTR lpszBuffer, int nMaxLength) const
  894. {
  895. ATLASSERT(::IsWindow(m_hWnd));
  896. *(LPWORD)lpszBuffer = (WORD)nMaxLength;
  897. return (int)::SendMessage(m_hWnd, EM_GETLINE, nIndex, (LPARAM)lpszBuffer);
  898. }
  899. TCHAR GetPasswordChar() const
  900. {
  901. ATLASSERT(::IsWindow(m_hWnd));
  902. return (TCHAR)::SendMessage(m_hWnd, EM_GETPASSWORDCHAR, 0, 0L);
  903. }
  904. void SetPasswordChar(TCHAR ch)
  905. {
  906. ATLASSERT(::IsWindow(m_hWnd));
  907. ::SendMessage(m_hWnd, EM_SETPASSWORDCHAR, ch, 0L);
  908. }
  909. EDITWORDBREAKPROC GetWordBreakProc() const
  910. {
  911. ATLASSERT(::IsWindow(m_hWnd));
  912. return (EDITWORDBREAKPROC)::SendMessage(m_hWnd, EM_GETWORDBREAKPROC, 0, 0L);
  913. }
  914. void SetWordBreakProc(EDITWORDBREAKPROC ewbprc)
  915. {
  916. ATLASSERT(::IsWindow(m_hWnd));
  917. ::SendMessage(m_hWnd, EM_SETWORDBREAKPROC, 0, (LPARAM)ewbprc);
  918. }
  919. int GetFirstVisibleLine() const
  920. {
  921. ATLASSERT(::IsWindow(m_hWnd));
  922. return (int)::SendMessage(m_hWnd, EM_GETFIRSTVISIBLELINE, 0, 0L);
  923. }
  924. int GetThumb() const
  925. {
  926. ATLASSERT(::IsWindow(m_hWnd));
  927. ATLASSERT((GetStyle() & ES_MULTILINE) != 0);
  928. return (int)::SendMessage(m_hWnd, EM_GETTHUMB, 0, 0L);
  929. }
  930. BOOL SetReadOnly(BOOL bReadOnly = TRUE)
  931. {
  932. ATLASSERT(::IsWindow(m_hWnd));
  933. return (BOOL)::SendMessage(m_hWnd, EM_SETREADONLY, bReadOnly, 0L);
  934. }
  935. #if (WINVER >= 0x0500)
  936. UINT GetImeStatus(UINT uStatus) const
  937. {
  938. ATLASSERT(::IsWindow(m_hWnd));
  939. return (UINT)::SendMessage(m_hWnd, EM_GETIMESTATUS, uStatus, 0L);
  940. }
  941. UINT SetImeStatus(UINT uStatus, UINT uData)
  942. {
  943. ATLASSERT(::IsWindow(m_hWnd));
  944. return (UINT)::SendMessage(m_hWnd, EM_SETIMESTATUS, uStatus, uData);
  945. }
  946. #endif //(WINVER >= 0x0500)
  947. // Operations
  948. void EmptyUndoBuffer()
  949. {
  950. ATLASSERT(::IsWindow(m_hWnd));
  951. ::SendMessage(m_hWnd, EM_EMPTYUNDOBUFFER, 0, 0L);
  952. }
  953. BOOL FmtLines(BOOL bAddEOL)
  954. {
  955. ATLASSERT(::IsWindow(m_hWnd));
  956. return (BOOL)::SendMessage(m_hWnd, EM_FMTLINES, bAddEOL, 0L);
  957. }
  958. void LimitText(int nChars = 0)
  959. {
  960. ATLASSERT(::IsWindow(m_hWnd));
  961. ::SendMessage(m_hWnd, EM_LIMITTEXT, nChars, 0L);
  962. }
  963. int LineFromChar(int nIndex = -1) const
  964. {
  965. ATLASSERT(::IsWindow(m_hWnd));
  966. return (int)::SendMessage(m_hWnd, EM_LINEFROMCHAR, nIndex, 0L);
  967. }
  968. int LineIndex(int nLine = -1) const
  969. {
  970. ATLASSERT(::IsWindow(m_hWnd));
  971. return (int)::SendMessage(m_hWnd, EM_LINEINDEX, nLine, 0L);
  972. }
  973. int LineLength(int nLine = -1) const
  974. {
  975. ATLASSERT(::IsWindow(m_hWnd));
  976. return (int)::SendMessage(m_hWnd, EM_LINELENGTH, nLine, 0L);
  977. }
  978. void LineScroll(int nLines, int nChars = 0)
  979. {
  980. ATLASSERT(::IsWindow(m_hWnd));
  981. ::SendMessage(m_hWnd, EM_LINESCROLL, nChars, nLines);
  982. }
  983. void ReplaceSel(LPCTSTR lpszNewText, BOOL bCanUndo = FALSE)
  984. {
  985. ATLASSERT(::IsWindow(m_hWnd));
  986. ::SendMessage(m_hWnd, EM_REPLACESEL, (WPARAM) bCanUndo, (LPARAM)lpszNewText);
  987. }
  988. void SetRect(LPCRECT lpRect)
  989. {
  990. ATLASSERT(::IsWindow(m_hWnd));
  991. ::SendMessage(m_hWnd, EM_SETRECT, 0, (LPARAM)lpRect);
  992. }
  993. void SetRectNP(LPCRECT lpRect)
  994. {
  995. ATLASSERT(::IsWindow(m_hWnd));
  996. ::SendMessage(m_hWnd, EM_SETRECTNP, 0, (LPARAM)lpRect);
  997. }
  998. void SetSel(DWORD dwSelection, BOOL bNoScroll = FALSE)
  999. {
  1000. ATLASSERT(::IsWindow(m_hWnd));
  1001. ::SendMessage(m_hWnd, EM_SETSEL, LOWORD(dwSelection), HIWORD(dwSelection));
  1002. if(!bNoScroll)
  1003. ::SendMessage(m_hWnd, EM_SCROLLCARET, 0, 0L);
  1004. }
  1005. void SetSel(int nStartChar, int nEndChar, BOOL bNoScroll = FALSE)
  1006. {
  1007. ATLASSERT(::IsWindow(m_hWnd));
  1008. ::SendMessage(m_hWnd, EM_SETSEL, nStartChar, nEndChar);
  1009. if(!bNoScroll)
  1010. ::SendMessage(m_hWnd, EM_SCROLLCARET, 0, 0L);
  1011. }
  1012. void SetSelAll(BOOL bNoScroll = FALSE)
  1013. {
  1014. SetSel(0, -1, bNoScroll);
  1015. }
  1016. void SetSelNone(BOOL bNoScroll = FALSE)
  1017. {
  1018. SetSel(-1, 0, bNoScroll);
  1019. }
  1020. BOOL SetTabStops(int nTabStops, LPINT rgTabStops)
  1021. {
  1022. ATLASSERT(::IsWindow(m_hWnd));
  1023. return (BOOL)::SendMessage(m_hWnd, EM_SETTABSTOPS, nTabStops, (LPARAM)rgTabStops);
  1024. }
  1025. BOOL SetTabStops()
  1026. {
  1027. ATLASSERT(::IsWindow(m_hWnd));
  1028. return (BOOL)::SendMessage(m_hWnd, EM_SETTABSTOPS, 0, 0L);
  1029. }
  1030. BOOL SetTabStops(const int& cxEachStop) // takes an 'int'
  1031. {
  1032. ATLASSERT(::IsWindow(m_hWnd));
  1033. return (BOOL)::SendMessage(m_hWnd, EM_SETTABSTOPS, 1, (LPARAM)(LPINT)&cxEachStop);
  1034. }
  1035. void ScrollCaret()
  1036. {
  1037. ATLASSERT(::IsWindow(m_hWnd));
  1038. ::SendMessage(m_hWnd, EM_SCROLLCARET, 0, 0L);
  1039. }
  1040. int Scroll(int nScrollAction)
  1041. {
  1042. ATLASSERT(::IsWindow(m_hWnd));
  1043. ATLASSERT((GetStyle() & ES_MULTILINE) != 0);
  1044. LRESULT lRet = ::SendMessage(m_hWnd, EM_SCROLL, nScrollAction, 0L);
  1045. if(!(BOOL)HIWORD(lRet))
  1046. return -1; // failed
  1047. return (int)(short)LOWORD(lRet);
  1048. }
  1049. void InsertText(int nInsertAfterChar, LPCTSTR lpstrText, BOOL bNoScroll = FALSE, BOOL bCanUndo = FALSE)
  1050. {
  1051. SetSel(nInsertAfterChar, nInsertAfterChar, bNoScroll);
  1052. ReplaceSel(lpstrText, bCanUndo);
  1053. }
  1054. void AppendText(LPCTSTR lpstrText, BOOL bNoScroll = FALSE, BOOL bCanUndo = FALSE)
  1055. {
  1056. InsertText(GetWindowTextLength(), lpstrText, bNoScroll, bCanUndo);
  1057. }
  1058. // Clipboard operations
  1059. BOOL Undo()
  1060. {
  1061. ATLASSERT(::IsWindow(m_hWnd));
  1062. return (BOOL)::SendMessage(m_hWnd, EM_UNDO, 0, 0L);
  1063. }
  1064. void Clear()
  1065. {
  1066. ATLASSERT(::IsWindow(m_hWnd));
  1067. ::SendMessage(m_hWnd, WM_CLEAR, 0, 0L);
  1068. }
  1069. void Copy()
  1070. {
  1071. ATLASSERT(::IsWindow(m_hWnd));
  1072. ::SendMessage(m_hWnd, WM_COPY, 0, 0L);
  1073. }
  1074. void Cut()
  1075. {
  1076. ATLASSERT(::IsWindow(m_hWnd));
  1077. ::SendMessage(m_hWnd, WM_CUT, 0, 0L);
  1078. }
  1079. void Paste()
  1080. {
  1081. ATLASSERT(::IsWindow(m_hWnd));
  1082. ::SendMessage(m_hWnd, WM_PASTE, 0, 0L);
  1083. }
  1084. };
  1085. typedef CEditT<CWindow> CEdit;
  1086. /////////////////////////////////////////////////////////////////////////////
  1087. // CEditCommands - message handlers for standard EDIT commands
  1088. // Chain to CEditCommands message map. Your class must also derive from CEdit.
  1089. // Example:
  1090. // class CMyEdit : public CWindowImpl<CMyEdit, CEdit>,
  1091. // public CEditCommands<CMyEdit>
  1092. // {
  1093. // public:
  1094. // BEGIN_MSG_MAP(CMyEdit)
  1095. // // your handlers...
  1096. // CHAIN_MSG_MAP_ALT(CEditCommands<CMyEdit>, 1)
  1097. // END_MSG_MAP()
  1098. // // other stuff...
  1099. // };
  1100. template <class T>
  1101. class CEditCommands
  1102. {
  1103. public:
  1104. BEGIN_MSG_MAP(CEditCommands< T >)
  1105. ALT_MSG_MAP(1)
  1106. COMMAND_ID_HANDLER(ID_EDIT_CLEAR, OnEditClear)
  1107. COMMAND_ID_HANDLER(ID_EDIT_CLEAR_ALL, OnEditClearAll)
  1108. COMMAND_ID_HANDLER(ID_EDIT_COPY, OnEditCopy)
  1109. COMMAND_ID_HANDLER(ID_EDIT_CUT, OnEditCut)
  1110. COMMAND_ID_HANDLER(ID_EDIT_PASTE, OnEditPaste)
  1111. COMMAND_ID_HANDLER(ID_EDIT_SELECT_ALL, OnEditSelectAll)
  1112. COMMAND_ID_HANDLER(ID_EDIT_UNDO, OnEditUndo)
  1113. END_MSG_MAP()
  1114. LRESULT OnEditClear(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
  1115. {
  1116. T* pT = static_cast<T*>(this);
  1117. pT->Clear();
  1118. return 0;
  1119. }
  1120. LRESULT OnEditClearAll(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
  1121. {
  1122. T* pT = static_cast<T*>(this);
  1123. pT->SetSel(0, -1);
  1124. pT->Clear();
  1125. return 0;
  1126. }
  1127. LRESULT OnEditCopy(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
  1128. {
  1129. T* pT = static_cast<T*>(this);
  1130. pT->Copy();
  1131. return 0;
  1132. }
  1133. LRESULT OnEditCut(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
  1134. {
  1135. T* pT = static_cast<T*>(this);
  1136. pT->Cut();
  1137. return 0;
  1138. }
  1139. LRESULT OnEditPaste(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
  1140. {
  1141. T* pT = static_cast<T*>(this);
  1142. pT->Paste();
  1143. return 0;
  1144. }
  1145. LRESULT OnEditSelectAll(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
  1146. {
  1147. T* pT = static_cast<T*>(this);
  1148. pT->SetSel(0, -1);
  1149. return 0;
  1150. }
  1151. LRESULT OnEditUndo(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
  1152. {
  1153. T* pT = static_cast<T*>(this);
  1154. pT->Undo();
  1155. return 0;
  1156. }
  1157. // State (update UI) helpers
  1158. BOOL CanCut() const
  1159. { return HasSelection(); }
  1160. BOOL CanCopy() const
  1161. { return HasSelection(); }
  1162. BOOL CanClear() const
  1163. { return HasSelection(); }
  1164. BOOL CanSelectAll() const
  1165. { return HasText(); }
  1166. BOOL CanFind() const
  1167. { return HasText(); }
  1168. BOOL CanRepeat() const
  1169. { return HasText(); }
  1170. BOOL CanReplace() const
  1171. { return HasText(); }
  1172. BOOL CanClearAll() const
  1173. { return HasText(); }
  1174. // Implementation
  1175. BOOL HasSelection() const
  1176. {
  1177. const T* pT = static_cast<const T*>(this);
  1178. int nMin, nMax;
  1179. ::SendMessage(pT->m_hWnd, EM_GETSEL, (WPARAM)&nMin, (LPARAM)&nMax);
  1180. return (nMin != nMax);
  1181. }
  1182. BOOL HasText() const
  1183. {
  1184. const T* pT = static_cast<const T*>(this);
  1185. return (pT->GetWindowTextLength() > 0);
  1186. }
  1187. };
  1188. /////////////////////////////////////////////////////////////////////////////
  1189. // CScrollBar - client side for a Windows SCROLLBAR control
  1190. template <class TBase>
  1191. class CScrollBarT : public TBase
  1192. {
  1193. public:
  1194. // Constructors
  1195. CScrollBarT(HWND hWnd = NULL) : TBase(hWnd) { }
  1196. CScrollBarT< TBase >& operator=(HWND hWnd)
  1197. {
  1198. m_hWnd = hWnd;
  1199. return *this;
  1200. }
  1201. HWND Create(HWND hWndParent, _U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
  1202. DWORD dwStyle = 0, DWORD dwExStyle = 0,
  1203. _U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
  1204. {
  1205. return CWindow::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
  1206. }
  1207. // Attributes
  1208. static LPCTSTR GetWndClassName()
  1209. {
  1210. return _T("SCROLLBAR");
  1211. }
  1212. int GetScrollPos() const
  1213. {
  1214. ATLASSERT(::IsWindow(m_hWnd));
  1215. return ::GetScrollPos(m_hWnd, SB_CTL);
  1216. }
  1217. int SetScrollPos(int nPos, BOOL bRedraw = TRUE)
  1218. {
  1219. ATLASSERT(::IsWindow(m_hWnd));
  1220. return ::SetScrollPos(m_hWnd, SB_CTL, nPos, bRedraw);
  1221. }
  1222. void GetScrollRange(LPINT lpMinPos, LPINT lpMaxPos) const
  1223. {
  1224. ATLASSERT(::IsWindow(m_hWnd));
  1225. ::GetScrollRange(m_hWnd, SB_CTL, lpMinPos, lpMaxPos);
  1226. }
  1227. void SetScrollRange(int nMinPos, int nMaxPos, BOOL bRedraw = TRUE)
  1228. {
  1229. ATLASSERT(::IsWindow(m_hWnd));
  1230. ::SetScrollRange(m_hWnd, SB_CTL, nMinPos, nMaxPos, bRedraw);
  1231. }
  1232. BOOL GetScrollInfo(LPSCROLLINFO lpScrollInfo) const
  1233. {
  1234. ATLASSERT(::IsWindow(m_hWnd));
  1235. return ::GetScrollInfo(m_hWnd, SB_CTL, lpScrollInfo);
  1236. }
  1237. int SetScrollInfo(LPSCROLLINFO lpScrollInfo, BOOL bRedraw = TRUE)
  1238. {
  1239. ATLASSERT(::IsWindow(m_hWnd));
  1240. return ::SetScrollInfo(m_hWnd, SB_CTL, lpScrollInfo, bRedraw);
  1241. }
  1242. int GetScrollLimit() const
  1243. {
  1244. int nMin, nMax;
  1245. ::GetScrollRange(m_hWnd, SB_CTL, &nMin, &nMax);
  1246. SCROLLINFO info;
  1247. info.cbSize = sizeof(SCROLLINFO);
  1248. info.fMask = SIF_PAGE;
  1249. if(::GetScrollInfo(m_hWnd, SB_CTL, &info))
  1250. nMax -= ((info.nPage-1) > 0) ? (info.nPage-1) : 0;
  1251. return nMax;
  1252. }
  1253. // Operations
  1254. void ShowScrollBar(BOOL bShow = TRUE)
  1255. {
  1256. ATLASSERT(::IsWindow(m_hWnd));
  1257. ::ShowScrollBar(m_hWnd, SB_CTL, bShow);
  1258. }
  1259. BOOL EnableScrollBar(UINT nArrowFlags = ESB_ENABLE_BOTH)
  1260. {
  1261. ATLASSERT(::IsWindow(m_hWnd));
  1262. return ::EnableScrollBar(m_hWnd, SB_CTL, nArrowFlags);
  1263. }
  1264. };
  1265. typedef CScrollBarT<CWindow> CScrollBar;
  1266. // --- Windows Common Controls ---
  1267. /////////////////////////////////////////////////////////////////////////////
  1268. // CImageList
  1269. class CImageList
  1270. {
  1271. public:
  1272. HIMAGELIST m_hImageList;
  1273. // Constructor
  1274. CImageList(HIMAGELIST hImageList = NULL) : m_hImageList(hImageList)
  1275. { }
  1276. // Operators, etc.
  1277. CImageList& operator=(HIMAGELIST hImageList)
  1278. {
  1279. m_hImageList = hImageList;
  1280. return *this;
  1281. }
  1282. operator HIMAGELIST() const { return m_hImageList; }
  1283. void Attach(HIMAGELIST hImageList)
  1284. {
  1285. ATLASSERT(m_hImageList == NULL);
  1286. ATLASSERT(hImageList != NULL);
  1287. m_hImageList = hImageList;
  1288. }
  1289. HIMAGELIST Detach()
  1290. {
  1291. HIMAGELIST hImageList = m_hImageList;
  1292. m_hImageList = NULL;
  1293. return hImageList;
  1294. }
  1295. bool IsNull() const { return (m_hImageList == NULL); }
  1296. // Attributes
  1297. int GetImageCount() const
  1298. {
  1299. ATLASSERT(m_hImageList != NULL);
  1300. return ImageList_GetImageCount(m_hImageList);
  1301. }
  1302. COLORREF GetBkColor() const
  1303. {
  1304. ATLASSERT(m_hImageList != NULL);
  1305. return ImageList_GetBkColor(m_hImageList);
  1306. }
  1307. COLORREF SetBkColor(COLORREF cr)
  1308. {
  1309. ATLASSERT(m_hImageList != NULL);
  1310. return ImageList_SetBkColor(m_hImageList, cr);
  1311. }
  1312. BOOL GetImageInfo(int nImage, IMAGEINFO* pImageInfo) const
  1313. {
  1314. ATLASSERT(m_hImageList != NULL);
  1315. return ImageList_GetImageInfo(m_hImageList, nImage, pImageInfo);
  1316. }
  1317. HICON GetIcon(int nIndex, UINT uFlags = ILD_NORMAL) const
  1318. {
  1319. ATLASSERT(m_hImageList != NULL);
  1320. return ImageList_GetIcon(m_hImageList, nIndex, uFlags);
  1321. }
  1322. BOOL GetIconSize(int& cx, int& cy) const
  1323. {
  1324. ATLASSERT(m_hImageList != NULL);
  1325. return ImageList_GetIconSize(m_hImageList, &cx, &cy);
  1326. }
  1327. BOOL GetIconSize(SIZE& size) const
  1328. {
  1329. ATLASSERT(m_hImageList != NULL);
  1330. return ImageList_GetIconSize(m_hImageList, (int*)&size.cx, (int*)&size.cy);
  1331. }
  1332. BOOL SetIconSize(int cx, int cy)
  1333. {
  1334. ATLASSERT(m_hImageList != NULL);
  1335. return ImageList_SetIconSize(m_hImageList, cx, cy);
  1336. }
  1337. BOOL SetIconSize(SIZE size)
  1338. {
  1339. ATLASSERT(m_hImageList != NULL);
  1340. return ImageList_SetIconSize(m_hImageList, size.cx, size.cy);
  1341. }
  1342. BOOL SetImageCount(UINT uNewCount)
  1343. {
  1344. ATLASSERT(m_hImageList != NULL);
  1345. return ImageList_SetImageCount(m_hImageList, uNewCount);
  1346. }
  1347. BOOL SetOverlayImage(int nImage, int nOverlay)
  1348. {
  1349. ATLASSERT(m_hImageList != NULL);
  1350. return ImageList_SetOverlayImage(m_hImageList, nImage, nOverlay);
  1351. }
  1352. // Operations
  1353. BOOL Create(int cx, int cy, UINT nFlags, int nInitial, int nGrow)
  1354. {
  1355. ATLASSERT(m_hImageList == NULL);
  1356. m_hImageList = ImageList_Create(cx, cy, nFlags, nInitial, nGrow);
  1357. return (m_hImageList != NULL) ? TRUE : FALSE;
  1358. }
  1359. BOOL Create(_U_STRINGorID bitmap, int cx, int nGrow, COLORREF crMask)
  1360. {
  1361. ATLASSERT(m_hImageList == NULL);
  1362. m_hImageList = ImageList_LoadBitmap(_Module.GetResourceInstance(), bitmap.m_lpstr, cx, nGrow, crMask);
  1363. return (m_hImageList != NULL) ? TRUE : FALSE;
  1364. }
  1365. BOOL CreateFromImage(_U_STRINGorID image, int cx, int nGrow, COLORREF crMask, UINT uType, UINT uFlags = LR_DEFAULTCOLOR | LR_DEFAULTSIZE)
  1366. {
  1367. ATLASSERT(m_hImageList == NULL);
  1368. m_hImageList = ImageList_LoadImage(_Module.GetResourceInstance(), image.m_lpstr, cx, nGrow, crMask, uType, uFlags);
  1369. return (m_hImageList != NULL) ? TRUE : FALSE;
  1370. }
  1371. BOOL Merge(HIMAGELIST hImageList1, int nImage1, HIMAGELIST hImageList2, int nImage2, int dx, int dy)
  1372. {
  1373. ATLASSERT(m_hImageList == NULL);
  1374. m_hImageList = ImageList_Merge(hImageList1, nImage1, hImageList2, nImage2, dx, dy);
  1375. return (m_hImageList != NULL) ? TRUE : FALSE;
  1376. }
  1377. BOOL Destroy()
  1378. {
  1379. if (m_hImageList == NULL)
  1380. return FALSE;
  1381. BOOL bRet = ImageList_Destroy(Detach());
  1382. if(bRet)
  1383. m_hImageList = NULL;
  1384. return bRet;
  1385. }
  1386. int Add(HBITMAP hBitmap, HBITMAP hBitmapMask = NULL)
  1387. {
  1388. ATLASSERT(m_hImageList != NULL);
  1389. return ImageList_Add(m_hImageList, hBitmap, hBitmapMask);
  1390. }
  1391. int Add(HBITMAP hBitmap, COLORREF crMask)
  1392. {
  1393. ATLASSERT(m_hImageList != NULL);
  1394. return ImageList_AddMasked(m_hImageList, hBitmap, crMask);
  1395. }
  1396. BOOL Remove(int nImage)
  1397. {
  1398. ATLASSERT(m_hImageList != NULL);
  1399. return ImageList_Remove(m_hImageList, nImage);
  1400. }
  1401. BOOL RemoveAll()
  1402. {
  1403. ATLASSERT(m_hImageList != NULL);
  1404. return ImageList_RemoveAll(m_hImageList);
  1405. }
  1406. BOOL Replace(int nImage, HBITMAP hBitmap, HBITMAP hBitmapMask)
  1407. {
  1408. ATLASSERT(m_hImageList != NULL);
  1409. return ImageList_Replace(m_hImageList, nImage, hBitmap, hBitmapMask);
  1410. }
  1411. int AddIcon(HICON hIcon)
  1412. {
  1413. ATLASSERT(m_hImageList != NULL);
  1414. return ImageList_AddIcon(m_hImageList, hIcon);
  1415. }
  1416. int ReplaceIcon(int nImage, HICON hIcon)
  1417. {
  1418. ATLASSERT(m_hImageList != NULL);
  1419. return ImageList_ReplaceIcon(m_hImageList, nImage, hIcon);
  1420. }
  1421. HICON ExtractIcon(int nImage)
  1422. {
  1423. ATLASSERT(m_hImageList != NULL);
  1424. return ImageList_ExtractIcon(NULL, m_hImageList, nImage);
  1425. }
  1426. BOOL Draw(HDC hDC, int nImage, int x, int y, UINT nStyle)
  1427. {
  1428. ATLASSERT(m_hImageList != NULL);
  1429. ATLASSERT(hDC != NULL);
  1430. return ImageList_Draw(m_hImageList, nImage, hDC, x, y, nStyle);
  1431. }
  1432. BOOL Draw(HDC hDC, int nImage, POINT pt, UINT nStyle)
  1433. {
  1434. ATLASSERT(m_hImageList != NULL);
  1435. ATLASSERT(hDC != NULL);
  1436. return ImageList_Draw(m_hImageList, nImage, hDC, pt.x, pt.y, nStyle);
  1437. }
  1438. BOOL DrawEx(int nImage, HDC hDC, int x, int y, int dx, int dy, COLORREF rgbBk, COLORREF rgbFg, UINT fStyle)
  1439. {
  1440. ATLASSERT(m_hImageList != NULL);
  1441. ATLASSERT(hDC != NULL);
  1442. return ImageList_DrawEx(m_hImageList, nImage, hDC, x, y, dx, dy, rgbBk, rgbFg, fStyle);
  1443. }
  1444. BOOL DrawEx(int nImage, HDC hDC, RECT& rect, COLORREF rgbBk, COLORREF rgbFg, UINT fStyle)
  1445. {
  1446. ATLASSERT(m_hImageList != NULL);
  1447. ATLASSERT(hDC != NULL);
  1448. return ImageList_DrawEx(m_hImageList, nImage, hDC, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, rgbBk, rgbFg, fStyle);
  1449. }
  1450. static BOOL DrawIndirect(IMAGELISTDRAWPARAMS* pimldp)
  1451. {
  1452. return ImageList_DrawIndirect(pimldp);
  1453. }
  1454. BOOL Copy(int nSrc, int nDst, UINT uFlags = ILCF_MOVE)
  1455. {
  1456. ATLASSERT(m_hImageList != NULL);
  1457. return ImageList_Copy(m_hImageList, nDst, m_hImageList, nSrc, uFlags);
  1458. }
  1459. HIMAGELIST Read(LPSTREAM lpStream)
  1460. {
  1461. ATLASSERT(m_hImageList == NULL);
  1462. return ImageList_Read(lpStream);
  1463. }
  1464. BOOL Write(LPSTREAM lpStream)
  1465. {
  1466. ATLASSERT(m_hImageList != NULL);
  1467. return ImageList_Write(m_hImageList, lpStream);
  1468. }
  1469. // Drag operations
  1470. BOOL BeginDrag(int nImage, POINT ptHotSpot)
  1471. {
  1472. ATLASSERT(m_hImageList != NULL);
  1473. return ImageList_BeginDrag(m_hImageList, nImage, ptHotSpot.x, ptHotSpot.y);
  1474. }
  1475. BOOL BeginDrag(int nImage, int xHotSpot, int yHotSpot)
  1476. {
  1477. ATLASSERT(m_hImageList != NULL);
  1478. return ImageList_BeginDrag(m_hImageList, nImage, xHotSpot, yHotSpot);
  1479. }
  1480. static void EndDrag()
  1481. {
  1482. ImageList_EndDrag();
  1483. }
  1484. static BOOL DragMove(POINT pt)
  1485. {
  1486. return ImageList_DragMove(pt.x, pt.y);
  1487. }
  1488. static BOOL DragMove(int x, int y)
  1489. {
  1490. return ImageList_DragMove(x, y);
  1491. }
  1492. BOOL SetDragCursorImage(int nDrag, POINT ptHotSpot)
  1493. {
  1494. ATLASSERT(m_hImageList != NULL);
  1495. return ImageList_SetDragCursorImage(m_hImageList, nDrag, ptHotSpot.x, ptHotSpot.y);
  1496. }
  1497. BOOL SetDragCursorImage(int nDrag, int xHotSpot, int yHotSpot)
  1498. {
  1499. ATLASSERT(m_hImageList != NULL);
  1500. return ImageList_SetDragCursorImage(m_hImageList, nDrag, xHotSpot, yHotSpot);
  1501. }
  1502. static BOOL DragShowNolock(BOOL bShow = TRUE)
  1503. {
  1504. return ImageList_DragShowNolock(bShow);
  1505. }
  1506. static CImageList GetDragImage(LPPOINT lpPoint, LPPOINT lpPointHotSpot)
  1507. {
  1508. return CImageList(ImageList_GetDragImage(lpPoint, lpPointHotSpot));
  1509. }
  1510. static BOOL DragEnter(HWND hWnd, POINT point)
  1511. {
  1512. return ImageList_DragEnter(hWnd, point.x, point.y);
  1513. }
  1514. static BOOL DragEnter(HWND hWnd, int x, int y)
  1515. {
  1516. return ImageList_DragEnter(hWnd, x, y);
  1517. }
  1518. static BOOL DragLeave(HWND hWnd)
  1519. {
  1520. return ImageList_DragLeave(hWnd);
  1521. }
  1522. #if (_WIN32_IE >= 0x0400)
  1523. CImageList Duplicate()
  1524. {
  1525. ATLASSERT(m_hImageList != NULL);
  1526. return CImageList(ImageList_Duplicate(m_hImageList));
  1527. }
  1528. static CImageList Duplicate(HIMAGELIST hImageList)
  1529. {
  1530. ATLASSERT(hImageList != NULL);
  1531. return CImageList(ImageList_Duplicate(hImageList));
  1532. }
  1533. #endif //(_WIN32_IE >= 0x0400)
  1534. };
  1535. /////////////////////////////////////////////////////////////////////////////
  1536. // CToolTipCtrl
  1537. class CToolInfo : public TOOLINFO
  1538. {
  1539. public:
  1540. CToolInfo(UINT nFlags, HWND hWnd, UINT nIDTool = 0, LPRECT lpRect = NULL, LPTSTR lpstrText = LPSTR_TEXTCALLBACK, LPARAM lUserParam = NULL)
  1541. {
  1542. Init(nFlags, hWnd, nIDTool, lpRect, lpstrText, lUserParam);
  1543. }
  1544. operator LPTOOLINFO() { return this; }
  1545. operator LPARAM() { return (LPARAM)this; }
  1546. void Init(UINT nFlags, HWND hWnd, UINT nIDTool = 0, LPRECT lpRect = NULL, LPTSTR lpstrText = LPSTR_TEXTCALLBACK, LPARAM lUserParam = NULL)
  1547. {
  1548. ATLASSERT(::IsWindow(hWnd));
  1549. memset(this, 0, sizeof(TOOLINFO));
  1550. cbSize = sizeof(TOOLINFO);
  1551. uFlags = nFlags;
  1552. if(nIDTool == 0)
  1553. {
  1554. hwnd = ::GetParent(hWnd);
  1555. uFlags |= TTF_IDISHWND;
  1556. uId = (UINT_PTR)hWnd;
  1557. }
  1558. else
  1559. {
  1560. hwnd = hWnd;
  1561. uId = nIDTool;
  1562. }
  1563. if(lpRect != NULL)
  1564. rect = *lpRect;
  1565. hinst = _Module.GetResourceInstance();
  1566. lpszText = lpstrText;
  1567. lParam = lUserParam;
  1568. }
  1569. };
  1570. template <class TBase>
  1571. class CToolTipCtrlT : public TBase
  1572. {
  1573. public:
  1574. // Constructors
  1575. CToolTipCtrlT(HWND hWnd = NULL) : TBase(hWnd) { }
  1576. CToolTipCtrlT< TBase >& operator=(HWND hWnd)
  1577. {
  1578. m_hWnd = hWnd;
  1579. return *this;
  1580. }
  1581. HWND Create(HWND hWndParent, _U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
  1582. DWORD dwStyle = 0, DWORD dwExStyle = 0,
  1583. _U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
  1584. {
  1585. return CWindow::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
  1586. }
  1587. // Attributes
  1588. static LPCTSTR GetWndClassName()
  1589. {
  1590. return TOOLTIPS_CLASS;
  1591. }
  1592. void GetText(LPTOOLINFO lpToolInfo) const
  1593. {
  1594. ATLASSERT(::IsWindow(m_hWnd));
  1595. ::SendMessage(m_hWnd, TTM_GETTEXT, 0, (LPARAM)&lpToolInfo);
  1596. }
  1597. void GetText(LPTSTR lpstrText, HWND hWnd, UINT nIDTool = 0) const
  1598. {
  1599. ATLASSERT(::IsWindow(m_hWnd));
  1600. ATLASSERT(hWnd != NULL);
  1601. CToolInfo ti(0, hWnd, nIDTool, NULL, lpstrText);
  1602. ::SendMessage(m_hWnd, TTM_GETTEXT, 0, ti);
  1603. }
  1604. BOOL GetToolInfo(LPTOOLINFO lpToolInfo) const
  1605. {
  1606. ATLASSERT(::IsWindow(m_hWnd));
  1607. return (BOOL)::SendMessage(m_hWnd, TTM_GETTOOLINFO, 0, (LPARAM)lpToolInfo);
  1608. }
  1609. BOOL GetToolInfo(HWND hWnd, UINT nIDTool, UINT* puFlags, LPRECT lpRect, LPTSTR lpstrText) const
  1610. {
  1611. ATLASSERT(::IsWindow(m_hWnd));
  1612. ATLASSERT(hWnd != NULL);
  1613. CToolInfo ti(0, hWnd, nIDTool, NULL, lpstrText);
  1614. BOOL bRet = (BOOL)::SendMessage(m_hWnd, TTM_GETTOOLINFO, 0, ti);
  1615. if(bRet)
  1616. {
  1617. *puFlags = ti.uFlags;
  1618. memcpy(lpRect, &(ti.rect), sizeof(RECT));
  1619. }
  1620. return bRet;
  1621. }
  1622. void SetToolInfo(LPTOOLINFO lpToolInfo)
  1623. {
  1624. ATLASSERT(::IsWindow(m_hWnd));
  1625. ::SendMessage(m_hWnd, TTM_SETTOOLINFO, 0, (LPARAM)lpToolInfo);
  1626. }
  1627. void SetToolRect(LPTOOLINFO lpToolInfo)
  1628. {
  1629. ATLASSERT(::IsWindow(m_hWnd));
  1630. ::SendMessage(m_hWnd, TTM_NEWTOOLRECT, 0, (LPARAM)lpToolInfo);
  1631. }
  1632. void SetToolRect(HWND hWnd, UINT nIDTool, LPCRECT lpRect)
  1633. {
  1634. ATLASSERT(::IsWindow(m_hWnd));
  1635. ATLASSERT(hWnd != NULL);
  1636. ATLASSERT(nIDTool != 0);
  1637. CToolInfo ti(0, hWnd, nIDTool, (LPRECT)lpRect, NULL);
  1638. ::SendMessage(m_hWnd, TTM_NEWTOOLRECT, 0, ti);
  1639. }
  1640. int GetToolCount() const
  1641. {
  1642. ATLASSERT(::IsWindow(m_hWnd));
  1643. return (int)::SendMessage(m_hWnd, TTM_GETTOOLCOUNT, 0, 0L);
  1644. }
  1645. int GetDelayTime(DWORD dwType) const
  1646. {
  1647. ATLASSERT(::IsWindow(m_hWnd));
  1648. return (int)::SendMessage(m_hWnd, TTM_GETDELAYTIME, dwType, 0L);
  1649. }
  1650. void SetDelayTime(DWORD dwType, int nTime)
  1651. {
  1652. ATLASSERT(::IsWindow(m_hWnd));
  1653. ::SendMessage(m_hWnd, TTM_SETDELAYTIME, dwType, MAKELPARAM(nTime, 0));
  1654. }
  1655. void GetMargin(LPRECT lpRect) const
  1656. {
  1657. ATLASSERT(::IsWindow(m_hWnd));
  1658. ::SendMessage(m_hWnd, TTM_GETMARGIN, 0, (LPARAM)lpRect);
  1659. }
  1660. void SetMargin(LPRECT lpRect)
  1661. {
  1662. ATLASSERT(::IsWindow(m_hWnd));
  1663. ::SendMessage(m_hWnd, TTM_SETMARGIN, 0, (LPARAM)lpRect);
  1664. }
  1665. int GetMaxTipWidth() const
  1666. {
  1667. ATLASSERT(::IsWindow(m_hWnd));
  1668. return (int)::SendMessage(m_hWnd, TTM_GETMAXTIPWIDTH, 0, 0L);
  1669. }
  1670. int SetMaxTipWidth(int nWidth)
  1671. {
  1672. ATLASSERT(::IsWindow(m_hWnd));
  1673. return (int)::SendMessage(m_hWnd, TTM_SETMAXTIPWIDTH, 0, nWidth);
  1674. }
  1675. COLORREF GetTipBkColor() const
  1676. {
  1677. ATLASSERT(::IsWindow(m_hWnd));
  1678. return (COLORREF)::SendMessage(m_hWnd, TTM_GETTIPBKCOLOR, 0, 0L);
  1679. }
  1680. void SetTipBkColor(COLORREF clr)
  1681. {
  1682. ATLASSERT(::IsWindow(m_hWnd));
  1683. ::SendMessage(m_hWnd, TTM_SETTIPBKCOLOR, (WPARAM)clr, 0L);
  1684. }
  1685. COLORREF GetTipTextColor() const
  1686. {
  1687. ATLASSERT(::IsWindow(m_hWnd));
  1688. return (COLORREF)::SendMessage(m_hWnd, TTM_GETTIPTEXTCOLOR, 0, 0L);
  1689. }
  1690. void SetTipTextColor(COLORREF clr)
  1691. {
  1692. ATLASSERT(::IsWindow(m_hWnd));
  1693. ::SendMessage(m_hWnd, TTM_SETTIPTEXTCOLOR, (WPARAM)clr, 0L);
  1694. }
  1695. BOOL GetCurrentTool(LPTOOLINFO lpToolInfo) const
  1696. {
  1697. ATLASSERT(::IsWindow(m_hWnd));
  1698. return (BOOL)::SendMessage(m_hWnd, TTM_GETCURRENTTOOL, 0, (LPARAM)lpToolInfo);
  1699. }
  1700. #if (_WIN32_IE >= 0x0500)
  1701. SIZE GetBubbleSize(LPTOOLINFO lpToolInfo) const
  1702. {
  1703. ATLASSERT(::IsWindow(m_hWnd));
  1704. DWORD dwRet = (DWORD)::SendMessage(m_hWnd, TTM_GETBUBBLESIZE, 0, (LPARAM)lpToolInfo);
  1705. SIZE size = { GET_X_LPARAM(dwRet), GET_Y_LPARAM(dwRet) };
  1706. return size;
  1707. }
  1708. BOOL SetTitle(UINT uIcon, LPCTSTR lpstrTitle)
  1709. {
  1710. ATLASSERT(::IsWindow(m_hWnd));
  1711. return (BOOL)::SendMessage(m_hWnd, TTM_SETTITLE, uIcon, (LPARAM)lpstrTitle);
  1712. }
  1713. #endif //(_WIN32_IE >= 0x0500)
  1714. // Operations
  1715. void Activate(BOOL bActivate)
  1716. {
  1717. ATLASSERT(::IsWindow(m_hWnd));
  1718. ::SendMessage(m_hWnd, TTM_ACTIVATE, bActivate, 0L);
  1719. }
  1720. BOOL AddTool(LPTOOLINFO lpToolInfo)
  1721. {
  1722. ATLASSERT(::IsWindow(m_hWnd));
  1723. return (BOOL)::SendMessage(m_hWnd, TTM_ADDTOOL, 0, (LPARAM)lpToolInfo);
  1724. }
  1725. BOOL AddTool(HWND hWnd, _U_STRINGorID text = LPSTR_TEXTCALLBACK, LPCRECT lpRectTool = NULL, UINT nIDTool = 0)
  1726. {
  1727. ATLASSERT(::IsWindow(m_hWnd));
  1728. ATLASSERT(hWnd != NULL);
  1729. // the toolrect and toolid must both be zero or both valid
  1730. ATLASSERT((lpRectTool != NULL && nIDTool != 0) || (lpRectTool == NULL && nIDTool == 0));
  1731. CToolInfo ti(0, hWnd, nIDTool, (LPRECT)lpRectTool, (LPTSTR)text.m_lpstr);
  1732. return (BOOL)::SendMessage(m_hWnd, TTM_ADDTOOL, 0, ti);
  1733. }
  1734. void DelTool(LPTOOLINFO lpToolInfo)
  1735. {
  1736. ATLASSERT(::IsWindow(m_hWnd));
  1737. ::SendMessage(m_hWnd, TTM_DELTOOL, 0, (LPARAM)lpToolInfo);
  1738. }
  1739. void DelTool(HWND hWnd, UINT nIDTool = 0)
  1740. {
  1741. ATLASSERT(::IsWindow(m_hWnd));
  1742. ATLASSERT(hWnd != NULL);
  1743. CToolInfo ti(0, hWnd, nIDTool, NULL, NULL);
  1744. ::SendMessage(m_hWnd, TTM_DELTOOL, 0, ti);
  1745. }
  1746. BOOL HitTest(LPTTHITTESTINFO lpHitTestInfo) const
  1747. {
  1748. ATLASSERT(::IsWindow(m_hWnd));
  1749. return (BOOL)::SendMessage(m_hWnd, TTM_HITTEST, 0, (LPARAM)lpHitTestInfo);
  1750. }
  1751. BOOL HitTest(HWND hWnd, POINT pt, LPTOOLINFO lpToolInfo) const
  1752. {
  1753. ATLASSERT(::IsWindow(m_hWnd));
  1754. ATLASSERT(hWnd != NULL);
  1755. ATLASSERT(lpToolInfo != NULL);
  1756. TTHITTESTINFO hti;
  1757. memset(&hti, 0, sizeof(hti));
  1758. hti.ti.cbSize = sizeof(TOOLINFO);
  1759. hti.hwnd = hWnd;
  1760. hti.pt.x = pt.x;
  1761. hti.pt.y = pt.y;
  1762. if((BOOL)::SendMessage(m_hWnd, TTM_HITTEST, 0, (LPARAM)&hti))
  1763. {
  1764. memcpy(lpToolInfo, &hti.ti, sizeof(TOOLINFO));
  1765. return TRUE;
  1766. }
  1767. return FALSE;
  1768. }
  1769. void RelayEvent(LPMSG lpMsg)
  1770. {
  1771. ATLASSERT(::IsWindow(m_hWnd));
  1772. ::SendMessage(m_hWnd, TTM_RELAYEVENT, 0, (LPARAM)lpMsg);
  1773. }
  1774. void UpdateTipText(LPTOOLINFO lpToolInfo)
  1775. {
  1776. ATLASSERT(::IsWindow(m_hWnd));
  1777. ::SendMessage(m_hWnd, TTM_UPDATETIPTEXT, 0, (LPARAM)lpToolInfo);
  1778. }
  1779. void UpdateTipText(_U_STRINGorID text, HWND hWnd, UINT nIDTool = 0)
  1780. {
  1781. ATLASSERT(::IsWindow(m_hWnd));
  1782. ATLASSERT(hWnd != NULL);
  1783. CToolInfo ti(0, hWnd, nIDTool, NULL, (LPTSTR)text.m_lpstr);
  1784. ::SendMessage(m_hWnd, TTM_UPDATETIPTEXT, 0, ti);
  1785. }
  1786. BOOL EnumTools(UINT nTool, LPTOOLINFO lpToolInfo) const
  1787. {
  1788. ATLASSERT(::IsWindow(m_hWnd));
  1789. return (BOOL)::SendMessage(m_hWnd, TTM_ENUMTOOLS, nTool, (LPARAM)lpToolInfo);
  1790. }
  1791. void Pop()
  1792. {
  1793. ATLASSERT(::IsWindow(m_hWnd));
  1794. ::SendMessage(m_hWnd, TTM_POP, 0, 0L);
  1795. }
  1796. void TrackActivate(LPTOOLINFO lpToolInfo, BOOL bActivate)
  1797. {
  1798. ATLASSERT(::IsWindow(m_hWnd));
  1799. ::SendMessage(m_hWnd, TTM_TRACKACTIVATE, bActivate, (LPARAM)lpToolInfo);
  1800. }
  1801. void TrackPosition(int xPos, int yPos)
  1802. {
  1803. ATLASSERT(::IsWindow(m_hWnd));
  1804. ::SendMessage(m_hWnd, TTM_TRACKPOSITION, 0, MAKELPARAM(xPos, yPos));
  1805. }
  1806. #if (_WIN32_IE >= 0x0400)
  1807. void Update()
  1808. {
  1809. ATLASSERT(::IsWindow(m_hWnd));
  1810. ::SendMessage(m_hWnd, TTM_UPDATE, 0, 0L);
  1811. }
  1812. #endif //(_WIN32_IE >= 0x0400)
  1813. #if (_WIN32_IE >= 0x0500)
  1814. BOOL AdjustRect(LPRECT lpRect, BOOL bLarger /*= TRUE*/)
  1815. {
  1816. ATLASSERT(::IsWindow(m_hWnd));
  1817. return (BOOL)::SendMessage(m_hWnd, TTM_ADJUSTRECT, bLarger, (LPARAM)lpRect);
  1818. }
  1819. #endif //(_WIN32_IE >= 0x0500)
  1820. };
  1821. typedef CToolTipCtrlT<CWindow> CToolTipCtrl;
  1822. /////////////////////////////////////////////////////////////////////////////
  1823. // CHeaderCtrl
  1824. template <class TBase>
  1825. class CHeaderCtrlT : public TBase
  1826. {
  1827. public:
  1828. // Constructors
  1829. CHeaderCtrlT(HWND hWnd = NULL) : TBase(hWnd) { }
  1830. CHeaderCtrlT< TBase >& operator=(HWND hWnd)
  1831. {
  1832. m_hWnd = hWnd;
  1833. return *this;
  1834. }
  1835. HWND Create(HWND hWndParent, _U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
  1836. DWORD dwStyle = 0, DWORD dwExStyle = 0,
  1837. _U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
  1838. {
  1839. return CWindow::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
  1840. }
  1841. // Attributes
  1842. static LPCTSTR GetWndClassName()
  1843. {
  1844. return WC_HEADER;
  1845. }
  1846. int GetItemCount() const
  1847. {
  1848. ATLASSERT(::IsWindow(m_hWnd));
  1849. return (int)::SendMessage(m_hWnd, HDM_GETITEMCOUNT, 0, 0L);
  1850. }
  1851. BOOL GetItem(int nIndex, LPHDITEM pHeaderItem) const
  1852. {
  1853. ATLASSERT(::IsWindow(m_hWnd));
  1854. return (BOOL)::SendMessage(m_hWnd, HDM_GETITEM, nIndex, (LPARAM)pHeaderItem);
  1855. }
  1856. BOOL SetItem(int nIndex, LPHDITEM pHeaderItem)
  1857. {
  1858. ATLASSERT(::IsWindow(m_hWnd));
  1859. return (BOOL)::SendMessage(m_hWnd, HDM_SETITEM, nIndex, (LPARAM)pHeaderItem);
  1860. }
  1861. CImageList GetImageList() const
  1862. {
  1863. ATLASSERT(::IsWindow(m_hWnd));
  1864. return CImageList((HIMAGELIST)::SendMessage(m_hWnd, HDM_GETIMAGELIST, 0, 0L));
  1865. }
  1866. CImageList SetImageList(HIMAGELIST hImageList)
  1867. {
  1868. ATLASSERT(::IsWindow(m_hWnd));
  1869. return CImageList((HIMAGELIST)::SendMessage(m_hWnd, HDM_SETIMAGELIST, 0, (LPARAM)hImageList));
  1870. }
  1871. BOOL GetOrderArray(int nSize, int* lpnArray) const
  1872. {
  1873. ATLASSERT(::IsWindow(m_hWnd));
  1874. return (BOOL)::SendMessage(m_hWnd, HDM_GETORDERARRAY, nSize, (LPARAM)lpnArray);
  1875. }
  1876. BOOL SetOrderArray(int nSize, int* lpnArray)
  1877. {
  1878. ATLASSERT(::IsWindow(m_hWnd));
  1879. return (BOOL)::SendMessage(m_hWnd, HDM_SETORDERARRAY, nSize, (LPARAM)lpnArray);
  1880. }
  1881. BOOL GetItemRect(int nIndex, LPRECT lpItemRect) const
  1882. {
  1883. ATLASSERT(::IsWindow(m_hWnd));
  1884. return (BOOL)::SendMessage(m_hWnd, HDM_GETITEMRECT, nIndex, (LPARAM)lpItemRect);
  1885. }
  1886. int SetHotDivider(BOOL bPos, DWORD dwInputValue)
  1887. {
  1888. ATLASSERT(::IsWindow(m_hWnd));
  1889. return (int)::SendMessage(m_hWnd, HDM_SETHOTDIVIDER, bPos, dwInputValue);
  1890. }
  1891. #if (_WIN32_IE >= 0x0400)
  1892. BOOL GetUnicodeFormat() const
  1893. {
  1894. ATLASSERT(::IsWindow(m_hWnd));
  1895. return (BOOL)::SendMessage(m_hWnd, HDM_GETUNICODEFORMAT, 0, 0L);
  1896. }
  1897. BOOL SetUnicodeFormat(BOOL bUnicode = TRUE)
  1898. {
  1899. ATLASSERT(::IsWindow(m_hWnd));
  1900. return (BOOL)::SendMessage(m_hWnd, HDM_SETUNICODEFORMAT, bUnicode, 0L);
  1901. }
  1902. #endif //(_WIN32_IE >= 0x0400)
  1903. #if (_WIN32_IE >= 0x0500)
  1904. int GetBitmapMargin() const
  1905. {
  1906. ATLASSERT(::IsWindow(m_hWnd));
  1907. return (int)::SendMessage(m_hWnd, HDM_GETBITMAPMARGIN, 0, 0L);
  1908. }
  1909. int SetBitmapMargin(int nWidth)
  1910. {
  1911. ATLASSERT(::IsWindow(m_hWnd));
  1912. return (int)::SendMessage(m_hWnd, HDM_SETBITMAPMARGIN, nWidth, 0L);
  1913. }
  1914. int SetFilterChangeTimeout(DWORD dwTimeOut)
  1915. {
  1916. ATLASSERT(::IsWindow(m_hWnd));
  1917. return (int)::SendMessage(m_hWnd, HDM_SETFILTERCHANGETIMEOUT, 0, dwTimeOut);
  1918. }
  1919. #endif //(_WIN32_IE >= 0x0500)
  1920. // Operations
  1921. int InsertItem(int nIndex, LPHDITEM phdi)
  1922. {
  1923. ATLASSERT(::IsWindow(m_hWnd));
  1924. return (int)::SendMessage(m_hWnd, HDM_INSERTITEM, nIndex, (LPARAM)phdi);
  1925. }
  1926. BOOL DeleteItem(int nIndex)
  1927. {
  1928. ATLASSERT(::IsWindow(m_hWnd));
  1929. return (BOOL)::SendMessage(m_hWnd, HDM_DELETEITEM, nIndex, 0L);
  1930. }
  1931. BOOL Layout(HD_LAYOUT* pHeaderLayout)
  1932. {
  1933. ATLASSERT(::IsWindow(m_hWnd));
  1934. return (BOOL)::SendMessage(m_hWnd, HDM_LAYOUT, 0, (LPARAM)pHeaderLayout);
  1935. }
  1936. int HitTest(LPHDHITTESTINFO lpHitTestInfo) const
  1937. {
  1938. ATLASSERT(::IsWindow(m_hWnd));
  1939. return (int)::SendMessage(m_hWnd, HDM_HITTEST, 0, (LPARAM)lpHitTestInfo);
  1940. }
  1941. int OrderToIndex(int nOrder)
  1942. {
  1943. ATLASSERT(::IsWindow(m_hWnd));
  1944. return (int)::SendMessage(m_hWnd, HDM_ORDERTOINDEX, nOrder, 0L);
  1945. }
  1946. CImageList CreateDragImage(int nIndex)
  1947. {
  1948. ATLASSERT(::IsWindow(m_hWnd));
  1949. return CImageList((HIMAGELIST)::SendMessage(m_hWnd, HDM_CREATEDRAGIMAGE, nIndex, 0L));
  1950. }
  1951. #if (_WIN32_IE >= 0x0500)
  1952. int EditFilter(int nColumn, BOOL bDiscardChanges)
  1953. {
  1954. ATLASSERT(::IsWindow(m_hWnd));
  1955. return (int)::SendMessage(m_hWnd, HDM_EDITFILTER, nColumn, MAKELPARAM(bDiscardChanges, 0));
  1956. }
  1957. int ClearFilter(int nColumn)
  1958. {
  1959. ATLASSERT(::IsWindow(m_hWnd));
  1960. return (int)::SendMessage(m_hWnd, HDM_CLEARFILTER, nColumn, 0L);
  1961. }
  1962. int ClearAllFilters()
  1963. {
  1964. ATLASSERT(::IsWindow(m_hWnd));
  1965. return (int)::SendMessage(m_hWnd, HDM_CLEARFILTER, (WPARAM)-1, 0L);
  1966. }
  1967. #endif //(_WIN32_IE >= 0x0500)
  1968. };
  1969. typedef CHeaderCtrlT<CWindow> CHeaderCtrl;
  1970. /////////////////////////////////////////////////////////////////////////////
  1971. // CListViewCtrl
  1972. template <class TBase>
  1973. class CListViewCtrlT : public TBase
  1974. {
  1975. public:
  1976. // Constructors
  1977. CListViewCtrlT(HWND hWnd = NULL) : TBase(hWnd) { }
  1978. CListViewCtrlT< TBase >& operator=(HWND hWnd)
  1979. {
  1980. m_hWnd = hWnd;
  1981. return *this;
  1982. }
  1983. HWND Create(HWND hWndParent, _U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
  1984. DWORD dwStyle = 0, DWORD dwExStyle = 0,
  1985. _U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
  1986. {
  1987. return CWindow::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
  1988. }
  1989. // Attributes
  1990. static LPCTSTR GetWndClassName()
  1991. {
  1992. return WC_LISTVIEW;
  1993. }
  1994. COLORREF GetBkColor() const
  1995. {
  1996. ATLASSERT(::IsWindow(m_hWnd));
  1997. return (COLORREF)::SendMessage(m_hWnd, LVM_GETBKCOLOR, 0, 0L);
  1998. }
  1999. BOOL SetBkColor(COLORREF cr)
  2000. {
  2001. ATLASSERT(::IsWindow(m_hWnd));
  2002. return (BOOL)::SendMessage(m_hWnd, LVM_SETBKCOLOR, 0, cr);
  2003. }
  2004. CImageList GetImageList(int nImageListType) const
  2005. {
  2006. ATLASSERT(::IsWindow(m_hWnd));
  2007. return CImageList((HIMAGELIST)::SendMessage(m_hWnd, LVM_GETIMAGELIST, nImageListType, 0L));
  2008. }
  2009. CImageList SetImageList(HIMAGELIST hImageList, int nImageList)
  2010. {
  2011. ATLASSERT(::IsWindow(m_hWnd));
  2012. return CImageList((HIMAGELIST)::SendMessage(m_hWnd, LVM_SETIMAGELIST, nImageList, (LPARAM)hImageList));
  2013. }
  2014. int GetItemCount() const
  2015. {
  2016. ATLASSERT(::IsWindow(m_hWnd));
  2017. return (int)::SendMessage(m_hWnd, LVM_GETITEMCOUNT, 0, 0L);
  2018. }
  2019. void SetItemCount(int nItems)
  2020. {
  2021. ATLASSERT(::IsWindow(m_hWnd));
  2022. ::SendMessage(m_hWnd, LVM_SETITEMCOUNT, nItems, 0L);
  2023. }
  2024. BOOL GetItem(LPLVITEM pItem) const
  2025. {
  2026. ATLASSERT(::IsWindow(m_hWnd));
  2027. return (BOOL)::SendMessage(m_hWnd, LVM_GETITEM, 0, (LPARAM)pItem);
  2028. }
  2029. BOOL SetItem(const LVITEM* pItem)
  2030. {
  2031. ATLASSERT(::IsWindow(m_hWnd));
  2032. return (BOOL)::SendMessage(m_hWnd, LVM_SETITEM, 0, (LPARAM)pItem);
  2033. }
  2034. BOOL SetItem(int nItem, int nSubItem, UINT nMask, LPCTSTR lpszItem,
  2035. int nImage, UINT nState, UINT nStateMask, LPARAM lParam)
  2036. {
  2037. ATLASSERT(::IsWindow(m_hWnd));
  2038. LVITEM lvi;
  2039. lvi.mask = nMask;
  2040. lvi.iItem = nItem;
  2041. lvi.iSubItem = nSubItem;
  2042. lvi.stateMask = nStateMask;
  2043. lvi.state = nState;
  2044. lvi.pszText = (LPTSTR) lpszItem;
  2045. lvi.iImage = nImage;
  2046. lvi.lParam = lParam;
  2047. return (BOOL)::SendMessage(m_hWnd, LVM_SETITEM, 0, (LPARAM)&lvi);
  2048. }
  2049. UINT GetItemState(int nItem, UINT nMask) const
  2050. {
  2051. ATLASSERT(::IsWindow(m_hWnd));
  2052. return (UINT)::SendMessage(m_hWnd, LVM_GETITEMSTATE, nItem, nMask);
  2053. }
  2054. BOOL SetItemState(int nItem, UINT nState, UINT nStateMask)
  2055. {
  2056. ATLASSERT(::IsWindow(m_hWnd));
  2057. return SetItem(nItem, 0, LVIF_STATE, NULL, 0, nState, nStateMask, 0);
  2058. }
  2059. BOOL SetItemState(int nItem, LPLVITEM pItem)
  2060. {
  2061. ATLASSERT(::IsWindow(m_hWnd));
  2062. return (BOOL)::SendMessage(m_hWnd, LVM_SETITEMSTATE, nItem, (LPARAM)pItem);
  2063. }
  2064. #ifndef _ATL_NO_COM
  2065. BOOL GetItemText(int nItem, int nSubItem, BSTR& bstrText) const
  2066. {
  2067. USES_CONVERSION;
  2068. ATLASSERT(::IsWindow(m_hWnd));
  2069. ATLASSERT(bstrText == NULL);
  2070. LVITEM lvi;
  2071. memset(&lvi, 0, sizeof(LVITEM));
  2072. lvi.iSubItem = nSubItem;
  2073. LPTSTR lpstrText = NULL;
  2074. int nRes = 0;
  2075. for(int nLen = 256; ; nLen *= 2)
  2076. {
  2077. ATLTRY(lpstrText = new TCHAR[nLen]);
  2078. if(lpstrText == NULL)
  2079. break;
  2080. lpstrText[0] = NULL;
  2081. lvi.cchTextMax = nLen;
  2082. lvi.pszText = lpstrText;
  2083. nRes = (int)::SendMessage(m_hWnd, LVM_GETITEMTEXT, (WPARAM)nItem, (LPARAM)&lvi);
  2084. if(nRes < nLen - 1)
  2085. break;
  2086. delete [] lpstrText;
  2087. lpstrText = NULL;
  2088. }
  2089. if(lpstrText != NULL)
  2090. {
  2091. if(nRes != 0)
  2092. bstrText = ::SysAllocString(T2OLE(lpstrText));
  2093. delete [] lpstrText;
  2094. }
  2095. return (bstrText != NULL) ? TRUE : FALSE;
  2096. }
  2097. #endif //!_ATL_NO_COM
  2098. #ifdef __ATLSTR_H__
  2099. int GetItemText(int nItem, int nSubItem, CString& strText) const
  2100. {
  2101. ATLASSERT(::IsWindow(m_hWnd));
  2102. LVITEM lvi;
  2103. memset(&lvi, 0, sizeof(LVITEM));
  2104. lvi.iSubItem = nSubItem;
  2105. strText.Empty();
  2106. int nRes = 0;
  2107. for(int nLen = 256; ; nLen *= 2)
  2108. {
  2109. lvi.cchTextMax = nLen;
  2110. lvi.pszText = strText.GetBufferSetLength(nLen);
  2111. nRes = (int)::SendMessage(m_hWnd, LVM_GETITEMTEXT, (WPARAM)nItem, (LPARAM)&lvi);
  2112. if(nRes < nLen - 1)
  2113. break;
  2114. }
  2115. strText.ReleaseBuffer();
  2116. return nRes;
  2117. }
  2118. #endif //__ATLSTR_H__
  2119. int GetItemText(int nItem, int nSubItem, LPTSTR lpszText, int nLen) const
  2120. {
  2121. ATLASSERT(::IsWindow(m_hWnd));
  2122. LVITEM lvi;
  2123. memset(&lvi, 0, sizeof(LVITEM));
  2124. lvi.iSubItem = nSubItem;
  2125. lvi.cchTextMax = nLen;
  2126. lvi.pszText = lpszText;
  2127. return (int)::SendMessage(m_hWnd, LVM_GETITEMTEXT, (WPARAM)nItem, (LPARAM)&lvi);
  2128. }
  2129. BOOL SetItemText(int nItem, int nSubItem, LPCTSTR lpszText)
  2130. {
  2131. ATLASSERT(::IsWindow(m_hWnd));
  2132. return SetItem(nItem, nSubItem, LVIF_TEXT, lpszText, 0, 0, 0, 0);
  2133. }
  2134. DWORD_PTR GetItemData(int nItem) const
  2135. {
  2136. ATLASSERT(::IsWindow(m_hWnd));
  2137. LVITEM lvi;
  2138. memset(&lvi, 0, sizeof(LVITEM));
  2139. lvi.iItem = nItem;
  2140. lvi.mask = LVIF_PARAM;
  2141. ::SendMessage(m_hWnd, LVM_GETITEM, 0, (LPARAM)&lvi);
  2142. return (DWORD_PTR)lvi.lParam;
  2143. }
  2144. BOOL SetItemData(int nItem, DWORD_PTR dwData)
  2145. {
  2146. ATLASSERT(::IsWindow(m_hWnd));
  2147. return SetItem(nItem, 0, LVIF_PARAM, NULL, 0, 0, 0, (LPARAM)dwData);
  2148. }
  2149. UINT GetCallbackMask() const
  2150. {
  2151. ATLASSERT(::IsWindow(m_hWnd));
  2152. return (UINT)::SendMessage(m_hWnd, LVM_GETCALLBACKMASK, 0, 0L);
  2153. }
  2154. BOOL SetCallbackMask(UINT nMask)
  2155. {
  2156. ATLASSERT(::IsWindow(m_hWnd));
  2157. return (BOOL)::SendMessage(m_hWnd, LVM_SETCALLBACKMASK, nMask, 0L);
  2158. }
  2159. BOOL GetItemPosition(int nItem, LPPOINT lpPoint) const
  2160. {
  2161. ATLASSERT(::IsWindow(m_hWnd));
  2162. return (BOOL)::SendMessage(m_hWnd, LVM_GETITEMPOSITION, nItem, (LPARAM)lpPoint);
  2163. }
  2164. BOOL SetItemPosition(int nItem, POINT pt)
  2165. {
  2166. ATLASSERT(::IsWindow(m_hWnd));
  2167. ATLASSERT(((GetStyle() & LVS_TYPEMASK) == LVS_ICON) || ((GetStyle() & LVS_TYPEMASK) == LVS_SMALLICON));
  2168. return (BOOL)::SendMessage(m_hWnd, LVM_SETITEMPOSITION32, nItem, (LPARAM)&pt);
  2169. }
  2170. BOOL SetItemPosition(int nItem, int x, int y)
  2171. {
  2172. ATLASSERT(::IsWindow(m_hWnd));
  2173. ATLASSERT(((GetStyle() & LVS_TYPEMASK) == LVS_ICON) || ((GetStyle() & LVS_TYPEMASK) == LVS_SMALLICON));
  2174. POINT pt = { x, y };
  2175. return (BOOL)::SendMessage(m_hWnd, LVM_SETITEMPOSITION32, nItem, (LPARAM)&pt);
  2176. }
  2177. int GetStringWidth(LPCTSTR lpsz) const
  2178. {
  2179. ATLASSERT(::IsWindow(m_hWnd));
  2180. return (int)::SendMessage(m_hWnd, LVM_GETSTRINGWIDTH, 0, (LPARAM)lpsz);
  2181. }
  2182. CEdit GetEditControl() const
  2183. {
  2184. ATLASSERT(::IsWindow(m_hWnd));
  2185. return CEdit((HWND)::SendMessage(m_hWnd, LVM_GETEDITCONTROL, 0, 0L));
  2186. }
  2187. BOOL GetColumn(int nCol, LV_COLUMN* pColumn) const
  2188. {
  2189. ATLASSERT(::IsWindow(m_hWnd));
  2190. return (BOOL)::SendMessage(m_hWnd, LVM_GETCOLUMN, nCol, (LPARAM)pColumn);
  2191. }
  2192. BOOL SetColumn(int nCol, const LV_COLUMN* pColumn)
  2193. {
  2194. ATLASSERT(::IsWindow(m_hWnd));
  2195. return (BOOL)::SendMessage(m_hWnd, LVM_SETCOLUMN, nCol, (LPARAM)pColumn);
  2196. }
  2197. int GetColumnWidth(int nCol) const
  2198. {
  2199. ATLASSERT(::IsWindow(m_hWnd));
  2200. return (int)::SendMessage(m_hWnd, LVM_GETCOLUMNWIDTH, nCol, 0L);
  2201. }
  2202. BOOL SetColumnWidth(int nCol, int cx)
  2203. {
  2204. ATLASSERT(::IsWindow(m_hWnd));
  2205. return (BOOL)::SendMessage(m_hWnd, LVM_SETCOLUMNWIDTH, nCol, MAKELPARAM(cx, 0));
  2206. }
  2207. BOOL GetViewRect(LPRECT lpRect) const
  2208. {
  2209. ATLASSERT(::IsWindow(m_hWnd));
  2210. return (BOOL)::SendMessage(m_hWnd, LVM_GETVIEWRECT, 0, (LPARAM)lpRect);
  2211. }
  2212. COLORREF GetTextColor() const
  2213. {
  2214. ATLASSERT(::IsWindow(m_hWnd));
  2215. return (COLORREF)::SendMessage(m_hWnd, LVM_GETTEXTCOLOR, 0, 0L);
  2216. }
  2217. BOOL SetTextColor(COLORREF cr)
  2218. {
  2219. ATLASSERT(::IsWindow(m_hWnd));
  2220. return (BOOL)::SendMessage(m_hWnd, LVM_SETTEXTCOLOR, 0, cr);
  2221. }
  2222. COLORREF GetTextBkColor() const
  2223. {
  2224. ATLASSERT(::IsWindow(m_hWnd));
  2225. return (COLORREF)::SendMessage(m_hWnd, LVM_GETTEXTBKCOLOR, 0, 0L);
  2226. }
  2227. BOOL SetTextBkColor(COLORREF cr)
  2228. {
  2229. ATLASSERT(::IsWindow(m_hWnd));
  2230. return (BOOL)::SendMessage(m_hWnd, LVM_SETTEXTBKCOLOR, 0, cr);
  2231. }
  2232. int GetTopIndex() const
  2233. {
  2234. ATLASSERT(::IsWindow(m_hWnd));
  2235. return (int)::SendMessage(m_hWnd, LVM_GETTOPINDEX, 0, 0L);
  2236. }
  2237. int GetCountPerPage() const
  2238. {
  2239. ATLASSERT(::IsWindow(m_hWnd));
  2240. return (int)::SendMessage(m_hWnd, LVM_GETCOUNTPERPAGE, 0, 0L);
  2241. }
  2242. BOOL GetOrigin(LPPOINT lpPoint) const
  2243. {
  2244. ATLASSERT(::IsWindow(m_hWnd));
  2245. return (BOOL)::SendMessage(m_hWnd, LVM_GETORIGIN, 0, (LPARAM)lpPoint);
  2246. }
  2247. UINT GetSelectedCount() const
  2248. {
  2249. ATLASSERT(::IsWindow(m_hWnd));
  2250. return (UINT)::SendMessage(m_hWnd, LVM_GETSELECTEDCOUNT, 0, 0L);
  2251. }
  2252. BOOL GetItemRect(int nItem, LPRECT lpRect, UINT nCode) const
  2253. {
  2254. ATLASSERT(::IsWindow(m_hWnd));
  2255. lpRect->left = nCode;
  2256. return (BOOL)::SendMessage(m_hWnd, LVM_GETITEMRECT, (WPARAM)nItem, (LPARAM)lpRect);
  2257. }
  2258. HCURSOR GetHotCursor() const
  2259. {
  2260. ATLASSERT(::IsWindow(m_hWnd));
  2261. return (HCURSOR)::SendMessage(m_hWnd, LVM_GETHOTCURSOR, 0, 0L);
  2262. }
  2263. HCURSOR SetHotCursor(HCURSOR hHotCursor)
  2264. {
  2265. ATLASSERT(::IsWindow(m_hWnd));
  2266. return (HCURSOR)::SendMessage(m_hWnd, LVM_SETHOTCURSOR, 0, (LPARAM)hHotCursor);
  2267. }
  2268. int GetHotItem() const
  2269. {
  2270. ATLASSERT(::IsWindow(m_hWnd));
  2271. return (int)::SendMessage(m_hWnd, LVM_GETHOTITEM, 0, 0L);
  2272. }
  2273. int SetHotItem(int nIndex)
  2274. {
  2275. ATLASSERT(::IsWindow(m_hWnd));
  2276. return (int)::SendMessage(m_hWnd, LVM_SETHOTITEM, nIndex, 0L);
  2277. }
  2278. BOOL GetColumnOrderArray(int nCount, int* lpnArray) const
  2279. {
  2280. ATLASSERT(::IsWindow(m_hWnd));
  2281. return (BOOL)::SendMessage(m_hWnd, LVM_GETCOLUMNORDERARRAY, nCount, (LPARAM)lpnArray);
  2282. }
  2283. BOOL SetColumnOrderArray(int nCount, int* lpnArray)
  2284. {
  2285. ATLASSERT(::IsWindow(m_hWnd));
  2286. return (BOOL)::SendMessage(m_hWnd, LVM_SETCOLUMNORDERARRAY, nCount, (LPARAM)lpnArray);
  2287. }
  2288. CHeaderCtrl GetHeader() const
  2289. {
  2290. ATLASSERT(::IsWindow(m_hWnd));
  2291. return CHeaderCtrl((HWND)::SendMessage(m_hWnd, LVM_GETHEADER, 0, 0L));
  2292. }
  2293. BOOL GetSubItemRect(int nItem, int nSubItem, int nFlag, LPRECT lpRect) const
  2294. {
  2295. ATLASSERT(::IsWindow(m_hWnd));
  2296. ATLASSERT((GetStyle() & LVS_TYPEMASK) == LVS_REPORT);
  2297. ATLASSERT(lpRect != NULL);
  2298. lpRect->top = nSubItem;
  2299. lpRect->left = nFlag;
  2300. return (BOOL)::SendMessage(m_hWnd, LVM_GETSUBITEMRECT, nItem, (LPARAM)lpRect);
  2301. }
  2302. DWORD SetIconSpacing(int cx, int cy)
  2303. {
  2304. ATLASSERT(::IsWindow(m_hWnd));
  2305. ATLASSERT((GetStyle() & LVS_TYPEMASK) == LVS_ICON);
  2306. return (DWORD)::SendMessage(m_hWnd, LVM_SETICONSPACING, 0, MAKELPARAM(cx, cy));
  2307. }
  2308. int GetISearchString(LPTSTR lpstr) const
  2309. {
  2310. ATLASSERT(::IsWindow(m_hWnd));
  2311. return (int)::SendMessage(m_hWnd, LVM_GETISEARCHSTRING, 0, (LPARAM)lpstr);
  2312. }
  2313. void GetItemSpacing(SIZE& sizeSpacing, BOOL bSmallIconView = FALSE) const
  2314. {
  2315. ATLASSERT(::IsWindow(m_hWnd));
  2316. DWORD dwRet = (DWORD)::SendMessage(m_hWnd, LVM_GETITEMSPACING, bSmallIconView, 0L);
  2317. sizeSpacing.cx = GET_X_LPARAM(dwRet);
  2318. sizeSpacing.cy = GET_Y_LPARAM(dwRet);
  2319. }
  2320. // single-selection only
  2321. int GetSelectedIndex() const
  2322. {
  2323. ATLASSERT(::IsWindow(m_hWnd));
  2324. ATLASSERT((GetStyle() & LVS_SINGLESEL) != 0);
  2325. return (int)::SendMessage(m_hWnd, LVM_GETNEXTITEM, (WPARAM)-1, MAKELPARAM(LVNI_ALL | LVNI_SELECTED, 0));
  2326. }
  2327. BOOL GetSelectedItem(LPLVITEM pItem) const
  2328. {
  2329. ATLASSERT(::IsWindow(m_hWnd));
  2330. ATLASSERT((GetStyle() & LVS_SINGLESEL) != 0);
  2331. ATLASSERT(pItem != NULL);
  2332. pItem->iItem = (int)::SendMessage(m_hWnd, LVM_GETNEXTITEM, (WPARAM)-1, MAKELPARAM(LVNI_ALL | LVNI_SELECTED, 0));
  2333. if(pItem->iItem == -1)
  2334. return FALSE;
  2335. return (BOOL)::SendMessage(m_hWnd, LVM_GETITEM, 0, (LPARAM)pItem);
  2336. }
  2337. // extended list view styles
  2338. DWORD GetExtendedListViewStyle() const
  2339. {
  2340. ATLASSERT(::IsWindow(m_hWnd));
  2341. return (DWORD)::SendMessage(m_hWnd, LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0L);
  2342. }
  2343. // dwExMask = 0 means all styles
  2344. DWORD SetExtendedListViewStyle(DWORD dwExStyle, DWORD dwExMask = 0)
  2345. {
  2346. ATLASSERT(::IsWindow(m_hWnd));
  2347. return (DWORD)::SendMessage(m_hWnd, LVM_SETEXTENDEDLISTVIEWSTYLE, dwExMask, dwExStyle);
  2348. }
  2349. // checkboxes only
  2350. BOOL GetCheckState(int nIndex) const
  2351. {
  2352. ATLASSERT(::IsWindow(m_hWnd));
  2353. ATLASSERT((GetExtendedListViewStyle() & LVS_EX_CHECKBOXES) != 0);
  2354. UINT uRet = GetItemState(nIndex, LVIS_STATEIMAGEMASK);
  2355. return (uRet >> 12) - 1;
  2356. }
  2357. BOOL SetCheckState(int nItem, BOOL bCheck)
  2358. {
  2359. int nCheck = bCheck ? 2 : 1; // one based index
  2360. return SetItemState(nItem, INDEXTOSTATEIMAGEMASK(nCheck), LVIS_STATEIMAGEMASK);
  2361. }
  2362. // view type
  2363. DWORD GetViewType() const
  2364. {
  2365. ATLASSERT(::IsWindow(m_hWnd));
  2366. return (GetStyle() & LVS_TYPEMASK);
  2367. }
  2368. DWORD SetViewType(DWORD dwType)
  2369. {
  2370. ATLASSERT(::IsWindow(m_hWnd));
  2371. ATLASSERT(dwType == LVS_ICON || dwType == LVS_SMALLICON || dwType == LVS_LIST || dwType == LVS_REPORT);
  2372. DWORD dwOldType = GetViewType();
  2373. if(dwType != dwOldType)
  2374. ModifyStyle(LVS_TYPEMASK, (dwType & LVS_TYPEMASK));
  2375. return dwOldType;
  2376. }
  2377. #if (_WIN32_IE >= 0x0400)
  2378. BOOL GetBkImage(LPLVBKIMAGE plvbki) const
  2379. {
  2380. ATLASSERT(::IsWindow(m_hWnd));
  2381. return (BOOL)::SendMessage(m_hWnd, LVM_GETBKIMAGE, 0, (LPARAM)plvbki);
  2382. }
  2383. BOOL SetBkImage(LPLVBKIMAGE plvbki)
  2384. {
  2385. ATLASSERT(::IsWindow(m_hWnd));
  2386. return (BOOL)::SendMessage(m_hWnd, LVM_SETBKIMAGE, 0, (LPARAM)plvbki);
  2387. }
  2388. int GetSelectionMark() const
  2389. {
  2390. ATLASSERT(::IsWindow(m_hWnd));
  2391. return (int)::SendMessage(m_hWnd, LVM_GETSELECTIONMARK, 0, 0L);
  2392. }
  2393. int SetSelectionMark(int nIndex)
  2394. {
  2395. ATLASSERT(::IsWindow(m_hWnd));
  2396. return (int)::SendMessage(m_hWnd, LVM_SETSELECTIONMARK, 0, nIndex);
  2397. }
  2398. BOOL GetWorkAreas(int nWorkAreas, LPRECT lpRect) const
  2399. {
  2400. ATLASSERT(::IsWindow(m_hWnd));
  2401. return (BOOL)::SendMessage(m_hWnd, LVM_GETWORKAREAS, nWorkAreas, (LPARAM)lpRect);
  2402. }
  2403. BOOL SetWorkAreas(int nWorkAreas, LPRECT lpRect)
  2404. {
  2405. ATLASSERT(::IsWindow(m_hWnd));
  2406. return (BOOL)::SendMessage(m_hWnd, LVM_SETWORKAREAS, nWorkAreas, (LPARAM)lpRect);
  2407. }
  2408. DWORD GetHoverTime() const
  2409. {
  2410. ATLASSERT(::IsWindow(m_hWnd));
  2411. ATLASSERT((GetExtendedListViewStyle() & (LVS_EX_TRACKSELECT | LVS_EX_ONECLICKACTIVATE | LVS_EX_TWOCLICKACTIVATE)) != 0);
  2412. return (DWORD)::SendMessage(m_hWnd, LVM_GETHOVERTIME, 0, 0L);
  2413. }
  2414. DWORD SetHoverTime(DWORD dwHoverTime)
  2415. {
  2416. ATLASSERT(::IsWindow(m_hWnd));
  2417. ATLASSERT((GetExtendedListViewStyle() & (LVS_EX_TRACKSELECT | LVS_EX_ONECLICKACTIVATE | LVS_EX_TWOCLICKACTIVATE)) != 0);
  2418. return (DWORD)::SendMessage(m_hWnd, LVM_SETHOVERTIME, 0, dwHoverTime);
  2419. }
  2420. BOOL GetNumberOfWorkAreas(int* pnWorkAreas) const
  2421. {
  2422. ATLASSERT(::IsWindow(m_hWnd));
  2423. return (BOOL)::SendMessage(m_hWnd, LVM_GETNUMBEROFWORKAREAS, 0, (LPARAM)pnWorkAreas);
  2424. }
  2425. void SetItemCountEx(int nItems, DWORD dwFlags)
  2426. {
  2427. ATLASSERT(::IsWindow(m_hWnd));
  2428. ATLASSERT(((GetStyle() & LVS_OWNERDATA) != 0) && (((GetStyle() & LVS_TYPEMASK) == LVS_REPORT) || ((GetStyle() & LVS_TYPEMASK) == LVS_LIST)));
  2429. ::SendMessage(m_hWnd, LVM_SETITEMCOUNT, nItems, dwFlags);
  2430. }
  2431. CToolTipCtrl GetToolTips() const
  2432. {
  2433. ATLASSERT(::IsWindow(m_hWnd));
  2434. return CToolTipCtrl((HWND)::SendMessage(m_hWnd, LVM_GETTOOLTIPS, 0, 0L));
  2435. }
  2436. CToolTipCtrl SetToolTips(HWND hWndTT)
  2437. {
  2438. ATLASSERT(::IsWindow(m_hWnd));
  2439. return CToolTipCtrl((HWND)::SendMessage(m_hWnd, LVM_SETTOOLTIPS, (WPARAM)hWndTT, 0L));
  2440. }
  2441. BOOL GetUnicodeFormat() const
  2442. {
  2443. ATLASSERT(::IsWindow(m_hWnd));
  2444. return (BOOL)::SendMessage(m_hWnd, LVM_GETUNICODEFORMAT, 0, 0L);
  2445. }
  2446. BOOL SetUnicodeFormat(BOOL bUnicode = TRUE)
  2447. {
  2448. ATLASSERT(::IsWindow(m_hWnd));
  2449. return (BOOL)::SendMessage(m_hWnd, LVM_SETUNICODEFORMAT, bUnicode, 0L);
  2450. }
  2451. #endif //(_WIN32_IE >= 0x0400)
  2452. // Operations
  2453. int InsertColumn(int nCol, const LV_COLUMN* pColumn)
  2454. {
  2455. ATLASSERT(::IsWindow(m_hWnd));
  2456. return (int)::SendMessage(m_hWnd, LVM_INSERTCOLUMN, nCol, (LPARAM)pColumn);
  2457. }
  2458. int InsertColumn(int nCol, LPCTSTR lpszColumnHeading, int nFormat, int nWidth, int nSubItem)
  2459. {
  2460. LV_COLUMN column;
  2461. column.mask = LVCF_TEXT|LVCF_FMT;
  2462. column.pszText = (LPTSTR)lpszColumnHeading;
  2463. column.fmt = nFormat;
  2464. if (nWidth != -1)
  2465. {
  2466. column.mask |= LVCF_WIDTH;
  2467. column.cx = nWidth;
  2468. }
  2469. if (nSubItem != -1)
  2470. {
  2471. column.mask |= LVCF_SUBITEM;
  2472. column.iSubItem = nSubItem;
  2473. }
  2474. return InsertColumn(nCol, &column);
  2475. }
  2476. BOOL DeleteColumn(int nCol)
  2477. {
  2478. ATLASSERT(::IsWindow(m_hWnd));
  2479. return (BOOL)::SendMessage(m_hWnd, LVM_DELETECOLUMN, nCol, 0L);
  2480. }
  2481. int InsertItem(UINT nMask, int nItem, LPCTSTR lpszItem, UINT nState, UINT nStateMask, int nImage, LPARAM lParam)
  2482. {
  2483. ATLASSERT(::IsWindow(m_hWnd));
  2484. LVITEM item;
  2485. item.mask = nMask;
  2486. item.iItem = nItem;
  2487. item.iSubItem = 0;
  2488. item.pszText = (LPTSTR)lpszItem;
  2489. item.state = nState;
  2490. item.stateMask = nStateMask;
  2491. item.iImage = nImage;
  2492. item.lParam = lParam;
  2493. return InsertItem(&item);
  2494. }
  2495. int InsertItem(const LVITEM* pItem)
  2496. {
  2497. ATLASSERT(::IsWindow(m_hWnd));
  2498. return (int)::SendMessage(m_hWnd, LVM_INSERTITEM, 0, (LPARAM)pItem);
  2499. }
  2500. int InsertItem(int nItem, LPCTSTR lpszItem)
  2501. {
  2502. ATLASSERT(::IsWindow(m_hWnd));
  2503. return InsertItem(LVIF_TEXT, nItem, lpszItem, 0, 0, 0, 0);
  2504. }
  2505. int InsertItem(int nItem, LPCTSTR lpszItem, int nImage)
  2506. {
  2507. ATLASSERT(::IsWindow(m_hWnd));
  2508. return InsertItem(LVIF_TEXT|LVIF_IMAGE, nItem, lpszItem, 0, 0, nImage, 0);
  2509. }
  2510. int GetNextItem(int nItem, int nFlags) const
  2511. {
  2512. ATLASSERT(::IsWindow(m_hWnd));
  2513. return (int)::SendMessage(m_hWnd, LVM_GETNEXTITEM, nItem, MAKELPARAM(nFlags, 0));
  2514. }
  2515. BOOL DeleteItem(int nItem)
  2516. {
  2517. ATLASSERT(::IsWindow(m_hWnd));
  2518. return (BOOL)::SendMessage(m_hWnd, LVM_DELETEITEM, nItem, 0L);
  2519. }
  2520. BOOL DeleteAllItems()
  2521. {
  2522. ATLASSERT(::IsWindow(m_hWnd));
  2523. return (BOOL)::SendMessage(m_hWnd, LVM_DELETEALLITEMS, 0, 0L);
  2524. }
  2525. int FindItem(LV_FINDINFO* pFindInfo, int nStart) const
  2526. {
  2527. ATLASSERT(::IsWindow(m_hWnd));
  2528. return (int)::SendMessage(m_hWnd, LVM_FINDITEM, nStart, (LPARAM)pFindInfo);
  2529. }
  2530. int HitTest(LV_HITTESTINFO* pHitTestInfo) const
  2531. {
  2532. ATLASSERT(::IsWindow(m_hWnd));
  2533. return (int)::SendMessage(m_hWnd, LVM_HITTEST, 0, (LPARAM)pHitTestInfo);
  2534. }
  2535. int HitTest(POINT pt, UINT* pFlags) const
  2536. {
  2537. ATLASSERT(::IsWindow(m_hWnd));
  2538. LV_HITTESTINFO hti;
  2539. hti.pt = pt;
  2540. int nRes = (int)::SendMessage(m_hWnd, LVM_HITTEST, 0, (LPARAM)&hti);
  2541. if (pFlags != NULL)
  2542. *pFlags = hti.flags;
  2543. return nRes;
  2544. }
  2545. BOOL EnsureVisible(int nItem, BOOL bPartialOK)
  2546. {
  2547. ATLASSERT(::IsWindow(m_hWnd));
  2548. return (BOOL)::SendMessage(m_hWnd, LVM_ENSUREVISIBLE, nItem, MAKELPARAM(bPartialOK, 0));
  2549. }
  2550. BOOL Scroll(SIZE size)
  2551. {
  2552. ATLASSERT(::IsWindow(m_hWnd));
  2553. return (BOOL)::SendMessage(m_hWnd, LVM_SCROLL, size.cx, size.cy);
  2554. }
  2555. BOOL RedrawItems(int nFirst, int nLast)
  2556. {
  2557. ATLASSERT(::IsWindow(m_hWnd));
  2558. return (BOOL)::SendMessage(m_hWnd, LVM_REDRAWITEMS, nFirst, nLast);
  2559. }
  2560. BOOL Arrange(UINT nCode)
  2561. {
  2562. ATLASSERT(::IsWindow(m_hWnd));
  2563. return (BOOL)::SendMessage(m_hWnd, LVM_ARRANGE, nCode, 0L);
  2564. }
  2565. CEdit EditLabel(int nItem)
  2566. {
  2567. ATLASSERT(::IsWindow(m_hWnd));
  2568. return CEdit((HWND)::SendMessage(m_hWnd, LVM_EDITLABEL, nItem, 0L));
  2569. }
  2570. BOOL Update(int nItem)
  2571. {
  2572. ATLASSERT(::IsWindow(m_hWnd));
  2573. return (BOOL)::SendMessage(m_hWnd, LVM_UPDATE, nItem, 0L);
  2574. }
  2575. BOOL SortItems(PFNLVCOMPARE pfnCompare, LPARAM lParamSort)
  2576. {
  2577. ATLASSERT(::IsWindow(m_hWnd));
  2578. return (BOOL)::SendMessage(m_hWnd, LVM_SORTITEMS, (WPARAM)lParamSort, (LPARAM)pfnCompare);
  2579. }
  2580. CImageList RemoveImageList(int nImageList)
  2581. {
  2582. ATLASSERT(::IsWindow(m_hWnd));
  2583. return CImageList((HIMAGELIST)::SendMessage(m_hWnd, LVM_SETIMAGELIST, (WPARAM)nImageList, NULL));
  2584. }
  2585. CImageList CreateDragImage(int nItem, LPPOINT lpPoint)
  2586. {
  2587. ATLASSERT(::IsWindow(m_hWnd));
  2588. return CImageList((HIMAGELIST)::SendMessage(m_hWnd, LVM_CREATEDRAGIMAGE, nItem, (LPARAM)lpPoint));
  2589. }
  2590. DWORD ApproximateViewRect(int cx = -1, int cy = -1, int nCount = -1)
  2591. {
  2592. ATLASSERT(::IsWindow(m_hWnd));
  2593. return (DWORD)::SendMessage(m_hWnd, LVM_APPROXIMATEVIEWRECT, nCount, MAKELPARAM(cx, cy));
  2594. }
  2595. int SubItemHitTest(LPLVHITTESTINFO lpInfo)
  2596. {
  2597. ATLASSERT(::IsWindow(m_hWnd));
  2598. return (int)::SendMessage(m_hWnd, LVM_SUBITEMHITTEST, 0, (LPARAM)lpInfo);
  2599. }
  2600. int AddColumn(LPCTSTR strItem, int nItem, int nSubItem = -1,
  2601. int nMask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM,
  2602. int nFmt = LVCFMT_LEFT)
  2603. {
  2604. ATLASSERT(::IsWindow(m_hWnd));
  2605. LV_COLUMN lvc;
  2606. lvc.mask = nMask;
  2607. lvc.fmt = nFmt;
  2608. lvc.pszText = (LPTSTR)strItem;
  2609. lvc.cx = GetStringWidth(lvc.pszText) + 15;
  2610. if(nMask & LVCF_SUBITEM)
  2611. lvc.iSubItem = (nSubItem != -1) ? nSubItem : nItem;
  2612. return InsertColumn(nItem, &lvc);
  2613. }
  2614. int AddItem(int nItem, int nSubItem, LPCTSTR strItem, int nImageIndex = -1)
  2615. {
  2616. ATLASSERT(::IsWindow(m_hWnd));
  2617. LVITEM lvItem;
  2618. lvItem.mask = LVIF_TEXT;
  2619. lvItem.iItem = nItem;
  2620. lvItem.iSubItem = nSubItem;
  2621. lvItem.pszText = (LPTSTR)strItem;
  2622. if(nImageIndex != -1)
  2623. {
  2624. lvItem.mask |= LVIF_IMAGE;
  2625. lvItem.iImage = nImageIndex;
  2626. }
  2627. if(nSubItem == 0)
  2628. return InsertItem(&lvItem);
  2629. return SetItem(&lvItem) ? nItem : -1;
  2630. }
  2631. #if (_WIN32_IE >= 0x0500)
  2632. BOOL SortItemsEx(PFNLVCOMPARE pfnCompare, LPARAM lParamSort)
  2633. {
  2634. ATLASSERT(::IsWindow(m_hWnd));
  2635. return (BOOL)::SendMessage(m_hWnd, LVM_SORTITEMSEX, (WPARAM)lParamSort, (LPARAM)pfnCompare);
  2636. }
  2637. #endif //(_WIN32_IE >= 0x0500)
  2638. // single-selection only
  2639. BOOL SelectItem(int nIndex)
  2640. {
  2641. ATLASSERT(::IsWindow(m_hWnd));
  2642. ATLASSERT((GetStyle() & LVS_SINGLESEL) != 0);
  2643. BOOL bRet = SetItemState(nIndex, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
  2644. if(bRet)
  2645. bRet = EnsureVisible(nIndex, FALSE);
  2646. return bRet;
  2647. }
  2648. };
  2649. typedef CListViewCtrlT<CWindow> CListViewCtrl;
  2650. /////////////////////////////////////////////////////////////////////////////
  2651. // CTreeViewCtrl
  2652. template <class TBase>
  2653. class CTreeViewCtrlT : public TBase
  2654. {
  2655. public:
  2656. // Constructors
  2657. CTreeViewCtrlT(HWND hWnd = NULL) : TBase(hWnd) { }
  2658. CTreeViewCtrlT< TBase >& operator=(HWND hWnd)
  2659. {
  2660. m_hWnd = hWnd;
  2661. return *this;
  2662. }
  2663. HWND Create(HWND hWndParent, _U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
  2664. DWORD dwStyle = 0, DWORD dwExStyle = 0,
  2665. _U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
  2666. {
  2667. return CWindow::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
  2668. }
  2669. // Attributes
  2670. static LPCTSTR GetWndClassName()
  2671. {
  2672. return WC_TREEVIEW;
  2673. }
  2674. UINT GetCount() const
  2675. {
  2676. ATLASSERT(::IsWindow(m_hWnd));
  2677. return (UINT)::SendMessage(m_hWnd, TVM_GETCOUNT, 0, 0L);
  2678. }
  2679. UINT GetIndent() const
  2680. {
  2681. ATLASSERT(::IsWindow(m_hWnd));
  2682. return (UINT)::SendMessage(m_hWnd, TVM_GETINDENT, 0, 0L);
  2683. }
  2684. void SetIndent(UINT nIndent)
  2685. {
  2686. ATLASSERT(::IsWindow(m_hWnd));
  2687. ::SendMessage(m_hWnd, TVM_SETINDENT, nIndent, 0L);
  2688. }
  2689. CImageList GetImageList(UINT nImageList) const
  2690. {
  2691. ATLASSERT(::IsWindow(m_hWnd));
  2692. return CImageList((HIMAGELIST)::SendMessage(m_hWnd, TVM_GETIMAGELIST, (UINT)nImageList, 0L));
  2693. }
  2694. CImageList SetImageList(HIMAGELIST hImageList, int nImageListType)
  2695. {
  2696. ATLASSERT(::IsWindow(m_hWnd));
  2697. return CImageList((HIMAGELIST)::SendMessage(m_hWnd, TVM_SETIMAGELIST, (UINT)nImageListType, (LPARAM)hImageList));
  2698. }
  2699. BOOL GetItem(LPTVITEM pItem) const
  2700. {
  2701. ATLASSERT(::IsWindow(m_hWnd));
  2702. return (BOOL)::SendMessage(m_hWnd, TVM_GETITEM, 0, (LPARAM)pItem);
  2703. }
  2704. BOOL SetItem(LPTVITEM pItem)
  2705. {
  2706. ATLASSERT(::IsWindow(m_hWnd));
  2707. return (BOOL)::SendMessage(m_hWnd, TVM_SETITEM, 0, (LPARAM)pItem);
  2708. }
  2709. BOOL SetItem(HTREEITEM hItem, UINT nMask, LPCTSTR lpszItem, int nImage,
  2710. int nSelectedImage, UINT nState, UINT nStateMask, LPARAM lParam)
  2711. {
  2712. ATLASSERT(::IsWindow(m_hWnd));
  2713. TVITEM item;
  2714. item.hItem = hItem;
  2715. item.mask = nMask;
  2716. item.pszText = (LPTSTR) lpszItem;
  2717. item.iImage = nImage;
  2718. item.iSelectedImage = nSelectedImage;
  2719. item.state = nState;
  2720. item.stateMask = nStateMask;
  2721. item.lParam = lParam;
  2722. return (BOOL)::SendMessage(m_hWnd, TVM_SETITEM, 0, (LPARAM)&item);
  2723. }
  2724. BOOL GetItemText(HTREEITEM hItem, LPTSTR lpstrText, int nLen) const
  2725. {
  2726. ATLASSERT(::IsWindow(m_hWnd));
  2727. ATLASSERT(lpstrText != NULL);
  2728. TVITEM item;
  2729. item.hItem = hItem;
  2730. item.mask = TVIF_TEXT;
  2731. item.pszText = lpstrText;
  2732. item.cchTextMax = nLen;
  2733. return (BOOL)::SendMessage(m_hWnd, TVM_GETITEM, 0, (LPARAM)&item);
  2734. }
  2735. #ifndef _ATL_NO_COM
  2736. BOOL GetItemText(HTREEITEM hItem, BSTR& bstrText) const
  2737. {
  2738. USES_CONVERSION;
  2739. ATLASSERT(::IsWindow(m_hWnd));
  2740. ATLASSERT(bstrText == NULL);
  2741. TVITEM item;
  2742. item.hItem = hItem;
  2743. item.mask = TVIF_TEXT;
  2744. LPTSTR lpstrText = NULL;
  2745. BOOL bRet = FALSE;
  2746. for(int nLen = 256; ; nLen *= 2)
  2747. {
  2748. ATLTRY(lpstrText = new TCHAR[nLen]);
  2749. if(lpstrText == NULL)
  2750. break;
  2751. lpstrText[0] = NULL;
  2752. item.pszText = lpstrText;
  2753. item.cchTextMax = nLen;
  2754. bRet = (BOOL)::SendMessage(m_hWnd, TVM_GETITEM, 0, (LPARAM)&item);
  2755. if(!bRet || (lstrlen(item.pszText) < nLen - 1))
  2756. break;
  2757. delete [] lpstrText;
  2758. lpstrText = NULL;
  2759. }
  2760. if(lpstrText != NULL)
  2761. {
  2762. if(bRet)
  2763. bstrText = ::SysAllocString(T2OLE(lpstrText));
  2764. delete [] lpstrText;
  2765. }
  2766. return (bstrText != NULL) ? TRUE : FALSE;
  2767. }
  2768. #endif //!_ATL_NO_COM
  2769. #ifdef __ATLSTR_H__
  2770. BOOL GetItemText(HTREEITEM hItem, CString& strText) const
  2771. {
  2772. ATLASSERT(::IsWindow(m_hWnd));
  2773. TVITEM item;
  2774. item.hItem = hItem;
  2775. item.mask = TVIF_TEXT;
  2776. strText.Empty();
  2777. BOOL bRet = FALSE;
  2778. for(int nLen = 256; ; nLen *= 2)
  2779. {
  2780. item.pszText = strText.GetBufferSetLength(nLen);
  2781. item.cchTextMax = nLen;
  2782. bRet = (BOOL)::SendMessage(m_hWnd, TVM_GETITEM, 0, (LPARAM)&item);
  2783. if(!bRet || (lstrlen(item.pszText) < nLen - 1))
  2784. break;
  2785. }
  2786. strText.ReleaseBuffer();
  2787. return bRet;
  2788. }
  2789. #endif //__ATLSTR_H__
  2790. BOOL SetItemText(HTREEITEM hItem, LPCTSTR lpszItem)
  2791. {
  2792. ATLASSERT(::IsWindow(m_hWnd));
  2793. return SetItem(hItem, TVIF_TEXT, lpszItem, 0, 0, 0, 0, NULL);
  2794. }
  2795. BOOL GetItemImage(HTREEITEM hItem, int& nImage, int& nSelectedImage) const
  2796. {
  2797. ATLASSERT(::IsWindow(m_hWnd));
  2798. TVITEM item;
  2799. item.hItem = hItem;
  2800. item.mask = TVIF_IMAGE|TVIF_SELECTEDIMAGE;
  2801. BOOL bRes = (BOOL)::SendMessage(m_hWnd, TVM_GETITEM, 0, (LPARAM)&item);
  2802. if (bRes)
  2803. {
  2804. nImage = item.iImage;
  2805. nSelectedImage = item.iSelectedImage;
  2806. }
  2807. return bRes;
  2808. }
  2809. BOOL SetItemImage(HTREEITEM hItem, int nImage, int nSelectedImage)
  2810. {
  2811. ATLASSERT(::IsWindow(m_hWnd));
  2812. return SetItem(hItem, TVIF_IMAGE|TVIF_SELECTEDIMAGE, NULL, nImage, nSelectedImage, 0, 0, NULL);
  2813. }
  2814. UINT GetItemState(HTREEITEM hItem, UINT nStateMask) const
  2815. {
  2816. ATLASSERT(::IsWindow(m_hWnd));
  2817. TVITEM item;
  2818. item.hItem = hItem;
  2819. item.mask = TVIF_STATE;
  2820. item.stateMask = nStateMask;
  2821. item.state = 0;
  2822. ::SendMessage(m_hWnd, TVM_GETITEM, 0, (LPARAM)&item);
  2823. return item.state;
  2824. }
  2825. BOOL SetItemState(HTREEITEM hItem, UINT nState, UINT nStateMask)
  2826. {
  2827. ATLASSERT(::IsWindow(m_hWnd));
  2828. return SetItem(hItem, TVIF_STATE, NULL, 0, 0, nState, nStateMask, NULL);
  2829. }
  2830. DWORD_PTR GetItemData(HTREEITEM hItem) const
  2831. {
  2832. ATLASSERT(::IsWindow(m_hWnd));
  2833. TVITEM item;
  2834. item.hItem = hItem;
  2835. item.mask = TVIF_PARAM;
  2836. ::SendMessage(m_hWnd, TVM_GETITEM, 0, (LPARAM)&item);
  2837. return (DWORD_PTR)item.lParam;
  2838. }
  2839. BOOL SetItemData(HTREEITEM hItem, DWORD_PTR dwData)
  2840. {
  2841. ATLASSERT(::IsWindow(m_hWnd));
  2842. return SetItem(hItem, TVIF_PARAM, NULL, 0, 0, 0, 0, (LPARAM)dwData);
  2843. }
  2844. CEdit GetEditControl() const
  2845. {
  2846. ATLASSERT(::IsWindow(m_hWnd));
  2847. return CEdit((HWND)::SendMessage(m_hWnd, TVM_GETEDITCONTROL, 0, 0L));
  2848. }
  2849. UINT GetVisibleCount() const
  2850. {
  2851. ATLASSERT(::IsWindow(m_hWnd));
  2852. return (UINT)::SendMessage(m_hWnd, TVM_GETVISIBLECOUNT, 0, 0L);
  2853. }
  2854. BOOL GetItemRect(HTREEITEM hItem, LPRECT lpRect, BOOL bTextOnly) const
  2855. {
  2856. ATLASSERT(::IsWindow(m_hWnd));
  2857. *(HTREEITEM*)lpRect = hItem;
  2858. return (BOOL)::SendMessage(m_hWnd, TVM_GETITEMRECT, (WPARAM)bTextOnly, (LPARAM)lpRect);
  2859. }
  2860. BOOL ItemHasChildren(HTREEITEM hItem) const
  2861. {
  2862. ATLASSERT(::IsWindow(m_hWnd));
  2863. TVITEM item;
  2864. item.hItem = hItem;
  2865. item.mask = TVIF_CHILDREN;
  2866. ::SendMessage(m_hWnd, TVM_GETITEM, 0, (LPARAM)&item);
  2867. return item.cChildren;
  2868. }
  2869. CToolTipCtrl GetToolTips() const
  2870. {
  2871. ATLASSERT(::IsWindow(m_hWnd));
  2872. return CToolTipCtrl((HWND)::SendMessage(m_hWnd, TVM_GETTOOLTIPS, 0, 0L));
  2873. }
  2874. CToolTipCtrl SetToolTips(HWND hWndTT)
  2875. {
  2876. ATLASSERT(::IsWindow(m_hWnd));
  2877. return CToolTipCtrl((HWND)::SendMessage(m_hWnd, TVM_SETTOOLTIPS, (WPARAM)hWndTT, 0L));
  2878. }
  2879. int GetISearchString(LPTSTR lpstr) const
  2880. {
  2881. ATLASSERT(::IsWindow(m_hWnd));
  2882. return (int)::SendMessage(m_hWnd, TVM_GETISEARCHSTRING, 0, (LPARAM)lpstr);
  2883. }
  2884. // checkboxes only
  2885. BOOL GetCheckState(HTREEITEM hItem) const
  2886. {
  2887. ATLASSERT(::IsWindow(m_hWnd));
  2888. ATLASSERT((GetStyle() & TVS_CHECKBOXES) != 0);
  2889. UINT uRet = GetItemState(hItem, TVIS_STATEIMAGEMASK);
  2890. return (uRet >> 12) - 1;
  2891. }
  2892. BOOL SetCheckState(HTREEITEM hItem, BOOL bCheck)
  2893. {
  2894. int nCheck = bCheck ? 2 : 1; // one based index
  2895. return SetItemState(hItem, INDEXTOSTATEIMAGEMASK(nCheck), TVIS_STATEIMAGEMASK);
  2896. }
  2897. #if (_WIN32_IE >= 0x0400)
  2898. COLORREF GetBkColor() const
  2899. {
  2900. ATLASSERT(::IsWindow(m_hWnd));
  2901. return (COLORREF)::SendMessage(m_hWnd, TVM_GETBKCOLOR, 0, 0L);
  2902. }
  2903. COLORREF SetBkColor(COLORREF clr)
  2904. {
  2905. ATLASSERT(::IsWindow(m_hWnd));
  2906. return (COLORREF)::SendMessage(m_hWnd, TVM_SETBKCOLOR, 0, (LPARAM)clr);
  2907. }
  2908. COLORREF GetInsertMarkColor() const
  2909. {
  2910. ATLASSERT(::IsWindow(m_hWnd));
  2911. return (COLORREF)::SendMessage(m_hWnd, TVM_GETINSERTMARKCOLOR, 0, 0L);
  2912. }
  2913. COLORREF SetInsertMarkColor(COLORREF clr)
  2914. {
  2915. ATLASSERT(::IsWindow(m_hWnd));
  2916. return (COLORREF)::SendMessage(m_hWnd, TVM_SETINSERTMARKCOLOR, 0, (LPARAM)clr);
  2917. }
  2918. int GetItemHeight() const
  2919. {
  2920. ATLASSERT(::IsWindow(m_hWnd));
  2921. return (int)::SendMessage(m_hWnd, TVM_GETITEMHEIGHT, 0, 0L);
  2922. }
  2923. int SetItemHeight(int cyHeight)
  2924. {
  2925. ATLASSERT(::IsWindow(m_hWnd));
  2926. return (int)::SendMessage(m_hWnd, TVM_SETITEMHEIGHT, cyHeight, 0L);
  2927. }
  2928. int GetScrollTime() const
  2929. {
  2930. ATLASSERT(::IsWindow(m_hWnd));
  2931. return (int)::SendMessage(m_hWnd, TVM_GETSCROLLTIME, 0, 0L);
  2932. }
  2933. int SetScrollTime(int nScrollTime)
  2934. {
  2935. ATLASSERT(::IsWindow(m_hWnd));
  2936. return (int)::SendMessage(m_hWnd, TVM_SETSCROLLTIME, nScrollTime, 0L);
  2937. }
  2938. COLORREF GetTextColor() const
  2939. {
  2940. ATLASSERT(::IsWindow(m_hWnd));
  2941. return (COLORREF)::SendMessage(m_hWnd, TVM_GETTEXTCOLOR, 0, 0L);
  2942. }
  2943. COLORREF SetTextColor(COLORREF clr)
  2944. {
  2945. ATLASSERT(::IsWindow(m_hWnd));
  2946. return (COLORREF)::SendMessage(m_hWnd, TVM_SETTEXTCOLOR, 0, (LPARAM)clr);
  2947. }
  2948. BOOL GetUnicodeFormat() const
  2949. {
  2950. ATLASSERT(::IsWindow(m_hWnd));
  2951. return (BOOL)::SendMessage(m_hWnd, TVM_GETUNICODEFORMAT, 0, 0L);
  2952. }
  2953. BOOL SetUnicodeFormat(BOOL bUnicode = TRUE)
  2954. {
  2955. ATLASSERT(::IsWindow(m_hWnd));
  2956. return (BOOL)::SendMessage(m_hWnd, TVM_SETUNICODEFORMAT, bUnicode, 0L);
  2957. }
  2958. #endif //(_WIN32_IE >= 0x0400)
  2959. #if (_WIN32_IE >= 0x0500)
  2960. COLORREF GetLineColor() const
  2961. {
  2962. ATLASSERT(::IsWindow(m_hWnd));
  2963. return (COLORREF)::SendMessage(m_hWnd, TVM_GETLINECOLOR, 0, 0L);
  2964. }
  2965. COLORREF SetLineColor(COLORREF clrNew /*= CLR_DEFAULT*/)
  2966. {
  2967. ATLASSERT(::IsWindow(m_hWnd));
  2968. return (COLORREF)::SendMessage(m_hWnd, TVM_SETLINECOLOR, 0, (LPARAM)clrNew);
  2969. }
  2970. #endif //(_WIN32_IE >= 0x0500)
  2971. // Operations
  2972. HTREEITEM InsertItem(LPTV_INSERTSTRUCT lpInsertStruct)
  2973. {
  2974. ATLASSERT(::IsWindow(m_hWnd));
  2975. return (HTREEITEM)::SendMessage(m_hWnd, TVM_INSERTITEM, 0, (LPARAM)lpInsertStruct);
  2976. }
  2977. HTREEITEM InsertItem(LPCTSTR lpszItem, int nImage,
  2978. int nSelectedImage, HTREEITEM hParent, HTREEITEM hInsertAfter)
  2979. {
  2980. ATLASSERT(::IsWindow(m_hWnd));
  2981. return InsertItem(TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE, lpszItem, nImage, nSelectedImage, 0, 0, 0, hParent, hInsertAfter);
  2982. }
  2983. HTREEITEM InsertItem(LPCTSTR lpszItem, HTREEITEM hParent, HTREEITEM hInsertAfter)
  2984. {
  2985. ATLASSERT(::IsWindow(m_hWnd));
  2986. return InsertItem(TVIF_TEXT, lpszItem, 0, 0, 0, 0, 0, hParent, hInsertAfter);
  2987. }
  2988. HTREEITEM InsertItem(UINT nMask, LPCTSTR lpszItem, int nImage,
  2989. int nSelectedImage, UINT nState, UINT nStateMask, LPARAM lParam,
  2990. HTREEITEM hParent, HTREEITEM hInsertAfter)
  2991. {
  2992. ATLASSERT(::IsWindow(m_hWnd));
  2993. TV_INSERTSTRUCT tvis;
  2994. tvis.hParent = hParent;
  2995. tvis.hInsertAfter = hInsertAfter;
  2996. tvis.item.mask = nMask;
  2997. tvis.item.pszText = (LPTSTR) lpszItem;
  2998. tvis.item.iImage = nImage;
  2999. tvis.item.iSelectedImage = nSelectedImage;
  3000. tvis.item.state = nState;
  3001. tvis.item.stateMask = nStateMask;
  3002. tvis.item.lParam = lParam;
  3003. return (HTREEITEM)::SendMessage(m_hWnd, TVM_INSERTITEM, 0, (LPARAM)&tvis);
  3004. }
  3005. BOOL DeleteItem(HTREEITEM hItem)
  3006. {
  3007. ATLASSERT(::IsWindow(m_hWnd));
  3008. return (BOOL)::SendMessage(m_hWnd, TVM_DELETEITEM, 0, (LPARAM)hItem);
  3009. }
  3010. BOOL DeleteAllItems()
  3011. {
  3012. ATLASSERT(::IsWindow(m_hWnd));
  3013. return (BOOL)::SendMessage(m_hWnd, TVM_DELETEITEM, 0, (LPARAM)TVI_ROOT);
  3014. }
  3015. BOOL Expand(HTREEITEM hItem, UINT nCode = TVE_EXPAND)
  3016. {
  3017. ATLASSERT(::IsWindow(m_hWnd));
  3018. return (BOOL)::SendMessage(m_hWnd, TVM_EXPAND, nCode, (LPARAM)hItem);
  3019. }
  3020. HTREEITEM GetNextItem(HTREEITEM hItem, UINT nCode) const
  3021. {
  3022. ATLASSERT(::IsWindow(m_hWnd));
  3023. return (HTREEITEM)::SendMessage(m_hWnd, TVM_GETNEXTITEM, nCode, (LPARAM)hItem);
  3024. }
  3025. HTREEITEM GetChildItem(HTREEITEM hItem) const
  3026. {
  3027. ATLASSERT(::IsWindow(m_hWnd));
  3028. return (HTREEITEM)::SendMessage(m_hWnd, TVM_GETNEXTITEM, TVGN_CHILD, (LPARAM)hItem);
  3029. }
  3030. HTREEITEM GetNextSiblingItem(HTREEITEM hItem) const
  3031. {
  3032. ATLASSERT(::IsWindow(m_hWnd));
  3033. return (HTREEITEM)::SendMessage(m_hWnd, TVM_GETNEXTITEM, TVGN_NEXT, (LPARAM)hItem);
  3034. }
  3035. HTREEITEM GetPrevSiblingItem(HTREEITEM hItem) const
  3036. {
  3037. ATLASSERT(::IsWindow(m_hWnd));
  3038. return (HTREEITEM)::SendMessage(m_hWnd, TVM_GETNEXTITEM, TVGN_PREVIOUS, (LPARAM)hItem);
  3039. }
  3040. HTREEITEM GetParentItem(HTREEITEM hItem) const
  3041. {
  3042. ATLASSERT(::IsWindow(m_hWnd));
  3043. return (HTREEITEM)::SendMessage(m_hWnd, TVM_GETNEXTITEM, TVGN_PARENT, (LPARAM)hItem);
  3044. }
  3045. HTREEITEM GetFirstVisibleItem() const
  3046. {
  3047. ATLASSERT(::IsWindow(m_hWnd));
  3048. return (HTREEITEM)::SendMessage(m_hWnd, TVM_GETNEXTITEM, TVGN_FIRSTVISIBLE, 0L);
  3049. }
  3050. HTREEITEM GetNextVisibleItem(HTREEITEM hItem) const
  3051. {
  3052. ATLASSERT(::IsWindow(m_hWnd));
  3053. return (HTREEITEM)::SendMessage(m_hWnd, TVM_GETNEXTITEM, TVGN_NEXTVISIBLE, (LPARAM)hItem);
  3054. }
  3055. HTREEITEM GetPrevVisibleItem(HTREEITEM hItem) const
  3056. {
  3057. ATLASSERT(::IsWindow(m_hWnd));
  3058. return (HTREEITEM)::SendMessage(m_hWnd, TVM_GETNEXTITEM, TVGN_PREVIOUSVISIBLE, (LPARAM)hItem);
  3059. }
  3060. HTREEITEM GetSelectedItem() const
  3061. {
  3062. ATLASSERT(::IsWindow(m_hWnd));
  3063. return (HTREEITEM)::SendMessage(m_hWnd, TVM_GETNEXTITEM, TVGN_CARET, 0L);
  3064. }
  3065. HTREEITEM GetDropHilightItem() const
  3066. {
  3067. ATLASSERT(::IsWindow(m_hWnd));
  3068. return (HTREEITEM)::SendMessage(m_hWnd, TVM_GETNEXTITEM, TVGN_DROPHILITE, 0L);
  3069. }
  3070. HTREEITEM GetRootItem() const
  3071. {
  3072. ATLASSERT(::IsWindow(m_hWnd));
  3073. return (HTREEITEM)::SendMessage(m_hWnd, TVM_GETNEXTITEM, TVGN_ROOT, 0L);
  3074. }
  3075. BOOL Select(HTREEITEM hItem, UINT nCode)
  3076. {
  3077. ATLASSERT(::IsWindow(m_hWnd));
  3078. return (BOOL)::SendMessage(m_hWnd, TVM_SELECTITEM, nCode, (LPARAM)hItem);
  3079. }
  3080. BOOL SelectItem(HTREEITEM hItem)
  3081. {
  3082. ATLASSERT(::IsWindow(m_hWnd));
  3083. return (BOOL)::SendMessage(m_hWnd, TVM_SELECTITEM, TVGN_CARET, (LPARAM)hItem);
  3084. }
  3085. BOOL SelectDropTarget(HTREEITEM hItem)
  3086. {
  3087. ATLASSERT(::IsWindow(m_hWnd));
  3088. return (BOOL)::SendMessage(m_hWnd, TVM_SELECTITEM, TVGN_DROPHILITE, (LPARAM)hItem);
  3089. }
  3090. BOOL SelectSetFirstVisible(HTREEITEM hItem)
  3091. {
  3092. ATLASSERT(::IsWindow(m_hWnd));
  3093. return (BOOL)::SendMessage(m_hWnd, TVM_SELECTITEM, TVGN_FIRSTVISIBLE, (LPARAM)hItem);
  3094. }
  3095. CEdit EditLabel(HTREEITEM hItem)
  3096. {
  3097. ATLASSERT(::IsWindow(m_hWnd));
  3098. return CEdit((HWND)::SendMessage(m_hWnd, TVM_EDITLABEL, 0, (LPARAM)hItem));
  3099. }
  3100. BOOL EndEditLabelNow(BOOL bCancel)
  3101. {
  3102. ATLASSERT(::IsWindow(m_hWnd));
  3103. return (BOOL)::SendMessage(m_hWnd, TVM_ENDEDITLABELNOW, bCancel, 0L);
  3104. }
  3105. HTREEITEM HitTest(TV_HITTESTINFO* pHitTestInfo)
  3106. {
  3107. ATLASSERT(::IsWindow(m_hWnd));
  3108. return (HTREEITEM)::SendMessage(m_hWnd, TVM_HITTEST, 0, (LPARAM)pHitTestInfo);
  3109. }
  3110. HTREEITEM HitTest(POINT pt, UINT* pFlags)
  3111. {
  3112. ATLASSERT(::IsWindow(m_hWnd));
  3113. TV_HITTESTINFO hti;
  3114. hti.pt = pt;
  3115. HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(m_hWnd, TVM_HITTEST, 0, (LPARAM)&hti);
  3116. if (pFlags != NULL)
  3117. *pFlags = hti.flags;
  3118. return hTreeItem;
  3119. }
  3120. BOOL SortChildren(HTREEITEM hItem)
  3121. {
  3122. ATLASSERT(::IsWindow(m_hWnd));
  3123. return (BOOL)::SendMessage(m_hWnd, TVM_SORTCHILDREN, 0, (LPARAM)hItem);
  3124. }
  3125. BOOL EnsureVisible(HTREEITEM hItem)
  3126. {
  3127. ATLASSERT(::IsWindow(m_hWnd));
  3128. return (BOOL)::SendMessage(m_hWnd, TVM_ENSUREVISIBLE, 0, (LPARAM)hItem);
  3129. }
  3130. BOOL SortChildrenCB(LPTV_SORTCB pSort)
  3131. {
  3132. ATLASSERT(::IsWindow(m_hWnd));
  3133. return (BOOL)::SendMessage(m_hWnd, TVM_SORTCHILDRENCB, 0, (LPARAM)pSort);
  3134. }
  3135. CImageList RemoveImageList(int nImageList)
  3136. {
  3137. ATLASSERT(::IsWindow(m_hWnd));
  3138. return CImageList((HIMAGELIST)::SendMessage(m_hWnd, TVM_SETIMAGELIST, (WPARAM)nImageList, NULL));
  3139. }
  3140. CImageList CreateDragImage(HTREEITEM hItem)
  3141. {
  3142. ATLASSERT(::IsWindow(m_hWnd));
  3143. return CImageList((HIMAGELIST)::SendMessage(m_hWnd, TVM_CREATEDRAGIMAGE, 0, (LPARAM)hItem));
  3144. }
  3145. #if (_WIN32_IE >= 0x0400)
  3146. BOOL SetInsertMark(HTREEITEM hTreeItem, BOOL bAfter)
  3147. {
  3148. ATLASSERT(::IsWindow(m_hWnd));
  3149. return (BOOL)::SendMessage(m_hWnd, TVM_SETINSERTMARK, bAfter, (LPARAM)hTreeItem);
  3150. }
  3151. BOOL RemoveInsertMark()
  3152. {
  3153. ATLASSERT(::IsWindow(m_hWnd));
  3154. return (BOOL)::SendMessage(m_hWnd, TVM_SETINSERTMARK, 0, 0L);
  3155. }
  3156. #endif //(_WIN32_IE >= 0x0400)
  3157. };
  3158. typedef CTreeViewCtrlT<CWindow> CTreeViewCtrl;
  3159. /////////////////////////////////////////////////////////////////////////////
  3160. // CTreeViewCtrlEx
  3161. typedef CTreeViewCtrlExT<CWindow> CTreeViewCtrlEx; // forward declaration
  3162. class CTreeItem
  3163. {
  3164. public:
  3165. HTREEITEM m_hTreeItem;
  3166. CTreeViewCtrlEx* m_pTreeView;
  3167. // Construction
  3168. CTreeItem(HTREEITEM hTreeItem = NULL, CTreeViewCtrlEx* pTreeView = NULL) : m_hTreeItem(hTreeItem), m_pTreeView(pTreeView)
  3169. { }
  3170. CTreeItem(const CTreeItem& posSrc)
  3171. {
  3172. *this = posSrc;
  3173. }
  3174. operator HTREEITEM() { return m_hTreeItem; }
  3175. CTreeItem& operator =(const CTreeItem& itemSrc)
  3176. {
  3177. m_hTreeItem = itemSrc.m_hTreeItem;
  3178. m_pTreeView = itemSrc.m_pTreeView;
  3179. return *this;
  3180. }
  3181. // Attributes
  3182. CTreeViewCtrlEx* GetTreeView() const { return m_pTreeView; }
  3183. BOOL operator !() const { return m_hTreeItem == NULL; }
  3184. BOOL IsNull() const { return m_hTreeItem == NULL; }
  3185. BOOL GetRect(LPRECT lpRect, BOOL bTextOnly) const;
  3186. BOOL GetText(LPTSTR lpstrText, int nLen) const;
  3187. #ifndef _ATL_NO_COM
  3188. BOOL GetText(BSTR& bstrText) const;
  3189. #endif //!_ATL_NO_COM
  3190. #ifdef __ATLSTR_H__
  3191. BOOL GetText(CString& strText) const;
  3192. #endif //__ATLSTR_H__
  3193. BOOL SetText(LPCTSTR lpszItem);
  3194. BOOL GetImage(int& nImage, int& nSelectedImage) const;
  3195. BOOL SetImage(int nImage, int nSelectedImage);
  3196. UINT GetState(UINT nStateMask) const;
  3197. BOOL SetState(UINT nState, UINT nStateMask);
  3198. DWORD_PTR GetData() const;
  3199. BOOL SetData(DWORD_PTR dwData);
  3200. BOOL SetItem(UINT nMask, LPCTSTR lpszItem, int nImage, int nSelectedImage, UINT nState, UINT nStateMask, LPARAM lParam);
  3201. // Operations
  3202. CTreeItem InsertAfter(LPCTSTR lpstrItem, HTREEITEM hItemAfter, int nImageIndex)
  3203. {
  3204. return _Insert(lpstrItem, nImageIndex, hItemAfter);
  3205. }
  3206. CTreeItem AddHead(LPCTSTR lpstrItem, int nImageIndex)
  3207. {
  3208. return _Insert(lpstrItem, nImageIndex, TVI_FIRST);
  3209. }
  3210. CTreeItem AddTail(LPCTSTR lpstrItem, int nImageIndex)
  3211. {
  3212. return _Insert(lpstrItem, nImageIndex, TVI_LAST);
  3213. }
  3214. CTreeItem GetChild() const;
  3215. CTreeItem GetNext(UINT nCode) const;
  3216. CTreeItem GetNextSibling() const;
  3217. CTreeItem GetPrevSibling() const;
  3218. CTreeItem GetParent() const;
  3219. CTreeItem GetFirstVisible() const;
  3220. CTreeItem GetNextVisible() const;
  3221. CTreeItem GetPrevVisible() const;
  3222. CTreeItem GetSelected() const;
  3223. CTreeItem GetDropHilight() const;
  3224. CTreeItem GetRoot() const;
  3225. BOOL HasChildren() const;
  3226. BOOL Delete();
  3227. BOOL Expand(UINT nCode = TVE_EXPAND);
  3228. BOOL Select(UINT nCode);
  3229. BOOL Select();
  3230. BOOL SelectDropTarget();
  3231. BOOL SelectSetFirstVisible();
  3232. HWND EditLabel();
  3233. HIMAGELIST CreateDragImage();
  3234. BOOL SortChildren();
  3235. BOOL EnsureVisible();
  3236. CTreeItem _Insert(LPCTSTR lpstrItem, int nImageIndex, HTREEITEM hItemAfter);
  3237. int GetImageIndex() const;
  3238. #if (_WIN32_IE >= 0x0400)
  3239. BOOL SetInsertMark(BOOL bAfter);
  3240. #endif //(_WIN32_IE >= 0x0400)
  3241. };
  3242. template <class TBase>
  3243. class CTreeViewCtrlExT : public CTreeViewCtrlT< TBase >
  3244. {
  3245. public:
  3246. // Constructors
  3247. CTreeViewCtrlExT(HWND hWnd = NULL) : CTreeViewCtrlT< TBase >(hWnd) { }
  3248. CTreeViewCtrlExT< TBase >& operator=(HWND hWnd)
  3249. {
  3250. m_hWnd = hWnd;
  3251. return *this;
  3252. }
  3253. // Operations (overides that return CTreeItem)
  3254. CTreeItem InsertItem(LPTV_INSERTSTRUCT lpInsertStruct)
  3255. {
  3256. ATLASSERT(::IsWindow(m_hWnd));
  3257. HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(m_hWnd, TVM_INSERTITEM, 0, (LPARAM)lpInsertStruct);
  3258. return CTreeItem(hTreeItem, this);
  3259. }
  3260. CTreeItem InsertItem(LPCTSTR lpszItem, int nImage,
  3261. int nSelectedImage, HTREEITEM hParent, HTREEITEM hInsertAfter)
  3262. {
  3263. ATLASSERT(::IsWindow(m_hWnd));
  3264. return InsertItem(TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE, lpszItem, nImage, nSelectedImage, 0, 0, 0, hParent, hInsertAfter);
  3265. }
  3266. CTreeItem InsertItem(LPCTSTR lpszItem, HTREEITEM hParent, HTREEITEM hInsertAfter)
  3267. {
  3268. ATLASSERT(::IsWindow(m_hWnd));
  3269. return InsertItem(TVIF_TEXT, lpszItem, 0, 0, 0, 0, 0, hParent, hInsertAfter);
  3270. }
  3271. CTreeItem GetNextItem(HTREEITEM hItem, UINT nCode)
  3272. {
  3273. ATLASSERT(::IsWindow(m_hWnd));
  3274. HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(m_hWnd, TVM_GETNEXTITEM, nCode, (LPARAM)hItem);
  3275. return CTreeItem(hTreeItem, this);
  3276. }
  3277. CTreeItem GetChildItem(HTREEITEM hItem)
  3278. {
  3279. ATLASSERT(::IsWindow(m_hWnd));
  3280. HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(m_hWnd, TVM_GETNEXTITEM, TVGN_CHILD, (LPARAM)hItem);
  3281. return CTreeItem(hTreeItem, this);
  3282. }
  3283. CTreeItem GetNextSiblingItem(HTREEITEM hItem)
  3284. {
  3285. ATLASSERT(::IsWindow(m_hWnd));
  3286. HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(m_hWnd, TVM_GETNEXTITEM, TVGN_NEXT, (LPARAM)hItem);
  3287. return CTreeItem(hTreeItem, this);
  3288. }
  3289. CTreeItem GetPrevSiblingItem(HTREEITEM hItem)
  3290. {
  3291. ATLASSERT(::IsWindow(m_hWnd));
  3292. HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(m_hWnd, TVM_GETNEXTITEM, TVGN_PREVIOUS, (LPARAM)hItem);
  3293. return CTreeItem(hTreeItem, this);
  3294. }
  3295. CTreeItem GetParentItem(HTREEITEM hItem)
  3296. {
  3297. ATLASSERT(::IsWindow(m_hWnd));
  3298. HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(m_hWnd, TVM_GETNEXTITEM, TVGN_PARENT, (LPARAM)hItem);
  3299. return CTreeItem(hTreeItem, this);
  3300. }
  3301. CTreeItem GetFirstVisibleItem()
  3302. {
  3303. ATLASSERT(::IsWindow(m_hWnd));
  3304. HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(m_hWnd, TVM_GETNEXTITEM, TVGN_FIRSTVISIBLE, 0L);
  3305. return CTreeItem(hTreeItem, this);
  3306. }
  3307. CTreeItem GetNextVisibleItem(HTREEITEM hItem)
  3308. {
  3309. ATLASSERT(::IsWindow(m_hWnd));
  3310. HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(m_hWnd, TVM_GETNEXTITEM, TVGN_NEXTVISIBLE, (LPARAM)hItem);
  3311. return CTreeItem(hTreeItem, this);
  3312. }
  3313. CTreeItem GetPrevVisibleItem(HTREEITEM hItem)
  3314. {
  3315. ATLASSERT(::IsWindow(m_hWnd));
  3316. HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(m_hWnd, TVM_GETNEXTITEM, TVGN_PREVIOUSVISIBLE, (LPARAM)hItem);
  3317. return CTreeItem(hTreeItem, this);
  3318. }
  3319. CTreeItem GetSelectedItem()
  3320. {
  3321. ATLASSERT(::IsWindow(m_hWnd));
  3322. HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(m_hWnd, TVM_GETNEXTITEM, TVGN_CARET, 0L);
  3323. return CTreeItem(hTreeItem, this);
  3324. }
  3325. CTreeItem GetDropHilightItem()
  3326. {
  3327. ATLASSERT(::IsWindow(m_hWnd));
  3328. HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(m_hWnd, TVM_GETNEXTITEM, TVGN_DROPHILITE, 0L);
  3329. return CTreeItem(hTreeItem, this);
  3330. }
  3331. CTreeItem GetRootItem()
  3332. {
  3333. ATLASSERT(::IsWindow(m_hWnd));
  3334. HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(m_hWnd, TVM_GETNEXTITEM, TVGN_ROOT, 0L);
  3335. return CTreeItem(hTreeItem, this);
  3336. }
  3337. CTreeItem HitTest(TV_HITTESTINFO* pHitTestInfo)
  3338. {
  3339. ATLASSERT(::IsWindow(m_hWnd));
  3340. HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(m_hWnd, TVM_HITTEST, 0, (LPARAM)pHitTestInfo);
  3341. return CTreeItem(hTreeItem, this);
  3342. }
  3343. CTreeItem InsertItem(UINT nMask, LPCTSTR lpszItem, int nImage,
  3344. int nSelectedImage, UINT nState, UINT nStateMask, LPARAM lParam,
  3345. HTREEITEM hParent, HTREEITEM hInsertAfter)
  3346. {
  3347. ATLASSERT(::IsWindow(m_hWnd));
  3348. TV_INSERTSTRUCT tvis;
  3349. tvis.hParent = hParent;
  3350. tvis.hInsertAfter = hInsertAfter;
  3351. tvis.item.mask = nMask;
  3352. tvis.item.pszText = (LPTSTR) lpszItem;
  3353. tvis.item.iImage = nImage;
  3354. tvis.item.iSelectedImage = nSelectedImage;
  3355. tvis.item.state = nState;
  3356. tvis.item.stateMask = nStateMask;
  3357. tvis.item.lParam = lParam;
  3358. HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(m_hWnd, TVM_INSERTITEM, 0, (LPARAM)&tvis);
  3359. return CTreeItem(hTreeItem, this);
  3360. }
  3361. CTreeItem HitTest(POINT pt, UINT* pFlags)
  3362. {
  3363. ATLASSERT(::IsWindow(m_hWnd));
  3364. TV_HITTESTINFO hti;
  3365. hti.pt = pt;
  3366. HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(m_hWnd, TVM_HITTEST, 0, (LPARAM)&hti);
  3367. if (pFlags != NULL)
  3368. *pFlags = hti.flags;
  3369. return CTreeItem(hTreeItem, this);
  3370. }
  3371. };
  3372. // CTreeItem inline methods
  3373. inline BOOL CTreeItem::GetRect(LPRECT lpRect, BOOL bTextOnly) const
  3374. {
  3375. ATLASSERT(m_pTreeView != NULL);
  3376. return m_pTreeView->GetItemRect(m_hTreeItem,lpRect,bTextOnly);
  3377. }
  3378. inline CTreeItem CTreeItem::GetNext(UINT nCode) const
  3379. {
  3380. ATLASSERT(m_pTreeView != NULL);
  3381. return m_pTreeView->GetNextItem(m_hTreeItem,nCode);
  3382. }
  3383. inline CTreeItem CTreeItem::GetChild() const
  3384. {
  3385. ATLASSERT(m_pTreeView != NULL);
  3386. return m_pTreeView->GetChildItem(m_hTreeItem);
  3387. }
  3388. inline CTreeItem CTreeItem::GetNextSibling() const
  3389. {
  3390. ATLASSERT(m_pTreeView != NULL);
  3391. return m_pTreeView->GetNextSiblingItem(m_hTreeItem);
  3392. }
  3393. inline CTreeItem CTreeItem::GetPrevSibling() const
  3394. {
  3395. ATLASSERT(m_pTreeView != NULL);
  3396. return m_pTreeView->GetPrevSiblingItem(m_hTreeItem);
  3397. }
  3398. inline CTreeItem CTreeItem::GetParent() const
  3399. {
  3400. ATLASSERT(m_pTreeView != NULL);
  3401. return m_pTreeView->GetParentItem(m_hTreeItem);
  3402. }
  3403. inline CTreeItem CTreeItem::GetFirstVisible() const
  3404. {
  3405. ATLASSERT(m_pTreeView != NULL);
  3406. return m_pTreeView->GetFirstVisibleItem();
  3407. }
  3408. inline CTreeItem CTreeItem::GetNextVisible() const
  3409. {
  3410. ATLASSERT(m_pTreeView != NULL);
  3411. return m_pTreeView->GetNextVisibleItem(m_hTreeItem);
  3412. }
  3413. inline CTreeItem CTreeItem::GetPrevVisible() const
  3414. {
  3415. ATLASSERT(m_pTreeView != NULL);
  3416. return m_pTreeView->GetPrevVisibleItem(m_hTreeItem);
  3417. }
  3418. inline CTreeItem CTreeItem::GetSelected() const
  3419. {
  3420. ATLASSERT(m_pTreeView != NULL);
  3421. return m_pTreeView->GetSelectedItem();
  3422. }
  3423. inline CTreeItem CTreeItem::GetDropHilight() const
  3424. {
  3425. ATLASSERT(m_pTreeView != NULL);
  3426. return m_pTreeView->GetDropHilightItem();
  3427. }
  3428. inline CTreeItem CTreeItem::GetRoot() const
  3429. {
  3430. ATLASSERT(m_pTreeView != NULL);
  3431. return m_pTreeView->GetRootItem();
  3432. }
  3433. inline BOOL CTreeItem::GetText(LPTSTR lpstrText, int nLen) const
  3434. {
  3435. ATLASSERT(m_pTreeView != NULL);
  3436. return m_pTreeView->GetItemText(m_hTreeItem, lpstrText, nLen);
  3437. }
  3438. #ifndef _ATL_NO_COM
  3439. #ifdef _OLEAUTO_H_
  3440. inline BOOL CTreeItem::GetText(BSTR& bstrText) const
  3441. {
  3442. ATLASSERT(m_pTreeView != NULL);
  3443. return m_pTreeView->GetItemText(m_hTreeItem, bstrText);
  3444. }
  3445. #endif // _OLEAUTO_H_
  3446. #endif //!_ATL_NO_COM
  3447. #ifdef __ATLSTR_H__
  3448. inline BOOL CTreeItem::GetText(CString& strText) const
  3449. {
  3450. ATLASSERT(m_pTreeView != NULL);
  3451. return m_pTreeView->GetItemText(m_hTreeItem, strText);
  3452. }
  3453. #endif //__ATLSTR_H__
  3454. inline BOOL CTreeItem::GetImage(int& nImage, int& nSelectedImage) const
  3455. {
  3456. ATLASSERT(m_pTreeView != NULL);
  3457. return m_pTreeView->GetItemImage(m_hTreeItem,nImage,nSelectedImage);
  3458. }
  3459. inline UINT CTreeItem::GetState(UINT nStateMask) const
  3460. {
  3461. ATLASSERT(m_pTreeView != NULL);
  3462. return m_pTreeView->GetItemState(m_hTreeItem,nStateMask);
  3463. }
  3464. inline DWORD_PTR CTreeItem::GetData() const
  3465. {
  3466. ATLASSERT(m_pTreeView != NULL);
  3467. return m_pTreeView->GetItemData(m_hTreeItem);
  3468. }
  3469. inline BOOL CTreeItem::SetItem(UINT nMask, LPCTSTR lpszItem, int nImage,
  3470. int nSelectedImage, UINT nState, UINT nStateMask, LPARAM lParam)
  3471. {
  3472. ATLASSERT(m_pTreeView != NULL);
  3473. return m_pTreeView->SetItem(m_hTreeItem, nMask, lpszItem, nImage, nSelectedImage, nState, nStateMask, lParam);
  3474. }
  3475. inline BOOL CTreeItem::SetText(LPCTSTR lpszItem)
  3476. {
  3477. ATLASSERT(m_pTreeView != NULL);
  3478. return m_pTreeView->SetItemText(m_hTreeItem,lpszItem);
  3479. }
  3480. inline BOOL CTreeItem::SetImage(int nImage, int nSelectedImage)
  3481. {
  3482. ATLASSERT(m_pTreeView != NULL);
  3483. return m_pTreeView->SetItemImage(m_hTreeItem,nImage,nSelectedImage);
  3484. }
  3485. inline BOOL CTreeItem::SetState(UINT nState, UINT nStateMask)
  3486. {
  3487. ATLASSERT(m_pTreeView != NULL);
  3488. return m_pTreeView->SetItemState(m_hTreeItem,nState,nStateMask);
  3489. }
  3490. inline BOOL CTreeItem::SetData(DWORD_PTR dwData)
  3491. {
  3492. ATLASSERT(m_pTreeView != NULL);
  3493. return m_pTreeView->SetItemData(m_hTreeItem,dwData);
  3494. }
  3495. inline BOOL CTreeItem::HasChildren() const
  3496. {
  3497. ATLASSERT(m_pTreeView != NULL);
  3498. return m_pTreeView->ItemHasChildren(m_hTreeItem);
  3499. }
  3500. inline BOOL CTreeItem::Delete()
  3501. {
  3502. ATLASSERT(m_pTreeView != NULL);
  3503. return m_pTreeView->DeleteItem(m_hTreeItem);
  3504. }
  3505. inline BOOL CTreeItem::Expand(UINT nCode)
  3506. {
  3507. ATLASSERT(m_pTreeView != NULL);
  3508. return m_pTreeView->Expand(m_hTreeItem,nCode);
  3509. }
  3510. inline BOOL CTreeItem::Select(UINT nCode)
  3511. {
  3512. ATLASSERT(m_pTreeView != NULL);
  3513. return m_pTreeView->Select(m_hTreeItem,nCode);
  3514. }
  3515. inline BOOL CTreeItem::Select()
  3516. {
  3517. ATLASSERT(m_pTreeView != NULL);
  3518. return m_pTreeView->SelectItem(m_hTreeItem);
  3519. }
  3520. inline BOOL CTreeItem::SelectDropTarget()
  3521. {
  3522. ATLASSERT(m_pTreeView != NULL);
  3523. return m_pTreeView->SelectDropTarget(m_hTreeItem);
  3524. }
  3525. inline BOOL CTreeItem::SelectSetFirstVisible()
  3526. {
  3527. ATLASSERT(m_pTreeView != NULL);
  3528. return m_pTreeView->SelectSetFirstVisible(m_hTreeItem);
  3529. }
  3530. inline HWND CTreeItem::EditLabel()
  3531. {
  3532. ATLASSERT(m_pTreeView != NULL);
  3533. return m_pTreeView->EditLabel(m_hTreeItem);
  3534. }
  3535. inline HIMAGELIST CTreeItem::CreateDragImage()
  3536. {
  3537. ATLASSERT(m_pTreeView != NULL);
  3538. return m_pTreeView->CreateDragImage(m_hTreeItem);
  3539. }
  3540. inline BOOL CTreeItem::SortChildren()
  3541. {
  3542. ATLASSERT(m_pTreeView != NULL);
  3543. return m_pTreeView->SortChildren(m_hTreeItem);
  3544. }
  3545. inline BOOL CTreeItem::EnsureVisible()
  3546. {
  3547. ATLASSERT(m_pTreeView != NULL);
  3548. return m_pTreeView->EnsureVisible(m_hTreeItem);
  3549. }
  3550. inline CTreeItem CTreeItem::_Insert(LPCTSTR lpstrItem, int nImageIndex, HTREEITEM hItemAfter)
  3551. {
  3552. ATLASSERT(m_pTreeView != NULL);
  3553. TV_INSERTSTRUCT ins;
  3554. ins.hParent = m_hTreeItem;
  3555. ins.hInsertAfter = hItemAfter;
  3556. ins.item.mask = TVIF_TEXT;
  3557. ins.item.pszText = (LPTSTR)lpstrItem;
  3558. if(nImageIndex != -1)
  3559. {
  3560. ins.item.mask |= TVIF_IMAGE | TVIF_SELECTEDIMAGE;
  3561. ins.item.iImage = nImageIndex;
  3562. ins.item.iSelectedImage = nImageIndex;
  3563. }
  3564. return CTreeItem(m_pTreeView->InsertItem(&ins), m_pTreeView);
  3565. }
  3566. inline int CTreeItem::GetImageIndex() const
  3567. {
  3568. ATLASSERT(m_pTreeView != NULL);
  3569. TVITEM item;
  3570. item.mask = TVIF_HANDLE | TVIF_IMAGE;
  3571. item.hItem = m_hTreeItem;
  3572. m_pTreeView->GetItem(&item);
  3573. return item.iImage;
  3574. }
  3575. #if (_WIN32_IE >= 0x0400)
  3576. inline BOOL CTreeItem::SetInsertMark(BOOL bAfter)
  3577. {
  3578. ATLASSERT(m_pTreeView != NULL);
  3579. return m_pTreeView->SetInsertMark(m_hTreeItem, bAfter);
  3580. }
  3581. #endif //(_WIN32_IE >= 0x0400)
  3582. /////////////////////////////////////////////////////////////////////////////
  3583. // CToolBarCtrl
  3584. template <class TBase>
  3585. class CToolBarCtrlT : public TBase
  3586. {
  3587. public:
  3588. // Construction
  3589. CToolBarCtrlT(HWND hWnd = NULL) : TBase(hWnd) { }
  3590. CToolBarCtrlT< TBase >& operator=(HWND hWnd)
  3591. {
  3592. m_hWnd = hWnd;
  3593. return *this;
  3594. }
  3595. HWND Create(HWND hWndParent, _U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
  3596. DWORD dwStyle = 0, DWORD dwExStyle = 0,
  3597. _U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
  3598. {
  3599. return CWindow::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
  3600. }
  3601. // Attributes
  3602. static LPCTSTR GetWndClassName()
  3603. {
  3604. return TOOLBARCLASSNAME;
  3605. }
  3606. BOOL IsButtonEnabled(int nID) const
  3607. {
  3608. ATLASSERT(::IsWindow(m_hWnd));
  3609. return (BOOL)::SendMessage(m_hWnd, TB_ISBUTTONENABLED, nID, 0L);
  3610. }
  3611. BOOL IsButtonChecked(int nID) const
  3612. {
  3613. ATLASSERT(::IsWindow(m_hWnd));
  3614. return (BOOL)::SendMessage(m_hWnd, TB_ISBUTTONCHECKED, nID, 0L);
  3615. }
  3616. BOOL IsButtonPressed(int nID) const
  3617. {
  3618. ATLASSERT(::IsWindow(m_hWnd));
  3619. return (BOOL)::SendMessage(m_hWnd, TB_ISBUTTONPRESSED, nID, 0L);
  3620. }
  3621. BOOL IsButtonHidden(int nID) const
  3622. {
  3623. ATLASSERT(::IsWindow(m_hWnd));
  3624. return(BOOL) ::SendMessage(m_hWnd, TB_ISBUTTONHIDDEN, nID, 0L);
  3625. }
  3626. BOOL IsButtonIndeterminate(int nID) const
  3627. {
  3628. ATLASSERT(::IsWindow(m_hWnd));
  3629. return (BOOL)::SendMessage(m_hWnd, TB_ISBUTTONINDETERMINATE, nID, 0L);
  3630. }
  3631. int GetState(int nID) const
  3632. {
  3633. ATLASSERT(::IsWindow(m_hWnd));
  3634. return (int)::SendMessage(m_hWnd, TB_GETSTATE, nID, 0L);
  3635. }
  3636. BOOL SetState(int nID, UINT nState)
  3637. {
  3638. ATLASSERT(::IsWindow(m_hWnd));
  3639. return (BOOL)::SendMessage(m_hWnd, TB_SETSTATE, nID, MAKELPARAM(nState, 0));
  3640. }
  3641. BOOL GetButton(int nIndex, LPTBBUTTON lpButton) const
  3642. {
  3643. ATLASSERT(::IsWindow(m_hWnd));
  3644. return (BOOL)::SendMessage(m_hWnd, TB_GETBUTTON, nIndex, (LPARAM)lpButton);
  3645. }
  3646. int GetButtonCount() const
  3647. {
  3648. ATLASSERT(::IsWindow(m_hWnd));
  3649. return (int)::SendMessage(m_hWnd, TB_BUTTONCOUNT, 0, 0L);
  3650. }
  3651. BOOL GetItemRect(int nIndex, LPRECT lpRect) const
  3652. {
  3653. ATLASSERT(::IsWindow(m_hWnd));
  3654. return (BOOL)::SendMessage(m_hWnd, TB_GETITEMRECT, nIndex, (LPARAM)lpRect);
  3655. }
  3656. void SetButtonStructSize(int nSize = sizeof(TBBUTTON))
  3657. {
  3658. ATLASSERT(::IsWindow(m_hWnd));
  3659. ::SendMessage(m_hWnd, TB_BUTTONSTRUCTSIZE, nSize, 0L);
  3660. }
  3661. BOOL SetButtonSize(SIZE size)
  3662. {
  3663. ATLASSERT(::IsWindow(m_hWnd));
  3664. return (BOOL)::SendMessage(m_hWnd, TB_SETBUTTONSIZE, 0, MAKELPARAM(size.cx, size.cy));
  3665. }
  3666. BOOL SetButtonSize(int cx, int cy)
  3667. {
  3668. ATLASSERT(::IsWindow(m_hWnd));
  3669. return (BOOL)::SendMessage(m_hWnd, TB_SETBUTTONSIZE, 0, MAKELPARAM(cx, cy));
  3670. }
  3671. BOOL SetBitmapSize(SIZE size)
  3672. {
  3673. ATLASSERT(::IsWindow(m_hWnd));
  3674. return (BOOL)::SendMessage(m_hWnd, TB_SETBITMAPSIZE, 0, MAKELPARAM(size.cx, size.cy));
  3675. }
  3676. BOOL SetBitmapSize(int cx, int cy)
  3677. {
  3678. ATLASSERT(::IsWindow(m_hWnd));
  3679. return (BOOL)::SendMessage(m_hWnd, TB_SETBITMAPSIZE, 0, MAKELPARAM(cx, cy));
  3680. }
  3681. CToolTipCtrl GetToolTips() const
  3682. {
  3683. ATLASSERT(::IsWindow(m_hWnd));
  3684. return CToolTipCtrl((HWND)::SendMessage(m_hWnd, TB_GETTOOLTIPS, 0, 0L));
  3685. }
  3686. void SetToolTips(HWND hWndToolTip)
  3687. {
  3688. ATLASSERT(::IsWindow(m_hWnd));
  3689. ::SendMessage(m_hWnd, TB_SETTOOLTIPS, (WPARAM)hWndToolTip, 0L);
  3690. }
  3691. void SetNotifyWnd(HWND hWnd)
  3692. {
  3693. ATLASSERT(::IsWindow(m_hWnd));
  3694. ::SendMessage(m_hWnd, TB_SETPARENT, (WPARAM)hWnd, 0L);
  3695. }
  3696. int GetRows() const
  3697. {
  3698. ATLASSERT(::IsWindow(m_hWnd));
  3699. return (int)::SendMessage(m_hWnd, TB_GETROWS, 0, 0L);
  3700. }
  3701. void SetRows(int nRows, BOOL bLarger, LPRECT lpRect)
  3702. {
  3703. ATLASSERT(::IsWindow(m_hWnd));
  3704. ::SendMessage(m_hWnd, TB_SETROWS, MAKELPARAM(nRows, bLarger), (LPARAM)lpRect);
  3705. }
  3706. BOOL SetCmdID(int nIndex, UINT nID)
  3707. {
  3708. ATLASSERT(::IsWindow(m_hWnd));
  3709. return (BOOL)::SendMessage(m_hWnd, TB_SETCMDID, nIndex, nID);
  3710. }
  3711. DWORD GetBitmapFlags() const
  3712. {
  3713. ATLASSERT(::IsWindow(m_hWnd));
  3714. return (DWORD)::SendMessage(m_hWnd, TB_GETBITMAPFLAGS, 0, 0L);
  3715. }
  3716. int GetBitmap(int nID) const
  3717. {
  3718. ATLASSERT(::IsWindow(m_hWnd));
  3719. return (int)::SendMessage(m_hWnd, TB_GETBITMAP, nID, 0L);
  3720. }
  3721. int GetButtonText(int nID, LPTSTR lpstrText) const
  3722. {
  3723. ATLASSERT(::IsWindow(m_hWnd));
  3724. return (int)::SendMessage(m_hWnd, TB_GETBUTTONTEXT, nID, (LPARAM)lpstrText);
  3725. }
  3726. CImageList GetImageList() const
  3727. {
  3728. ATLASSERT(::IsWindow(m_hWnd));
  3729. return CImageList((HIMAGELIST)::SendMessage(m_hWnd, TB_GETIMAGELIST, 0, 0L));
  3730. }
  3731. CImageList SetImageList(HIMAGELIST hImageList)
  3732. {
  3733. ATLASSERT(::IsWindow(m_hWnd));
  3734. return CImageList((HIMAGELIST)::SendMessage(m_hWnd, TB_SETIMAGELIST, 0, (LPARAM)hImageList));
  3735. }
  3736. CImageList GetDisabledImageList() const
  3737. {
  3738. ATLASSERT(::IsWindow(m_hWnd));
  3739. return CImageList((HIMAGELIST)::SendMessage(m_hWnd, TB_GETDISABLEDIMAGELIST, 0, 0L));
  3740. }
  3741. CImageList SetDisabledImageList(HIMAGELIST hImageList)
  3742. {
  3743. ATLASSERT(::IsWindow(m_hWnd));
  3744. return CImageList((HIMAGELIST)::SendMessage(m_hWnd, TB_SETDISABLEDIMAGELIST, 0, (LPARAM)hImageList));
  3745. }
  3746. CImageList GetHotImageList() const
  3747. {
  3748. ATLASSERT(::IsWindow(m_hWnd));
  3749. return CImageList((HIMAGELIST)::SendMessage(m_hWnd, TB_GETHOTIMAGELIST, 0, 0L));
  3750. }
  3751. CImageList SetHotImageList(HIMAGELIST hImageList)
  3752. {
  3753. ATLASSERT(::IsWindow(m_hWnd));
  3754. return CImageList((HIMAGELIST)::SendMessage(m_hWnd, TB_SETHOTIMAGELIST, 0, (LPARAM)hImageList));
  3755. }
  3756. DWORD GetStyle() const
  3757. {
  3758. ATLASSERT(::IsWindow(m_hWnd));
  3759. return (DWORD)::SendMessage(m_hWnd, TB_GETSTYLE, 0, 0L);
  3760. }
  3761. void SetStyle(DWORD dwStyle)
  3762. {
  3763. ATLASSERT(::IsWindow(m_hWnd));
  3764. ::SendMessage(m_hWnd, TB_SETSTYLE, 0, dwStyle);
  3765. }
  3766. DWORD GetButtonSize() const
  3767. {
  3768. ATLASSERT(::IsWindow(m_hWnd));
  3769. return (DWORD)::SendMessage(m_hWnd, TB_GETBUTTONSIZE, 0, 0L);
  3770. }
  3771. void GetButtonSize(SIZE& size) const
  3772. {
  3773. ATLASSERT(::IsWindow(m_hWnd));
  3774. DWORD dwRet = (DWORD)::SendMessage(m_hWnd, TB_GETBUTTONSIZE, 0, 0L);
  3775. size.cx = LOWORD(dwRet);
  3776. size.cy = HIWORD(dwRet);
  3777. }
  3778. BOOL GetRect(int nID, LPRECT lpRect) const
  3779. {
  3780. ATLASSERT(::IsWindow(m_hWnd));
  3781. return (BOOL)::SendMessage(m_hWnd, TB_GETRECT, nID, (LPARAM)lpRect);
  3782. }
  3783. int GetTextRows() const
  3784. {
  3785. ATLASSERT(::IsWindow(m_hWnd));
  3786. return (int)::SendMessage(m_hWnd, TB_GETTEXTROWS, 0, 0L);
  3787. }
  3788. BOOL SetButtonWidth(int cxMin, int cxMax)
  3789. {
  3790. ATLASSERT(::IsWindow(m_hWnd));
  3791. return (BOOL)::SendMessage(m_hWnd, TB_SETBUTTONWIDTH, 0, MAKELPARAM(cxMin, cxMax));
  3792. }
  3793. BOOL SetIndent(int nIndent)
  3794. {
  3795. ATLASSERT(::IsWindow(m_hWnd));
  3796. return (BOOL)::SendMessage(m_hWnd, TB_SETINDENT, nIndent, 0L);
  3797. }
  3798. BOOL SetMaxTextRows(int nMaxTextRows)
  3799. {
  3800. ATLASSERT(::IsWindow(m_hWnd));
  3801. return (BOOL)::SendMessage(m_hWnd, TB_SETMAXTEXTROWS, nMaxTextRows, 0L);
  3802. }
  3803. #if (_WIN32_IE >= 0x0400)
  3804. BOOL GetAnchorHighlight() const
  3805. {
  3806. ATLASSERT(::IsWindow(m_hWnd));
  3807. return (BOOL)::SendMessage(m_hWnd, TB_GETANCHORHIGHLIGHT, 0, 0L);
  3808. }
  3809. BOOL SetAnchorHighlight(BOOL bEnable = TRUE)
  3810. {
  3811. ATLASSERT(::IsWindow(m_hWnd));
  3812. return (BOOL)::SendMessage(m_hWnd, TB_SETANCHORHIGHLIGHT, bEnable, 0L);
  3813. }
  3814. int GetButtonInfo(int nID, LPTBBUTTONINFO lptbbi) const
  3815. {
  3816. ATLASSERT(::IsWindow(m_hWnd));
  3817. return (int)::SendMessage(m_hWnd, TB_GETBUTTONINFO, nID, (LPARAM)lptbbi);
  3818. }
  3819. BOOL SetButtonInfo(int nID, LPTBBUTTONINFO lptbbi)
  3820. {
  3821. ATLASSERT(::IsWindow(m_hWnd));
  3822. return (BOOL)::SendMessage(m_hWnd, TB_SETBUTTONINFO, nID, (LPARAM)lptbbi);
  3823. }
  3824. int GetHotItem() const
  3825. {
  3826. ATLASSERT(::IsWindow(m_hWnd));
  3827. return (int)::SendMessage(m_hWnd, TB_GETHOTITEM, 0, 0L);
  3828. }
  3829. int SetHotItem(int nItem)
  3830. {
  3831. ATLASSERT(::IsWindow(m_hWnd));
  3832. return (int)::SendMessage(m_hWnd, TB_SETHOTITEM, nItem, 0L);
  3833. }
  3834. BOOL IsButtonHighlighted(int nButtonID) const
  3835. {
  3836. ATLASSERT(::IsWindow(m_hWnd));
  3837. return (BOOL)::SendMessage(m_hWnd, TB_ISBUTTONHIGHLIGHTED, nButtonID, 0L);
  3838. }
  3839. DWORD SetDrawTextFlags(DWORD dwMask, DWORD dwFlags)
  3840. {
  3841. ATLASSERT(::IsWindow(m_hWnd));
  3842. return (DWORD)::SendMessage(m_hWnd, TB_SETDRAWTEXTFLAGS, dwMask, dwFlags);
  3843. }
  3844. BOOL GetColorScheme(LPCOLORSCHEME lpcs) const
  3845. {
  3846. ATLASSERT(::IsWindow(m_hWnd));
  3847. return (BOOL)::SendMessage(m_hWnd, TB_GETCOLORSCHEME, 0, (LPARAM)lpcs);
  3848. }
  3849. void SetColorScheme(LPCOLORSCHEME lpcs)
  3850. {
  3851. ATLASSERT(::IsWindow(m_hWnd));
  3852. ::SendMessage(m_hWnd, TB_SETCOLORSCHEME, 0, (LPARAM)lpcs);
  3853. }
  3854. DWORD GetExtendedStyle() const
  3855. {
  3856. ATLASSERT(::IsWindow(m_hWnd));
  3857. return (DWORD)::SendMessage(m_hWnd, TB_GETEXTENDEDSTYLE, 0, 0L);
  3858. }
  3859. DWORD SetExtendedStyle(DWORD dwStyle)
  3860. {
  3861. ATLASSERT(::IsWindow(m_hWnd));
  3862. return (DWORD)::SendMessage(m_hWnd, TB_SETEXTENDEDSTYLE, 0, dwStyle);
  3863. }
  3864. void GetInsertMark(LPTBINSERTMARK lptbim) const
  3865. {
  3866. ATLASSERT(::IsWindow(m_hWnd));
  3867. ::SendMessage(m_hWnd, TB_GETINSERTMARK, 0, (LPARAM)lptbim);
  3868. }
  3869. void SetInsertMark(LPTBINSERTMARK lptbim)
  3870. {
  3871. ATLASSERT(::IsWindow(m_hWnd));
  3872. ::SendMessage(m_hWnd, TB_SETINSERTMARK, 0, (LPARAM)lptbim);
  3873. }
  3874. COLORREF GetInsertMarkColor() const
  3875. {
  3876. ATLASSERT(::IsWindow(m_hWnd));
  3877. return (COLORREF)::SendMessage(m_hWnd, TB_GETINSERTMARKCOLOR, 0, 0L);
  3878. }
  3879. COLORREF SetInsertMarkColor(COLORREF clr)
  3880. {
  3881. ATLASSERT(::IsWindow(m_hWnd));
  3882. return (COLORREF)::SendMessage(m_hWnd, TB_SETINSERTMARKCOLOR, 0, (LPARAM)clr);
  3883. }
  3884. BOOL GetMaxSize(LPSIZE lpSize) const
  3885. {
  3886. ATLASSERT(::IsWindow(m_hWnd));
  3887. return (BOOL)::SendMessage(m_hWnd, TB_GETMAXSIZE, 0, (LPARAM)lpSize);
  3888. }
  3889. void GetPadding(LPSIZE lpSizePadding) const
  3890. {
  3891. ATLASSERT(::IsWindow(m_hWnd));
  3892. ATLASSERT(lpSizePadding != NULL);
  3893. DWORD dwRet = (DWORD)::SendMessage(m_hWnd, TB_GETPADDING, 0, 0L);
  3894. lpSizePadding->cx = GET_X_LPARAM(dwRet);
  3895. lpSizePadding->cy = GET_Y_LPARAM(dwRet);
  3896. }
  3897. void SetPadding(int cx, int cy, LPSIZE lpSizePadding = NULL)
  3898. {
  3899. ATLASSERT(::IsWindow(m_hWnd));
  3900. DWORD dwRet = (DWORD)::SendMessage(m_hWnd, TB_SETPADDING, 0, MAKELPARAM(cx, cy));
  3901. if(lpSizePadding != NULL)
  3902. {
  3903. lpSizePadding->cx = GET_X_LPARAM(dwRet);
  3904. lpSizePadding->cy = GET_Y_LPARAM(dwRet);
  3905. }
  3906. }
  3907. BOOL GetUnicodeFormat() const
  3908. {
  3909. ATLASSERT(::IsWindow(m_hWnd));
  3910. return (BOOL)::SendMessage(m_hWnd, TB_GETUNICODEFORMAT, 0, 0L);
  3911. }
  3912. BOOL SetUnicodeFormat(BOOL bUnicode = TRUE)
  3913. {
  3914. ATLASSERT(::IsWindow(m_hWnd));
  3915. return (BOOL)::SendMessage(m_hWnd, TB_SETUNICODEFORMAT, bUnicode, 0L);
  3916. }
  3917. #endif //(_WIN32_IE >= 0x0400)
  3918. #if (_WIN32_IE >= 0x0500)
  3919. int GetString(int nString, LPTSTR lpstrString, int cchMaxLen) const
  3920. {
  3921. ATLASSERT(::IsWindow(m_hWnd));
  3922. return (int)::SendMessage(m_hWnd, TB_GETSTRING, MAKEWPARAM(cchMaxLen, nString), (LPARAM)lpstrString);
  3923. }
  3924. int GetStringBSTR(int nString, BSTR& bstrString) const
  3925. {
  3926. USES_CONVERSION;
  3927. ATLASSERT(::IsWindow(m_hWnd));
  3928. ATLASSERT(bstrString == NULL);
  3929. int nLength = (int)(short)LOWORD(::SendMessage(m_hWnd, TB_GETSTRING, MAKEWPARAM(0, nString), NULL));
  3930. if(nLength != -1)
  3931. {
  3932. LPTSTR lpszString = (LPTSTR)_alloca((nLength + 1) * sizeof(TCHAR));
  3933. nLength = (int)::SendMessage(m_hWnd, TB_GETSTRING, MAKEWPARAM(nLength + 1, nString), (LPARAM)lpszString);
  3934. if(nLength != -1)
  3935. bstrString = ::SysAllocString(T2OLE(lpszString));
  3936. }
  3937. return nLength;
  3938. }
  3939. #ifdef __ATLSTR_H__
  3940. int GetString(int nString, CString& str) const
  3941. {
  3942. ATLASSERT(::IsWindow(m_hWnd));
  3943. int nLength = (int)(short)LOWORD(::SendMessage(m_hWnd, TB_GETSTRING, MAKEWPARAM(0, nString), NULL));
  3944. if(nLength != -1)
  3945. {
  3946. nLength = (int)::SendMessage(m_hWnd, TB_GETSTRING, MAKEWPARAM(nLength + 1, nString), (LPARAM)str.GetBufferSetLength(nLength+1));
  3947. str.ReleaseBuffer();
  3948. }
  3949. return nLength;
  3950. }
  3951. #endif //__ATLSTR_H__
  3952. #endif //(_WIN32_IE >= 0x0500)
  3953. // Operations
  3954. BOOL EnableButton(int nID, BOOL bEnable = TRUE)
  3955. {
  3956. ATLASSERT(::IsWindow(m_hWnd));
  3957. return (BOOL)::SendMessage(m_hWnd, TB_ENABLEBUTTON, nID, MAKELPARAM(bEnable, 0));
  3958. }
  3959. BOOL CheckButton(int nID, BOOL bCheck = TRUE)
  3960. {
  3961. ATLASSERT(::IsWindow(m_hWnd));
  3962. return (BOOL)::SendMessage(m_hWnd, TB_CHECKBUTTON, nID, MAKELPARAM(bCheck, 0));
  3963. }
  3964. BOOL PressButton(int nID, BOOL bPress = TRUE)
  3965. {
  3966. ATLASSERT(::IsWindow(m_hWnd));
  3967. return (BOOL)::SendMessage(m_hWnd, TB_PRESSBUTTON, nID, MAKELPARAM(bPress, 0));
  3968. }
  3969. BOOL HideButton(int nID, BOOL bHide = TRUE)
  3970. {
  3971. ATLASSERT(::IsWindow(m_hWnd));
  3972. return (BOOL)::SendMessage(m_hWnd, TB_HIDEBUTTON, nID, MAKELPARAM(bHide, 0));
  3973. }
  3974. BOOL Indeterminate(int nID, BOOL bIndeterminate = TRUE)
  3975. {
  3976. ATLASSERT(::IsWindow(m_hWnd));
  3977. return (BOOL)::SendMessage(m_hWnd, TB_INDETERMINATE, nID, MAKELPARAM(bIndeterminate, 0));
  3978. }
  3979. int AddBitmap(int nNumButtons, UINT nBitmapID)
  3980. {
  3981. ATLASSERT(::IsWindow(m_hWnd));
  3982. TBADDBITMAP tbab;
  3983. tbab.hInst = _Module.GetResourceInstance();
  3984. ATLASSERT(tbab.hInst != NULL);
  3985. tbab.nID = nBitmapID;
  3986. return (int)::SendMessage(m_hWnd, TB_ADDBITMAP, (WPARAM)nNumButtons, (LPARAM)&tbab);
  3987. }
  3988. int AddBitmap(int nNumButtons, HBITMAP hBitmap)
  3989. {
  3990. ATLASSERT(::IsWindow(m_hWnd));
  3991. TBADDBITMAP tbab;
  3992. tbab.hInst = NULL;
  3993. tbab.nID = (UINT_PTR)hBitmap;
  3994. return (int)::SendMessage(m_hWnd, TB_ADDBITMAP, (WPARAM)nNumButtons, (LPARAM)&tbab);
  3995. }
  3996. BOOL AddButtons(int nNumButtons, LPTBBUTTON lpButtons)
  3997. {
  3998. ATLASSERT(::IsWindow(m_hWnd));
  3999. return (BOOL)::SendMessage(m_hWnd, TB_ADDBUTTONS, nNumButtons, (LPARAM)lpButtons);
  4000. }
  4001. BOOL InsertButton(int nIndex, LPTBBUTTON lpButton)
  4002. {
  4003. ATLASSERT(::IsWindow(m_hWnd));
  4004. return (BOOL)::SendMessage(m_hWnd, TB_INSERTBUTTON, nIndex, (LPARAM)lpButton);
  4005. }
  4006. BOOL DeleteButton(int nIndex)
  4007. {
  4008. ATLASSERT(::IsWindow(m_hWnd));
  4009. return (BOOL)::SendMessage(m_hWnd, TB_DELETEBUTTON, nIndex, 0L);
  4010. }
  4011. UINT CommandToIndex(UINT nID) const
  4012. {
  4013. ATLASSERT(::IsWindow(m_hWnd));
  4014. return (UINT)::SendMessage(m_hWnd, TB_COMMANDTOINDEX, nID, 0L);
  4015. }
  4016. void SaveState(HKEY hKeyRoot, LPCTSTR lpszSubKey, LPCTSTR lpszValueName)
  4017. {
  4018. ATLASSERT(::IsWindow(m_hWnd));
  4019. TBSAVEPARAMS tbs;
  4020. tbs.hkr = hKeyRoot;
  4021. tbs.pszSubKey = lpszSubKey;
  4022. tbs.pszValueName = lpszValueName;
  4023. ::SendMessage(m_hWnd, TB_SAVERESTORE, (WPARAM)TRUE, (LPARAM)&tbs);
  4024. }
  4025. void RestoreState(HKEY hKeyRoot, LPCTSTR lpszSubKey, LPCTSTR lpszValueName)
  4026. {
  4027. ATLASSERT(::IsWindow(m_hWnd));
  4028. TBSAVEPARAMS tbs;
  4029. tbs.hkr = hKeyRoot;
  4030. tbs.pszSubKey = lpszSubKey;
  4031. tbs.pszValueName = lpszValueName;
  4032. ::SendMessage(m_hWnd, TB_SAVERESTORE, (WPARAM)FALSE, (LPARAM)&tbs);
  4033. }
  4034. void Customize()
  4035. {
  4036. ATLASSERT(::IsWindow(m_hWnd));
  4037. ::SendMessage(m_hWnd, TB_CUSTOMIZE, 0, 0L);
  4038. }
  4039. int AddString(UINT nStringID)
  4040. {
  4041. ATLASSERT(::IsWindow(m_hWnd));
  4042. return (int)::SendMessage(m_hWnd, TB_ADDSTRING, (WPARAM)_Module.GetResourceInstance(), (LPARAM)nStringID);
  4043. }
  4044. int AddStrings(LPCTSTR lpszStrings)
  4045. {
  4046. ATLASSERT(::IsWindow(m_hWnd));
  4047. return (int)::SendMessage(m_hWnd, TB_ADDSTRING, 0, (LPARAM)lpszStrings);
  4048. }
  4049. void AutoSize()
  4050. {
  4051. ATLASSERT(::IsWindow(m_hWnd));
  4052. ::SendMessage(m_hWnd, TB_AUTOSIZE, 0, 0L);
  4053. }
  4054. BOOL ChangeBitmap(int nID, int nBitmap)
  4055. {
  4056. ATLASSERT(::IsWindow(m_hWnd));
  4057. return (BOOL)::SendMessage(m_hWnd, TB_CHANGEBITMAP, nID, MAKELPARAM(nBitmap, 0));
  4058. }
  4059. int LoadImages(int nBitmapID)
  4060. {
  4061. ATLASSERT(::IsWindow(m_hWnd));
  4062. return (int)::SendMessage(m_hWnd, TB_LOADIMAGES, nBitmapID, (LPARAM)_Module.GetResourceInstance());
  4063. }
  4064. int LoadStdImages(int nBitmapID)
  4065. {
  4066. ATLASSERT(::IsWindow(m_hWnd));
  4067. return (int)::SendMessage(m_hWnd, TB_LOADIMAGES, nBitmapID, (LPARAM)HINST_COMMCTRL);
  4068. }
  4069. BOOL ReplaceBitmap(LPTBREPLACEBITMAP ptbrb)
  4070. {
  4071. ATLASSERT(::IsWindow(m_hWnd));
  4072. return (BOOL)::SendMessage(m_hWnd, TB_REPLACEBITMAP, 0, (LPARAM)ptbrb);
  4073. }
  4074. #if (_WIN32_IE >= 0x0400)
  4075. int HitTest(LPPOINT lpPoint)
  4076. {
  4077. ATLASSERT(::IsWindow(m_hWnd));
  4078. return (int)::SendMessage(m_hWnd, TB_HITTEST, 0, (LPARAM)lpPoint);
  4079. }
  4080. BOOL InsertMarkHitTest(LPPOINT lpPoint, LPTBINSERTMARK lptbim)
  4081. {
  4082. ATLASSERT(::IsWindow(m_hWnd));
  4083. return (BOOL)::SendMessage(m_hWnd, TB_INSERTMARKHITTEST, (WPARAM)lpPoint, (LPARAM)lptbim);
  4084. }
  4085. BOOL InsertMarkHitTest(int x, int y, LPTBINSERTMARK lptbim)
  4086. {
  4087. ATLASSERT(::IsWindow(m_hWnd));
  4088. POINT pt = { x, y };
  4089. return (BOOL)::SendMessage(m_hWnd, TB_INSERTMARKHITTEST, (WPARAM)&pt, (LPARAM)lptbim);
  4090. }
  4091. BOOL MapAccelerator(TCHAR chAccel, int& nID) const
  4092. {
  4093. ATLASSERT(::IsWindow(m_hWnd));
  4094. return (BOOL)::SendMessage(m_hWnd, TB_MAPACCELERATOR, (WPARAM)chAccel, (LPARAM)&nID);
  4095. }
  4096. BOOL MarkButton(int nID, BOOL bHighlight = TRUE)
  4097. {
  4098. ATLASSERT(::IsWindow(m_hWnd));
  4099. return (BOOL)::SendMessage(m_hWnd, TB_MARKBUTTON, nID, MAKELPARAM(bHighlight, 0));
  4100. }
  4101. BOOL MoveButton(int nOldPos, int nNewPos)
  4102. {
  4103. ATLASSERT(::IsWindow(m_hWnd));
  4104. return (BOOL)::SendMessage(m_hWnd, TB_MOVEBUTTON, nOldPos, nNewPos);
  4105. }
  4106. HRESULT GetObject(REFIID iid, LPVOID* ppvObject)
  4107. {
  4108. ATLASSERT(::IsWindow(m_hWnd));
  4109. return (HRESULT)::SendMessage(m_hWnd, TB_GETOBJECT, (WPARAM)&iid, (LPARAM)ppvObject);
  4110. }
  4111. #endif //(_WIN32_IE >= 0x0400)
  4112. };
  4113. typedef CToolBarCtrlT<CWindow> CToolBarCtrl;
  4114. /////////////////////////////////////////////////////////////////////////////
  4115. // CStatusBarCtrl
  4116. template <class TBase>
  4117. class CStatusBarCtrlT : public TBase
  4118. {
  4119. public:
  4120. // Constructors
  4121. CStatusBarCtrlT(HWND hWnd = NULL) : TBase(hWnd) { }
  4122. CStatusBarCtrlT< TBase >& operator=(HWND hWnd)
  4123. {
  4124. m_hWnd = hWnd;
  4125. return *this;
  4126. }
  4127. HWND Create(HWND hWndParent, _U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
  4128. DWORD dwStyle = 0, DWORD dwExStyle = 0,
  4129. _U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
  4130. {
  4131. return CWindow::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
  4132. }
  4133. // Methods
  4134. static LPCTSTR GetWndClassName()
  4135. {
  4136. return STATUSCLASSNAME;
  4137. }
  4138. int GetParts(int nParts, int* pParts) const
  4139. {
  4140. ATLASSERT(::IsWindow(m_hWnd));
  4141. return (int)::SendMessage(m_hWnd, SB_GETPARTS, nParts, (LPARAM)pParts);
  4142. }
  4143. BOOL SetParts(int nParts, int* pWidths)
  4144. {
  4145. ATLASSERT(::IsWindow(m_hWnd));
  4146. return (BOOL)::SendMessage(m_hWnd, SB_SETPARTS, nParts, (LPARAM)pWidths);
  4147. }
  4148. int GetTextLength(int nPane, int* pType = NULL) const
  4149. {
  4150. ATLASSERT(::IsWindow(m_hWnd));
  4151. ATLASSERT(nPane < 256);
  4152. DWORD dwRet = (DWORD)::SendMessage(m_hWnd, SB_GETTEXTLENGTH, (WPARAM)nPane, 0L);
  4153. if (pType != NULL)
  4154. *pType = (int)(short)HIWORD(dwRet);
  4155. return (int)(short)LOWORD(dwRet);
  4156. }
  4157. int GetText(int nPane, LPTSTR lpszText, int* pType = NULL) const
  4158. {
  4159. ATLASSERT(::IsWindow(m_hWnd));
  4160. ATLASSERT(nPane < 256);
  4161. DWORD dwRet = (DWORD)::SendMessage(m_hWnd, SB_GETTEXT, (WPARAM)nPane, (LPARAM)lpszText);
  4162. if(pType != NULL)
  4163. *pType = (int)(short)HIWORD(dwRet);
  4164. return (int)(short)LOWORD(dwRet);
  4165. }
  4166. #ifndef _ATL_NO_COM
  4167. BOOL GetTextBSTR(int nPane, BSTR& bstrText, int* pType = NULL) const
  4168. {
  4169. USES_CONVERSION;
  4170. ATLASSERT(::IsWindow(m_hWnd));
  4171. ATLASSERT(nPane < 256);
  4172. ATLASSERT(bstrText == NULL);
  4173. int nLength = (int)(short)LOWORD(::SendMessage(m_hWnd, SB_GETTEXTLENGTH, (WPARAM)nPane, 0L));
  4174. if(nLength == 0)
  4175. return FALSE;
  4176. LPTSTR lpszText = (LPTSTR)_alloca((nLength + 1) * sizeof(TCHAR));
  4177. if(!GetText(nPane, lpszText, pType))
  4178. return FALSE;
  4179. bstrText = ::SysAllocString(T2OLE(lpszText));
  4180. return (bstrText != NULL) ? TRUE : FALSE;
  4181. }
  4182. #endif //!_ATL_NO_COM
  4183. #ifdef __ATLSTR_H__
  4184. int GetText(int nPane, CString& strText, int* pType = NULL) const
  4185. {
  4186. ATLASSERT(::IsWindow(m_hWnd));
  4187. ATLASSERT(nPane < 256);
  4188. int nLength = (int)(short)LOWORD(::SendMessage(m_hWnd, SB_GETTEXTLENGTH, (WPARAM)nPane, 0L));
  4189. if(nLength == 0)
  4190. return 0;
  4191. return GetText(nPane, strText.GetBufferSetLength(nLength), pType);
  4192. }
  4193. #endif //__ATLSTR_H__
  4194. BOOL SetText(int nPane, LPCTSTR lpszText, int nType = 0)
  4195. {
  4196. ATLASSERT(::IsWindow(m_hWnd));
  4197. ATLASSERT(nPane < 256);
  4198. return (BOOL)::SendMessage(m_hWnd, SB_SETTEXT, (nPane | nType), (LPARAM)lpszText);
  4199. }
  4200. BOOL GetRect(int nPane, LPRECT lpRect) const
  4201. {
  4202. ATLASSERT(::IsWindow(m_hWnd));
  4203. ATLASSERT(nPane < 256);
  4204. return (BOOL)::SendMessage(m_hWnd, SB_GETRECT, nPane, (LPARAM)lpRect);
  4205. }
  4206. BOOL GetBorders(int* pBorders) const
  4207. {
  4208. ATLASSERT(::IsWindow(m_hWnd));
  4209. return (BOOL)::SendMessage(m_hWnd, SB_GETBORDERS, 0, (LPARAM)pBorders);
  4210. }
  4211. BOOL GetBorders(int& nHorz, int& nVert, int& nSpacing) const
  4212. {
  4213. ATLASSERT(::IsWindow(m_hWnd));
  4214. int borders[3];
  4215. BOOL bResult = (BOOL)::SendMessage(m_hWnd, SB_GETBORDERS, 0, (LPARAM)&borders);
  4216. if(bResult)
  4217. {
  4218. nHorz = borders[0];
  4219. nVert = borders[1];
  4220. nSpacing = borders[2];
  4221. }
  4222. return bResult;
  4223. }
  4224. void SetMinHeight(int nMin)
  4225. {
  4226. ATLASSERT(::IsWindow(m_hWnd));
  4227. ::SendMessage(m_hWnd, SB_SETMINHEIGHT, nMin, 0L);
  4228. }
  4229. BOOL SetSimple(BOOL bSimple = TRUE)
  4230. {
  4231. ATLASSERT(::IsWindow(m_hWnd));
  4232. return (BOOL)::SendMessage(m_hWnd, SB_SIMPLE, bSimple, 0L);
  4233. }
  4234. BOOL IsSimple() const
  4235. {
  4236. ATLASSERT(::IsWindow(m_hWnd));
  4237. return (BOOL)::SendMessage(m_hWnd, SB_ISSIMPLE, 0, 0L);
  4238. }
  4239. #if (_WIN32_IE >= 0x0400)
  4240. COLORREF SetBkColor(COLORREF clrBk)
  4241. {
  4242. ATLASSERT(::IsWindow(m_hWnd));
  4243. return (COLORREF)::SendMessage(m_hWnd, SB_SETBKCOLOR, 0, (LPARAM)clrBk);
  4244. }
  4245. BOOL GetUnicodeFormat() const
  4246. {
  4247. ATLASSERT(::IsWindow(m_hWnd));
  4248. return (BOOL)::SendMessage(m_hWnd, SB_GETUNICODEFORMAT, 0, 0L);
  4249. }
  4250. BOOL SetUnicodeFormat(BOOL bUnicode = TRUE)
  4251. {
  4252. ATLASSERT(::IsWindow(m_hWnd));
  4253. return (BOOL)::SendMessage(m_hWnd, SB_SETUNICODEFORMAT, bUnicode, 0L);
  4254. }
  4255. void GetTipText(int nPane, LPTSTR lpstrText, int nSize) const
  4256. {
  4257. ATLASSERT(::IsWindow(m_hWnd));
  4258. ATLASSERT(nPane < 256);
  4259. ::SendMessage(m_hWnd, SB_GETTIPTEXT, MAKEWPARAM(nPane, nSize), (LPARAM)lpstrText);
  4260. }
  4261. void SetTipText(int nPane, LPCTSTR lpstrText)
  4262. {
  4263. ATLASSERT(::IsWindow(m_hWnd));
  4264. ATLASSERT(nPane < 256);
  4265. ::SendMessage(m_hWnd, SB_SETTIPTEXT, nPane, (LPARAM)lpstrText);
  4266. }
  4267. HICON GetIcon(int nPane) const
  4268. {
  4269. ATLASSERT(::IsWindow(m_hWnd));
  4270. ATLASSERT(nPane < 256);
  4271. return (HICON)::SendMessage(m_hWnd, SB_GETICON, nPane, 0L);
  4272. }
  4273. BOOL SetIcon(int nPane, HICON hIcon)
  4274. {
  4275. ATLASSERT(::IsWindow(m_hWnd));
  4276. ATLASSERT(nPane < 256);
  4277. return (BOOL)::SendMessage(m_hWnd, SB_SETICON, nPane, (LPARAM)hIcon);
  4278. }
  4279. #endif //(_WIN32_IE >= 0x0400)
  4280. };
  4281. typedef CStatusBarCtrlT<CWindow> CStatusBarCtrl;
  4282. /////////////////////////////////////////////////////////////////////////////
  4283. // CTabCtrl
  4284. template <class TBase>
  4285. class CTabCtrlT : public TBase
  4286. {
  4287. public:
  4288. // Constructors
  4289. CTabCtrlT(HWND hWnd = NULL) : TBase(hWnd) { }
  4290. CTabCtrlT< TBase >& operator=(HWND hWnd)
  4291. {
  4292. m_hWnd = hWnd;
  4293. return *this;
  4294. }
  4295. HWND Create(HWND hWndParent, _U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
  4296. DWORD dwStyle = 0, DWORD dwExStyle = 0,
  4297. _U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
  4298. {
  4299. return CWindow::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
  4300. }
  4301. // Attributes
  4302. static LPCTSTR GetWndClassName()
  4303. {
  4304. return WC_TABCONTROL;
  4305. }
  4306. CImageList GetImageList() const
  4307. {
  4308. ATLASSERT(::IsWindow(m_hWnd));
  4309. return CImageList((HIMAGELIST)::SendMessage(m_hWnd, TCM_GETIMAGELIST, 0, 0L));
  4310. }
  4311. CImageList SetImageList(HIMAGELIST hImageList)
  4312. {
  4313. ATLASSERT(::IsWindow(m_hWnd));
  4314. return CImageList((HIMAGELIST)::SendMessage(m_hWnd, TCM_SETIMAGELIST, 0, (LPARAM)hImageList));
  4315. }
  4316. int GetItemCount() const
  4317. {
  4318. ATLASSERT(::IsWindow(m_hWnd));
  4319. return (int)::SendMessage(m_hWnd, TCM_GETITEMCOUNT, 0, 0L);
  4320. }
  4321. BOOL GetItem(int nItem, LPTCITEM pTabCtrlItem) const
  4322. {
  4323. ATLASSERT(::IsWindow(m_hWnd));
  4324. return (BOOL)::SendMessage(m_hWnd, TCM_GETITEM, nItem, (LPARAM)pTabCtrlItem);
  4325. }
  4326. BOOL SetItem(int nItem, LPTCITEM pTabCtrlItem)
  4327. {
  4328. ATLASSERT(::IsWindow(m_hWnd));
  4329. return (BOOL)::SendMessage(m_hWnd, TCM_SETITEM, nItem, (LPARAM)pTabCtrlItem);
  4330. }
  4331. BOOL GetItemRect(int nItem, LPRECT lpRect) const
  4332. {
  4333. ATLASSERT(::IsWindow(m_hWnd));
  4334. return (BOOL)::SendMessage(m_hWnd, TCM_GETITEMRECT, nItem, (LPARAM)lpRect);
  4335. }
  4336. int GetCurSel() const
  4337. {
  4338. ATLASSERT(::IsWindow(m_hWnd));
  4339. return (int)::SendMessage(m_hWnd, TCM_GETCURSEL, 0, 0L);
  4340. }
  4341. int SetCurSel(int nItem)
  4342. {
  4343. ATLASSERT(::IsWindow(m_hWnd));
  4344. return (int)::SendMessage(m_hWnd, TCM_SETCURSEL, nItem, 0L);
  4345. }
  4346. SIZE SetItemSize(SIZE size)
  4347. {
  4348. ATLASSERT(::IsWindow(m_hWnd));
  4349. DWORD dwSize = (DWORD)::SendMessage(m_hWnd, TCM_SETITEMSIZE, 0, MAKELPARAM(size.cx, size.cy));
  4350. SIZE sizeRet = { GET_X_LPARAM(dwSize), GET_Y_LPARAM(dwSize) };
  4351. return sizeRet;
  4352. }
  4353. void SetPadding(SIZE size)
  4354. {
  4355. ATLASSERT(::IsWindow(m_hWnd));
  4356. ::SendMessage(m_hWnd, TCM_SETPADDING, 0, MAKELPARAM(size.cx, size.cy));
  4357. }
  4358. int GetRowCount() const
  4359. {
  4360. ATLASSERT(::IsWindow(m_hWnd));
  4361. return (int)::SendMessage(m_hWnd, TCM_GETROWCOUNT, 0, 0L);
  4362. }
  4363. CToolTipCtrl GetTooltips() const
  4364. {
  4365. ATLASSERT(::IsWindow(m_hWnd));
  4366. return CToolTipCtrl((HWND)::SendMessage(m_hWnd, TCM_GETTOOLTIPS, 0, 0L));
  4367. }
  4368. void SetTooltips(HWND hWndToolTip)
  4369. {
  4370. ATLASSERT(::IsWindow(m_hWnd));
  4371. ::SendMessage(m_hWnd, TCM_SETTOOLTIPS, (WPARAM)hWndToolTip, 0L);
  4372. }
  4373. int GetCurFocus() const
  4374. {
  4375. ATLASSERT(::IsWindow(m_hWnd));
  4376. return (int)::SendMessage(m_hWnd, TCM_GETCURFOCUS, 0, 0L);
  4377. }
  4378. void SetCurFocus(int nItem)
  4379. {
  4380. ATLASSERT(::IsWindow(m_hWnd));
  4381. ::SendMessage(m_hWnd, TCM_SETCURFOCUS, nItem, 0L);
  4382. }
  4383. BOOL SetItemExtra(int cbExtra)
  4384. {
  4385. ATLASSERT(::IsWindow(m_hWnd));
  4386. ATLASSERT(GetItemCount() == 0); // must be empty
  4387. return (BOOL)::SendMessage(m_hWnd, TCM_SETITEMEXTRA, cbExtra, 0L);
  4388. }
  4389. int SetMinTabWidth(int nWidth = -1)
  4390. {
  4391. ATLASSERT(::IsWindow(m_hWnd));
  4392. return (int)::SendMessage(m_hWnd, TCM_SETMINTABWIDTH, 0, nWidth);
  4393. }
  4394. #if (_WIN32_IE >= 0x0400)
  4395. DWORD GetExtendedStyle() const
  4396. {
  4397. ATLASSERT(::IsWindow(m_hWnd));
  4398. return (DWORD)::SendMessage(m_hWnd, TCM_GETEXTENDEDSTYLE, 0, 0L);
  4399. }
  4400. DWORD SetExtendedStyle(DWORD dwExMask, DWORD dwExStyle)
  4401. {
  4402. ATLASSERT(::IsWindow(m_hWnd));
  4403. return (DWORD)::SendMessage(m_hWnd, TCM_SETEXTENDEDSTYLE, dwExMask, dwExStyle);
  4404. }
  4405. BOOL GetUnicodeFormat() const
  4406. {
  4407. ATLASSERT(::IsWindow(m_hWnd));
  4408. return (BOOL)::SendMessage(m_hWnd, TCM_GETUNICODEFORMAT, 0, 0L);
  4409. }
  4410. BOOL SetUnicodeFormat(BOOL bUnicode = TRUE)
  4411. {
  4412. ATLASSERT(::IsWindow(m_hWnd));
  4413. return (BOOL)::SendMessage(m_hWnd, TCM_SETUNICODEFORMAT, bUnicode, 0L);
  4414. }
  4415. #endif //(_WIN32_IE >= 0x0400)
  4416. // Operations
  4417. BOOL InsertItem(int nItem, LPTCITEM pTabCtrlItem)
  4418. {
  4419. ATLASSERT(::IsWindow(m_hWnd));
  4420. return (BOOL)::SendMessage(m_hWnd, TCM_INSERTITEM, nItem, (LPARAM)pTabCtrlItem);
  4421. }
  4422. BOOL DeleteItem(int nItem)
  4423. {
  4424. ATLASSERT(::IsWindow(m_hWnd));
  4425. return (BOOL)::SendMessage(m_hWnd, TCM_DELETEITEM, nItem, 0L);
  4426. }
  4427. BOOL DeleteAllItems()
  4428. {
  4429. ATLASSERT(::IsWindow(m_hWnd));
  4430. return (BOOL)::SendMessage(m_hWnd, TCM_DELETEALLITEMS, 0, 0L);
  4431. }
  4432. void AdjustRect(BOOL bLarger, LPRECT lpRect)
  4433. {
  4434. ATLASSERT(::IsWindow(m_hWnd));
  4435. ::SendMessage(m_hWnd, TCM_ADJUSTRECT, bLarger, (LPARAM)lpRect);
  4436. }
  4437. void RemoveImage(int nImage)
  4438. {
  4439. ATLASSERT(::IsWindow(m_hWnd));
  4440. ::SendMessage(m_hWnd, TCM_REMOVEIMAGE, nImage, 0L);
  4441. }
  4442. int HitTest(TC_HITTESTINFO* pHitTestInfo) const
  4443. {
  4444. ATLASSERT(::IsWindow(m_hWnd));
  4445. return (int)::SendMessage(m_hWnd, TCM_HITTEST, 0, (LPARAM)pHitTestInfo);
  4446. }
  4447. void DeselectAll(BOOL bExcludeFocus = TRUE)
  4448. {
  4449. ATLASSERT(::IsWindow(m_hWnd));
  4450. ::SendMessage(m_hWnd, TCM_DESELECTALL, bExcludeFocus, 0L);
  4451. }
  4452. #if (_WIN32_IE >= 0x0400)
  4453. BOOL HighlightItem(int nIndex, BOOL bHighlight = TRUE)
  4454. {
  4455. ATLASSERT(::IsWindow(m_hWnd));
  4456. return (BOOL)::SendMessage(m_hWnd, TCM_HIGHLIGHTITEM, nIndex, MAKELPARAM(bHighlight, 0));
  4457. }
  4458. #endif //(_WIN32_IE >= 0x0400)
  4459. };
  4460. typedef CTabCtrlT<CWindow> CTabCtrl;
  4461. /////////////////////////////////////////////////////////////////////////////
  4462. // CTrackBarCtrl
  4463. template <class TBase>
  4464. class CTrackBarCtrlT : public TBase
  4465. {
  4466. public:
  4467. // Constructors
  4468. CTrackBarCtrlT(HWND hWnd = NULL) : TBase(hWnd) { }
  4469. CTrackBarCtrlT< TBase >& operator=(HWND hWnd)
  4470. {
  4471. m_hWnd = hWnd;
  4472. return *this;
  4473. }
  4474. HWND Create(HWND hWndParent, _U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
  4475. DWORD dwStyle = 0, DWORD dwExStyle = 0,
  4476. _U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
  4477. {
  4478. return CWindow::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
  4479. }
  4480. // Attributes
  4481. static LPCTSTR GetWndClassName()
  4482. {
  4483. return TRACKBAR_CLASS;
  4484. }
  4485. int GetLineSize() const
  4486. {
  4487. ATLASSERT(::IsWindow(m_hWnd));
  4488. return (int)::SendMessage(m_hWnd, TBM_GETLINESIZE, 0, 0L);
  4489. }
  4490. int SetLineSize(int nSize)
  4491. {
  4492. ATLASSERT(::IsWindow(m_hWnd));
  4493. return (int)::SendMessage(m_hWnd, TBM_SETLINESIZE, 0, nSize);
  4494. }
  4495. int GetPageSize() const
  4496. {
  4497. ATLASSERT(::IsWindow(m_hWnd));
  4498. return (int)::SendMessage(m_hWnd, TBM_GETPAGESIZE, 0, 0L);
  4499. }
  4500. int SetPageSize(int nSize)
  4501. {
  4502. ATLASSERT(::IsWindow(m_hWnd));
  4503. return (int)::SendMessage(m_hWnd, TBM_SETPAGESIZE, 0, nSize);
  4504. }
  4505. int GetRangeMin() const
  4506. {
  4507. ATLASSERT(::IsWindow(m_hWnd));
  4508. return (int)::SendMessage(m_hWnd, TBM_GETRANGEMIN, 0, 0L);
  4509. }
  4510. void SetRangeMin(int nMin, BOOL bRedraw = FALSE)
  4511. {
  4512. ATLASSERT(::IsWindow(m_hWnd));
  4513. ::SendMessage(m_hWnd, TBM_SETRANGEMIN, bRedraw, nMin);
  4514. }
  4515. int GetRangeMax() const
  4516. {
  4517. ATLASSERT(::IsWindow(m_hWnd));
  4518. return (int)::SendMessage(m_hWnd, TBM_GETRANGEMAX, 0, 0L);
  4519. }
  4520. void SetRangeMax(int nMax, BOOL bRedraw = FALSE)
  4521. {
  4522. ATLASSERT(::IsWindow(m_hWnd));
  4523. ::SendMessage(m_hWnd, TBM_SETRANGEMAX, bRedraw, nMax);
  4524. }
  4525. void GetRange(int& nMin, int& nMax) const
  4526. {
  4527. nMin = GetRangeMin();
  4528. nMax = GetRangeMax();
  4529. }
  4530. void SetRange(int nMin, int nMax, BOOL bRedraw = TRUE)
  4531. {
  4532. ATLASSERT(::IsWindow(m_hWnd));
  4533. ::SendMessage(m_hWnd, TBM_SETRANGE, bRedraw, MAKELPARAM(nMin, nMax));
  4534. }
  4535. int GetSelStart() const
  4536. {
  4537. ATLASSERT(::IsWindow(m_hWnd));
  4538. return (int)::SendMessage(m_hWnd, TBM_GETSELSTART, 0, 0L);
  4539. }
  4540. void SetSelStart(int nMin)
  4541. {
  4542. ATLASSERT(::IsWindow(m_hWnd));
  4543. ::SendMessage(m_hWnd, TBM_SETSELSTART, 0, (LPARAM)nMin);
  4544. }
  4545. int GetSelEnd() const
  4546. {
  4547. ATLASSERT(::IsWindow(m_hWnd));
  4548. return (int)::SendMessage(m_hWnd, TBM_GETSELEND, 0, 0L);
  4549. }
  4550. void SetSelEnd(int nMax)
  4551. {
  4552. ATLASSERT(::IsWindow(m_hWnd));
  4553. ::SendMessage(m_hWnd, TBM_SETSELEND, 0, (LPARAM)nMax);
  4554. }
  4555. void GetSelection(int& nMin, int& nMax) const
  4556. {
  4557. nMin = GetSelStart();
  4558. nMax = GetSelEnd();
  4559. }
  4560. void SetSelection(int nMin, int nMax)
  4561. {
  4562. SetSelStart(nMin);
  4563. SetSelEnd(nMax);
  4564. }
  4565. void GetChannelRect(LPRECT lprc) const
  4566. {
  4567. ATLASSERT(::IsWindow(m_hWnd));
  4568. ::SendMessage(m_hWnd, TBM_GETCHANNELRECT, 0, (LPARAM)lprc);
  4569. }
  4570. void GetThumbRect(LPRECT lprc) const
  4571. {
  4572. ATLASSERT(::IsWindow(m_hWnd));
  4573. ::SendMessage(m_hWnd, TBM_GETTHUMBRECT, 0, (LPARAM)lprc);
  4574. }
  4575. int GetPos() const
  4576. {
  4577. ATLASSERT(::IsWindow(m_hWnd));
  4578. return (int)::SendMessage(m_hWnd, TBM_GETPOS, 0, 0L);
  4579. }
  4580. void SetPos(int nPos)
  4581. {
  4582. ATLASSERT(::IsWindow(m_hWnd));
  4583. ::SendMessage(m_hWnd, TBM_SETPOS, TRUE, nPos);
  4584. }
  4585. UINT GetNumTics() const
  4586. {
  4587. ATLASSERT(::IsWindow(m_hWnd));
  4588. return (UINT)::SendMessage(m_hWnd, TBM_GETNUMTICS, 0, 0L);
  4589. }
  4590. DWORD* GetTicArray() const
  4591. {
  4592. ATLASSERT(::IsWindow(m_hWnd));
  4593. return (DWORD*)::SendMessage(m_hWnd, TBM_GETPTICS, 0, 0L);
  4594. }
  4595. int GetTic(int nTic) const
  4596. {
  4597. ATLASSERT(::IsWindow(m_hWnd));
  4598. return (int)::SendMessage(m_hWnd, TBM_GETTIC, nTic, 0L);
  4599. }
  4600. BOOL SetTic(int nTic)
  4601. {
  4602. ATLASSERT(::IsWindow(m_hWnd));
  4603. return (BOOL)::SendMessage(m_hWnd, TBM_SETTIC, 0, nTic);
  4604. }
  4605. int GetTicPos(int nTic) const
  4606. {
  4607. ATLASSERT(::IsWindow(m_hWnd));
  4608. return (int)::SendMessage(m_hWnd, TBM_GETTICPOS, nTic, 0L);
  4609. }
  4610. void SetTicFreq(int nFreq)
  4611. {
  4612. ATLASSERT(::IsWindow(m_hWnd));
  4613. ::SendMessage(m_hWnd, TBM_SETTICFREQ, nFreq, 0L);
  4614. }
  4615. int GetThumbLength() const
  4616. {
  4617. ATLASSERT(::IsWindow(m_hWnd));
  4618. return (int)::SendMessage(m_hWnd, TBM_GETTHUMBLENGTH, 0, 0L);
  4619. }
  4620. void SetThumbLength(int nLength)
  4621. {
  4622. ATLASSERT(::IsWindow(m_hWnd));
  4623. ::SendMessage(m_hWnd, TBM_SETTHUMBLENGTH, nLength, 0L);
  4624. }
  4625. void SetSel(int nStart, int nEnd, BOOL bRedraw = TRUE)
  4626. {
  4627. ATLASSERT(::IsWindow(m_hWnd));
  4628. ATLASSERT((GetStyle() & TBS_ENABLESELRANGE) != 0);
  4629. ::SendMessage(m_hWnd, TBM_SETSEL, bRedraw, MAKELPARAM(nStart, nEnd));
  4630. }
  4631. CWindow GetBuddy(BOOL bLeft = TRUE) const
  4632. {
  4633. ATLASSERT(::IsWindow(m_hWnd));
  4634. return CWindow((HWND)::SendMessage(m_hWnd, TBM_GETBUDDY, bLeft, 0L));
  4635. }
  4636. CWindow SetBuddy(HWND hWndBuddy, BOOL bLeft = TRUE)
  4637. {
  4638. ATLASSERT(::IsWindow(m_hWnd));
  4639. return CWindow((HWND)::SendMessage(m_hWnd, TBM_SETBUDDY, bLeft, (LPARAM)hWndBuddy));
  4640. }
  4641. CToolTipCtrl GetToolTips() const
  4642. {
  4643. ATLASSERT(::IsWindow(m_hWnd));
  4644. return CToolTipCtrl((HWND)::SendMessage(m_hWnd, TBM_GETTOOLTIPS, 0, 0L));
  4645. }
  4646. void SetToolTips(HWND hWndTT)
  4647. {
  4648. ATLASSERT(::IsWindow(m_hWnd));
  4649. ::SendMessage(m_hWnd, TBM_SETTOOLTIPS, (WPARAM)hWndTT, 0L);
  4650. }
  4651. int SetTipSide(int nSide)
  4652. {
  4653. ATLASSERT(::IsWindow(m_hWnd));
  4654. return (int)::SendMessage(m_hWnd, TBM_SETTIPSIDE, nSide, 0L);
  4655. }
  4656. #if (_WIN32_IE >= 0x0400)
  4657. BOOL GetUnicodeFormat() const
  4658. {
  4659. ATLASSERT(::IsWindow(m_hWnd));
  4660. return (BOOL)::SendMessage(m_hWnd, TBM_GETUNICODEFORMAT, 0, 0L);
  4661. }
  4662. BOOL SetUnicodeFormat(BOOL bUnicode = TRUE)
  4663. {
  4664. ATLASSERT(::IsWindow(m_hWnd));
  4665. return (BOOL)::SendMessage(m_hWnd, TBM_SETUNICODEFORMAT, bUnicode, 0L);
  4666. }
  4667. #endif //(_WIN32_IE >= 0x0400)
  4668. // Operations
  4669. void ClearSel(BOOL bRedraw = FALSE)
  4670. {
  4671. ATLASSERT(::IsWindow(m_hWnd));
  4672. ::SendMessage(m_hWnd, TBM_CLEARSEL, bRedraw, 0L);
  4673. }
  4674. void VerifyPos()
  4675. {
  4676. ATLASSERT(::IsWindow(m_hWnd));
  4677. ::SendMessage(m_hWnd, TBM_SETPOS, FALSE, 0L);
  4678. }
  4679. void ClearTics(BOOL bRedraw = FALSE)
  4680. {
  4681. ATLASSERT(::IsWindow(m_hWnd));
  4682. ::SendMessage(m_hWnd, TBM_CLEARTICS, bRedraw, 0L);
  4683. }
  4684. };
  4685. typedef CTrackBarCtrlT<CWindow> CTrackBarCtrl;
  4686. /////////////////////////////////////////////////////////////////////////////
  4687. // CUpDownCtrl
  4688. template <class TBase>
  4689. class CUpDownCtrlT : public TBase
  4690. {
  4691. public:
  4692. // Constructors
  4693. CUpDownCtrlT(HWND hWnd = NULL) : TBase(hWnd) { }
  4694. CUpDownCtrlT< TBase >& operator=(HWND hWnd)
  4695. {
  4696. m_hWnd = hWnd;
  4697. return *this;
  4698. }
  4699. HWND Create(HWND hWndParent, _U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
  4700. DWORD dwStyle = 0, DWORD dwExStyle = 0,
  4701. _U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
  4702. {
  4703. return CWindow::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
  4704. }
  4705. // Attributes
  4706. static LPCTSTR GetWndClassName()
  4707. {
  4708. return UPDOWN_CLASS;
  4709. }
  4710. UINT GetAccel(int nAccel, UDACCEL* pAccel) const
  4711. {
  4712. ATLASSERT(::IsWindow(m_hWnd));
  4713. return (UINT)LOWORD(::SendMessage(m_hWnd, UDM_GETACCEL, nAccel, (LPARAM)pAccel));
  4714. }
  4715. BOOL SetAccel(int nAccel, UDACCEL* pAccel)
  4716. {
  4717. ATLASSERT(::IsWindow(m_hWnd));
  4718. return (BOOL)LOWORD(::SendMessage(m_hWnd, UDM_SETACCEL, nAccel, (LPARAM)pAccel));
  4719. }
  4720. UINT GetBase() const
  4721. {
  4722. ATLASSERT(::IsWindow(m_hWnd));
  4723. return (UINT)LOWORD(::SendMessage(m_hWnd, UDM_GETBASE, 0, 0L));
  4724. }
  4725. int SetBase(int nBase)
  4726. {
  4727. ATLASSERT(::IsWindow(m_hWnd));
  4728. return (int)::SendMessage(m_hWnd, UDM_SETBASE, nBase, 0L);
  4729. }
  4730. CWindow GetBuddy() const
  4731. {
  4732. ATLASSERT(::IsWindow(m_hWnd));
  4733. return CWindow((HWND)::SendMessage(m_hWnd, UDM_GETBUDDY, 0, 0L));
  4734. }
  4735. CWindow SetBuddy(HWND hWndBuddy)
  4736. {
  4737. ATLASSERT(::IsWindow(m_hWnd));
  4738. return CWindow((HWND)::SendMessage(m_hWnd, UDM_SETBUDDY, (WPARAM)hWndBuddy, 0L));
  4739. }
  4740. int GetPos() const
  4741. {
  4742. ATLASSERT(::IsWindow(m_hWnd));
  4743. return (int)::SendMessage(m_hWnd, UDM_GETPOS, 0, 0L);
  4744. }
  4745. int SetPos(int nPos)
  4746. {
  4747. ATLASSERT(::IsWindow(m_hWnd));
  4748. return (int)(short)LOWORD(::SendMessage(m_hWnd, UDM_SETPOS, 0, MAKELPARAM(nPos, 0)));
  4749. }
  4750. DWORD GetRange() const
  4751. {
  4752. ATLASSERT(::IsWindow(m_hWnd));
  4753. return (DWORD)::SendMessage(m_hWnd, UDM_GETRANGE, 0, 0L);
  4754. }
  4755. void GetRange(int& nLower, int& nUpper) const
  4756. {
  4757. ATLASSERT(::IsWindow(m_hWnd));
  4758. DWORD dwRet = (DWORD)::SendMessage(m_hWnd, UDM_GETRANGE, 0, 0L);
  4759. nLower = (int)(short)HIWORD(dwRet);
  4760. nUpper = (int)(short)LOWORD(dwRet);
  4761. }
  4762. void SetRange(int nLower, int nUpper)
  4763. {
  4764. ATLASSERT(::IsWindow(m_hWnd));
  4765. ::SendMessage(m_hWnd, UDM_SETRANGE, 0, MAKELPARAM(nUpper, nLower));
  4766. }
  4767. #if (_WIN32_IE >= 0x0400)
  4768. void SetRange32(int nLower, int nUpper)
  4769. {
  4770. ATLASSERT(::IsWindow(m_hWnd));
  4771. ::SendMessage(m_hWnd, UDM_SETRANGE32, nLower, nUpper);
  4772. }
  4773. void GetRange32(int& nLower, int& nUpper) const
  4774. {
  4775. ATLASSERT(::IsWindow(m_hWnd));
  4776. ::SendMessage(m_hWnd, UDM_GETRANGE32, (WPARAM)&nLower, (LPARAM)&nUpper);
  4777. }
  4778. BOOL GetUnicodeFormat() const
  4779. {
  4780. ATLASSERT(::IsWindow(m_hWnd));
  4781. return (BOOL)::SendMessage(m_hWnd, UDM_GETUNICODEFORMAT, 0, 0L);
  4782. }
  4783. BOOL SetUnicodeFormat(BOOL bUnicode = TRUE)
  4784. {
  4785. ATLASSERT(::IsWindow(m_hWnd));
  4786. return (BOOL)::SendMessage(m_hWnd, UDM_SETUNICODEFORMAT, bUnicode, 0L);
  4787. }
  4788. #endif //(_WIN32_IE >= 0x0400)
  4789. #if (_WIN32_IE >= 0x0500)
  4790. int GetPos32(LPBOOL lpbError /*= NULL*/) const
  4791. {
  4792. ATLASSERT(::IsWindow(m_hWnd));
  4793. return (int)::SendMessage(m_hWnd, UDM_GETPOS32, 0, (LPARAM)lpbError);
  4794. }
  4795. int SetPos32(int nPos)
  4796. {
  4797. ATLASSERT(::IsWindow(m_hWnd));
  4798. return (int)::SendMessage(m_hWnd, UDM_SETPOS32, 0, (LPARAM)nPos);
  4799. }
  4800. #endif //(_WIN32_IE >= 0x0500)
  4801. };
  4802. typedef CUpDownCtrlT<CWindow> CUpDownCtrl;
  4803. /////////////////////////////////////////////////////////////////////////////
  4804. // CProgressBarCtrl
  4805. template <class TBase>
  4806. class CProgressBarCtrlT : public TBase
  4807. {
  4808. public:
  4809. // Constructors
  4810. CProgressBarCtrlT(HWND hWnd = NULL) : TBase(hWnd) { }
  4811. CProgressBarCtrlT< TBase >& operator=(HWND hWnd)
  4812. {
  4813. m_hWnd = hWnd;
  4814. return *this;
  4815. }
  4816. HWND Create(HWND hWndParent, _U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
  4817. DWORD dwStyle = 0, DWORD dwExStyle = 0,
  4818. _U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
  4819. {
  4820. return CWindow::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
  4821. }
  4822. // Attributes
  4823. static LPCTSTR GetWndClassName()
  4824. {
  4825. return PROGRESS_CLASS;
  4826. }
  4827. DWORD SetRange(int nLower, int nUpper)
  4828. {
  4829. ATLASSERT(::IsWindow(m_hWnd));
  4830. return (DWORD)::SendMessage(m_hWnd, PBM_SETRANGE, 0, MAKELPARAM(nLower, nUpper));
  4831. }
  4832. int SetPos(int nPos)
  4833. {
  4834. ATLASSERT(::IsWindow(m_hWnd));
  4835. return (int)(short)LOWORD(::SendMessage(m_hWnd, PBM_SETPOS, nPos, 0L));
  4836. }
  4837. int OffsetPos(int nPos)
  4838. {
  4839. ATLASSERT(::IsWindow(m_hWnd));
  4840. return (int)(short)LOWORD(::SendMessage(m_hWnd, PBM_DELTAPOS, nPos, 0L));
  4841. }
  4842. int SetStep(int nStep)
  4843. {
  4844. ATLASSERT(::IsWindow(m_hWnd));
  4845. return (int)(short)LOWORD(::SendMessage(m_hWnd, PBM_SETSTEP, nStep, 0L));
  4846. }
  4847. UINT GetPos() const
  4848. {
  4849. ATLASSERT(::IsWindow(m_hWnd));
  4850. return (UINT)::SendMessage(m_hWnd, PBM_GETPOS, 0, 0L);
  4851. }
  4852. void GetRange(PPBRANGE pPBRange) const
  4853. {
  4854. ATLASSERT(::IsWindow(m_hWnd));
  4855. ATLASSERT(pPBRange != NULL);
  4856. ::SendMessage(m_hWnd, PBM_GETRANGE, TRUE, (LPARAM)pPBRange);
  4857. }
  4858. int GetRangeLimit(BOOL bLimit) const
  4859. {
  4860. ATLASSERT(::IsWindow(m_hWnd));
  4861. return (int)::SendMessage(m_hWnd, PBM_GETRANGE, bLimit, (LPARAM)NULL);
  4862. }
  4863. DWORD SetRange32(int nMin, int nMax)
  4864. {
  4865. ATLASSERT(::IsWindow(m_hWnd));
  4866. return (DWORD)::SendMessage(m_hWnd, PBM_SETRANGE32, nMin, nMax);
  4867. }
  4868. #if (_WIN32_IE >= 0x0400)
  4869. COLORREF SetBarColor(COLORREF clr)
  4870. {
  4871. ATLASSERT(::IsWindow(m_hWnd));
  4872. return (COLORREF)::SendMessage(m_hWnd, PBM_SETBARCOLOR, 0, (LPARAM)clr);
  4873. }
  4874. COLORREF SetBkColor(COLORREF clr)
  4875. {
  4876. ATLASSERT(::IsWindow(m_hWnd));
  4877. return (COLORREF)::SendMessage(m_hWnd, PBM_SETBKCOLOR, 0, (LPARAM)clr);
  4878. }
  4879. #endif //(_WIN32_IE >= 0x0400)
  4880. // Operations
  4881. int StepIt()
  4882. {
  4883. ATLASSERT(::IsWindow(m_hWnd));
  4884. return (int)(short)LOWORD(::SendMessage(m_hWnd, PBM_STEPIT, 0, 0L));
  4885. }
  4886. };
  4887. typedef CProgressBarCtrlT<CWindow> CProgressBarCtrl;
  4888. /////////////////////////////////////////////////////////////////////////////
  4889. // CHotKeyCtrl
  4890. template <class TBase>
  4891. class CHotKeyCtrlT : public TBase
  4892. {
  4893. public:
  4894. // Constructors
  4895. CHotKeyCtrlT(HWND hWnd = NULL) : TBase(hWnd) { }
  4896. CHotKeyCtrlT< TBase >& operator=(HWND hWnd)
  4897. {
  4898. m_hWnd = hWnd;
  4899. return *this;
  4900. }
  4901. HWND Create(HWND hWndParent, _U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
  4902. DWORD dwStyle = 0, DWORD dwExStyle = 0,
  4903. _U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
  4904. {
  4905. return CWindow::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
  4906. }
  4907. // Attributes
  4908. static LPCTSTR GetWndClassName()
  4909. {
  4910. return HOTKEY_CLASS;
  4911. }
  4912. DWORD GetHotKey() const
  4913. {
  4914. ATLASSERT(::IsWindow(m_hWnd));
  4915. return (DWORD)::SendMessage(m_hWnd, HKM_GETHOTKEY, 0, 0L);
  4916. }
  4917. void GetHotKey(WORD &wVirtualKeyCode, WORD &wModifiers) const
  4918. {
  4919. ATLASSERT(::IsWindow(m_hWnd));
  4920. DWORD dw = (DWORD)::SendMessage(m_hWnd, HKM_GETHOTKEY, 0, 0L);
  4921. wVirtualKeyCode = LOBYTE(LOWORD(dw));
  4922. wModifiers = HIBYTE(LOWORD(dw));
  4923. }
  4924. void SetHotKey(WORD wVirtualKeyCode, WORD wModifiers)
  4925. {
  4926. ATLASSERT(::IsWindow(m_hWnd));
  4927. ::SendMessage(m_hWnd, HKM_SETHOTKEY, MAKEWORD(wVirtualKeyCode, wModifiers), 0L);
  4928. }
  4929. void SetRules(WORD wInvalidComb, WORD wModifiers)
  4930. {
  4931. ATLASSERT(::IsWindow(m_hWnd));
  4932. ::SendMessage(m_hWnd, HKM_SETRULES, wInvalidComb, MAKELPARAM(wModifiers, 0));
  4933. }
  4934. };
  4935. typedef CHotKeyCtrlT<CWindow> CHotKeyCtrl;
  4936. /////////////////////////////////////////////////////////////////////////////
  4937. // CAnimateCtrl
  4938. template <class TBase>
  4939. class CAnimateCtrlT : public TBase
  4940. {
  4941. public:
  4942. // Constructors
  4943. CAnimateCtrlT(HWND hWnd = NULL) : TBase(hWnd) { }
  4944. CAnimateCtrlT< TBase >& operator=(HWND hWnd)
  4945. {
  4946. m_hWnd = hWnd;
  4947. return *this;
  4948. }
  4949. HWND Create(HWND hWndParent, _U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
  4950. DWORD dwStyle = 0, DWORD dwExStyle = 0,
  4951. _U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
  4952. {
  4953. return CWindow::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
  4954. }
  4955. // Attributes
  4956. static LPCTSTR GetWndClassName()
  4957. {
  4958. return ANIMATE_CLASS;
  4959. }
  4960. // Operations
  4961. BOOL Open(_U_STRINGorID FileName)
  4962. {
  4963. ATLASSERT(::IsWindow(m_hWnd));
  4964. return (BOOL)::SendMessage(m_hWnd, ACM_OPEN, 0, (LPARAM)FileName.m_lpstr);
  4965. }
  4966. BOOL Play(UINT nFrom, UINT nTo, UINT nRep)
  4967. {
  4968. ATLASSERT(::IsWindow(m_hWnd));
  4969. return (BOOL)::SendMessage(m_hWnd, ACM_PLAY, nRep, MAKELPARAM(nFrom, nTo));
  4970. }
  4971. BOOL Stop()
  4972. {
  4973. ATLASSERT(::IsWindow(m_hWnd));
  4974. return (BOOL)::SendMessage(m_hWnd, ACM_STOP, 0, 0L);
  4975. }
  4976. BOOL Close()
  4977. {
  4978. ATLASSERT(::IsWindow(m_hWnd));
  4979. return (BOOL)::SendMessage(m_hWnd, ACM_OPEN, 0, 0L);
  4980. }
  4981. BOOL Seek(UINT nTo)
  4982. {
  4983. ATLASSERT(::IsWindow(m_hWnd));
  4984. return (BOOL)::SendMessage(m_hWnd, ACM_PLAY, 0, MAKELPARAM(nTo, nTo));
  4985. }
  4986. };
  4987. typedef CAnimateCtrlT<CWindow> CAnimateCtrl;
  4988. /////////////////////////////////////////////////////////////////////////////
  4989. // CRichEditCtrl
  4990. #ifdef _UNICODE
  4991. #if (_RICHEDIT_VER == 0x0100)
  4992. #undef RICHEDIT_CLASS
  4993. #define RICHEDIT_CLASS L"RICHEDIT"
  4994. #endif //(_RICHEDIT_VER == 0x0100)
  4995. #endif //_UNICODE
  4996. template <class TBase>
  4997. class CRichEditCtrlT : public TBase
  4998. {
  4999. public:
  5000. // Constructors
  5001. CRichEditCtrlT(HWND hWnd = NULL) : TBase(hWnd) { }
  5002. CRichEditCtrlT< TBase >& operator=(HWND hWnd)
  5003. {
  5004. m_hWnd = hWnd;
  5005. return *this;
  5006. }
  5007. HWND Create(HWND hWndParent, _U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
  5008. DWORD dwStyle = 0, DWORD dwExStyle = 0,
  5009. _U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
  5010. {
  5011. return CWindow::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
  5012. }
  5013. // Attributes
  5014. static LPCTSTR GetWndClassName()
  5015. {
  5016. return RICHEDIT_CLASS;
  5017. }
  5018. static LPCTSTR GetLibraryName()
  5019. {
  5020. #if (_RICHEDIT_VER >= 0x0200)
  5021. return _T("RICHED20.DLL");
  5022. #else
  5023. return _T("RICHED32.DLL");
  5024. #endif
  5025. }
  5026. int GetLineCount() const
  5027. {
  5028. ATLASSERT(::IsWindow(m_hWnd));
  5029. return (int)::SendMessage(m_hWnd, EM_GETLINECOUNT, 0, 0L);
  5030. }
  5031. BOOL GetModify() const
  5032. {
  5033. ATLASSERT(::IsWindow(m_hWnd));
  5034. return (BOOL)::SendMessage(m_hWnd, EM_GETMODIFY, 0, 0L);
  5035. }
  5036. void SetModify(BOOL bModified = TRUE)
  5037. {
  5038. ATLASSERT(::IsWindow(m_hWnd));
  5039. ::SendMessage(m_hWnd, EM_SETMODIFY, bModified, 0L);
  5040. }
  5041. void GetRect(LPRECT lpRect) const
  5042. {
  5043. ATLASSERT(::IsWindow(m_hWnd));
  5044. ::SendMessage(m_hWnd, EM_GETRECT, 0, (LPARAM)lpRect);
  5045. }
  5046. DWORD GetOptions() const
  5047. {
  5048. ATLASSERT(::IsWindow(m_hWnd));
  5049. return (DWORD)::SendMessage(m_hWnd, EM_GETOPTIONS, 0, 0L);
  5050. }
  5051. DWORD SetOptions(WORD wOperation, DWORD dwOptions)
  5052. {
  5053. ATLASSERT(::IsWindow(m_hWnd));
  5054. return (DWORD)::SendMessage(m_hWnd, EM_SETOPTIONS, wOperation, dwOptions);
  5055. }
  5056. // NOTE: first word in lpszBuffer must contain the size of the buffer!
  5057. int GetLine(int nIndex, LPTSTR lpszBuffer) const
  5058. {
  5059. ATLASSERT(::IsWindow(m_hWnd));
  5060. return (int)::SendMessage(m_hWnd, EM_GETLINE, nIndex, (LPARAM)lpszBuffer);
  5061. }
  5062. int GetLine(int nIndex, LPTSTR lpszBuffer, int nMaxLength) const
  5063. {
  5064. ATLASSERT(::IsWindow(m_hWnd));
  5065. *(LPINT)lpszBuffer = nMaxLength;
  5066. return (int)::SendMessage(m_hWnd, EM_GETLINE, nIndex, (LPARAM)lpszBuffer);
  5067. }
  5068. BOOL CanUndo() const
  5069. {
  5070. ATLASSERT(::IsWindow(m_hWnd));
  5071. return (BOOL)::SendMessage(m_hWnd, EM_CANUNDO, 0, 0L);
  5072. }
  5073. BOOL CanPaste(UINT nFormat = 0) const
  5074. {
  5075. ATLASSERT(::IsWindow(m_hWnd));
  5076. return (BOOL)::SendMessage(m_hWnd, EM_CANPASTE, nFormat, 0L);
  5077. }
  5078. void GetSel(LONG& nStartChar, LONG& nEndChar) const
  5079. {
  5080. ATLASSERT(::IsWindow(m_hWnd));
  5081. CHARRANGE cr;
  5082. ::SendMessage(m_hWnd, EM_EXGETSEL, 0, (LPARAM)&cr);
  5083. nStartChar = cr.cpMin;
  5084. nEndChar = cr.cpMax;
  5085. }
  5086. void GetSel(CHARRANGE &cr) const
  5087. {
  5088. ATLASSERT(::IsWindow(m_hWnd));
  5089. ::SendMessage(m_hWnd, EM_EXGETSEL, 0, (LPARAM)&cr);
  5090. }
  5091. int SetSel(LONG nStartChar, LONG nEndChar)
  5092. {
  5093. ATLASSERT(::IsWindow(m_hWnd));
  5094. CHARRANGE cr = { nStartChar, nEndChar };
  5095. return (int)::SendMessage(m_hWnd, EM_EXSETSEL, 0, (LPARAM)&cr);
  5096. }
  5097. int SetSel(CHARRANGE &cr)
  5098. {
  5099. ATLASSERT(::IsWindow(m_hWnd));
  5100. return (int)::SendMessage(m_hWnd, EM_EXSETSEL, 0, (LPARAM)&cr);
  5101. }
  5102. int SetSelAll()
  5103. {
  5104. return SetSel(0, -1);
  5105. }
  5106. int SetSelNone()
  5107. {
  5108. return SetSel(-1, 0);
  5109. }
  5110. DWORD GetDefaultCharFormat(CHARFORMAT& cf) const
  5111. {
  5112. ATLASSERT(::IsWindow(m_hWnd));
  5113. cf.cbSize = sizeof(CHARFORMAT);
  5114. return (DWORD)::SendMessage(m_hWnd, EM_GETCHARFORMAT, 0, (LPARAM)&cf);
  5115. }
  5116. DWORD GetSelectionCharFormat(CHARFORMAT& cf) const
  5117. {
  5118. ATLASSERT(::IsWindow(m_hWnd));
  5119. cf.cbSize = sizeof(CHARFORMAT);
  5120. return (DWORD)::SendMessage(m_hWnd, EM_GETCHARFORMAT, 1, (LPARAM)&cf);
  5121. }
  5122. DWORD GetEventMask() const
  5123. {
  5124. ATLASSERT(::IsWindow(m_hWnd));
  5125. return (DWORD)::SendMessage(m_hWnd, EM_GETEVENTMASK, 0, 0L);
  5126. }
  5127. LONG GetLimitText() const
  5128. {
  5129. ATLASSERT(::IsWindow(m_hWnd));
  5130. return (LONG)::SendMessage(m_hWnd, EM_GETLIMITTEXT, 0, 0L);
  5131. }
  5132. DWORD GetParaFormat(PARAFORMAT& pf) const
  5133. {
  5134. ATLASSERT(::IsWindow(m_hWnd));
  5135. pf.cbSize = sizeof(PARAFORMAT);
  5136. return (DWORD)::SendMessage(m_hWnd, EM_GETPARAFORMAT, 0, (LPARAM)&pf);
  5137. }
  5138. // richedit EM_GETSELTEXT is ANSI
  5139. LONG GetSelText(LPSTR lpBuf) const
  5140. {
  5141. ATLASSERT(::IsWindow(m_hWnd));
  5142. return (LONG)::SendMessage(m_hWnd, EM_GETSELTEXT, 0, (LPARAM)lpBuf);
  5143. }
  5144. #ifndef _ATL_NO_COM
  5145. BOOL GetSelTextBSTR(BSTR& bstrText) const
  5146. {
  5147. USES_CONVERSION;
  5148. ATLASSERT(::IsWindow(m_hWnd));
  5149. ATLASSERT(bstrText == NULL);
  5150. CHARRANGE cr;
  5151. cr.cpMin = cr.cpMax = 0;
  5152. ::SendMessage(m_hWnd, EM_EXGETSEL, 0, (LPARAM)&cr);
  5153. LPSTR lpstrText = (char*)_alloca((cr.cpMax - cr.cpMin + 1) * 2);
  5154. lpstrText[0] = 0;
  5155. if(::SendMessage(m_hWnd, EM_GETSELTEXT, 0, (LPARAM)lpstrText) == 0)
  5156. return FALSE;
  5157. bstrText = ::SysAllocString(A2W(lpstrText));
  5158. return (bstrText != NULL) ? TRUE : FALSE;
  5159. }
  5160. #endif //!_ATL_NO_COM
  5161. #ifdef __ATLSTR_H__
  5162. LONG GetSelText(CString& strText) const
  5163. {
  5164. ATLASSERT(::IsWindow(m_hWnd));
  5165. CHARRANGE cr;
  5166. cr.cpMin = cr.cpMax = 0;
  5167. ::SendMessage(m_hWnd, EM_EXGETSEL, 0, (LPARAM)&cr);
  5168. LPSTR lpstrText = (char*)_alloca((cr.cpMax - cr.cpMin + 1) * 2);
  5169. lpstrText[0] = 0;
  5170. LONG lLen = (LONG)::SendMessage(m_hWnd, EM_GETSELTEXT, 0, (LPARAM)lpstrText);
  5171. if(lLen == 0)
  5172. return 0;
  5173. USES_CONVERSION;
  5174. strText = A2T(lpstrText);
  5175. return lLen;
  5176. }
  5177. #endif //__ATLSTR_H__
  5178. WORD GetSelectionType() const
  5179. {
  5180. ATLASSERT(::IsWindow(m_hWnd));
  5181. return (WORD)::SendMessage(m_hWnd, EM_SELECTIONTYPE, 0, 0L);
  5182. }
  5183. COLORREF SetBackgroundColor(COLORREF cr)
  5184. {
  5185. ATLASSERT(::IsWindow(m_hWnd));
  5186. return (COLORREF)::SendMessage(m_hWnd, EM_SETBKGNDCOLOR, 0, cr);
  5187. }
  5188. COLORREF SetBackgroundColor() // sets to system background
  5189. {
  5190. ATLASSERT(::IsWindow(m_hWnd));
  5191. return (COLORREF)::SendMessage(m_hWnd, EM_SETBKGNDCOLOR, 1, 0);
  5192. }
  5193. BOOL SetDefaultCharFormat(CHARFORMAT& cf)
  5194. {
  5195. ATLASSERT(::IsWindow(m_hWnd));
  5196. cf.cbSize = sizeof(CHARFORMAT);
  5197. return (BOOL)::SendMessage(m_hWnd, EM_SETCHARFORMAT, 0, (LPARAM)&cf);
  5198. }
  5199. BOOL SetSelectionCharFormat(CHARFORMAT& cf)
  5200. {
  5201. ATLASSERT(::IsWindow(m_hWnd));
  5202. cf.cbSize = sizeof(CHARFORMAT);
  5203. return (BOOL)::SendMessage(m_hWnd, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf);
  5204. }
  5205. BOOL SetWordCharFormat(CHARFORMAT& cf)
  5206. {
  5207. ATLASSERT(::IsWindow(m_hWnd));
  5208. cf.cbSize = sizeof(CHARFORMAT);
  5209. return (BOOL)::SendMessage(m_hWnd, EM_SETCHARFORMAT, SCF_SELECTION | SCF_WORD, (LPARAM)&cf);
  5210. }
  5211. DWORD SetEventMask(DWORD dwEventMask)
  5212. {
  5213. ATLASSERT(::IsWindow(m_hWnd));
  5214. return (DWORD)::SendMessage(m_hWnd, EM_SETEVENTMASK, 0, dwEventMask);
  5215. }
  5216. BOOL SetParaFormat(PARAFORMAT& pf)
  5217. {
  5218. ATLASSERT(::IsWindow(m_hWnd));
  5219. pf.cbSize = sizeof(PARAFORMAT);
  5220. return (BOOL)::SendMessage(m_hWnd, EM_SETPARAFORMAT, 0, (LPARAM)&pf);
  5221. }
  5222. BOOL SetTargetDevice(HDC hDC, int cxLineWidth)
  5223. {
  5224. ATLASSERT(::IsWindow(m_hWnd));
  5225. return (BOOL)::SendMessage(m_hWnd, EM_SETTARGETDEVICE, (WPARAM)hDC, cxLineWidth);
  5226. }
  5227. int GetTextLength() const
  5228. {
  5229. ATLASSERT(::IsWindow(m_hWnd));
  5230. return (int)::SendMessage(m_hWnd, WM_GETTEXTLENGTH, 0, 0L);
  5231. }
  5232. BOOL SetReadOnly(BOOL bReadOnly = TRUE)
  5233. {
  5234. ATLASSERT(::IsWindow(m_hWnd));
  5235. return (BOOL)::SendMessage(m_hWnd, EM_SETREADONLY, bReadOnly, 0L);
  5236. }
  5237. int GetFirstVisibleLine() const
  5238. {
  5239. ATLASSERT(::IsWindow(m_hWnd));
  5240. return (int)::SendMessage(m_hWnd, EM_GETFIRSTVISIBLELINE, 0, 0L);
  5241. }
  5242. int GetTextRange(TEXTRANGE* pTextRange) const
  5243. {
  5244. ATLASSERT(::IsWindow(m_hWnd));
  5245. return (int)::SendMessage(m_hWnd, EM_GETTEXTRANGE, 0, (LPARAM)pTextRange);
  5246. }
  5247. int GetTextRange(LONG nStartChar, LONG nEndChar, LPSTR lpstrText) const
  5248. {
  5249. ATLASSERT(::IsWindow(m_hWnd));
  5250. TEXTRANGE tr;
  5251. tr.chrg.cpMin = nStartChar;
  5252. tr.chrg.cpMax = nEndChar;
  5253. tr.lpstrText = lpstrText;
  5254. return (int)::SendMessage(m_hWnd, EM_GETTEXTRANGE, 0, (LPARAM)&tr);
  5255. }
  5256. EDITWORDBREAKPROCEX GetWordBreakProcEx() const
  5257. {
  5258. ATLASSERT(::IsWindow(m_hWnd));
  5259. return (EDITWORDBREAKPROCEX)::SendMessage(m_hWnd, EM_GETWORDBREAKPROCEX, 0, 0L);
  5260. }
  5261. EDITWORDBREAKPROCEX SetWordBreakProcEx(EDITWORDBREAKPROCEX pfnEditWordBreakProcEx)
  5262. {
  5263. ATLASSERT(::IsWindow(m_hWnd));
  5264. return (EDITWORDBREAKPROCEX)::SendMessage(m_hWnd, EM_SETWORDBREAKPROCEX, 0, (LPARAM)pfnEditWordBreakProcEx);
  5265. }
  5266. #if (_RICHEDIT_VER >= 0x0200)
  5267. DWORD GetDefaultCharFormat(CHARFORMAT2& cf) const
  5268. {
  5269. ATLASSERT(::IsWindow(m_hWnd));
  5270. cf.cbSize = sizeof(CHARFORMAT2);
  5271. return (DWORD)::SendMessage(m_hWnd, EM_GETCHARFORMAT, 0, (LPARAM)&cf);
  5272. }
  5273. BOOL SetDefaultCharFormat(CHARFORMAT2& cf)
  5274. {
  5275. ATLASSERT(::IsWindow(m_hWnd));
  5276. cf.cbSize = sizeof(CHARFORMAT2);
  5277. return (BOOL)::SendMessage(m_hWnd, EM_SETCHARFORMAT, 0, (LPARAM)&cf);
  5278. }
  5279. DWORD GetSelectionCharFormat(CHARFORMAT2& cf) const
  5280. {
  5281. ATLASSERT(::IsWindow(m_hWnd));
  5282. cf.cbSize = sizeof(CHARFORMAT2);
  5283. return (DWORD)::SendMessage(m_hWnd, EM_GETCHARFORMAT, 1, (LPARAM)&cf);
  5284. }
  5285. BOOL SetSelectionCharFormat(CHARFORMAT2& cf)
  5286. {
  5287. ATLASSERT(::IsWindow(m_hWnd));
  5288. cf.cbSize = sizeof(CHARFORMAT2);
  5289. return (BOOL)::SendMessage(m_hWnd, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf);
  5290. }
  5291. BOOL SetWordCharFormat(CHARFORMAT2& cf)
  5292. {
  5293. ATLASSERT(::IsWindow(m_hWnd));
  5294. cf.cbSize = sizeof(CHARFORMAT2);
  5295. return (BOOL)::SendMessage(m_hWnd, EM_SETCHARFORMAT, SCF_SELECTION | SCF_WORD, (LPARAM)&cf);
  5296. }
  5297. DWORD GetParaFormat(PARAFORMAT2& pf) const
  5298. {
  5299. ATLASSERT(::IsWindow(m_hWnd));
  5300. pf.cbSize = sizeof(PARAFORMAT2);
  5301. return (DWORD)::SendMessage(m_hWnd, EM_GETPARAFORMAT, 0, (LPARAM)&pf);
  5302. }
  5303. BOOL SetParaFormat(PARAFORMAT2& pf)
  5304. {
  5305. ATLASSERT(::IsWindow(m_hWnd));
  5306. pf.cbSize = sizeof(PARAFORMAT2);
  5307. return (BOOL)::SendMessage(m_hWnd, EM_SETPARAFORMAT, 0, (LPARAM)&pf);
  5308. }
  5309. TEXTMODE GetTextMode() const
  5310. {
  5311. ATLASSERT(::IsWindow(m_hWnd));
  5312. return (TEXTMODE)::SendMessage(m_hWnd, EM_GETTEXTMODE, 0, 0L);
  5313. }
  5314. BOOL SetTextMode(TEXTMODE enumTextMode)
  5315. {
  5316. ATLASSERT(::IsWindow(m_hWnd));
  5317. return !(BOOL)::SendMessage(m_hWnd, EM_SETTEXTMODE, enumTextMode, 0L);
  5318. }
  5319. UNDONAMEID GetUndoName() const
  5320. {
  5321. ATLASSERT(::IsWindow(m_hWnd));
  5322. return (UNDONAMEID)::SendMessage(m_hWnd, EM_GETUNDONAME, 0, 0L);
  5323. }
  5324. UNDONAMEID GetRedoName() const
  5325. {
  5326. ATLASSERT(::IsWindow(m_hWnd));
  5327. return (UNDONAMEID)::SendMessage(m_hWnd, EM_GETREDONAME, 0, 0L);
  5328. }
  5329. BOOL CanRedo() const
  5330. {
  5331. ATLASSERT(::IsWindow(m_hWnd));
  5332. return (BOOL)::SendMessage(m_hWnd, EM_CANREDO, 0, 0L);
  5333. }
  5334. BOOL GetAutoURLDetect() const
  5335. {
  5336. ATLASSERT(::IsWindow(m_hWnd));
  5337. return (BOOL)::SendMessage(m_hWnd, EM_GETAUTOURLDETECT, 0, 0L);
  5338. }
  5339. BOOL SetAutoURLDetect(BOOL bAutoDetect = TRUE)
  5340. {
  5341. ATLASSERT(::IsWindow(m_hWnd));
  5342. return !(BOOL)::SendMessage(m_hWnd, EM_AUTOURLDETECT, bAutoDetect, 0L);
  5343. }
  5344. // this method is deprecated, please use SetAutoURLDetect
  5345. BOOL EnableAutoURLDetect(BOOL bEnable = TRUE) { return SetAutoURLDetect(bEnable); }
  5346. UINT SetUndoLimit(UINT uUndoLimit)
  5347. {
  5348. ATLASSERT(::IsWindow(m_hWnd));
  5349. return (UINT)::SendMessage(m_hWnd, EM_SETUNDOLIMIT, uUndoLimit, 0L);
  5350. }
  5351. void SetPalette(HPALETTE hPalette)
  5352. {
  5353. ATLASSERT(::IsWindow(m_hWnd));
  5354. ::SendMessage(m_hWnd, EM_SETPALETTE, (WPARAM)hPalette, 0L);
  5355. }
  5356. int GetTextEx(GETTEXTEX* pGetTextEx, LPTSTR lpstrText) const
  5357. {
  5358. ATLASSERT(::IsWindow(m_hWnd));
  5359. return (int)::SendMessage(m_hWnd, EM_GETTEXTEX, (WPARAM)pGetTextEx, (LPARAM)lpstrText);
  5360. }
  5361. int GetTextEx(LPTSTR lpstrText, int nTextLen, DWORD dwFlags = GT_DEFAULT, UINT uCodePage = CP_ACP, LPCSTR lpDefaultChar = NULL, LPBOOL lpUsedDefChar = NULL) const
  5362. {
  5363. ATLASSERT(::IsWindow(m_hWnd));
  5364. GETTEXTEX gte;
  5365. gte.cb = nTextLen * sizeof(TCHAR);
  5366. gte.codepage = uCodePage;
  5367. gte.flags = dwFlags;
  5368. gte.lpDefaultChar = lpDefaultChar;
  5369. gte.lpUsedDefChar = lpUsedDefChar;
  5370. return (int)::SendMessage(m_hWnd, EM_GETTEXTEX, (WPARAM)&gte, (LPARAM)lpstrText);
  5371. }
  5372. int GetTextLengthEx(GETTEXTLENGTHEX* pGetTextLengthEx) const
  5373. {
  5374. ATLASSERT(::IsWindow(m_hWnd));
  5375. return (int)::SendMessage(m_hWnd, EM_GETTEXTLENGTHEX, (WPARAM)pGetTextLengthEx, 0L);
  5376. }
  5377. int GetTextLengthEx(DWORD dwFlags = GTL_DEFAULT, UINT uCodePage = CP_ACP) const
  5378. {
  5379. ATLASSERT(::IsWindow(m_hWnd));
  5380. GETTEXTLENGTHEX gtle;
  5381. gtle.codepage = uCodePage;
  5382. gtle.flags = dwFlags;
  5383. return (int)::SendMessage(m_hWnd, EM_GETTEXTLENGTHEX, (WPARAM)&gtle, 0L);
  5384. }
  5385. #endif //(_RICHEDIT_VER >= 0x0200)
  5386. #if (_RICHEDIT_VER >= 0x0300)
  5387. int SetTextEx(SETTEXTEX* pSetTextEx, LPCTSTR lpstrText)
  5388. {
  5389. ATLASSERT(::IsWindow(m_hWnd));
  5390. return (int)::SendMessage(m_hWnd, EM_SETTEXTEX, (WPARAM)pSetTextEx, (LPARAM)lpstrText);
  5391. }
  5392. int SetTextEx(LPCTSTR lpstrText, DWORD dwFlags = ST_DEFAULT, UINT uCodePage = CP_ACP)
  5393. {
  5394. ATLASSERT(::IsWindow(m_hWnd));
  5395. SETTEXTEX ste;
  5396. ste.flags = dwFlags;
  5397. ste.codepage = uCodePage;
  5398. return (int)::SendMessage(m_hWnd, EM_SETTEXTEX, (WPARAM)&ste, (LPARAM)lpstrText);
  5399. }
  5400. int GetEditStyle() const
  5401. {
  5402. ATLASSERT(::IsWindow(m_hWnd));
  5403. return (int)::SendMessage(m_hWnd, EM_GETEDITSTYLE, 0, 0L);
  5404. }
  5405. int SetEditStyle(int nStyle, int nMask = -1)
  5406. {
  5407. ATLASSERT(::IsWindow(m_hWnd));
  5408. if(nMask == -1)
  5409. nMask = nStyle; // set everything specified
  5410. return (int)::SendMessage(m_hWnd, EM_SETEDITSTYLE, nStyle, nMask);
  5411. }
  5412. BOOL SetFontSize(int nFontSizeDelta)
  5413. {
  5414. ATLASSERT(::IsWindow(m_hWnd));
  5415. ATLASSERT(nFontSizeDelta >= -1637 && nFontSizeDelta <= 1638);
  5416. return (BOOL)::SendMessage(m_hWnd, EM_SETFONTSIZE, nFontSizeDelta, 0L);
  5417. }
  5418. void GetScrollPos(LPPOINT lpPoint) const
  5419. {
  5420. ATLASSERT(::IsWindow(m_hWnd));
  5421. ATLASSERT(lpPoint != NULL);
  5422. ::SendMessage(m_hWnd, EM_GETSCROLLPOS, 0, (LPARAM)lpPoint);
  5423. }
  5424. void SetScrollPos(LPPOINT lpPoint)
  5425. {
  5426. ATLASSERT(::IsWindow(m_hWnd));
  5427. ATLASSERT(lpPoint != NULL);
  5428. ::SendMessage(m_hWnd, EM_SETSCROLLPOS, 0, (LPARAM)lpPoint);
  5429. }
  5430. BOOL GetZoom(int& nNum, int& nDen) const
  5431. {
  5432. ATLASSERT(::IsWindow(m_hWnd));
  5433. return (BOOL)::SendMessage(m_hWnd, EM_GETZOOM, (WPARAM)&nNum, (LPARAM)&nDen);
  5434. }
  5435. BOOL SetZoom(int nNum, int nDen)
  5436. {
  5437. ATLASSERT(::IsWindow(m_hWnd));
  5438. ATLASSERT(nNum >= 0 && nNum <= 64);
  5439. ATLASSERT(nDen >= 0 && nDen <= 64);
  5440. return (BOOL)::SendMessage(m_hWnd, EM_SETZOOM, nNum, nDen);
  5441. }
  5442. BOOL SetZoomOff()
  5443. {
  5444. ATLASSERT(::IsWindow(m_hWnd));
  5445. return (BOOL)::SendMessage(m_hWnd, EM_SETZOOM, 0, 0L);
  5446. }
  5447. #endif //(_RICHEDIT_VER >= 0x0300)
  5448. // Operations
  5449. void LimitText(LONG nChars = 0)
  5450. {
  5451. ATLASSERT(::IsWindow(m_hWnd));
  5452. ::SendMessage(m_hWnd, EM_EXLIMITTEXT, 0, nChars);
  5453. }
  5454. int LineFromChar(LONG nIndex) const
  5455. {
  5456. ATLASSERT(::IsWindow(m_hWnd));
  5457. return (int)::SendMessage(m_hWnd, EM_EXLINEFROMCHAR, 0, nIndex);
  5458. }
  5459. POINT PosFromChar(LONG nChar) const
  5460. {
  5461. ATLASSERT(::IsWindow(m_hWnd));
  5462. POINT point;
  5463. ::SendMessage(m_hWnd, EM_POSFROMCHAR, (WPARAM)&point, nChar);
  5464. return point;
  5465. }
  5466. int CharFromPos(POINT pt) const
  5467. {
  5468. ATLASSERT(::IsWindow(m_hWnd));
  5469. return (int)::SendMessage(m_hWnd, EM_CHARFROMPOS, 0, MAKELPARAM(pt.x, pt.y));
  5470. }
  5471. void EmptyUndoBuffer()
  5472. {
  5473. ATLASSERT(::IsWindow(m_hWnd));
  5474. ::SendMessage(m_hWnd, EM_EMPTYUNDOBUFFER, 0, 0L);
  5475. }
  5476. int LineIndex(int nLine = -1) const
  5477. {
  5478. ATLASSERT(::IsWindow(m_hWnd));
  5479. return (int)::SendMessage(m_hWnd, EM_LINEINDEX, nLine, 0L);
  5480. }
  5481. int LineLength(int nLine = -1) const
  5482. {
  5483. ATLASSERT(::IsWindow(m_hWnd));
  5484. return (int)::SendMessage(m_hWnd, EM_LINELENGTH, nLine, 0L);
  5485. }
  5486. BOOL LineScroll(int nLines, int nChars = 0)
  5487. {
  5488. ATLASSERT(::IsWindow(m_hWnd));
  5489. return (BOOL)::SendMessage(m_hWnd, EM_LINESCROLL, nChars, nLines);
  5490. }
  5491. void ReplaceSel(LPCTSTR lpszNewText, BOOL bCanUndo = FALSE)
  5492. {
  5493. ATLASSERT(::IsWindow(m_hWnd));
  5494. ::SendMessage(m_hWnd, EM_REPLACESEL, (WPARAM) bCanUndo, (LPARAM)lpszNewText);
  5495. }
  5496. void SetRect(LPCRECT lpRect)
  5497. {
  5498. ATLASSERT(::IsWindow(m_hWnd));
  5499. ::SendMessage(m_hWnd, EM_SETRECT, 0, (LPARAM)lpRect);
  5500. }
  5501. BOOL DisplayBand(LPRECT pDisplayRect)
  5502. {
  5503. ATLASSERT(::IsWindow(m_hWnd));
  5504. return (BOOL)::SendMessage(m_hWnd, EM_DISPLAYBAND, 0, (LPARAM)pDisplayRect);
  5505. }
  5506. LONG FindText(DWORD dwFlags, FINDTEXT& ft) const
  5507. {
  5508. ATLASSERT(::IsWindow(m_hWnd));
  5509. #if (_RICHEDIT_VER >= 0x0200) && defined(_UNICODE)
  5510. return (LONG)::SendMessage(m_hWnd, EM_FINDTEXTW, dwFlags, (LPARAM)&ft);
  5511. #else
  5512. return (LONG)::SendMessage(m_hWnd, EM_FINDTEXT, dwFlags, (LPARAM)&ft);
  5513. #endif
  5514. }
  5515. LONG FindText(DWORD dwFlags, FINDTEXTEX& ft) const
  5516. {
  5517. ATLASSERT(::IsWindow(m_hWnd));
  5518. #if (_RICHEDIT_VER >= 0x0200) && defined(_UNICODE)
  5519. return (LONG)::SendMessage(m_hWnd, EM_FINDTEXTEXW, dwFlags, (LPARAM)&ft);
  5520. #else
  5521. return (LONG)::SendMessage(m_hWnd, EM_FINDTEXTEX, dwFlags, (LPARAM)&ft);
  5522. #endif
  5523. }
  5524. LONG FormatRange(FORMATRANGE& fr, BOOL bDisplay = TRUE)
  5525. {
  5526. ATLASSERT(::IsWindow(m_hWnd));
  5527. return (LONG)::SendMessage(m_hWnd, EM_FORMATRANGE, bDisplay, (LPARAM)&fr);
  5528. }
  5529. void HideSelection(BOOL bHide = TRUE, BOOL bChangeStyle = FALSE)
  5530. {
  5531. ATLASSERT(::IsWindow(m_hWnd));
  5532. ::SendMessage(m_hWnd, EM_HIDESELECTION, bHide, bChangeStyle);
  5533. }
  5534. void PasteSpecial(UINT uClipFormat, DWORD dwAspect = 0, HMETAFILE hMF = 0)
  5535. {
  5536. ATLASSERT(::IsWindow(m_hWnd));
  5537. REPASTESPECIAL reps = { dwAspect, (DWORD_PTR)hMF };
  5538. ::SendMessage(m_hWnd, EM_PASTESPECIAL, uClipFormat, (LPARAM)&reps);
  5539. }
  5540. void RequestResize()
  5541. {
  5542. ATLASSERT(::IsWindow(m_hWnd));
  5543. ::SendMessage(m_hWnd, EM_REQUESTRESIZE, 0, 0L);
  5544. }
  5545. LONG StreamIn(UINT uFormat, EDITSTREAM& es)
  5546. {
  5547. ATLASSERT(::IsWindow(m_hWnd));
  5548. return (LONG)::SendMessage(m_hWnd, EM_STREAMIN, uFormat, (LPARAM)&es);
  5549. }
  5550. LONG StreamOut(UINT uFormat, EDITSTREAM& es)
  5551. {
  5552. ATLASSERT(::IsWindow(m_hWnd));
  5553. return (LONG)::SendMessage(m_hWnd, EM_STREAMOUT, uFormat, (LPARAM)&es);
  5554. }
  5555. DWORD FindWordBreak(int nCode, LONG nStartChar)
  5556. {
  5557. ATLASSERT(::IsWindow(m_hWnd));
  5558. return (DWORD)::SendMessage(m_hWnd, EM_FINDWORDBREAK, nCode, nStartChar);
  5559. }
  5560. // Additional operations
  5561. void ScrollCaret()
  5562. {
  5563. ATLASSERT(::IsWindow(m_hWnd));
  5564. ::SendMessage(m_hWnd, EM_SCROLLCARET, 0, 0L);
  5565. }
  5566. int InsertText(long nInsertAfterChar, LPCTSTR lpstrText, BOOL bCanUndo = FALSE)
  5567. {
  5568. int nRet = SetSel(nInsertAfterChar, nInsertAfterChar);
  5569. ReplaceSel(lpstrText, bCanUndo);
  5570. return nRet;
  5571. }
  5572. int AppendText(LPCTSTR lpstrText, BOOL bCanUndo = FALSE)
  5573. {
  5574. return InsertText(GetWindowTextLength(), lpstrText, bCanUndo);
  5575. }
  5576. // Clipboard operations
  5577. BOOL Undo()
  5578. {
  5579. ATLASSERT(::IsWindow(m_hWnd));
  5580. return (BOOL)::SendMessage(m_hWnd, EM_UNDO, 0, 0L);
  5581. }
  5582. void Clear()
  5583. {
  5584. ATLASSERT(::IsWindow(m_hWnd));
  5585. ::SendMessage(m_hWnd, WM_CLEAR, 0, 0L);
  5586. }
  5587. void Copy()
  5588. {
  5589. ATLASSERT(::IsWindow(m_hWnd));
  5590. ::SendMessage(m_hWnd, WM_COPY, 0, 0L);
  5591. }
  5592. void Cut()
  5593. {
  5594. ATLASSERT(::IsWindow(m_hWnd));
  5595. ::SendMessage(m_hWnd, WM_CUT, 0, 0L);
  5596. }
  5597. void Paste()
  5598. {
  5599. ATLASSERT(::IsWindow(m_hWnd));
  5600. ::SendMessage(m_hWnd, WM_PASTE, 0, 0L);
  5601. }
  5602. // OLE support
  5603. IRichEditOle* GetOleInterface() const
  5604. {
  5605. ATLASSERT(::IsWindow(m_hWnd));
  5606. IRichEditOle *pRichEditOle = NULL;
  5607. ::SendMessage(m_hWnd, EM_GETOLEINTERFACE, 0, (LPARAM)&pRichEditOle);
  5608. return pRichEditOle;
  5609. }
  5610. BOOL SetOleCallback(IRichEditOleCallback* pCallback)
  5611. {
  5612. ATLASSERT(::IsWindow(m_hWnd));
  5613. return (BOOL)::SendMessage(m_hWnd, EM_SETOLECALLBACK, 0, (LPARAM)pCallback);
  5614. }
  5615. #if (_RICHEDIT_VER >= 0x0200)
  5616. BOOL Redo()
  5617. {
  5618. ATLASSERT(::IsWindow(m_hWnd));
  5619. return (BOOL)::SendMessage(m_hWnd, EM_REDO, 0, 0L);
  5620. }
  5621. void StopGroupTyping()
  5622. {
  5623. ATLASSERT(::IsWindow(m_hWnd));
  5624. ::SendMessage(m_hWnd, EM_STOPGROUPTYPING, 0, 0L);
  5625. }
  5626. void ShowScrollBar(int nBarType, BOOL bVisible = TRUE)
  5627. {
  5628. ATLASSERT(::IsWindow(m_hWnd));
  5629. ::SendMessage(m_hWnd, EM_SHOWSCROLLBAR, nBarType, bVisible);
  5630. }
  5631. #endif //(_RICHEDIT_VER >= 0x0200)
  5632. };
  5633. typedef CRichEditCtrlT<CWindow> CRichEditCtrl;
  5634. /////////////////////////////////////////////////////////////////////////////
  5635. // CRichEditCommands - message handlers for standard EDIT commands
  5636. // Chain to CRichEditCommands message map. Your class must also derive from CRichEditCtrl.
  5637. // Example:
  5638. // class CMyRichEdit : public CWindowImpl<CMyRichEdit, CRichEditCtrl>,
  5639. // public CRichEditCommands<CMyRichEdit>
  5640. // {
  5641. // public:
  5642. // BEGIN_MSG_MAP(CMyRichEdit)
  5643. // // your handlers...
  5644. // CHAIN_MSG_MAP_ALT(CRichEditCommands<CMyRichEdit>, 1)
  5645. // END_MSG_MAP()
  5646. // // other stuff...
  5647. // };
  5648. template <class T>
  5649. class CRichEditCommands : public CEditCommands< T >
  5650. {
  5651. public:
  5652. BEGIN_MSG_MAP(CRichEditCommands< T >)
  5653. ALT_MSG_MAP(1)
  5654. COMMAND_ID_HANDLER(ID_EDIT_CLEAR, CEditCommands< T >::OnEditClear)
  5655. COMMAND_ID_HANDLER(ID_EDIT_CLEAR_ALL, CEditCommands< T >::OnEditClearAll)
  5656. COMMAND_ID_HANDLER(ID_EDIT_COPY, CEditCommands< T >::OnEditCopy)
  5657. COMMAND_ID_HANDLER(ID_EDIT_CUT, CEditCommands< T >::OnEditCut)
  5658. COMMAND_ID_HANDLER(ID_EDIT_PASTE, CEditCommands< T >::OnEditPaste)
  5659. COMMAND_ID_HANDLER(ID_EDIT_SELECT_ALL, CEditCommands< T >::OnEditSelectAll)
  5660. COMMAND_ID_HANDLER(ID_EDIT_UNDO, CEditCommands< T >::OnEditUndo)
  5661. #if (_RICHEDIT_VER >= 0x0200)
  5662. COMMAND_ID_HANDLER(ID_EDIT_REDO, OnEditRedo)
  5663. #endif //(_RICHEDIT_VER >= 0x0200)
  5664. END_MSG_MAP()
  5665. #if (_RICHEDIT_VER >= 0x0200)
  5666. LRESULT OnEditRedo(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
  5667. {
  5668. T* pT = static_cast<T*>(this);
  5669. pT->Redo();
  5670. return 0;
  5671. }
  5672. #endif //(_RICHEDIT_VER >= 0x0200)
  5673. // State (update UI) helpers
  5674. BOOL CanCut() const
  5675. { return HasSelection(); }
  5676. BOOL CanCopy() const
  5677. { return HasSelection(); }
  5678. BOOL CanClear() const
  5679. { return HasSelection(); }
  5680. // Implementation
  5681. BOOL HasSelection() const
  5682. {
  5683. const T* pT = static_cast<const T*>(this);
  5684. return (pT->GetSelectionType() != SEL_EMPTY);
  5685. }
  5686. };
  5687. /////////////////////////////////////////////////////////////////////////////
  5688. // CDragListBox
  5689. template <class TBase>
  5690. class CDragListBoxT : public CListBoxT< TBase >
  5691. {
  5692. public:
  5693. // Constructors
  5694. CDragListBoxT(HWND hWnd = NULL) : CListBoxT< TBase >(hWnd) { }
  5695. CDragListBoxT< TBase >& operator=(HWND hWnd)
  5696. {
  5697. m_hWnd = hWnd;
  5698. return *this;
  5699. }
  5700. HWND Create(HWND hWndParent, _U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
  5701. DWORD dwStyle = 0, DWORD dwExStyle = 0,
  5702. _U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
  5703. {
  5704. HWND hWnd = CWindow::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
  5705. if(hWnd != NULL)
  5706. MakeDragList();
  5707. return hWnd;
  5708. }
  5709. // Operations
  5710. BOOL MakeDragList()
  5711. {
  5712. ATLASSERT(::IsWindow(m_hWnd));
  5713. ATLASSERT((GetStyle() & (LBS_MULTIPLESEL | LBS_EXTENDEDSEL)) == 0);
  5714. return ::MakeDragList(m_hWnd);
  5715. }
  5716. int LBItemFromPt(POINT pt, BOOL bAutoScroll = TRUE)
  5717. {
  5718. ATLASSERT(::IsWindow(m_hWnd));
  5719. return ::LBItemFromPt(m_hWnd, pt, bAutoScroll);
  5720. }
  5721. void DrawInsert(int nItem)
  5722. {
  5723. ATLASSERT(::IsWindow(m_hWnd));
  5724. ::DrawInsert(GetParent(), m_hWnd, nItem);
  5725. }
  5726. static UINT GetDragListMessage()
  5727. {
  5728. static UINT uDragListMessage = 0;
  5729. if(uDragListMessage == 0)
  5730. {
  5731. ::EnterCriticalSection(&_Module.m_csStaticDataInit);
  5732. if(uDragListMessage == 0)
  5733. uDragListMessage = ::RegisterWindowMessage(DRAGLISTMSGSTRING);
  5734. ::LeaveCriticalSection(&_Module.m_csStaticDataInit);
  5735. }
  5736. ATLASSERT(uDragListMessage != 0);
  5737. return uDragListMessage;
  5738. }
  5739. };
  5740. typedef CDragListBoxT<CWindow> CDragListBox;
  5741. template <class T>
  5742. class CDragListNotifyImpl
  5743. {
  5744. public:
  5745. BEGIN_MSG_MAP(CDragListNotifyImpl< T >)
  5746. MESSAGE_HANDLER(CDragListBox::GetDragListMessage(), OnDragListNotify)
  5747. END_MSG_MAP()
  5748. LRESULT OnDragListNotify(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  5749. {
  5750. uMsg; // avoid level 4 warning
  5751. ATLASSERT(uMsg == CDragListBox::GetDragListMessage());
  5752. T* pT = static_cast<T*>(this);
  5753. LPDRAGLISTINFO lpDragListInfo = (LPDRAGLISTINFO)lParam;
  5754. LRESULT lRet = 0;
  5755. switch(lpDragListInfo->uNotification)
  5756. {
  5757. case DL_BEGINDRAG:
  5758. lRet = (LPARAM)pT->OnBeginDrag((int)wParam, lpDragListInfo->hWnd, lpDragListInfo->ptCursor);
  5759. break;
  5760. case DL_CANCELDRAG:
  5761. pT->OnCancelDrag((int)wParam, lpDragListInfo->hWnd, lpDragListInfo->ptCursor);
  5762. break;
  5763. case DL_DRAGGING:
  5764. lRet = (LPARAM)pT->OnDragging((int)wParam, lpDragListInfo->hWnd, lpDragListInfo->ptCursor);
  5765. break;
  5766. case DL_DROPPED:
  5767. pT->OnDropped((int)wParam, lpDragListInfo->hWnd, lpDragListInfo->ptCursor);
  5768. break;
  5769. default:
  5770. ATLTRACE2(atlTraceUI, 0, _T("Unknown DragListBox notification\n"));
  5771. bHandled = FALSE; // don't handle it
  5772. break;
  5773. }
  5774. return lRet;
  5775. }
  5776. // Overrideables
  5777. BOOL OnBeginDrag(int /*nCtlID*/, HWND /*hWndDragList*/, POINT /*ptCursor*/)
  5778. {
  5779. return TRUE; // allow dragging
  5780. }
  5781. void OnCancelDrag(int /*nCtlID*/, HWND /*hWndDragList*/, POINT /*ptCursor*/)
  5782. {
  5783. // nothing to do
  5784. }
  5785. int OnDragging(int /*nCtlID*/, HWND /*hWndDragList*/, POINT /*ptCursor*/)
  5786. {
  5787. return 0; // don't change cursor
  5788. }
  5789. void OnDropped(int /*nCtlID*/, HWND /*hWndDragList*/, POINT /*ptCursor*/)
  5790. {
  5791. // nothing to do
  5792. }
  5793. };
  5794. /////////////////////////////////////////////////////////////////////////////
  5795. // CReBarCtrl
  5796. template <class TBase>
  5797. class CReBarCtrlT : public TBase
  5798. {
  5799. public:
  5800. // Constructors
  5801. CReBarCtrlT(HWND hWnd = NULL) : TBase(hWnd) { }
  5802. CReBarCtrlT< TBase >& operator=(HWND hWnd)
  5803. {
  5804. m_hWnd = hWnd;
  5805. return *this;
  5806. }
  5807. HWND Create(HWND hWndParent, _U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
  5808. DWORD dwStyle = 0, DWORD dwExStyle = 0,
  5809. _U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
  5810. {
  5811. return CWindow::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
  5812. }
  5813. // Attributes
  5814. static LPCTSTR GetWndClassName()
  5815. {
  5816. return REBARCLASSNAME;
  5817. }
  5818. UINT GetBandCount() const
  5819. {
  5820. ATLASSERT(::IsWindow(m_hWnd));
  5821. return (UINT)::SendMessage(m_hWnd, RB_GETBANDCOUNT, 0, 0L);
  5822. }
  5823. BOOL GetBandInfo(int nBand, LPREBARBANDINFO lprbbi) const
  5824. {
  5825. ATLASSERT(::IsWindow(m_hWnd));
  5826. return (BOOL)::SendMessage(m_hWnd, RB_GETBANDINFO, nBand, (LPARAM)lprbbi);
  5827. }
  5828. BOOL SetBandInfo(int nBand, LPREBARBANDINFO lprbbi)
  5829. {
  5830. ATLASSERT(::IsWindow(m_hWnd));
  5831. return (BOOL)::SendMessage(m_hWnd, RB_SETBANDINFO, nBand, (LPARAM)lprbbi);
  5832. }
  5833. BOOL GetBarInfo(LPREBARINFO lprbi) const
  5834. {
  5835. ATLASSERT(::IsWindow(m_hWnd));
  5836. return (BOOL)::SendMessage(m_hWnd, RB_GETBARINFO, 0, (LPARAM)lprbi);
  5837. }
  5838. BOOL SetBarInfo(LPREBARINFO lprbi)
  5839. {
  5840. ATLASSERT(::IsWindow(m_hWnd));
  5841. return (BOOL)::SendMessage(m_hWnd, RB_SETBARINFO, 0, (LPARAM)lprbi);
  5842. }
  5843. UINT GetRowCount() const
  5844. {
  5845. ATLASSERT(::IsWindow(m_hWnd));
  5846. return (UINT)::SendMessage(m_hWnd, RB_GETROWCOUNT, 0, 0L);
  5847. }
  5848. UINT GetRowHeight(int nBand) const
  5849. {
  5850. ATLASSERT(::IsWindow(m_hWnd));
  5851. return (UINT)::SendMessage(m_hWnd, RB_GETROWHEIGHT, nBand, 0L);
  5852. }
  5853. #if (_WIN32_IE >= 0x0400)
  5854. COLORREF GetTextColor() const
  5855. {
  5856. ATLASSERT(::IsWindow(m_hWnd));
  5857. return (COLORREF)::SendMessage(m_hWnd, RB_GETTEXTCOLOR, 0, 0L);
  5858. }
  5859. COLORREF SetTextColor(COLORREF clr)
  5860. {
  5861. ATLASSERT(::IsWindow(m_hWnd));
  5862. return (COLORREF)::SendMessage(m_hWnd, RB_SETTEXTCOLOR, 0, (LPARAM)clr);
  5863. }
  5864. COLORREF GetBkColor() const
  5865. {
  5866. ATLASSERT(::IsWindow(m_hWnd));
  5867. return (COLORREF)::SendMessage(m_hWnd, RB_GETBKCOLOR, 0, 0L);
  5868. }
  5869. COLORREF SetBkColor(COLORREF clr)
  5870. {
  5871. ATLASSERT(::IsWindow(m_hWnd));
  5872. return (COLORREF)::SendMessage(m_hWnd, RB_SETBKCOLOR, 0, (LPARAM)clr);
  5873. }
  5874. UINT GetBarHeight() const
  5875. {
  5876. ATLASSERT(::IsWindow(m_hWnd));
  5877. return (UINT)::SendMessage(m_hWnd, RB_GETBARHEIGHT, 0, 0L);
  5878. }
  5879. BOOL GetRect(int nBand, LPRECT lpRect) const
  5880. {
  5881. ATLASSERT(::IsWindow(m_hWnd));
  5882. return (BOOL)::SendMessage(m_hWnd, RB_GETRECT, nBand, (LPARAM)lpRect);
  5883. }
  5884. CToolTipCtrl GetToolTips() const
  5885. {
  5886. ATLASSERT(::IsWindow(m_hWnd));
  5887. return CToolTipCtrl((HWND)::SendMessage(m_hWnd, RB_GETTOOLTIPS, 0, 0L));
  5888. }
  5889. void SetToolTips(HWND hwndToolTip)
  5890. {
  5891. ATLASSERT(::IsWindow(m_hWnd));
  5892. ::SendMessage(m_hWnd, RB_SETTOOLTIPS, (WPARAM)hwndToolTip, 0L);
  5893. }
  5894. void GetBandBorders(int nBand, LPRECT lpRect) const
  5895. {
  5896. ATLASSERT(::IsWindow(m_hWnd));
  5897. ATLASSERT(lpRect != NULL);
  5898. ::SendMessage(m_hWnd, RB_GETBANDBORDERS, nBand, (LPARAM)lpRect);
  5899. }
  5900. BOOL GetColorScheme(LPCOLORSCHEME lpColorScheme) const
  5901. {
  5902. ATLASSERT(::IsWindow(m_hWnd));
  5903. ATLASSERT(lpColorScheme != NULL);
  5904. return (BOOL)::SendMessage(m_hWnd, RB_GETCOLORSCHEME, 0, (LPARAM)lpColorScheme);
  5905. }
  5906. void SetColorScheme(LPCOLORSCHEME lpColorScheme)
  5907. {
  5908. ATLASSERT(::IsWindow(m_hWnd));
  5909. ATLASSERT(lpColorScheme != NULL);
  5910. ::SendMessage(m_hWnd, RB_SETCOLORSCHEME, 0, (LPARAM)lpColorScheme);
  5911. }
  5912. HPALETTE GetPalette() const
  5913. {
  5914. ATLASSERT(::IsWindow(m_hWnd));
  5915. return (HPALETTE)::SendMessage(m_hWnd, RB_GETPALETTE, 0, 0L);
  5916. }
  5917. HPALETTE SetPalette(HPALETTE hPalette)
  5918. {
  5919. ATLASSERT(::IsWindow(m_hWnd));
  5920. return (HPALETTE)::SendMessage(m_hWnd, RB_SETPALETTE, 0, (LPARAM)hPalette);
  5921. }
  5922. BOOL GetUnicodeFormat() const
  5923. {
  5924. ATLASSERT(::IsWindow(m_hWnd));
  5925. return (BOOL)::SendMessage(m_hWnd, RB_GETUNICODEFORMAT, 0, 0L);
  5926. }
  5927. BOOL SetUnicodeFormat(BOOL bUnicode = TRUE)
  5928. {
  5929. ATLASSERT(::IsWindow(m_hWnd));
  5930. return (BOOL)::SendMessage(m_hWnd, RB_SETUNICODEFORMAT, bUnicode, 0L);
  5931. }
  5932. #endif //(_WIN32_IE >= 0x0400)
  5933. // Operations
  5934. BOOL InsertBand(int nBand, LPREBARBANDINFO lprbbi)
  5935. {
  5936. ATLASSERT(::IsWindow(m_hWnd));
  5937. lprbbi->cbSize = sizeof(REBARBANDINFO);
  5938. return (BOOL)::SendMessage(m_hWnd, RB_INSERTBAND, nBand, (LPARAM)lprbbi);
  5939. }
  5940. BOOL DeleteBand(int nBand)
  5941. {
  5942. ATLASSERT(::IsWindow(m_hWnd));
  5943. return (BOOL)::SendMessage(m_hWnd, RB_DELETEBAND, nBand, 0L);
  5944. }
  5945. CWindow SetNotifyWnd(HWND hWnd)
  5946. {
  5947. ATLASSERT(::IsWindow(m_hWnd));
  5948. return CWindow((HWND)::SendMessage(m_hWnd, RB_SETPARENT, (WPARAM)hWnd, 0L));
  5949. }
  5950. #if (_WIN32_IE >= 0x0400)
  5951. void BeginDrag(int nBand, DWORD dwPos)
  5952. {
  5953. ATLASSERT(::IsWindow(m_hWnd));
  5954. ::SendMessage(m_hWnd, RB_BEGINDRAG, nBand, dwPos);
  5955. }
  5956. void BeginDrag(int nBand, int xPos, int yPos)
  5957. {
  5958. ATLASSERT(::IsWindow(m_hWnd));
  5959. ::SendMessage(m_hWnd, RB_BEGINDRAG, nBand, MAKELPARAM(xPos, yPos));
  5960. }
  5961. void EndDrag()
  5962. {
  5963. ATLASSERT(::IsWindow(m_hWnd));
  5964. ::SendMessage(m_hWnd, RB_ENDDRAG, 0, 0L);
  5965. }
  5966. void DragMove(DWORD dwPos)
  5967. {
  5968. ATLASSERT(::IsWindow(m_hWnd));
  5969. ::SendMessage(m_hWnd, RB_DRAGMOVE, 0, dwPos);
  5970. }
  5971. void DragMove(int xPos, int yPos)
  5972. {
  5973. ATLASSERT(::IsWindow(m_hWnd));
  5974. ::SendMessage(m_hWnd, RB_DRAGMOVE, 0, MAKELPARAM(xPos, yPos));
  5975. }
  5976. void GetDropTarget(IDropTarget** ppDropTarget) const
  5977. {
  5978. ATLASSERT(::IsWindow(m_hWnd));
  5979. ::SendMessage(m_hWnd, RB_GETDROPTARGET, 0, (LPARAM)ppDropTarget);
  5980. }
  5981. void MaximizeBand(int nBand)
  5982. {
  5983. ATLASSERT(::IsWindow(m_hWnd));
  5984. ::SendMessage(m_hWnd, RB_MAXIMIZEBAND, nBand, 0L);
  5985. }
  5986. void MinimizeBand(int nBand)
  5987. {
  5988. ATLASSERT(::IsWindow(m_hWnd));
  5989. ::SendMessage(m_hWnd, RB_MINIMIZEBAND, nBand, 0L);
  5990. }
  5991. BOOL SizeToRect(LPRECT lpRect)
  5992. {
  5993. ATLASSERT(::IsWindow(m_hWnd));
  5994. return (BOOL)::SendMessage(m_hWnd, RB_SIZETORECT, 0, (LPARAM)lpRect);
  5995. }
  5996. int IdToIndex(UINT uBandID) const
  5997. {
  5998. ATLASSERT(::IsWindow(m_hWnd));
  5999. return (int)::SendMessage(m_hWnd, RB_IDTOINDEX, uBandID, 0L);
  6000. }
  6001. int HitTest(LPRBHITTESTINFO lprbht) const
  6002. {
  6003. ATLASSERT(::IsWindow(m_hWnd));
  6004. return (int)::SendMessage(m_hWnd, RB_HITTEST, 0, (LPARAM)lprbht);
  6005. }
  6006. BOOL ShowBand(int nBand, BOOL bShow)
  6007. {
  6008. ATLASSERT(::IsWindow(m_hWnd));
  6009. return (BOOL)::SendMessage(m_hWnd, RB_SHOWBAND, nBand, bShow);
  6010. }
  6011. BOOL MoveBand(int nBand, int nNewPos)
  6012. {
  6013. ATLASSERT(::IsWindow(m_hWnd));
  6014. ATLASSERT(nNewPos >= 0 && nNewPos <= ((int)GetBandCount() - 1));
  6015. return (BOOL)::SendMessage(m_hWnd, RB_MOVEBAND, nBand, nNewPos);
  6016. }
  6017. #endif //(_WIN32_IE >= 0x0400)
  6018. #if (_WIN32_IE >= 0x0500)
  6019. void PushChevron(int nBand, LPARAM lAppValue)
  6020. {
  6021. ATLASSERT(::IsWindow(m_hWnd));
  6022. ::SendMessage(m_hWnd, RB_PUSHCHEVRON, nBand, lAppValue);
  6023. }
  6024. #endif //(_WIN32_IE >= 0x0500)
  6025. };
  6026. typedef CReBarCtrlT<CWindow> CReBarCtrl;
  6027. /////////////////////////////////////////////////////////////////////////////
  6028. // CComboBoxEx
  6029. template <class TBase>
  6030. class CComboBoxExT : public CComboBoxT< TBase >
  6031. {
  6032. public:
  6033. // Constructors
  6034. CComboBoxExT(HWND hWnd = NULL) : CComboBoxT< TBase >(hWnd) { }
  6035. CComboBoxExT< TBase >& operator=(HWND hWnd)
  6036. {
  6037. m_hWnd = hWnd;
  6038. return *this;
  6039. }
  6040. HWND Create(HWND hWndParent, _U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
  6041. DWORD dwStyle = 0, DWORD dwExStyle = 0,
  6042. _U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
  6043. {
  6044. return CWindow::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
  6045. }
  6046. // Attributes
  6047. static LPCTSTR GetWndClassName()
  6048. {
  6049. return WC_COMBOBOXEX;
  6050. }
  6051. CImageList GetImageList() const
  6052. {
  6053. ATLASSERT(::IsWindow(m_hWnd));
  6054. return CImageList((HIMAGELIST)::SendMessage(m_hWnd, CBEM_GETIMAGELIST, 0, 0L));
  6055. }
  6056. CImageList SetImageList(HIMAGELIST hImageList)
  6057. {
  6058. ATLASSERT(::IsWindow(m_hWnd));
  6059. return CImageList((HIMAGELIST)::SendMessage(m_hWnd, CBEM_SETIMAGELIST, 0, (LPARAM)hImageList));
  6060. }
  6061. #if (_WIN32_IE >= 0x0400)
  6062. DWORD GetExtendedStyle() const
  6063. {
  6064. ATLASSERT(::IsWindow(m_hWnd));
  6065. return (DWORD)::SendMessage(m_hWnd, CBEM_GETEXTENDEDSTYLE, 0, 0L);
  6066. }
  6067. DWORD SetExtendedStyle(DWORD dwExMask, DWORD dwExStyle)
  6068. {
  6069. ATLASSERT(::IsWindow(m_hWnd));
  6070. return (DWORD)::SendMessage(m_hWnd, CBEM_SETEXTENDEDSTYLE, dwExMask, dwExStyle);
  6071. }
  6072. BOOL GetUnicodeFormat() const
  6073. {
  6074. ATLASSERT(::IsWindow(m_hWnd));
  6075. return (BOOL)::SendMessage(m_hWnd, CBEM_GETUNICODEFORMAT, 0, 0L);
  6076. }
  6077. BOOL SetUnicodeFormat(BOOL bUnicode = TRUE)
  6078. {
  6079. ATLASSERT(::IsWindow(m_hWnd));
  6080. return (BOOL)::SendMessage(m_hWnd, CBEM_SETUNICODEFORMAT, bUnicode, 0L);
  6081. }
  6082. #endif //(_WIN32_IE >= 0x0400)
  6083. // Operations
  6084. int InsertItem(const COMBOBOXEXITEM FAR* lpcCBItem)
  6085. {
  6086. ATLASSERT(::IsWindow(m_hWnd));
  6087. return (int)::SendMessage(m_hWnd, CBEM_INSERTITEM, 0, (LPARAM)lpcCBItem);
  6088. }
  6089. int DeleteItem(int nIndex)
  6090. {
  6091. ATLASSERT(::IsWindow(m_hWnd));
  6092. return (int)::SendMessage(m_hWnd, CBEM_DELETEITEM, nIndex, 0L);
  6093. }
  6094. BOOL GetItem(PCOMBOBOXEXITEM pCBItem) const
  6095. {
  6096. ATLASSERT(::IsWindow(m_hWnd));
  6097. return (BOOL)::SendMessage(m_hWnd, CBEM_GETITEM, 0, (LPARAM)pCBItem);
  6098. }
  6099. BOOL SetItem(const COMBOBOXEXITEM FAR* lpcCBItem)
  6100. {
  6101. ATLASSERT(::IsWindow(m_hWnd));
  6102. return (BOOL)::SendMessage(m_hWnd, CBEM_SETITEM, 0, (LPARAM)lpcCBItem);
  6103. }
  6104. CComboBox GetComboCtrl() const
  6105. {
  6106. ATLASSERT(::IsWindow(m_hWnd));
  6107. return CComboBox((HWND)::SendMessage(m_hWnd, CBEM_GETCOMBOCONTROL, 0, 0L));
  6108. }
  6109. CEdit GetEditCtrl() const
  6110. {
  6111. ATLASSERT(::IsWindow(m_hWnd));
  6112. return CEdit((HWND)::SendMessage(m_hWnd, CBEM_GETEDITCONTROL, 0, 0L));
  6113. }
  6114. BOOL HasEditChanged() const
  6115. {
  6116. ATLASSERT(::IsWindow(m_hWnd));
  6117. return (BOOL)::SendMessage(m_hWnd, CBEM_HASEDITCHANGED, 0, 0L);
  6118. }
  6119. };
  6120. typedef CComboBoxExT<CWindow> CComboBoxEx;
  6121. /////////////////////////////////////////////////////////////////////////////
  6122. // CMonthCalendarCtrl
  6123. template <class TBase>
  6124. class CMonthCalendarCtrlT : public TBase
  6125. {
  6126. public:
  6127. // Constructors
  6128. CMonthCalendarCtrlT(HWND hWnd = NULL) : TBase(hWnd) { }
  6129. CMonthCalendarCtrlT< TBase >& operator=(HWND hWnd)
  6130. {
  6131. m_hWnd = hWnd;
  6132. return *this;
  6133. }
  6134. HWND Create(HWND hWndParent, _U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
  6135. DWORD dwStyle = 0, DWORD dwExStyle = 0,
  6136. _U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
  6137. {
  6138. return CWindow::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
  6139. }
  6140. // Attributes
  6141. static LPCTSTR GetWndClassName()
  6142. {
  6143. return MONTHCAL_CLASS;
  6144. }
  6145. COLORREF GetColor(int nColorType) const
  6146. {
  6147. ATLASSERT(::IsWindow(m_hWnd));
  6148. return (COLORREF)::SendMessage(m_hWnd, MCM_GETCOLOR, nColorType, 0L);
  6149. }
  6150. COLORREF SetColor(int nColorType, COLORREF clr)
  6151. {
  6152. ATLASSERT(::IsWindow(m_hWnd));
  6153. return (COLORREF)::SendMessage(m_hWnd, MCM_SETCOLOR, nColorType, clr);
  6154. }
  6155. BOOL GetCurSel(LPSYSTEMTIME lpSysTime) const
  6156. {
  6157. ATLASSERT(::IsWindow(m_hWnd));
  6158. return (BOOL)::SendMessage(m_hWnd, MCM_GETCURSEL, 0, (LPARAM)lpSysTime);
  6159. }
  6160. BOOL SetCurSel(LPSYSTEMTIME lpSysTime)
  6161. {
  6162. ATLASSERT(::IsWindow(m_hWnd));
  6163. return (BOOL)::SendMessage(m_hWnd, MCM_SETCURSEL, 0, (LPARAM)lpSysTime);
  6164. }
  6165. int GetFirstDayOfWeek(BOOL* pbLocaleVal = NULL) const
  6166. {
  6167. ATLASSERT(::IsWindow(m_hWnd));
  6168. DWORD dwRet = (DWORD)::SendMessage(m_hWnd, MCM_GETFIRSTDAYOFWEEK, 0, 0L);
  6169. if(pbLocaleVal != NULL)
  6170. *pbLocaleVal = (BOOL)HIWORD(dwRet);
  6171. return (int)(short)LOWORD(dwRet);
  6172. }
  6173. int SetFirstDayOfWeek(int nDay, BOOL* pbLocaleVal = NULL)
  6174. {
  6175. ATLASSERT(::IsWindow(m_hWnd));
  6176. DWORD dwRet = (DWORD)::SendMessage(m_hWnd, MCM_SETFIRSTDAYOFWEEK, 0, nDay);
  6177. if(pbLocaleVal != NULL)
  6178. *pbLocaleVal = (BOOL)HIWORD(dwRet);
  6179. return (int)(short)LOWORD(dwRet);
  6180. }
  6181. int GetMaxSelCount() const
  6182. {
  6183. ATLASSERT(::IsWindow(m_hWnd));
  6184. return (int)::SendMessage(m_hWnd, MCM_GETMAXSELCOUNT, 0, 0L);
  6185. }
  6186. BOOL SetMaxSelCount(int nMax)
  6187. {
  6188. ATLASSERT(::IsWindow(m_hWnd));
  6189. return (BOOL)::SendMessage(m_hWnd, MCM_SETMAXSELCOUNT, nMax, 0L);
  6190. }
  6191. int GetMonthDelta() const
  6192. {
  6193. ATLASSERT(::IsWindow(m_hWnd));
  6194. return (int)::SendMessage(m_hWnd, MCM_GETMONTHDELTA, 0, 0L);
  6195. }
  6196. int SetMonthDelta(int nDelta)
  6197. {
  6198. ATLASSERT(::IsWindow(m_hWnd));
  6199. return (int)::SendMessage(m_hWnd, MCM_SETMONTHDELTA, nDelta, 0L);
  6200. }
  6201. DWORD GetRange(LPSYSTEMTIME lprgSysTimeArray) const
  6202. {
  6203. ATLASSERT(::IsWindow(m_hWnd));
  6204. return (DWORD)::SendMessage(m_hWnd, MCM_GETRANGE, 0, (LPARAM)lprgSysTimeArray);
  6205. }
  6206. BOOL SetRange(DWORD dwFlags, LPSYSTEMTIME lprgSysTimeArray)
  6207. {
  6208. ATLASSERT(::IsWindow(m_hWnd));
  6209. return (BOOL)::SendMessage(m_hWnd, MCM_SETRANGE, dwFlags, (LPARAM)lprgSysTimeArray);
  6210. }
  6211. BOOL GetSelRange(LPSYSTEMTIME lprgSysTimeArray) const
  6212. {
  6213. ATLASSERT(::IsWindow(m_hWnd));
  6214. return (BOOL)::SendMessage(m_hWnd, MCM_GETSELRANGE, 0, (LPARAM)lprgSysTimeArray);
  6215. }
  6216. BOOL SetSelRange(LPSYSTEMTIME lprgSysTimeArray)
  6217. {
  6218. ATLASSERT(::IsWindow(m_hWnd));
  6219. return (BOOL)::SendMessage(m_hWnd, MCM_SETSELRANGE, 0, (LPARAM)lprgSysTimeArray);
  6220. }
  6221. BOOL GetToday(LPSYSTEMTIME lpSysTime) const
  6222. {
  6223. ATLASSERT(::IsWindow(m_hWnd));
  6224. return (BOOL)::SendMessage(m_hWnd, MCM_GETTODAY, 0, (LPARAM)lpSysTime);
  6225. }
  6226. void SetToday(LPSYSTEMTIME lpSysTime)
  6227. {
  6228. ATLASSERT(::IsWindow(m_hWnd));
  6229. ::SendMessage(m_hWnd, MCM_SETTODAY, 0, (LPARAM)lpSysTime);
  6230. }
  6231. BOOL GetMinReqRect(LPRECT lpRectInfo) const
  6232. {
  6233. ATLASSERT(::IsWindow(m_hWnd));
  6234. return (BOOL)::SendMessage(m_hWnd, MCM_GETMINREQRECT, 0, (LPARAM)lpRectInfo);
  6235. }
  6236. int GetMonthRange() const
  6237. {
  6238. ATLASSERT(::IsWindow(m_hWnd));
  6239. return (int)::SendMessage(m_hWnd, MCM_GETMAXTODAYWIDTH, 0, 0L);
  6240. }
  6241. #if (_WIN32_IE >= 0x0400)
  6242. BOOL GetUnicodeFormat() const
  6243. {
  6244. ATLASSERT(::IsWindow(m_hWnd));
  6245. return (BOOL)::SendMessage(m_hWnd, MCM_GETUNICODEFORMAT, 0, 0L);
  6246. }
  6247. BOOL SetUnicodeFormat(BOOL bUnicode = TRUE)
  6248. {
  6249. ATLASSERT(::IsWindow(m_hWnd));
  6250. return (BOOL)::SendMessage(m_hWnd, MCM_SETUNICODEFORMAT, bUnicode, 0L);
  6251. }
  6252. #endif //(_WIN32_IE >= 0x0400)
  6253. // Operations
  6254. int GetMonthRange(DWORD dwFlags, LPSYSTEMTIME lprgSysTimeArray) const
  6255. {
  6256. ATLASSERT(::IsWindow(m_hWnd));
  6257. return (int)::SendMessage(m_hWnd, MCM_GETMONTHRANGE, dwFlags, (LPARAM)lprgSysTimeArray);
  6258. }
  6259. BOOL SetDayState(int nMonths, LPMONTHDAYSTATE lpDayStateArray)
  6260. {
  6261. ATLASSERT(::IsWindow(m_hWnd));
  6262. return (BOOL)::SendMessage(m_hWnd, MCM_SETDAYSTATE, nMonths, (LPARAM)lpDayStateArray);
  6263. }
  6264. DWORD HitTest(PMCHITTESTINFO pMCHitTest) const
  6265. {
  6266. ATLASSERT(::IsWindow(m_hWnd));
  6267. return (DWORD)::SendMessage(m_hWnd, MCM_HITTEST, 0, (LPARAM)pMCHitTest);
  6268. }
  6269. };
  6270. typedef CMonthCalendarCtrlT<CWindow> CMonthCalendarCtrl;
  6271. /////////////////////////////////////////////////////////////////////////////
  6272. // CDateTimePickerCtrl
  6273. template <class TBase>
  6274. class CDateTimePickerCtrlT : public TBase
  6275. {
  6276. public:
  6277. // Constructors
  6278. CDateTimePickerCtrlT(HWND hWnd = NULL) : TBase(hWnd) { }
  6279. CDateTimePickerCtrlT< TBase >& operator=(HWND hWnd)
  6280. {
  6281. m_hWnd = hWnd;
  6282. return *this;
  6283. }
  6284. HWND Create(HWND hWndParent, _U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
  6285. DWORD dwStyle = 0, DWORD dwExStyle = 0,
  6286. _U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
  6287. {
  6288. return CWindow::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
  6289. }
  6290. // Operations
  6291. static LPCTSTR GetWndClassName()
  6292. {
  6293. return DATETIMEPICK_CLASS;
  6294. }
  6295. BOOL SetFormat(LPTSTR lpszFormat)
  6296. {
  6297. ATLASSERT(::IsWindow(m_hWnd));
  6298. return (BOOL)::SendMessage(m_hWnd, DTM_SETFORMAT, 0, (LPARAM)lpszFormat);
  6299. }
  6300. COLORREF GetMonthCalColor(int nColorType) const
  6301. {
  6302. ATLASSERT(::IsWindow(m_hWnd));
  6303. return (COLORREF)::SendMessage(m_hWnd, DTM_GETMCCOLOR, nColorType, 0L);
  6304. }
  6305. COLORREF SetMonthCalColor(int nColorType, COLORREF clr)
  6306. {
  6307. ATLASSERT(::IsWindow(m_hWnd));
  6308. return (COLORREF)::SendMessage(m_hWnd, DTM_SETMCCOLOR, nColorType, clr);
  6309. }
  6310. DWORD GetRange(LPSYSTEMTIME lpSysTimeArray) const
  6311. {
  6312. ATLASSERT(::IsWindow(m_hWnd));
  6313. return (DWORD)::SendMessage(m_hWnd, DTM_GETRANGE, 0, (LPARAM)lpSysTimeArray);
  6314. }
  6315. BOOL SetRange(DWORD dwFlags, LPSYSTEMTIME lpSysTimeArray)
  6316. {
  6317. ATLASSERT(::IsWindow(m_hWnd));
  6318. return (BOOL)::SendMessage(m_hWnd, DTM_SETRANGE, dwFlags, (LPARAM)lpSysTimeArray);
  6319. }
  6320. DWORD GetSystemTime(LPSYSTEMTIME lpSysTime) const
  6321. {
  6322. ATLASSERT(::IsWindow(m_hWnd));
  6323. return (DWORD)::SendMessage(m_hWnd, DTM_GETSYSTEMTIME, 0, (LPARAM)lpSysTime);
  6324. }
  6325. BOOL SetSystemTime(DWORD dwFlags, LPSYSTEMTIME lpSysTime)
  6326. {
  6327. ATLASSERT(::IsWindow(m_hWnd));
  6328. return (BOOL)::SendMessage(m_hWnd, DTM_SETSYSTEMTIME, dwFlags, (LPARAM)lpSysTime);
  6329. }
  6330. CMonthCalendarCtrl GetMonthCal() const
  6331. {
  6332. ATLASSERT(::IsWindow(m_hWnd));
  6333. return CMonthCalendarCtrl((HWND)::SendMessage(m_hWnd, DTM_GETMONTHCAL, 0, 0L));
  6334. }
  6335. #if (_WIN32_IE >= 0x0400)
  6336. CFontHandle GetMonthCalFont() const
  6337. {
  6338. ATLASSERT(::IsWindow(m_hWnd));
  6339. return CFontHandle((HFONT)::SendMessage(m_hWnd, DTM_GETMCFONT, 0, 0L));
  6340. }
  6341. void SetMonthCalFont(HFONT hFont, BOOL bRedraw = TRUE)
  6342. {
  6343. ATLASSERT(::IsWindow(m_hWnd));
  6344. ::SendMessage(m_hWnd, DTM_SETMCFONT, (WPARAM)hFont, MAKELPARAM(bRedraw, 0));
  6345. }
  6346. #endif //(_WIN32_IE >= 0x0400)
  6347. };
  6348. typedef CDateTimePickerCtrlT<CWindow> CDateTimePickerCtrl;
  6349. /////////////////////////////////////////////////////////////////////////////
  6350. // CFlatScrollBarImpl - support for flat scroll bars
  6351. #if (_WIN32_IE >= 0x0400)
  6352. template <class T>
  6353. class CFlatScrollBarImpl
  6354. {
  6355. public:
  6356. // Initialization
  6357. BOOL FlatSB_Initialize()
  6358. {
  6359. T* pT = static_cast<T*>(this);
  6360. ATLASSERT(::IsWindow(pT->m_hWnd));
  6361. return ::InitializeFlatSB(pT->m_hWnd);
  6362. }
  6363. HRESULT FlatSB_Uninitialize()
  6364. {
  6365. T* pT = static_cast<T*>(this);
  6366. ATLASSERT(::IsWindow(pT->m_hWnd));
  6367. return ::UninitializeFlatSB(pT->m_hWnd);
  6368. }
  6369. // Flat scroll bar properties
  6370. BOOL FlatSB_GetScrollProp(UINT uIndex, LPINT lpnValue) const
  6371. {
  6372. const T* pT = static_cast<const T*>(this);
  6373. ATLASSERT(::IsWindow(pT->m_hWnd));
  6374. return ::FlatSB_GetScrollProp(pT->m_hWnd, uIndex, lpnValue);
  6375. }
  6376. BOOL FlatSB_SetScrollProp(UINT uIndex, int nValue, BOOL bRedraw = TRUE)
  6377. {
  6378. T* pT = static_cast<T*>(this);
  6379. ATLASSERT(::IsWindow(pT->m_hWnd));
  6380. return ::FlatSB_SetScrollProp(pT->m_hWnd, uIndex, nValue, bRedraw);
  6381. }
  6382. // Attributes
  6383. int FlatSB_GetScrollPos(int nBar) const
  6384. {
  6385. const T* pT = static_cast<const T*>(this);
  6386. ATLASSERT(::IsWindow(pT->m_hWnd));
  6387. return ::FlatSB_GetScrollPos(pT->m_hWnd, nBar);
  6388. }
  6389. int FlatSB_SetScrollPos(int nBar, int nPos, BOOL bRedraw = TRUE)
  6390. {
  6391. T* pT = static_cast<T*>(this);
  6392. ATLASSERT(::IsWindow(pT->m_hWnd));
  6393. return ::FlatSB_SetScrollPos(pT->m_hWnd, nBar, nPos, bRedraw);
  6394. }
  6395. BOOL FlatSB_GetScrollRange(int nBar, LPINT lpMinPos, LPINT lpMaxPos) const
  6396. {
  6397. const T* pT = static_cast<const T*>(this);
  6398. ATLASSERT(::IsWindow(pT->m_hWnd));
  6399. return ::FlatSB_GetScrollRange(pT->m_hWnd, nBar, lpMinPos, lpMaxPos);
  6400. }
  6401. BOOL FlatSB_SetScrollRange(int nBar, int nMinPos, int nMaxPos, BOOL bRedraw = TRUE)
  6402. {
  6403. T* pT = static_cast<T*>(this);
  6404. ATLASSERT(::IsWindow(pT->m_hWnd));
  6405. return ::FlatSB_SetScrollRange(pT->m_hWnd, nBar, nMinPos, nMaxPos, bRedraw);
  6406. }
  6407. BOOL FlatSB_GetScrollInfo(int nBar, LPSCROLLINFO lpScrollInfo) const
  6408. {
  6409. const T* pT = static_cast<const T*>(this);
  6410. ATLASSERT(::IsWindow(pT->m_hWnd));
  6411. return ::FlatSB_GetScrollInfo(pT->m_hWnd, nBar, lpScrollInfo);
  6412. }
  6413. int FlatSB_SetScrollInfo(int nBar, LPSCROLLINFO lpScrollInfo, BOOL bRedraw = TRUE)
  6414. {
  6415. T* pT = static_cast<T*>(this);
  6416. ATLASSERT(::IsWindow(pT->m_hWnd));
  6417. return ::FlatSB_SetScrollInfo(pT->m_hWnd, nBar, lpScrollInfo, bRedraw);
  6418. }
  6419. // Operations
  6420. BOOL FlatSB_ShowScrollBar(UINT nBar, BOOL bShow = TRUE)
  6421. {
  6422. T* pT = static_cast<T*>(this);
  6423. ATLASSERT(::IsWindow(pT->m_hWnd));
  6424. return ::FlatSB_ShowScrollBar(pT->m_hWnd, nBar, bShow);
  6425. }
  6426. BOOL FlatSB_EnableScrollBar(UINT uSBFlags, UINT uArrowFlags = ESB_ENABLE_BOTH)
  6427. {
  6428. T* pT = static_cast<T*>(this);
  6429. ATLASSERT(::IsWindow(pT->m_hWnd));
  6430. return ::FlatSB_EnableScrollBar(pT->m_hWnd, uSBFlags, uArrowFlags);
  6431. }
  6432. };
  6433. template <class TBase>
  6434. class CFlatScrollBarT : public TBase, public CFlatScrollBarImpl<CFlatScrollBarT< TBase > >
  6435. {
  6436. public:
  6437. CFlatScrollBarT(HWND hWnd = NULL) : TBase(hWnd) { }
  6438. CFlatScrollBarT< TBase >& operator=(HWND hWnd)
  6439. {
  6440. m_hWnd = hWnd;
  6441. return *this;
  6442. }
  6443. };
  6444. typedef CFlatScrollBarT<CWindow> CFlatScrollBar;
  6445. #endif //(_WIN32_IE >= 0x0400)
  6446. /////////////////////////////////////////////////////////////////////////////
  6447. // CIPAddressCtrl
  6448. #if (_WIN32_IE >= 0x0400)
  6449. template <class TBase>
  6450. class CIPAddressCtrlT : public TBase
  6451. {
  6452. public:
  6453. // Constructors
  6454. CIPAddressCtrlT(HWND hWnd = NULL) : TBase(hWnd) { }
  6455. CIPAddressCtrlT< TBase >& operator=(HWND hWnd)
  6456. {
  6457. m_hWnd = hWnd;
  6458. return *this;
  6459. }
  6460. HWND Create(HWND hWndParent, _U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
  6461. DWORD dwStyle = 0, DWORD dwExStyle = 0,
  6462. _U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
  6463. {
  6464. return CWindow::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
  6465. }
  6466. // Atteributes
  6467. static LPCTSTR GetWndClassName()
  6468. {
  6469. return WC_IPADDRESS;
  6470. }
  6471. BOOL IsBlank() const
  6472. {
  6473. ATLASSERT(::IsWindow(m_hWnd));
  6474. return (BOOL)::SendMessage(m_hWnd, IPM_ISBLANK, 0, 0L);
  6475. }
  6476. int GetAddress(LPDWORD lpdwAddress) const
  6477. {
  6478. ATLASSERT(::IsWindow(m_hWnd));
  6479. return (int)::SendMessage(m_hWnd, IPM_GETADDRESS, 0, (LPARAM)lpdwAddress);
  6480. }
  6481. void SetAddress(DWORD dwAddress)
  6482. {
  6483. ATLASSERT(::IsWindow(m_hWnd));
  6484. ::SendMessage(m_hWnd, IPM_SETADDRESS, 0, dwAddress);
  6485. }
  6486. void ClearAddress()
  6487. {
  6488. ATLASSERT(::IsWindow(m_hWnd));
  6489. ::SendMessage(m_hWnd, IPM_CLEARADDRESS, 0, 0L);
  6490. }
  6491. void SetRange(int nField, WORD wRange)
  6492. {
  6493. ATLASSERT(::IsWindow(m_hWnd));
  6494. ::SendMessage(m_hWnd, IPM_SETRANGE, nField, wRange);
  6495. }
  6496. void SetRange(int nField, BYTE nMin, BYTE nMax)
  6497. {
  6498. ATLASSERT(::IsWindow(m_hWnd));
  6499. ::SendMessage(m_hWnd, IPM_SETRANGE, nField, MAKEIPRANGE(nMin, nMax));
  6500. }
  6501. void SetFocus(int nField)
  6502. {
  6503. ATLASSERT(::IsWindow(m_hWnd));
  6504. ::SendMessage(m_hWnd, IPM_SETFOCUS, nField, 0L);
  6505. }
  6506. };
  6507. typedef CIPAddressCtrlT<CWindow> CIPAddressCtrl;
  6508. #endif //(_WIN32_IE >= 0x0400)
  6509. /////////////////////////////////////////////////////////////////////////////
  6510. // CPagerCtrl
  6511. #if (_WIN32_IE >= 0x0400)
  6512. template <class TBase>
  6513. class CPagerCtrlT : public TBase
  6514. {
  6515. public:
  6516. // Constructors
  6517. CPagerCtrlT(HWND hWnd = NULL) : TBase(hWnd) { }
  6518. CPagerCtrlT< TBase >& operator=(HWND hWnd)
  6519. {
  6520. m_hWnd = hWnd;
  6521. return *this;
  6522. }
  6523. HWND Create(HWND hWndParent, _U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
  6524. DWORD dwStyle = 0, DWORD dwExStyle = 0,
  6525. _U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
  6526. {
  6527. return CWindow::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
  6528. }
  6529. // Attributes
  6530. static LPCTSTR GetWndClassName()
  6531. {
  6532. return WC_PAGESCROLLER;
  6533. }
  6534. int GetButtonSize() const
  6535. {
  6536. ATLASSERT(::IsWindow(m_hWnd));
  6537. return (int)::SendMessage(m_hWnd, PGM_GETBUTTONSIZE, 0, 0L);
  6538. }
  6539. int SetButtonSize(int nButtonSize)
  6540. {
  6541. ATLASSERT(::IsWindow(m_hWnd));
  6542. return (int)::SendMessage(m_hWnd, PGM_SETBUTTONSIZE, 0, nButtonSize);
  6543. }
  6544. DWORD GetButtonState(int nButton) const
  6545. {
  6546. ATLASSERT(::IsWindow(m_hWnd));
  6547. ATLASSERT(nButton == PGB_TOPORLEFT || nButton == PGB_BOTTOMORRIGHT);
  6548. return (DWORD)::SendMessage(m_hWnd, PGM_GETBUTTONSTATE, 0, nButton);
  6549. }
  6550. COLORREF GetBkColor() const
  6551. {
  6552. ATLASSERT(::IsWindow(m_hWnd));
  6553. return (COLORREF)::SendMessage(m_hWnd, PGM_GETBKCOLOR, 0, 0L);
  6554. }
  6555. COLORREF SetBkColor(COLORREF clrBk)
  6556. {
  6557. ATLASSERT(::IsWindow(m_hWnd));
  6558. return (COLORREF)::SendMessage(m_hWnd, PGM_SETBKCOLOR, 0, (LPARAM)clrBk);
  6559. }
  6560. int GetBorder() const
  6561. {
  6562. ATLASSERT(::IsWindow(m_hWnd));
  6563. return (int)::SendMessage(m_hWnd, PGM_GETBORDER, 0, 0L);
  6564. }
  6565. int SetBorder(int nBorderSize)
  6566. {
  6567. ATLASSERT(::IsWindow(m_hWnd));
  6568. return (int)::SendMessage(m_hWnd, PGM_SETBORDER, 0, nBorderSize);
  6569. }
  6570. int GetPos() const
  6571. {
  6572. ATLASSERT(::IsWindow(m_hWnd));
  6573. return (int)::SendMessage(m_hWnd, PGM_GETPOS, 0, 0L);
  6574. }
  6575. int SetPos(int nPos)
  6576. {
  6577. ATLASSERT(::IsWindow(m_hWnd));
  6578. return (int)::SendMessage(m_hWnd, PGM_SETPOS, 0, nPos);
  6579. }
  6580. // Operations
  6581. void SetChild(HWND hWndChild)
  6582. {
  6583. ATLASSERT(::IsWindow(m_hWnd));
  6584. ::SendMessage(m_hWnd, PGM_SETCHILD, 0, (LPARAM)hWndChild);
  6585. }
  6586. void ForwardMouse(BOOL bForward = TRUE)
  6587. {
  6588. ATLASSERT(::IsWindow(m_hWnd));
  6589. ::SendMessage(m_hWnd, PGM_FORWARDMOUSE, bForward, 0L);
  6590. }
  6591. void RecalcSize()
  6592. {
  6593. ATLASSERT(::IsWindow(m_hWnd));
  6594. ::SendMessage(m_hWnd, PGM_RECALCSIZE, 0, 0L);
  6595. }
  6596. void GetDropTarget(IDropTarget** ppDropTarget)
  6597. {
  6598. ATLASSERT(::IsWindow(m_hWnd));
  6599. ATLASSERT(ppDropTarget != NULL);
  6600. ::SendMessage(m_hWnd, PGM_GETDROPTARGET, 0, (LPARAM)ppDropTarget);
  6601. }
  6602. };
  6603. typedef CPagerCtrlT<CWindow> CPagerCtrl;
  6604. #endif //(_WIN32_IE >= 0x0400)
  6605. /////////////////////////////////////////////////////////////////////////////
  6606. // CCustomDraw - MI class for custom-draw support
  6607. template <class T>
  6608. class CCustomDraw
  6609. {
  6610. public:
  6611. #if !defined(_ATL_TMP_IMPL1) && !defined(_ATL_TMP_IMPL2)
  6612. BOOL m_bHandledCD;
  6613. BOOL IsMsgHandled() const
  6614. {
  6615. return m_bHandledCD;
  6616. }
  6617. void SetMsgHandled(BOOL bHandled)
  6618. {
  6619. m_bHandledCD = bHandled;
  6620. }
  6621. #endif //!defined(_ATL_TMP_IMPL1) && !defined(_ATL_TMP_IMPL2)
  6622. // Message map and handlers
  6623. BEGIN_MSG_MAP(CCustomDraw< T >)
  6624. NOTIFY_CODE_HANDLER(NM_CUSTOMDRAW, OnCustomDraw)
  6625. ALT_MSG_MAP(1)
  6626. REFLECTED_NOTIFY_CODE_HANDLER(NM_CUSTOMDRAW, OnCustomDraw)
  6627. END_MSG_MAP()
  6628. // message handler
  6629. LRESULT OnCustomDraw(int idCtrl, LPNMHDR pnmh, BOOL& bHandled)
  6630. {
  6631. T* pT = static_cast<T*>(this);
  6632. pT->SetMsgHandled(TRUE);
  6633. LPNMCUSTOMDRAW lpNMCustomDraw = (LPNMCUSTOMDRAW)pnmh;
  6634. DWORD dwRet = 0;
  6635. switch(lpNMCustomDraw->dwDrawStage)
  6636. {
  6637. case CDDS_PREPAINT:
  6638. dwRet = pT->OnPrePaint(idCtrl, lpNMCustomDraw);
  6639. break;
  6640. case CDDS_POSTPAINT:
  6641. dwRet = pT->OnPostPaint(idCtrl, lpNMCustomDraw);
  6642. break;
  6643. case CDDS_PREERASE:
  6644. dwRet = pT->OnPreErase(idCtrl, lpNMCustomDraw);
  6645. break;
  6646. case CDDS_POSTERASE:
  6647. dwRet = pT->OnPostErase(idCtrl, lpNMCustomDraw);
  6648. break;
  6649. case CDDS_ITEMPREPAINT:
  6650. dwRet = pT->OnItemPrePaint(idCtrl, lpNMCustomDraw);
  6651. break;
  6652. case CDDS_ITEMPOSTPAINT:
  6653. dwRet = pT->OnItemPostPaint(idCtrl, lpNMCustomDraw);
  6654. break;
  6655. case CDDS_ITEMPREERASE:
  6656. dwRet = pT->OnItemPreErase(idCtrl, lpNMCustomDraw);
  6657. break;
  6658. case CDDS_ITEMPOSTERASE:
  6659. dwRet = pT->OnItemPostErase(idCtrl, lpNMCustomDraw);
  6660. break;
  6661. default:
  6662. pT->SetMsgHandled(FALSE);
  6663. break;
  6664. }
  6665. bHandled = pT->IsMsgHandled();
  6666. return dwRet;
  6667. }
  6668. // Overrideables
  6669. DWORD OnPrePaint(int /*idCtrl*/, LPNMCUSTOMDRAW /*lpNMCustomDraw*/)
  6670. {
  6671. return CDRF_DODEFAULT;
  6672. }
  6673. DWORD OnPostPaint(int /*idCtrl*/, LPNMCUSTOMDRAW /*lpNMCustomDraw*/)
  6674. {
  6675. return CDRF_DODEFAULT;
  6676. }
  6677. DWORD OnPreErase(int /*idCtrl*/, LPNMCUSTOMDRAW /*lpNMCustomDraw*/)
  6678. {
  6679. return CDRF_DODEFAULT;
  6680. }
  6681. DWORD OnPostErase(int /*idCtrl*/, LPNMCUSTOMDRAW /*lpNMCustomDraw*/)
  6682. {
  6683. return CDRF_DODEFAULT;
  6684. }
  6685. DWORD OnItemPrePaint(int /*idCtrl*/, LPNMCUSTOMDRAW /*lpNMCustomDraw*/)
  6686. {
  6687. return CDRF_DODEFAULT;
  6688. }
  6689. DWORD OnItemPostPaint(int /*idCtrl*/, LPNMCUSTOMDRAW /*lpNMCustomDraw*/)
  6690. {
  6691. return CDRF_DODEFAULT;
  6692. }
  6693. DWORD OnItemPreErase(int /*idCtrl*/, LPNMCUSTOMDRAW /*lpNMCustomDraw*/)
  6694. {
  6695. return CDRF_DODEFAULT;
  6696. }
  6697. DWORD OnItemPostErase(int /*idCtrl*/, LPNMCUSTOMDRAW /*lpNMCustomDraw*/)
  6698. {
  6699. return CDRF_DODEFAULT;
  6700. }
  6701. };
  6702. }; //namespace WTL
  6703. #endif // __ATLCTRLS_H__