home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / atl / atlcon / atlcontrols.h < prev    next >
C/C++ Source or Header  |  1998-04-03  |  172KB  |  5,947 lines

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