/thirdparty/wtl/atlctrls.h

http://crashrpt.googlecode.com/ · C Header · 10033 lines · 8164 code · 1548 blank · 321 comment · 433 complexity · 568a835c698d37e8daf2a4b28c1f5c17 MD5 · raw file

Large files are truncated click here to view the full file

  1. // Windows Template Library - WTL version 8.1
  2. // Copyright (C) Microsoft Corporation. All rights reserved.
  3. //
  4. // This file is a part of the Windows Template Library.
  5. // The use and distribution terms for this software are covered by the
  6. // Common Public License 1.0 (http://opensource.org/licenses/cpl1.0.php)
  7. // which can be found in the file CPL.TXT at the root of this distribution.
  8. // By using this software in any fashion, you are agreeing to be bound by
  9. // the terms of this license. You must not remove this notice, or
  10. // any other, from this software.
  11. #ifndef __ATLCTRLS_H__
  12. #define __ATLCTRLS_H__
  13. #pragma once
  14. #ifndef __ATLAPP_H__
  15. #error atlctrls.h requires atlapp.h to be included first
  16. #endif
  17. #ifndef __ATLWIN_H__
  18. #error atlctrls.h requires atlwin.h to be included first
  19. #endif
  20. #ifndef _WIN32_WCE
  21. #include <richedit.h>
  22. #include <richole.h>
  23. #elif defined(WIN32_PLATFORM_WFSP) && !defined(_WINUSERM_H_)
  24. #include <winuserm.h>
  25. #endif // !_WIN32_WCE
  26. // protect template members from windowsx.h macros
  27. #ifdef _INC_WINDOWSX
  28. #undef GetNextSibling
  29. #undef GetPrevSibling
  30. #endif // _INC_WINDOWSX
  31. ///////////////////////////////////////////////////////////////////////////////
  32. // Classes in this file:
  33. //
  34. // CStaticT<TBase> - CStatic
  35. // CButtonT<TBase> - CButton
  36. // CListBoxT<TBase> - CListBox
  37. // CComboBoxT<TBase> - CComboBox
  38. // CEditT<TBase> - CEdit
  39. // CEditCommands<T>
  40. // CScrollBarT<TBase> - CScrollBar
  41. //
  42. // CImageList
  43. // CListViewCtrlT<TBase> - CListViewCtrl
  44. // CTreeViewCtrlT<TBase> - CTreeViewCtrl
  45. // CTreeItemT<TBase> - CTreeItem
  46. // CTreeViewCtrlExT<TBase> - CTreeViewCtrlEx
  47. // CHeaderCtrlT<TBase> - CHeaderCtrl
  48. // CToolBarCtrlT<TBase> - CToolBarCtrl
  49. // CStatusBarCtrlT<TBase> - CStatusBarCtrl
  50. // CTabCtrlT<TBase> - CTabCtrl
  51. // CToolInfo
  52. // CToolTipCtrlT<TBase> - CToolTipCtrl
  53. // CTrackBarCtrlT<TBase> - CTrackBarCtrl
  54. // CUpDownCtrlT<TBase> - CUpDownCtrl
  55. // CProgressBarCtrlT<TBase> - CProgressBarCtrl
  56. // CHotKeyCtrlT<TBase> - CHotKeyCtrl
  57. // CAnimateCtrlT<TBase> - CAnimateCtrl
  58. // CRichEditCtrlT<TBase> - CRichEditCtrl
  59. // CRichEditCommands<T>
  60. // CDragListBoxT<TBase> - CDragListBox
  61. // CDragListNotifyImpl<T>
  62. // CReBarCtrlT<TBase> - CReBarCtrl
  63. // CComboBoxExT<TBase> - CComboBoxEx
  64. // CDateTimePickerCtrlT<TBase> - CDateTimePickerCtrl
  65. // CMonthCalendarCtrlT<TBase> - CMonthCalendarCtrl
  66. // CFlatScrollBarImpl<T>
  67. // CFlatScrollBarT<TBase> - CFlatScrollBar
  68. // CIPAddressCtrlT<TBase> - CIPAddressCtrl
  69. // CPagerCtrlT<TBase> - CPagerCtrl
  70. // CLinkCtrlT<TBase> - CLinkCtrl
  71. //
  72. // CCustomDraw<T>
  73. //
  74. // CCECommandBarCtrlT<TBase> - CCECommandBarCtrl
  75. // CCECommandBandsCtrlT<TBase> - CCECommandBandsCtrl
  76. namespace WTL
  77. {
  78. // These are wrapper classes for Windows standard and common controls.
  79. // To implement a window based on a control, use following:
  80. // Example: Implementing a window based on a list box
  81. //
  82. // class CMyListBox : CWindowImpl<CMyListBox, CListBox>
  83. // {
  84. // public:
  85. // BEGIN_MSG_MAP(CMyListBox)
  86. // // put your message handler entries here
  87. // END_MSG_MAP()
  88. // };
  89. // --- Standard Windows controls ---
  90. ///////////////////////////////////////////////////////////////////////////////
  91. // CStatic - client side for a Windows STATIC control
  92. template <class TBase>
  93. class CStaticT : public TBase
  94. {
  95. public:
  96. // Constructors
  97. CStaticT(HWND hWnd = NULL) : TBase(hWnd)
  98. { }
  99. CStaticT< TBase >& operator =(HWND hWnd)
  100. {
  101. m_hWnd = hWnd;
  102. return *this;
  103. }
  104. HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
  105. DWORD dwStyle = 0, DWORD dwExStyle = 0,
  106. ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
  107. {
  108. return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
  109. }
  110. // Attributes
  111. static LPCTSTR GetWndClassName()
  112. {
  113. return _T("STATIC");
  114. }
  115. #ifndef _WIN32_WCE
  116. HICON GetIcon() const
  117. {
  118. ATLASSERT(::IsWindow(m_hWnd));
  119. return (HICON)::SendMessage(m_hWnd, STM_GETICON, 0, 0L);
  120. }
  121. HICON SetIcon(HICON hIcon)
  122. {
  123. ATLASSERT(::IsWindow(m_hWnd));
  124. return (HICON)::SendMessage(m_hWnd, STM_SETICON, (WPARAM)hIcon, 0L);
  125. }
  126. HENHMETAFILE GetEnhMetaFile() const
  127. {
  128. ATLASSERT(::IsWindow(m_hWnd));
  129. return (HENHMETAFILE)::SendMessage(m_hWnd, STM_GETIMAGE, IMAGE_ENHMETAFILE, 0L);
  130. }
  131. HENHMETAFILE SetEnhMetaFile(HENHMETAFILE hMetaFile)
  132. {
  133. ATLASSERT(::IsWindow(m_hWnd));
  134. return (HENHMETAFILE)::SendMessage(m_hWnd, STM_SETIMAGE, IMAGE_ENHMETAFILE, (LPARAM)hMetaFile);
  135. }
  136. #else // CE specific
  137. HICON GetIcon() const
  138. {
  139. ATLASSERT(::IsWindow(m_hWnd));
  140. return (HICON)::SendMessage(m_hWnd, STM_GETIMAGE, IMAGE_ICON, 0L);
  141. }
  142. HICON SetIcon(HICON hIcon)
  143. {
  144. ATLASSERT(::IsWindow(m_hWnd));
  145. return (HICON)::SendMessage(m_hWnd, STM_SETIMAGE, IMAGE_ICON, (LPARAM)hIcon);
  146. }
  147. #endif // _WIN32_WCE
  148. CBitmapHandle GetBitmap() const
  149. {
  150. ATLASSERT(::IsWindow(m_hWnd));
  151. return CBitmapHandle((HBITMAP)::SendMessage(m_hWnd, STM_GETIMAGE, IMAGE_BITMAP, 0L));
  152. }
  153. CBitmapHandle SetBitmap(HBITMAP hBitmap)
  154. {
  155. ATLASSERT(::IsWindow(m_hWnd));
  156. return CBitmapHandle((HBITMAP)::SendMessage(m_hWnd, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBitmap));
  157. }
  158. HCURSOR GetCursor() const
  159. {
  160. ATLASSERT(::IsWindow(m_hWnd));
  161. return (HCURSOR)::SendMessage(m_hWnd, STM_GETIMAGE, IMAGE_CURSOR, 0L);
  162. }
  163. HCURSOR SetCursor(HCURSOR hCursor)
  164. {
  165. ATLASSERT(::IsWindow(m_hWnd));
  166. return (HCURSOR)::SendMessage(m_hWnd, STM_SETIMAGE, IMAGE_CURSOR, (LPARAM)hCursor);
  167. }
  168. };
  169. typedef CStaticT<ATL::CWindow> CStatic;
  170. ///////////////////////////////////////////////////////////////////////////////
  171. // CButton - client side for a Windows BUTTON control
  172. template <class TBase>
  173. class CButtonT : public TBase
  174. {
  175. public:
  176. // Constructors
  177. CButtonT(HWND hWnd = NULL) : TBase(hWnd)
  178. { }
  179. CButtonT< TBase >& operator =(HWND hWnd)
  180. {
  181. m_hWnd = hWnd;
  182. return *this;
  183. }
  184. HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
  185. DWORD dwStyle = 0, DWORD dwExStyle = 0,
  186. ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
  187. {
  188. return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
  189. }
  190. // Attributes
  191. static LPCTSTR GetWndClassName()
  192. {
  193. return _T("BUTTON");
  194. }
  195. UINT GetState() const
  196. {
  197. ATLASSERT(::IsWindow(m_hWnd));
  198. return (UINT)::SendMessage(m_hWnd, BM_GETSTATE, 0, 0L);
  199. }
  200. void SetState(BOOL bHighlight)
  201. {
  202. ATLASSERT(::IsWindow(m_hWnd));
  203. ::SendMessage(m_hWnd, BM_SETSTATE, bHighlight, 0L);
  204. }
  205. int GetCheck() const
  206. {
  207. ATLASSERT(::IsWindow(m_hWnd));
  208. return (int)::SendMessage(m_hWnd, BM_GETCHECK, 0, 0L);
  209. }
  210. void SetCheck(int nCheck)
  211. {
  212. ATLASSERT(::IsWindow(m_hWnd));
  213. ::SendMessage(m_hWnd, BM_SETCHECK, nCheck, 0L);
  214. }
  215. UINT GetButtonStyle() const
  216. {
  217. ATLASSERT(::IsWindow(m_hWnd));
  218. return (UINT)::GetWindowLong(m_hWnd, GWL_STYLE) & 0xFFFF;
  219. }
  220. void SetButtonStyle(UINT nStyle, BOOL bRedraw = TRUE)
  221. {
  222. ATLASSERT(::IsWindow(m_hWnd));
  223. ::SendMessage(m_hWnd, BM_SETSTYLE, nStyle, (LPARAM)bRedraw);
  224. }
  225. #ifndef _WIN32_WCE
  226. HICON GetIcon() const
  227. {
  228. ATLASSERT(::IsWindow(m_hWnd));
  229. return (HICON)::SendMessage(m_hWnd, BM_GETIMAGE, IMAGE_ICON, 0L);
  230. }
  231. HICON SetIcon(HICON hIcon)
  232. {
  233. ATLASSERT(::IsWindow(m_hWnd));
  234. return (HICON)::SendMessage(m_hWnd, BM_SETIMAGE, IMAGE_ICON, (LPARAM)hIcon);
  235. }
  236. CBitmapHandle GetBitmap() const
  237. {
  238. ATLASSERT(::IsWindow(m_hWnd));
  239. return CBitmapHandle((HBITMAP)::SendMessage(m_hWnd, BM_GETIMAGE, IMAGE_BITMAP, 0L));
  240. }
  241. CBitmapHandle SetBitmap(HBITMAP hBitmap)
  242. {
  243. ATLASSERT(::IsWindow(m_hWnd));
  244. return CBitmapHandle((HBITMAP)::SendMessage(m_hWnd, BM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBitmap));
  245. }
  246. #endif // !_WIN32_WCE
  247. #if (_WIN32_WINNT >= 0x0501)
  248. BOOL GetIdealSize(LPSIZE lpSize) const
  249. {
  250. ATLASSERT(::IsWindow(m_hWnd));
  251. return (BOOL)::SendMessage(m_hWnd, BCM_GETIDEALSIZE, 0, (LPARAM)lpSize);
  252. }
  253. BOOL GetImageList(PBUTTON_IMAGELIST pButtonImagelist) const
  254. {
  255. ATLASSERT(::IsWindow(m_hWnd));
  256. return (BOOL)::SendMessage(m_hWnd, BCM_GETIMAGELIST, 0, (LPARAM)pButtonImagelist);
  257. }
  258. BOOL SetImageList(PBUTTON_IMAGELIST pButtonImagelist)
  259. {
  260. ATLASSERT(::IsWindow(m_hWnd));
  261. return (BOOL)::SendMessage(m_hWnd, BCM_SETIMAGELIST, 0, (LPARAM)pButtonImagelist);
  262. }
  263. BOOL GetTextMargin(LPRECT lpRect) const
  264. {
  265. ATLASSERT(::IsWindow(m_hWnd));
  266. return (BOOL)::SendMessage(m_hWnd, BCM_GETTEXTMARGIN, 0, (LPARAM)lpRect);
  267. }
  268. BOOL SetTextMargin(LPRECT lpRect)
  269. {
  270. ATLASSERT(::IsWindow(m_hWnd));
  271. return (BOOL)::SendMessage(m_hWnd, BCM_SETTEXTMARGIN, 0, (LPARAM)lpRect);
  272. }
  273. #endif // (_WIN32_WINNT >= 0x0501)
  274. #if (WINVER >= 0x0600)
  275. void SetDontClick(BOOL bDontClick)
  276. {
  277. ATLASSERT(::IsWindow(m_hWnd));
  278. ::SendMessage(m_hWnd, BM_SETDONTCLICK, (WPARAM)bDontClick, 0L);
  279. }
  280. #endif // (WINVER >= 0x0600)
  281. #if (_WIN32_WINNT >= 0x0600)
  282. BOOL SetDropDownState(BOOL bDropDown)
  283. {
  284. ATLASSERT(::IsWindow(m_hWnd));
  285. ATLASSERT((GetStyle() & (BS_SPLITBUTTON | BS_DEFSPLITBUTTON)) != 0);
  286. return (BOOL)::SendMessage(m_hWnd, BCM_SETDROPDOWNSTATE, (WPARAM)bDropDown, 0L);
  287. }
  288. BOOL GetSplitInfo(PBUTTON_SPLITINFO pSplitInfo) const
  289. {
  290. ATLASSERT(::IsWindow(m_hWnd));
  291. ATLASSERT((GetStyle() & (BS_SPLITBUTTON | BS_DEFSPLITBUTTON)) != 0);
  292. return (BOOL)::SendMessage(m_hWnd, BCM_GETSPLITINFO, 0, (LPARAM)pSplitInfo);
  293. }
  294. BOOL SetSplitInfo(PBUTTON_SPLITINFO pSplitInfo)
  295. {
  296. ATLASSERT(::IsWindow(m_hWnd));
  297. ATLASSERT((GetStyle() & (BS_SPLITBUTTON | BS_DEFSPLITBUTTON)) != 0);
  298. return (BOOL)::SendMessage(m_hWnd, BCM_SETSPLITINFO, 0, (LPARAM)pSplitInfo);
  299. }
  300. int GetNoteLength() const
  301. {
  302. ATLASSERT(::IsWindow(m_hWnd));
  303. ATLASSERT((GetStyle() & (BS_COMMANDLINK | BS_DEFCOMMANDLINK)) != 0);
  304. return (int)::SendMessage(m_hWnd, BCM_GETNOTELENGTH, 0, 0L);
  305. }
  306. BOOL GetNote(LPWSTR lpstrNoteText, int cchNoteText) const
  307. {
  308. ATLASSERT(::IsWindow(m_hWnd));
  309. ATLASSERT((GetStyle() & (BS_COMMANDLINK | BS_DEFCOMMANDLINK)) != 0);
  310. return (BOOL)::SendMessage(m_hWnd, BCM_GETNOTE, cchNoteText, (LPARAM)lpstrNoteText);
  311. }
  312. BOOL SetNote(LPCWSTR lpstrNoteText)
  313. {
  314. ATLASSERT(::IsWindow(m_hWnd));
  315. ATLASSERT((GetStyle() & (BS_COMMANDLINK | BS_DEFCOMMANDLINK)) != 0);
  316. return (BOOL)::SendMessage(m_hWnd, BCM_SETNOTE, 0, (LPARAM)lpstrNoteText);
  317. }
  318. LRESULT SetElevationRequiredState(BOOL bSet)
  319. {
  320. ATLASSERT(::IsWindow(m_hWnd));
  321. return ::SendMessage(m_hWnd, BCM_SETSHIELD, 0, (LPARAM)bSet);
  322. }
  323. #endif // (_WIN32_WINNT >= 0x0600)
  324. // Operations
  325. void Click()
  326. {
  327. ATLASSERT(::IsWindow(m_hWnd));
  328. ::SendMessage(m_hWnd, BM_CLICK, 0, 0L);
  329. }
  330. };
  331. typedef CButtonT<ATL::CWindow> CButton;
  332. ///////////////////////////////////////////////////////////////////////////////
  333. // CListBox - client side for a Windows LISTBOX control
  334. template <class TBase>
  335. class CListBoxT : public TBase
  336. {
  337. public:
  338. // Constructors
  339. CListBoxT(HWND hWnd = NULL) : TBase(hWnd)
  340. { }
  341. CListBoxT< TBase >& operator =(HWND hWnd)
  342. {
  343. m_hWnd = hWnd;
  344. return *this;
  345. }
  346. HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
  347. DWORD dwStyle = 0, DWORD dwExStyle = 0,
  348. ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
  349. {
  350. return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
  351. }
  352. // Attributes
  353. static LPCTSTR GetWndClassName()
  354. {
  355. return _T("LISTBOX");
  356. }
  357. // for entire listbox
  358. int GetCount() const
  359. {
  360. ATLASSERT(::IsWindow(m_hWnd));
  361. return (int)::SendMessage(m_hWnd, LB_GETCOUNT, 0, 0L);
  362. }
  363. #ifndef _WIN32_WCE
  364. int SetCount(int cItems)
  365. {
  366. ATLASSERT(::IsWindow(m_hWnd));
  367. ATLASSERT(((GetStyle() & LBS_NODATA) != 0) && ((GetStyle() & LBS_HASSTRINGS) == 0));
  368. return (int)::SendMessage(m_hWnd, LB_SETCOUNT, cItems, 0L);
  369. }
  370. #endif // !_WIN32_WCE
  371. int GetHorizontalExtent() const
  372. {
  373. ATLASSERT(::IsWindow(m_hWnd));
  374. return (int)::SendMessage(m_hWnd, LB_GETHORIZONTALEXTENT, 0, 0L);
  375. }
  376. void SetHorizontalExtent(int cxExtent)
  377. {
  378. ATLASSERT(::IsWindow(m_hWnd));
  379. ::SendMessage(m_hWnd, LB_SETHORIZONTALEXTENT, cxExtent, 0L);
  380. }
  381. int GetTopIndex() const
  382. {
  383. ATLASSERT(::IsWindow(m_hWnd));
  384. return (int)::SendMessage(m_hWnd, LB_GETTOPINDEX, 0, 0L);
  385. }
  386. int SetTopIndex(int nIndex)
  387. {
  388. ATLASSERT(::IsWindow(m_hWnd));
  389. return (int)::SendMessage(m_hWnd, LB_SETTOPINDEX, nIndex, 0L);
  390. }
  391. LCID GetLocale() const
  392. {
  393. ATLASSERT(::IsWindow(m_hWnd));
  394. return (LCID)::SendMessage(m_hWnd, LB_GETLOCALE, 0, 0L);
  395. }
  396. LCID SetLocale(LCID nNewLocale)
  397. {
  398. ATLASSERT(::IsWindow(m_hWnd));
  399. return (LCID)::SendMessage(m_hWnd, LB_SETLOCALE, (WPARAM)nNewLocale, 0L);
  400. }
  401. #if (WINVER >= 0x0500) && !defined(_WIN32_WCE)
  402. DWORD GetListBoxInfo() const
  403. {
  404. ATLASSERT(::IsWindow(m_hWnd));
  405. #if (_WIN32_WINNT >= 0x0501)
  406. return (DWORD)::SendMessage(m_hWnd, LB_GETLISTBOXINFO, 0, 0L);
  407. #else // !(_WIN32_WINNT >= 0x0501)
  408. return ::GetListBoxInfo(m_hWnd);
  409. #endif // !(_WIN32_WINNT >= 0x0501)
  410. }
  411. #endif // (WINVER >= 0x0500) && !defined(_WIN32_WCE)
  412. // for single-selection listboxes
  413. int GetCurSel() const
  414. {
  415. ATLASSERT(::IsWindow(m_hWnd));
  416. ATLASSERT((GetStyle() & (LBS_MULTIPLESEL | LBS_EXTENDEDSEL)) == 0);
  417. return (int)::SendMessage(m_hWnd, LB_GETCURSEL, 0, 0L);
  418. }
  419. int SetCurSel(int nSelect)
  420. {
  421. ATLASSERT(::IsWindow(m_hWnd));
  422. ATLASSERT((GetStyle() & (LBS_MULTIPLESEL | LBS_EXTENDEDSEL)) == 0);
  423. return (int)::SendMessage(m_hWnd, LB_SETCURSEL, nSelect, 0L);
  424. }
  425. // for multiple-selection listboxes
  426. int GetSel(int nIndex) const // also works for single-selection
  427. {
  428. ATLASSERT(::IsWindow(m_hWnd));
  429. return (int)::SendMessage(m_hWnd, LB_GETSEL, nIndex, 0L);
  430. }
  431. int SetSel(int nIndex, BOOL bSelect = TRUE)
  432. {
  433. ATLASSERT(::IsWindow(m_hWnd));
  434. ATLASSERT((GetStyle() & (LBS_MULTIPLESEL | LBS_EXTENDEDSEL)) != 0);
  435. return (int)::SendMessage(m_hWnd, LB_SETSEL, bSelect, nIndex);
  436. }
  437. int GetSelCount() const
  438. {
  439. ATLASSERT(::IsWindow(m_hWnd));
  440. ATLASSERT((GetStyle() & (LBS_MULTIPLESEL | LBS_EXTENDEDSEL)) != 0);
  441. return (int)::SendMessage(m_hWnd, LB_GETSELCOUNT, 0, 0L);
  442. }
  443. int GetSelItems(int nMaxItems, LPINT rgIndex) const
  444. {
  445. ATLASSERT(::IsWindow(m_hWnd));
  446. ATLASSERT((GetStyle() & (LBS_MULTIPLESEL | LBS_EXTENDEDSEL)) != 0);
  447. return (int)::SendMessage(m_hWnd, LB_GETSELITEMS, nMaxItems, (LPARAM)rgIndex);
  448. }
  449. int GetAnchorIndex() const
  450. {
  451. ATLASSERT(::IsWindow(m_hWnd));
  452. ATLASSERT((GetStyle() & (LBS_MULTIPLESEL | LBS_EXTENDEDSEL)) != 0);
  453. return (int)::SendMessage(m_hWnd, LB_GETANCHORINDEX, 0, 0L);
  454. }
  455. void SetAnchorIndex(int nIndex)
  456. {
  457. ATLASSERT(::IsWindow(m_hWnd));
  458. ATLASSERT((GetStyle() & (LBS_MULTIPLESEL | LBS_EXTENDEDSEL)) != 0);
  459. ::SendMessage(m_hWnd, LB_SETANCHORINDEX, nIndex, 0L);
  460. }
  461. int GetCaretIndex() const
  462. {
  463. ATLASSERT(::IsWindow(m_hWnd));
  464. return (int)::SendMessage(m_hWnd, LB_GETCARETINDEX, 0, 0);
  465. }
  466. int SetCaretIndex(int nIndex, BOOL bScroll = TRUE)
  467. {
  468. ATLASSERT(::IsWindow(m_hWnd));
  469. return (int)::SendMessage(m_hWnd, LB_SETCARETINDEX, nIndex, MAKELONG(bScroll, 0));
  470. }
  471. // for listbox items
  472. DWORD_PTR GetItemData(int nIndex) const
  473. {
  474. ATLASSERT(::IsWindow(m_hWnd));
  475. return (DWORD_PTR)::SendMessage(m_hWnd, LB_GETITEMDATA, nIndex, 0L);
  476. }
  477. int SetItemData(int nIndex, DWORD_PTR dwItemData)
  478. {
  479. ATLASSERT(::IsWindow(m_hWnd));
  480. return (int)::SendMessage(m_hWnd, LB_SETITEMDATA, nIndex, (LPARAM)dwItemData);
  481. }
  482. void* GetItemDataPtr(int nIndex) const
  483. {
  484. ATLASSERT(::IsWindow(m_hWnd));
  485. return (void*)::SendMessage(m_hWnd, LB_GETITEMDATA, nIndex, 0L);
  486. }
  487. int SetItemDataPtr(int nIndex, void* pData)
  488. {
  489. ATLASSERT(::IsWindow(m_hWnd));
  490. return SetItemData(nIndex, (DWORD_PTR)pData);
  491. }
  492. int GetItemRect(int nIndex, LPRECT lpRect) const
  493. {
  494. ATLASSERT(::IsWindow(m_hWnd));
  495. return (int)::SendMessage(m_hWnd, LB_GETITEMRECT, nIndex, (LPARAM)lpRect);
  496. }
  497. int GetText(int nIndex, LPTSTR lpszBuffer) const
  498. {
  499. ATLASSERT(::IsWindow(m_hWnd));
  500. return (int)::SendMessage(m_hWnd, LB_GETTEXT, nIndex, (LPARAM)lpszBuffer);
  501. }
  502. #ifndef _ATL_NO_COM
  503. #ifdef _OLEAUTO_H_
  504. BOOL GetTextBSTR(int nIndex, BSTR& bstrText) const
  505. {
  506. USES_CONVERSION;
  507. ATLASSERT(::IsWindow(m_hWnd));
  508. ATLASSERT(bstrText == NULL);
  509. int nLen = GetTextLen(nIndex);
  510. if(nLen == LB_ERR)
  511. return FALSE;
  512. CTempBuffer<TCHAR, _WTL_STACK_ALLOC_THRESHOLD> buff;
  513. LPTSTR lpstrText = buff.Allocate(nLen + 1);
  514. if(lpstrText == NULL)
  515. return FALSE;
  516. if(GetText(nIndex, lpstrText) == LB_ERR)
  517. return FALSE;
  518. bstrText = ::SysAllocString(T2OLE(lpstrText));
  519. return (bstrText != NULL) ? TRUE : FALSE;
  520. }
  521. #endif // _OLEAUTO_H_
  522. #endif // !_ATL_NO_COM
  523. #if defined(_WTL_USE_CSTRING) || defined(__ATLSTR_H__)
  524. int GetText(int nIndex, _CSTRING_NS::CString& strText) const
  525. {
  526. ATLASSERT(::IsWindow(m_hWnd));
  527. int cchLen = GetTextLen(nIndex);
  528. if(cchLen == LB_ERR)
  529. return LB_ERR;
  530. int nRet = LB_ERR;
  531. LPTSTR lpstr = strText.GetBufferSetLength(cchLen);
  532. if(lpstr != NULL)
  533. {
  534. nRet = GetText(nIndex, lpstr);
  535. strText.ReleaseBuffer();
  536. }
  537. return nRet;
  538. }
  539. #endif // defined(_WTL_USE_CSTRING) || defined(__ATLSTR_H__)
  540. int GetTextLen(int nIndex) const
  541. {
  542. ATLASSERT(::IsWindow(m_hWnd));
  543. return (int)::SendMessage(m_hWnd, LB_GETTEXTLEN, nIndex, 0L);
  544. }
  545. int GetItemHeight(int nIndex) const
  546. {
  547. ATLASSERT(::IsWindow(m_hWnd));
  548. return (int)::SendMessage(m_hWnd, LB_GETITEMHEIGHT, nIndex, 0L);
  549. }
  550. int SetItemHeight(int nIndex, UINT cyItemHeight)
  551. {
  552. ATLASSERT(::IsWindow(m_hWnd));
  553. return (int)::SendMessage(m_hWnd, LB_SETITEMHEIGHT, nIndex, MAKELONG(cyItemHeight, 0));
  554. }
  555. // Settable only attributes
  556. void SetColumnWidth(int cxWidth)
  557. {
  558. ATLASSERT(::IsWindow(m_hWnd));
  559. ::SendMessage(m_hWnd, LB_SETCOLUMNWIDTH, cxWidth, 0L);
  560. }
  561. BOOL SetTabStops(int nTabStops, LPINT rgTabStops)
  562. {
  563. ATLASSERT(::IsWindow(m_hWnd));
  564. ATLASSERT((GetStyle() & LBS_USETABSTOPS) != 0);
  565. return (BOOL)::SendMessage(m_hWnd, LB_SETTABSTOPS, nTabStops, (LPARAM)rgTabStops);
  566. }
  567. BOOL SetTabStops()
  568. {
  569. ATLASSERT(::IsWindow(m_hWnd));
  570. ATLASSERT((GetStyle() & LBS_USETABSTOPS) != 0);
  571. return (BOOL)::SendMessage(m_hWnd, LB_SETTABSTOPS, 0, 0L);
  572. }
  573. BOOL SetTabStops(const int& cxEachStop) // takes an 'int'
  574. {
  575. ATLASSERT(::IsWindow(m_hWnd));
  576. ATLASSERT((GetStyle() & LBS_USETABSTOPS) != 0);
  577. return (BOOL)::SendMessage(m_hWnd, LB_SETTABSTOPS, 1, (LPARAM)(LPINT)&cxEachStop);
  578. }
  579. // Operations
  580. int InitStorage(int nItems, UINT nBytes)
  581. {
  582. ATLASSERT(::IsWindow(m_hWnd));
  583. return (int)::SendMessage(m_hWnd, LB_INITSTORAGE, (WPARAM)nItems, nBytes);
  584. }
  585. void ResetContent()
  586. {
  587. ATLASSERT(::IsWindow(m_hWnd));
  588. ::SendMessage(m_hWnd, LB_RESETCONTENT, 0, 0L);
  589. }
  590. UINT ItemFromPoint(POINT pt, BOOL& bOutside) const
  591. {
  592. ATLASSERT(::IsWindow(m_hWnd));
  593. DWORD dw = (DWORD)::SendMessage(m_hWnd, LB_ITEMFROMPOINT, 0, MAKELPARAM(pt.x, pt.y));
  594. bOutside = (BOOL)HIWORD(dw);
  595. return (UINT)LOWORD(dw);
  596. }
  597. // manipulating listbox items
  598. int AddString(LPCTSTR lpszItem)
  599. {
  600. ATLASSERT(::IsWindow(m_hWnd));
  601. return (int)::SendMessage(m_hWnd, LB_ADDSTRING, 0, (LPARAM)lpszItem);
  602. }
  603. int DeleteString(UINT nIndex)
  604. {
  605. ATLASSERT(::IsWindow(m_hWnd));
  606. return (int)::SendMessage(m_hWnd, LB_DELETESTRING, nIndex, 0L);
  607. }
  608. int InsertString(int nIndex, LPCTSTR lpszItem)
  609. {
  610. ATLASSERT(::IsWindow(m_hWnd));
  611. return (int)::SendMessage(m_hWnd, LB_INSERTSTRING, nIndex, (LPARAM)lpszItem);
  612. }
  613. #ifndef _WIN32_WCE
  614. int Dir(UINT attr, LPCTSTR lpszWildCard)
  615. {
  616. ATLASSERT(::IsWindow(m_hWnd));
  617. return (int)::SendMessage(m_hWnd, LB_DIR, attr, (LPARAM)lpszWildCard);
  618. }
  619. int AddFile(LPCTSTR lpstrFileName)
  620. {
  621. ATLASSERT(::IsWindow(m_hWnd));
  622. return (int)::SendMessage(m_hWnd, LB_ADDFILE, 0, (LPARAM)lpstrFileName);
  623. }
  624. #endif // !_WIN32_WCE
  625. // selection helpers
  626. int FindString(int nStartAfter, LPCTSTR lpszItem) const
  627. {
  628. ATLASSERT(::IsWindow(m_hWnd));
  629. return (int)::SendMessage(m_hWnd, LB_FINDSTRING, nStartAfter, (LPARAM)lpszItem);
  630. }
  631. int FindStringExact(int nIndexStart, LPCTSTR lpszFind) const
  632. {
  633. ATLASSERT(::IsWindow(m_hWnd));
  634. return (int)::SendMessage(m_hWnd, LB_FINDSTRINGEXACT, nIndexStart, (LPARAM)lpszFind);
  635. }
  636. int SelectString(int nStartAfter, LPCTSTR lpszItem)
  637. {
  638. ATLASSERT(::IsWindow(m_hWnd));
  639. return (int)::SendMessage(m_hWnd, LB_SELECTSTRING, nStartAfter, (LPARAM)lpszItem);
  640. }
  641. int SelItemRange(BOOL bSelect, int nFirstItem, int nLastItem)
  642. {
  643. ATLASSERT(::IsWindow(m_hWnd));
  644. ATLASSERT((GetStyle() & (LBS_MULTIPLESEL | LBS_EXTENDEDSEL)) != 0);
  645. ATLASSERT(nFirstItem <= nLastItem);
  646. return bSelect ? (int)::SendMessage(m_hWnd, LB_SELITEMRANGEEX, nFirstItem, nLastItem) : (int)::SendMessage(m_hWnd, LB_SELITEMRANGEEX, nLastItem, nFirstItem);
  647. }
  648. #ifdef WIN32_PLATFORM_WFSP // SmartPhone only messages
  649. DWORD GetInputMode(BOOL bCurrentMode = TRUE)
  650. {
  651. return SendMessage(LB_GETINPUTMODE, 0, (LPARAM)bCurrentMode);
  652. }
  653. BOOL SetInputMode(DWORD dwMode)
  654. {
  655. return SendMessage(LB_SETINPUTMODE, 0, (LPARAM)dwMode);
  656. }
  657. #endif // WIN32_PLATFORM_WFSP
  658. };
  659. typedef CListBoxT<ATL::CWindow> CListBox;
  660. ///////////////////////////////////////////////////////////////////////////////
  661. // CComboBox - client side for a Windows COMBOBOX control
  662. #ifndef WIN32_PLATFORM_WFSP // No COMBOBOX on SmartPhones
  663. template <class TBase>
  664. class CComboBoxT : public TBase
  665. {
  666. public:
  667. // Constructors
  668. CComboBoxT(HWND hWnd = NULL) : TBase(hWnd)
  669. { }
  670. CComboBoxT< TBase >& operator =(HWND hWnd)
  671. {
  672. m_hWnd = hWnd;
  673. return *this;
  674. }
  675. HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
  676. DWORD dwStyle = 0, DWORD dwExStyle = 0,
  677. ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
  678. {
  679. return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
  680. }
  681. // Attributes
  682. static LPCTSTR GetWndClassName()
  683. {
  684. return _T("COMBOBOX");
  685. }
  686. // for entire combo box
  687. int GetCount() const
  688. {
  689. ATLASSERT(::IsWindow(m_hWnd));
  690. return (int)::SendMessage(m_hWnd, CB_GETCOUNT, 0, 0L);
  691. }
  692. int GetCurSel() const
  693. {
  694. ATLASSERT(::IsWindow(m_hWnd));
  695. return (int)::SendMessage(m_hWnd, CB_GETCURSEL, 0, 0L);
  696. }
  697. int SetCurSel(int nSelect)
  698. {
  699. ATLASSERT(::IsWindow(m_hWnd));
  700. return (int)::SendMessage(m_hWnd, CB_SETCURSEL, nSelect, 0L);
  701. }
  702. LCID GetLocale() const
  703. {
  704. ATLASSERT(::IsWindow(m_hWnd));
  705. return (LCID)::SendMessage(m_hWnd, CB_GETLOCALE, 0, 0L);
  706. }
  707. LCID SetLocale(LCID nNewLocale)
  708. {
  709. ATLASSERT(::IsWindow(m_hWnd));
  710. return (LCID)::SendMessage(m_hWnd, CB_SETLOCALE, (WPARAM)nNewLocale, 0L);
  711. }
  712. int GetTopIndex() const
  713. {
  714. ATLASSERT(::IsWindow(m_hWnd));
  715. return (int)::SendMessage(m_hWnd, CB_GETTOPINDEX, 0, 0L);
  716. }
  717. int SetTopIndex(int nIndex)
  718. {
  719. ATLASSERT(::IsWindow(m_hWnd));
  720. return (int)::SendMessage(m_hWnd, CB_SETTOPINDEX, nIndex, 0L);
  721. }
  722. UINT GetHorizontalExtent() const
  723. {
  724. ATLASSERT(::IsWindow(m_hWnd));
  725. return (UINT)::SendMessage(m_hWnd, CB_GETHORIZONTALEXTENT, 0, 0L);
  726. }
  727. void SetHorizontalExtent(UINT nExtent)
  728. {
  729. ATLASSERT(::IsWindow(m_hWnd));
  730. ::SendMessage(m_hWnd, CB_SETHORIZONTALEXTENT, nExtent, 0L);
  731. }
  732. int GetDroppedWidth() const
  733. {
  734. ATLASSERT(::IsWindow(m_hWnd));
  735. return (int)::SendMessage(m_hWnd, CB_GETDROPPEDWIDTH, 0, 0L);
  736. }
  737. int SetDroppedWidth(UINT nWidth)
  738. {
  739. ATLASSERT(::IsWindow(m_hWnd));
  740. return (int)::SendMessage(m_hWnd, CB_SETDROPPEDWIDTH, nWidth, 0L);
  741. }
  742. #if ((WINVER >= 0x0500) && !defined(_WIN32_WCE)) || (defined(_WIN32_WCE) && (_WIN32_WCE >= 420))
  743. BOOL GetComboBoxInfo(PCOMBOBOXINFO pComboBoxInfo) const
  744. {
  745. ATLASSERT(::IsWindow(m_hWnd));
  746. #if ((_WIN32_WINNT >= 0x0501) && !defined(_WIN32_WCE)) || (defined(_WIN32_WCE) && (_WIN32_WCE >= 420))
  747. return (BOOL)::SendMessage(m_hWnd, CB_GETCOMBOBOXINFO, 0, (LPARAM)pComboBoxInfo);
  748. #else // !((_WIN32_WINNT >= 0x0501) && !defined(_WIN32_WCE)) || (defined(_WIN32_WCE) && (_WIN32_WCE >= 420))
  749. return ::GetComboBoxInfo(m_hWnd, pComboBoxInfo);
  750. #endif // !((_WIN32_WINNT >= 0x0501) && !defined(_WIN32_WCE)) || (defined(_WIN32_WCE) && (_WIN32_WCE >= 420))
  751. }
  752. #endif // ((WINVER >= 0x0500) && !defined(_WIN32_WCE)) || (defined(_WIN32_WCE) && (_WIN32_WCE >= 420))
  753. // for edit control
  754. DWORD GetEditSel() const
  755. {
  756. ATLASSERT(::IsWindow(m_hWnd));
  757. return (DWORD)::SendMessage(m_hWnd, CB_GETEDITSEL, 0, 0L);
  758. }
  759. BOOL SetEditSel(int nStartChar, int nEndChar)
  760. {
  761. ATLASSERT(::IsWindow(m_hWnd));
  762. return (BOOL)::SendMessage(m_hWnd, CB_SETEDITSEL, 0, MAKELONG(nStartChar, nEndChar));
  763. }
  764. // for combobox item
  765. DWORD_PTR GetItemData(int nIndex) const
  766. {
  767. ATLASSERT(::IsWindow(m_hWnd));
  768. return (DWORD_PTR)::SendMessage(m_hWnd, CB_GETITEMDATA, nIndex, 0L);
  769. }
  770. int SetItemData(int nIndex, DWORD_PTR dwItemData)
  771. {
  772. ATLASSERT(::IsWindow(m_hWnd));
  773. return (int)::SendMessage(m_hWnd, CB_SETITEMDATA, nIndex, (LPARAM)dwItemData);
  774. }
  775. void* GetItemDataPtr(int nIndex) const
  776. {
  777. ATLASSERT(::IsWindow(m_hWnd));
  778. return (void*)GetItemData(nIndex);
  779. }
  780. int SetItemDataPtr(int nIndex, void* pData)
  781. {
  782. ATLASSERT(::IsWindow(m_hWnd));
  783. return SetItemData(nIndex, (DWORD_PTR)pData);
  784. }
  785. int GetLBText(int nIndex, LPTSTR lpszText) const
  786. {
  787. ATLASSERT(::IsWindow(m_hWnd));
  788. return (int)::SendMessage(m_hWnd, CB_GETLBTEXT, nIndex, (LPARAM)lpszText);
  789. }
  790. #ifndef _ATL_NO_COM
  791. BOOL GetLBTextBSTR(int nIndex, BSTR& bstrText) const
  792. {
  793. USES_CONVERSION;
  794. ATLASSERT(::IsWindow(m_hWnd));
  795. ATLASSERT(bstrText == NULL);
  796. int nLen = GetLBTextLen(nIndex);
  797. if(nLen == CB_ERR)
  798. return FALSE;
  799. CTempBuffer<TCHAR, _WTL_STACK_ALLOC_THRESHOLD> buff;
  800. LPTSTR lpstrText = buff.Allocate(nLen + 1);
  801. if(lpstrText == NULL)
  802. return FALSE;
  803. if(GetLBText(nIndex, lpstrText) == CB_ERR)
  804. return FALSE;
  805. bstrText = ::SysAllocString(T2OLE(lpstrText));
  806. return (bstrText != NULL) ? TRUE : FALSE;
  807. }
  808. #endif // !_ATL_NO_COM
  809. #if defined(_WTL_USE_CSTRING) || defined(__ATLSTR_H__)
  810. int GetLBText(int nIndex, _CSTRING_NS::CString& strText) const
  811. {
  812. ATLASSERT(::IsWindow(m_hWnd));
  813. int cchLen = GetLBTextLen(nIndex);
  814. if(cchLen == CB_ERR)
  815. return CB_ERR;
  816. int nRet = CB_ERR;
  817. LPTSTR lpstr = strText.GetBufferSetLength(cchLen);
  818. if(lpstr != NULL)
  819. {
  820. nRet = GetLBText(nIndex, lpstr);
  821. strText.ReleaseBuffer();
  822. }
  823. return nRet;
  824. }
  825. #endif // defined(_WTL_USE_CSTRING) || defined(__ATLSTR_H__)
  826. int GetLBTextLen(int nIndex) const
  827. {
  828. ATLASSERT(::IsWindow(m_hWnd));
  829. return (int)::SendMessage(m_hWnd, CB_GETLBTEXTLEN, nIndex, 0L);
  830. }
  831. int GetItemHeight(int nIndex) const
  832. {
  833. ATLASSERT(::IsWindow(m_hWnd));
  834. return (int)::SendMessage(m_hWnd, CB_GETITEMHEIGHT, nIndex, 0L);
  835. }
  836. int SetItemHeight(int nIndex, UINT cyItemHeight)
  837. {
  838. ATLASSERT(::IsWindow(m_hWnd));
  839. return (int)::SendMessage(m_hWnd, CB_SETITEMHEIGHT, nIndex, MAKELONG(cyItemHeight, 0));
  840. }
  841. BOOL GetExtendedUI() const
  842. {
  843. ATLASSERT(::IsWindow(m_hWnd));
  844. return (BOOL)::SendMessage(m_hWnd, CB_GETEXTENDEDUI, 0, 0L);
  845. }
  846. int SetExtendedUI(BOOL bExtended = TRUE)
  847. {
  848. ATLASSERT(::IsWindow(m_hWnd));
  849. return (int)::SendMessage(m_hWnd, CB_SETEXTENDEDUI, bExtended, 0L);
  850. }
  851. void GetDroppedControlRect(LPRECT lprect) const
  852. {
  853. ATLASSERT(::IsWindow(m_hWnd));
  854. ::SendMessage(m_hWnd, CB_GETDROPPEDCONTROLRECT, 0, (LPARAM)lprect);
  855. }
  856. BOOL GetDroppedState() const
  857. {
  858. ATLASSERT(::IsWindow(m_hWnd));
  859. return (BOOL)::SendMessage(m_hWnd, CB_GETDROPPEDSTATE, 0, 0L);
  860. }
  861. #if (_WIN32_WINNT >= 0x0501)
  862. int GetMinVisible() const
  863. {
  864. ATLASSERT(::IsWindow(m_hWnd));
  865. return (int)::SendMessage(m_hWnd, CB_GETMINVISIBLE, 0, 0L);
  866. }
  867. BOOL SetMinVisible(int nMinVisible)
  868. {
  869. ATLASSERT(::IsWindow(m_hWnd));
  870. return (BOOL)::SendMessage(m_hWnd, CB_SETMINVISIBLE, nMinVisible, 0L);
  871. }
  872. // Vista only
  873. BOOL GetCueBannerText(LPWSTR lpwText, int cchText) const
  874. {
  875. #ifndef CB_GETCUEBANNER
  876. const UINT CB_GETCUEBANNER = (CBM_FIRST + 4);
  877. #endif
  878. ATLASSERT(::IsWindow(m_hWnd));
  879. return (BOOL)::SendMessage(m_hWnd, CB_GETCUEBANNER, (WPARAM)lpwText, cchText);
  880. }
  881. // Vista only
  882. BOOL SetCueBannerText(LPCWSTR lpcwText)
  883. {
  884. #ifndef CB_SETCUEBANNER
  885. const UINT CB_SETCUEBANNER = (CBM_FIRST + 3);
  886. #endif
  887. ATLASSERT(::IsWindow(m_hWnd));
  888. return (BOOL)::SendMessage(m_hWnd, CB_SETCUEBANNER, 0, (LPARAM)lpcwText);
  889. }
  890. #endif // (_WIN32_WINNT >= 0x0501)
  891. // Operations
  892. int InitStorage(int nItems, UINT nBytes)
  893. {
  894. ATLASSERT(::IsWindow(m_hWnd));
  895. return (int)::SendMessage(m_hWnd, CB_INITSTORAGE, (WPARAM)nItems, nBytes);
  896. }
  897. void ResetContent()
  898. {
  899. ATLASSERT(::IsWindow(m_hWnd));
  900. ::SendMessage(m_hWnd, CB_RESETCONTENT, 0, 0L);
  901. }
  902. // for edit control
  903. BOOL LimitText(int nMaxChars)
  904. {
  905. ATLASSERT(::IsWindow(m_hWnd));
  906. return (BOOL)::SendMessage(m_hWnd, CB_LIMITTEXT, nMaxChars, 0L);
  907. }
  908. // for drop-down combo boxes
  909. void ShowDropDown(BOOL bShowIt = TRUE)
  910. {
  911. ATLASSERT(::IsWindow(m_hWnd));
  912. ::SendMessage(m_hWnd, CB_SHOWDROPDOWN, bShowIt, 0L);
  913. }
  914. // manipulating listbox items
  915. int AddString(LPCTSTR lpszString)
  916. {
  917. ATLASSERT(::IsWindow(m_hWnd));
  918. return (int)::SendMessage(m_hWnd, CB_ADDSTRING, 0, (LPARAM)lpszString);
  919. }
  920. int DeleteString(UINT nIndex)
  921. {
  922. ATLASSERT(::IsWindow(m_hWnd));
  923. return (int)::SendMessage(m_hWnd, CB_DELETESTRING, nIndex, 0L);
  924. }
  925. int InsertString(int nIndex, LPCTSTR lpszString)
  926. {
  927. ATLASSERT(::IsWindow(m_hWnd));
  928. return (int)::SendMessage(m_hWnd, CB_INSERTSTRING, nIndex, (LPARAM)lpszString);
  929. }
  930. #ifndef _WIN32_WCE
  931. int Dir(UINT attr, LPCTSTR lpszWildCard)
  932. {
  933. ATLASSERT(::IsWindow(m_hWnd));
  934. return (int)::SendMessage(m_hWnd, CB_DIR, attr, (LPARAM)lpszWildCard);
  935. }
  936. #endif // !_WIN32_WCE
  937. // selection helpers
  938. int FindString(int nStartAfter, LPCTSTR lpszString) const
  939. {
  940. ATLASSERT(::IsWindow(m_hWnd));
  941. return (int)::SendMessage(m_hWnd, CB_FINDSTRING, nStartAfter, (LPARAM)lpszString);
  942. }
  943. int FindStringExact(int nIndexStart, LPCTSTR lpszFind) const
  944. {
  945. ATLASSERT(::IsWindow(m_hWnd));
  946. return (int)::SendMessage(m_hWnd, CB_FINDSTRINGEXACT, nIndexStart, (LPARAM)lpszFind);
  947. }
  948. int SelectString(int nStartAfter, LPCTSTR lpszString)
  949. {
  950. ATLASSERT(::IsWindow(m_hWnd));
  951. return (int)::SendMessage(m_hWnd, CB_SELECTSTRING, nStartAfter, (LPARAM)lpszString);
  952. }
  953. // Clipboard operations
  954. void Clear()
  955. {
  956. ATLASSERT(::IsWindow(m_hWnd));
  957. ::SendMessage(m_hWnd, WM_CLEAR, 0, 0L);
  958. }
  959. void Copy()
  960. {
  961. ATLASSERT(::IsWindow(m_hWnd));
  962. ::SendMessage(m_hWnd, WM_COPY, 0, 0L);
  963. }
  964. void Cut()
  965. {
  966. ATLASSERT(::IsWindow(m_hWnd));
  967. ::SendMessage(m_hWnd, WM_CUT, 0, 0L);
  968. }
  969. void Paste()
  970. {
  971. ATLASSERT(::IsWindow(m_hWnd));
  972. ::SendMessage(m_hWnd, WM_PASTE, 0, 0L);
  973. }
  974. };
  975. typedef CComboBoxT<ATL::CWindow> CComboBox;
  976. #endif // !WIN32_PLATFORM_WFSP
  977. ///////////////////////////////////////////////////////////////////////////////
  978. // CEdit - client side for a Windows EDIT control
  979. template <class TBase>
  980. class CEditT : public TBase
  981. {
  982. public:
  983. // Constructors
  984. CEditT(HWND hWnd = NULL) : TBase(hWnd)
  985. { }
  986. CEditT< TBase >& operator =(HWND hWnd)
  987. {
  988. m_hWnd = hWnd;
  989. return *this;
  990. }
  991. HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
  992. DWORD dwStyle = 0, DWORD dwExStyle = 0,
  993. ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
  994. {
  995. return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
  996. }
  997. // Attributes
  998. static LPCTSTR GetWndClassName()
  999. {
  1000. return _T("EDIT");
  1001. }
  1002. BOOL CanUndo() const
  1003. {
  1004. ATLASSERT(::IsWindow(m_hWnd));
  1005. return (BOOL)::SendMessage(m_hWnd, EM_CANUNDO, 0, 0L);
  1006. }
  1007. int GetLineCount() const
  1008. {
  1009. ATLASSERT(::IsWindow(m_hWnd));
  1010. return (int)::SendMessage(m_hWnd, EM_GETLINECOUNT, 0, 0L);
  1011. }
  1012. BOOL GetModify() const
  1013. {
  1014. ATLASSERT(::IsWindow(m_hWnd));
  1015. return (BOOL)::SendMessage(m_hWnd, EM_GETMODIFY, 0, 0L);
  1016. }
  1017. void SetModify(BOOL bModified = TRUE)
  1018. {
  1019. ATLASSERT(::IsWindow(m_hWnd));
  1020. ::SendMessage(m_hWnd, EM_SETMODIFY, bModified, 0L);
  1021. }
  1022. void GetRect(LPRECT lpRect) const
  1023. {
  1024. ATLASSERT(::IsWindow(m_hWnd));
  1025. ::SendMessage(m_hWnd, EM_GETRECT, 0, (LPARAM)lpRect);
  1026. }
  1027. DWORD GetSel() const
  1028. {
  1029. ATLASSERT(::IsWindow(m_hWnd));
  1030. return (DWORD)::SendMessage(m_hWnd, EM_GETSEL, 0, 0L);
  1031. }
  1032. void GetSel(int& nStartChar, int& nEndChar) const
  1033. {
  1034. ATLASSERT(::IsWindow(m_hWnd));
  1035. ::SendMessage(m_hWnd, EM_GETSEL, (WPARAM)&nStartChar, (LPARAM)&nEndChar);
  1036. }
  1037. #ifndef _WIN32_WCE
  1038. HLOCAL GetHandle() const
  1039. {
  1040. ATLASSERT(::IsWindow(m_hWnd));
  1041. return (HLOCAL)::SendMessage(m_hWnd, EM_GETHANDLE, 0, 0L);
  1042. }
  1043. void SetHandle(HLOCAL hBuffer)
  1044. {
  1045. ATLASSERT(::IsWindow(m_hWnd));
  1046. ::SendMessage(m_hWnd, EM_SETHANDLE, (WPARAM)hBuffer, 0L);
  1047. }
  1048. #endif // !_WIN32_WCE
  1049. DWORD GetMargins() const
  1050. {
  1051. ATLASSERT(::IsWindow(m_hWnd));
  1052. return (DWORD)::SendMessage(m_hWnd, EM_GETMARGINS, 0, 0L);
  1053. }
  1054. void SetMargins(UINT nLeft, UINT nRight)
  1055. {
  1056. ATLASSERT(::IsWindow(m_hWnd));
  1057. ::SendMessage(m_hWnd, EM_SETMARGINS, EC_LEFTMARGIN|EC_RIGHTMARGIN, MAKELONG(nLeft, nRight));
  1058. }
  1059. UINT GetLimitText() const
  1060. {
  1061. ATLASSERT(::IsWindow(m_hWnd));
  1062. return (UINT)::SendMessage(m_hWnd, EM_GETLIMITTEXT, 0, 0L);
  1063. }
  1064. void SetLimitText(UINT nMax)
  1065. {
  1066. ATLASSERT(::IsWindow(m_hWnd));
  1067. ::SendMessage(m_hWnd, EM_SETLIMITTEXT, nMax, 0L);
  1068. }
  1069. POINT PosFromChar(UINT nChar) const
  1070. {
  1071. ATLASSERT(::IsWindow(m_hWnd));
  1072. DWORD dwRet = (DWORD)::SendMessage(m_hWnd, EM_POSFROMCHAR, nChar, 0);
  1073. POINT point = { GET_X_LPARAM(dwRet), GET_Y_LPARAM(dwRet) };
  1074. return point;
  1075. }
  1076. int CharFromPos(POINT pt, int* pLine = NULL) const
  1077. {
  1078. ATLASSERT(::IsWindow(m_hWnd));
  1079. DWORD dwRet = (DWORD)::SendMessage(m_hWnd, EM_CHARFROMPOS, 0, MAKELPARAM(pt.x, pt.y));
  1080. if(pLine != NULL)
  1081. *pLine = (int)(short)HIWORD(dwRet);
  1082. return (int)(short)LOWORD(dwRet);
  1083. }
  1084. // NOTE: first word in lpszBuffer must contain the size of the buffer!
  1085. int GetLine(int nIndex, LPTSTR lpszBuffer) const
  1086. {
  1087. ATLASSERT(::IsWindow(m_hWnd));
  1088. return (int)::SendMessage(m_hWnd, EM_GETLINE, nIndex, (LPARAM)lpszBuffer);
  1089. }
  1090. int GetLine(int nIndex, LPTSTR lpszBuffer, int nMaxLength) const
  1091. {
  1092. ATLASSERT(::IsWindow(m_hWnd));
  1093. *(LPWORD)lpszBuffer = (WORD)nMaxLength;
  1094. return (int)::SendMessage(m_hWnd, EM_GETLINE, nIndex, (LPARAM)lpszBuffer);
  1095. }
  1096. TCHAR GetPasswordChar() const
  1097. {
  1098. ATLASSERT(::IsWindow(m_hWnd));
  1099. return (TCHAR)::SendMessage(m_hWnd, EM_GETPASSWORDCHAR, 0, 0L);
  1100. }
  1101. void SetPasswordChar(TCHAR ch)
  1102. {
  1103. ATLASSERT(::IsWindow(m_hWnd));
  1104. ::SendMessage(m_hWnd, EM_SETPASSWORDCHAR, ch, 0L);
  1105. }
  1106. #ifndef _WIN32_WCE
  1107. EDITWORDBREAKPROC GetWordBreakProc() const
  1108. {
  1109. ATLASSERT(::IsWindow(m_hWnd));
  1110. return (EDITWORDBREAKPROC)::SendMessage(m_hWnd, EM_GETWORDBREAKPROC, 0, 0L);
  1111. }
  1112. void SetWordBreakProc(EDITWORDBREAKPROC ewbprc)
  1113. {
  1114. ATLASSERT(::IsWindow(m_hWnd));
  1115. ::SendMessage(m_hWnd, EM_SETWORDBREAKPROC, 0, (LPARAM)ewbprc);
  1116. }
  1117. #endif // !_WIN32_WCE
  1118. int GetFirstVisibleLine() const
  1119. {
  1120. ATLASSERT(::IsWindow(m_hWnd));
  1121. return (int)::SendMessage(m_hWnd, EM_GETFIRSTVISIBLELINE, 0, 0L);
  1122. }
  1123. #ifndef _WIN32_WCE
  1124. int GetThumb() const
  1125. {
  1126. ATLASSERT(::IsWindow(m_hWnd));
  1127. ATLASSERT((GetStyle() & ES_MULTILINE) != 0);
  1128. return (int)::SendMessage(m_hWnd, EM_GETTHUMB, 0, 0L);
  1129. }
  1130. #endif // !_WIN32_WCE
  1131. BOOL SetReadOnly(BOOL bReadOnly = TRUE)
  1132. {
  1133. ATLASSERT(::IsWindow(m_hWnd));
  1134. return (BOOL)::SendMessage(m_hWnd, EM_SETREADONLY, bReadOnly, 0L);
  1135. }
  1136. #if (WINVER >= 0x0500) && !defined(_WIN32_WCE)
  1137. UINT GetImeStatus(UINT uStatus) const
  1138. {
  1139. ATLASSERT(::IsWindow(m_hWnd));
  1140. return (UINT)::SendMessage(m_hWnd, EM_GETIMESTATUS, uStatus, 0L);
  1141. }
  1142. UINT SetImeStatus(UINT uStatus, UINT uData)
  1143. {
  1144. ATLASSERT(::IsWindow(m_hWnd));
  1145. return (UINT)::SendMessage(m_hWnd, EM_SETIMESTATUS, uStatus, uData);
  1146. }
  1147. #endif // (WINVER >= 0x0500) && !defined(_WIN32_WCE)
  1148. #if (_WIN32_WINNT >= 0x0501)
  1149. BOOL GetCueBannerText(LPCWSTR lpstrText, int cchText) const
  1150. {
  1151. ATLASSERT(::IsWindow(m_hWnd));
  1152. return (BOOL)::SendMessage(m_hWnd, EM_GETCUEBANNER, (WPARAM)lpstrText, cchText);
  1153. }
  1154. // bKeepWithFocus - Vista only
  1155. BOOL SetCueBannerText(LPCWSTR lpstrText, BOOL bKeepWithFocus = FALSE)
  1156. {
  1157. ATLASSERT(::IsWindow(m_hWnd));
  1158. return (BOOL)::SendMessage(m_hWnd, EM_SETCUEBANNER, (WPARAM)bKeepWithFocus, (LPARAM)(lpstrText));
  1159. }
  1160. #endif // (_WIN32_WINNT >= 0x0501)
  1161. // Operations
  1162. void EmptyUndoBuffer()
  1163. {
  1164. ATLASSERT(::IsWindow(m_hWnd));
  1165. ::SendMessage(m_hWnd, EM_EMPTYUNDOBUFFER, 0, 0L);
  1166. }
  1167. BOOL FmtLines(BOOL bAddEOL)
  1168. {
  1169. ATLASSERT(::IsWindow(m_hWnd));
  1170. return (BOOL)::SendMessage(m_hWnd, EM_FMTLINES, bAddEOL, 0L);
  1171. }
  1172. void LimitText(int nChars = 0)
  1173. {
  1174. ATLASSERT(::IsWindow(m_hWnd));
  1175. ::SendMessage(m_hWnd, EM_LIMITTEXT, nChars, 0L);
  1176. }
  1177. int LineFromChar(int nIndex = -1) const
  1178. {
  1179. ATLASSERT(::IsWindow(m_hWnd));
  1180. return (int)::SendMessage(m_hWnd, EM_LINEFROMCHAR, nIndex, 0L);
  1181. }
  1182. int LineIndex(int nLine = -1) const
  1183. {
  1184. ATLASSERT(::IsWindow(m_hWnd));
  1185. return (int)::SendMessage(m_hWnd, EM_LINEINDEX, nLine, 0L);
  1186. }
  1187. int LineLength(int nLine = -1) const
  1188. {
  1189. ATLASSERT(::IsWindow(m_hWnd));
  1190. return (int)::SendMessage(m_hWnd, EM_LINELENGTH, nLine, 0L);
  1191. }
  1192. void LineScroll(int nLines, int nChars = 0)
  1193. {
  1194. ATLASSERT(::IsWindow(m_hWnd));
  1195. ::SendMessage(m_hWnd, EM_LINESCROLL, nChars, nLines);
  1196. }
  1197. void ReplaceSel(LPCTSTR lpszNewText, BOOL bCanUndo = FALSE)
  1198. {
  1199. ATLASSERT(::IsWindow(m_hWnd));
  1200. ::SendMessage(m_hWnd, EM_REPLACESEL, (WPARAM) bCanUndo, (LPARAM)lpszNewText);
  1201. }
  1202. void SetRect(LPCRECT lpRect)
  1203. {
  1204. ATLASSERT(::IsWindow(m_hWnd));
  1205. ::SendMessage(m_hWnd, EM_SETRECT, 0, (LPARAM)lpRect);
  1206. }
  1207. void SetRectNP(LPCRECT lpRect)
  1208. {
  1209. ATLASSERT(::IsWindow(m_hWnd));
  1210. ::SendMessage(m_hWnd, EM_SETRECTNP, 0, (LPARAM)lpRect);
  1211. }
  1212. void SetSel(DWORD dwSelection, BOOL bNoScroll = FALSE)
  1213. {
  1214. ATLASSERT(::IsWindow(m_hWnd));
  1215. ::SendMessage(m_hWnd, EM_SETSEL, LOWORD(dwSelection), HIWORD(dwSelection));
  1216. if(!bNoScroll)
  1217. ::SendMessage(m_hWnd, EM_SCROLLCARET, 0, 0L);
  1218. }
  1219. void SetSel(int nStartChar, int nEndChar, BOOL bNoScroll = FALSE)
  1220. {
  1221. ATLASSERT(::IsWindow(m_hWnd));
  1222. ::SendMessage(m_hWnd, EM_SETSEL, nStartChar, nEndChar);
  1223. if(!bNoScroll)
  1224. ::SendMessage(m_hWnd, EM_SCROLLCARET, 0, 0L);
  1225. }
  1226. void SetSelAll(BOOL bNoScroll = FALSE)
  1227. {
  1228. SetSel(0, -1, bNoScroll);
  1229. }
  1230. void SetSelNone(BOOL bNoScroll = FALSE)
  1231. {
  1232. SetSel(-1, 0, bNoScroll);
  1233. }
  1234. BOOL SetTabStops(int nTabStops, LPINT rgTabStops)
  1235. {
  1236. ATLASSERT(::IsWindow(m_hWnd));
  1237. return (BOOL)::SendMessage(m_hWnd, EM_SETTABSTOPS, nTabStops, (LPARAM)rgTabStops);
  1238. }
  1239. BOOL SetTabStops()
  1240. {
  1241. ATLASSERT(::IsWindow(m_hWnd));
  1242. return (BOOL)::SendMessage(m_hWnd, EM_SETTABSTOPS, 0, 0L);
  1243. }
  1244. BOOL SetTabStops(const int& cxEachStop) // takes an 'int'
  1245. {
  1246. ATLASSERT(::IsWindow(m_hWnd));
  1247. return (BOOL)::SendMessage(m_hWnd, EM_SETTABSTOPS, 1, (LPARAM)(LPINT)&cxEachStop);
  1248. }
  1249. void ScrollCaret()
  1250. {
  1251. ATLASSERT(::IsWindow(m_hWnd));
  1252. ::SendMessage(m_hWnd, EM_SCROLLCARET, 0, 0L);
  1253. }
  1254. int Scroll(int nScrollAction)
  1255. {
  1256. ATLASSERT(::IsWindow(m_hWnd));
  1257. ATLASSERT((GetStyle() & ES_MULTILINE) != 0);
  1258. LRESULT lRet = ::SendMessage(m_hWnd, EM_SCROLL, nScrollAction, 0L);
  1259. if(!(BOOL)HIWORD(lRet))
  1260. return -1; // failed
  1261. return (int)(short)LOWORD(lRet);
  1262. }
  1263. void InsertText(int nInsertAfterChar, LPCTSTR lpstrText, BOOL bNoScroll = FALSE, BOOL bCanUndo = FALSE)
  1264. {
  1265. SetSel(nInsertAfterChar, nInsertAfterChar, bNoScroll);
  1266. ReplaceSel(lpstrText, bCanUndo);
  1267. }
  1268. void AppendText(LPCTSTR lpstrText, BOOL bNoScroll = FALSE, BOOL bCanUndo = FALSE)
  1269. {
  1270. InsertText(GetWindowTextLength(), lpstrText, bNoScroll, bCanUndo);
  1271. }
  1272. #if (_WIN32_WINNT >= 0x0501)
  1273. BOOL ShowBalloonTip(PEDITBALLOONTIP pEditBaloonTip)
  1274. {
  1275. ATLASSERT(::IsWindow(m_hWnd));
  1276. return (BOOL)::SendMessage(m_hWnd, EM_SHOWBALLOONTIP, 0, (LPARAM)pEditBaloonTip);
  1277. }
  1278. BOOL HideBalloonTip()
  1279. {
  1280. ATLASSERT(::IsWindow(m_hWnd));
  1281. return (BOOL)::SendMessage(m_hWnd, EM_HIDEBALLOONTIP, 0, 0L);
  1282. }
  1283. #endif // (_WIN32_WINNT >= 0x0501)
  1284. #if (_WIN32_WINNT >= 0x0600)
  1285. DWORD GetHilite() const
  1286. {
  1287. ATLASSERT(::IsWindow(m_hWnd));
  1288. return (DWORD)::SendMessage(m_hWnd, EM_GETHILITE, 0, 0L);
  1289. }
  1290. void GetHilite(int& nStartChar, int& nEndChar) const
  1291. {
  1292. ATLASSERT(::IsWindow(m_hWnd));
  1293. DWORD dwRet = (DWORD)::SendMessage(m_hWnd, EM_GETHILITE, 0, 0L);
  1294. nStartChar = (int)(short)LOWORD(dwRet);
  1295. nEndChar = (int)(short)HIWORD(dwRet);
  1296. }
  1297. void SetHilite(int nStartChar, int nEndChar)
  1298. {
  1299. ATLASSERT(::IsWindow(m_hWnd));
  1300. ::SendMessage(m_hWnd, EM_SETHILITE, nStartChar, nEndChar);
  1301. }
  1302. #endif // (_WIN32_WINNT >= 0x0600)
  1303. // Clipboard operations
  1304. BOOL Undo()
  1305. {
  1306. ATLASSERT(::IsWindow(m_hWnd));
  1307. return (BOOL)::SendMessage(m_hWnd, EM_UNDO, 0, 0L);
  1308. }
  1309. void Clear()
  1310. {
  1311. ATLASSERT(::IsWindow(m_hWnd));
  1312. ::SendMessage(m_hWnd, WM_CLEAR, 0, 0L);
  1313. }
  1314. void Copy()
  1315. {
  1316. ATLASSERT(::IsWindow(m_hWnd));
  1317. ::SendMessage(m_hWnd, WM_COPY, 0, 0L);
  1318. }
  1319. void Cut()
  1320. {
  1321. ATLASSERT(::IsWindow(m_hWnd));
  1322. ::SendMessage(m_hWnd, WM_CUT, 0, 0L);
  1323. }
  1324. void Paste()
  1325. {
  1326. ATLASSERT(::IsWindow(m_hWnd));
  1327. ::SendMessage(m_hWnd, WM_PASTE, 0, 0L);
  1328. }
  1329. #ifdef WIN32_PLATFORM_WFSP // SmartPhone only messages
  1330. DWORD GetExtendedStyle()
  1331. {
  1332. return SendMessage(EM_GETEXTENDEDSTYLE);
  1333. }
  1334. DWORD SetExtendedStyle(DWORD dwMask, DWORD dwExStyle)
  1335. {
  1336. return SendMessage(EM_SETEXTENDEDSTYLE, (WPARAM)dwMask, (LPARAM)dwExStyle);
  1337. }
  1338. DWORD GetInputMode(BOOL bCurrentMode = TRUE)
  1339. {
  1340. return SendMessage(EM_GETINPUTMODE, 0, (LPARAM)bCurrentMode);
  1341. }
  1342. BOOL SetInputMode(DWORD dwMode)
  1343. {
  1344. return SendMessage(EM_SETINPUTMODE, 0, (LPARAM)dwMode);
  1345. }
  1346. BOOL SetSymbols(LPCTSTR szSymbols)
  1347. {
  1348. return SendMessage(EM_SETSYMBOLS, 0, (LPARAM)szSymbols);
  1349. }
  1350. BOOL ResetSymbols()
  1351. {
  1352. return SendMessage(EM_SETSYMBOLS);
  1353. }
  1354. #endif // WIN32_PLATFORM_WFSP
  1355. };
  1356. typedef CEditT<ATL::CWindow> CEdit;
  1357. ///////////////////////////////////////////////////////////////////////////////
  1358. // CEditCommands - message handlers for standard EDIT commands
  1359. // Chain to CEditCommands message map. Your class must also derive from CEdit.
  1360. // Example:
  1361. // class CMyEdit : public CWindowImpl<CMyEdit, CEdit>,
  1362. // public CEditCommands<CMyEdit>
  1363. // {
  1364. // public:
  1365. // BEGIN_MSG_MAP(CMyEdit)
  1366. // // your handlers...
  1367. // CHAIN_MSG_MAP_ALT(CEditCommands<CMyEdit>, 1)
  1368. // END_MSG_MAP()
  1369. // // other stuff...
  1370. // };
  1371. template <class T>
  1372. class CEditCommands
  1373. {
  1374. public:
  1375. BEGIN_MSG_MAP(CEditCommands< T >)
  1376. ALT_MSG_MAP(1)
  1377. COMMAND_ID_HANDLER(ID_EDIT_CLEAR, OnEditClear)
  1378. COMMAND_ID_HANDLER(ID_EDIT_CLEAR_ALL, OnEditClearAll)
  1379. COMMAND_ID_HANDLER(ID_EDIT_COPY, OnEditCopy)
  1380. COMMAND_ID_HANDLER(ID_EDIT_CUT, OnEditCut)
  1381. COMMAND_ID_HANDLER(ID_EDIT_PASTE, OnEditPaste)
  1382. COMMAND_ID_HANDLER(ID_EDIT_SELECT_ALL, OnEditSelectAll)
  1383. COMMAND_ID_HANDLER(ID_EDIT_UNDO, OnEditUndo)
  1384. END_MSG_MAP()
  1385. LRESULT OnEditClear(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
  1386. {
  1387. T* pT = static_cast<T*>(this);
  1388. pT->Clear();
  1389. return 0;
  1390. }
  1391. LRESULT OnEditClearAll(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
  1392. {
  1393. T* pT = static_cast<T*>(this);
  1394. pT->SetSel(0, -1);
  1395. pT->Clear();
  1396. return 0;
  1397. }
  1398. LRESULT OnEditCopy(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
  1399. {
  1400. T* pT = static_cast<T*>(this);
  1401. pT->Copy();
  1402. return 0;
  1403. }
  1404. LRESULT OnEditCut(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
  1405. {
  1406. T* pT = static_cast<T*>(this);
  1407. pT->Cut();
  1408. return 0;
  1409. }
  1410. LRESULT OnEditPaste(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
  1411. {
  1412. T* pT = static_cast<T*>(this);
  1413. pT->Paste();
  1414. return 0;
  1415. }
  1416. LRESULT OnEditSelectAll(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
  1417. {
  1418. T* pT = static_cast<T*>(this);
  1419. pT->SetSel(0, -1);
  1420. return 0;
  1421. }
  1422. LRESULT OnEditUndo(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
  1423. {
  1424. T* pT = static_cast<T*>(this);
  1425. pT->Undo();
  1426. return 0;
  1427. }
  1428. // State (update UI) helpers
  1429. BOOL CanCut() const
  1430. { return HasSelection(); }
  1431. BOOL CanCopy() const
  1432. { return HasSelection(); }
  1433. BOOL CanClear() const
  1434. { return HasSelection(); }
  1435. BOOL CanSelectAll() const
  1436. { return HasText(); }
  1437. BOOL CanFind() const
  1438. { return HasText(); }
  1439. BOOL CanRepeat() const
  1440. { return HasText(); }
  1441. BOOL CanReplace() const
  1442. { return HasText(); }
  1443. BOOL CanClearAll() const
  1444. { return HasText(); }
  1445. // Implementation
  1446. BOOL HasSelection() const
  1447. {
  1448. const T* pT = static_cast<const T*>(this);
  1449. int nMin, nMax;
  1450. ::SendMessage(pT->m_hWnd, EM_GETSEL, (WPARAM)&nMin, (LPARAM)&nMax);
  1451. return (nMin != nMax);
  1452. }
  1453. BOOL HasText() const
  1454. {
  1455. const T* pT = static_cast<const T*>(this);
  1456. return (pT->GetWindowTextLength() > 0);
  1457. }
  1458. };
  1459. ///////////////////////////////////////////////////////////////////////////////
  1460. // CScrollBar - client side for a Windows SCROLLBAR control
  1461. template <class TBase>
  1462. class CScrollBarT : public TBase
  1463. {
  1464. public:
  1465. // Constructors
  1466. CScrollBarT(HWND hWnd = NULL) : TBase(hWnd)
  1467. { }
  1468. CScrollBarT< TBase >& operator =(HWND hWnd)
  1469. {
  1470. m_hWnd = hWnd;
  1471. return *this;
  1472. }
  1473. HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
  1474. DWORD dwStyle = 0, DWORD dwExStyle = 0,
  1475. ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
  1476. {
  1477. return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
  1478. }
  1479. // Attributes
  1480. static LPCTSTR GetWndClassName()
  1481. {
  1482. return _T("SCROLLBAR");
  1483. }
  1484. #ifndef _WIN32_WCE
  1485. int GetScrollPos() const
  1486. {
  1487. ATLASSERT(::IsWindow(m_hWnd));
  1488. return ::GetScrollPos(m_hWnd, SB_CTL);
  1489. }
  1490. #endif // !_WIN32_WCE
  1491. int SetScrollPos(int nPos, BOOL bRedraw = TRUE)
  1492. {
  1493. ATLASSERT(::IsWindow(m_hWnd));
  1494. return ::SetScrollPos(m_hWnd, SB_CTL, nPos, bRedraw);
  1495. }
  1496. #ifndef _WIN32_WCE
  1497. void GetScrollRange(LPINT lpMinPos, LPINT lpMaxPos) const
  1498. {
  1499. ATLASSERT(::IsWindow(m_hWnd));
  1500. ::GetScrollRange(m_hWnd, SB_CTL, lpMinPos, lpMaxPos);
  1501. }
  1502. #endif // !_WIN32_WCE
  1503. void SetScrollRange(int nMinPos, int nMaxPos, BOOL bRedraw = TRUE)
  1504. {
  1505. ATLASSERT(::IsWindow(m_hWnd));
  1506. ::SetScrollRange(m_hWnd, SB_CTL, nMinPos, nMaxPos, bRedraw);
  1507. }
  1508. BOOL GetScrollInfo(LPSCROLLINFO lpScrollInfo) const
  1509. {
  1510. ATLASSERT(::IsWindow(m_hWnd));
  1511. return ::GetScrollInfo(m_hWnd, SB_CTL, lpScrollInfo);
  1512. }
  1513. int SetScrollInfo(LPSCROLLINFO lpScrollInfo, BOOL bRedraw = TRUE)
  1514. {
  1515. ATLASSERT(::IsWindow(m_hWnd));
  1516. return ::SetScrollInfo(m_hWnd, SB_CTL, lpScrollInfo, bRedraw);
  1517. }
  1518. #ifndef _WIN32_WCE
  1519. int GetScrollLimit() const
  1520. {
  1521. int nMin = 0, nMax = 0;
  1522. ::GetScrollRange(m_hWnd, SB_CTL, &nMin, &nMax);
  1523. SCROLLINFO info = { sizeof(SCROLLINFO), SIF_PAGE };
  1524. if(::GetScrollInfo(m_hWnd, SB_CTL, &info))
  1525. nMax -= ((info.nPage - 1) > 0) ? (info.nPage - 1) : 0;
  1526. return nMax;
  1527. }
  1528. #if (WINVER >= 0x0500)
  1529. BOOL GetScrollBarInfo(PSCROLLBARINFO pScrollBarInfo) const
  1530. {
  1531. ATLASSERT(::IsWindow(m_hWnd));
  1532. #if (_WIN32_WINNT >= 0x0501)
  1533. return (BOOL)::SendMessage(m_hWnd, SBM_GETSCROLLBARINFO, 0, (LPARAM)pScrollBarInfo);
  1534. #else // !(_WIN32_WINNT >= 0x0501)
  1535. return ::GetScrollBarInfo(m_hWnd, OBJID_CLIENT, pScrollBarInfo);
  1536. #endif // !(_WIN32_WINNT >= 0x0501)
  1537. }
  1538. #endif // (WINVER >= 0x0500)
  1539. // Operations
  1540. void ShowScrollBar(BOOL bShow = TRUE)
  1541. {
  1542. ATLASSERT(::IsWindow(m_hWnd));
  1543. ::ShowScrollBar(m_hWnd, SB_CTL, bShow);
  1544. }
  1545. BOOL EnableScrollBar(UINT nArrowFlags = ESB_ENABLE_BOTH)
  1546. {
  1547. ATLASSERT(::IsWindow(m_hWnd));
  1548. return ::EnableScrollBar(m_hWnd, SB_CTL, nArrowFlags);
  1549. }
  1550. #endif // !_WIN32_WCE
  1551. };
  1552. typedef CScrollBarT<ATL::CWindow> CScrollBar;
  1553. // --- Windows Common Controls ---
  1554. ///////////////////////////////////////////////////////////////////////////////
  1555. // CImageList
  1556. class CImageList
  1557. {
  1558. public:
  1559. HIMAGELIST m_hImageList;
  1560. // Constructor
  1561. CImageList(HIMAGELIST hImageList = NULL) : m_hImageList(hImageList)
  1562. { }
  1563. // Operators, etc.
  1564. CImageList& operator =(HIMAGELIST hImageList)
  1565. {
  1566. m_hImageList = hImageList;
  1567. return *this;
  1568. }
  1569. operator HIMAGELIST() const { return m_hImageList; }
  1570. void Attach(HIMAGELIST hImageList)
  1571. {
  1572. ATLASSERT(m_hImageList == NULL);
  1573. ATLASSERT(hImageList != NULL);
  1574. m_hImageList = hImageList;
  1575. }
  1576. HIMAGELIST Detach()
  1577. {
  1578. HIMAGELIST hImageList = m_hImageList;
  1579. m_hImageList = NULL;
  1580. return hImageList;
  1581. }
  1582. bool IsNull() const { return (m_hImageList == NULL); }
  1583. // Attributes
  1584. int GetImageCount() const
  1585. {
  1586. ATLASSERT(m_hImageList != NULL);
  1587. return ImageList_GetImageCount(m_hImageList);
  1588. }
  1589. COLORREF GetBkColor() const
  1590. {
  1591. ATLASSERT(m_hImageList != NULL);
  1592. return ImageList_GetBkColor(m_hImageList);
  1593. }
  1594. COLORREF SetBkColor(COLORREF cr)
  1595. {
  1596. ATLASSERT(m_hImageList != NULL);
  1597. return ImageList_SetBkColor(m_hImageList, cr);
  1598. }
  1599. BOOL GetImageInfo(int nImage, IMAGEINFO* p