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.

6134 lines
195 KiB

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