1 // Win32++ Version 7.3
\r
2 // Released: 30th November 2011
\r
6 // url: https://sourceforge.net/projects/win32-framework
\r
9 // Copyright (c) 2005-2011 David Nash
\r
11 // Permission is hereby granted, free of charge, to
\r
12 // any person obtaining a copy of this software and
\r
13 // associated documentation files (the "Software"),
\r
14 // to deal in the Software without restriction, including
\r
15 // without limitation the rights to use, copy, modify,
\r
16 // merge, publish, distribute, sublicense, and/or sell
\r
17 // copies of the Software, and to permit persons to whom
\r
18 // the Software is furnished to do so, subject to the
\r
19 // following conditions:
\r
21 // The above copyright notice and this permission notice
\r
22 // shall be included in all copies or substantial portions
\r
25 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
\r
26 // ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
\r
27 // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
\r
28 // PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
\r
29 // SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
\r
30 // ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
\r
31 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
\r
32 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
\r
33 // OR OTHER DEALINGS IN THE SOFTWARE.
\r
35 ////////////////////////////////////////////////////////
\r
39 #ifndef _WIN32XX_LISTVIEW_H_
\r
40 #define _WIN32XX_LISTVIEW_H_
\r
42 #include "wincore.h"
\r
43 #include "commctrl.h"
\r
48 class CListView : public CWnd
\r
52 virtual ~CListView() {}
\r
53 virtual void PreRegisterClass(WNDCLASS &wc);
\r
56 CSize ApproximateViewRect(CSize sz = CSize(-1, -1), int iCount = -1) const;
\r
57 COLORREF GetBkColor( ) const;
\r
58 BOOL GetBkImage( LVBKIMAGE& lvbkImage ) const;
\r
59 UINT GetCallbackMask( ) const;
\r
60 BOOL GetCheckState( UINT nItem ) const;
\r
61 BOOL GetColumn( int iCol, LVCOLUMN& Column ) const;
\r
62 BOOL GetColumnOrderArray( LPINT piArray, int iCount = -1 );
\r
63 int GetColumnWidth( int iCol ) const;
\r
64 int GetCountPerPage( ) const;
\r
65 CEdit* GetEditControl( ) const;
\r
66 DWORD GetExtendedStyle( ) const;
\r
67 CHeader* GetHeader( ) const;
\r
68 HCURSOR GetHotCursor( );
\r
69 int GetHotItem( ) const;
\r
70 DWORD GetHoverTime( ) const;
\r
71 HIMAGELIST GetImageList( int nImageType ) const;
\r
72 BOOL GetItem( LVITEM& lvItem ) const;
\r
73 int GetItemCount( ) const;
\r
74 DWORD_PTR GetItemData( int iItem ) const;
\r
75 BOOL GetItemPosition( int iItem, CPoint& pt ) const;
\r
76 BOOL GetItemRect( int iItem, CRect& rc, UINT nCode ) const;
\r
77 UINT GetItemState( int iItem, UINT nMask ) const;
\r
78 CString GetItemText( int iItem, int iSubItem, UINT nTextMax = 260 ) const;
\r
79 int GetNextItem( int iItem, int iFlags ) const;
\r
80 UINT GetNumberOfWorkAreas( ) const;
\r
81 BOOL GetOrigin( CPoint& pt ) const;
\r
82 UINT GetSelectedCount( ) const;
\r
83 int GetSelectionMark( ) const;
\r
84 int GetStringWidth( LPCTSTR pszString ) const;
\r
85 BOOL GetSubItemRect( int iItem, int iSubItem, int iCode, CRect& rc ) const;
\r
86 COLORREF GetTextBkColor( ) const;
\r
87 COLORREF GetTextColor( ) const;
\r
88 CToolTip* GetToolTips( ) const;
\r
89 int GetTopIndex( ) const;
\r
90 BOOL GetViewRect( CRect& rc ) const;
\r
91 void GetWorkAreas( int iWorkAreas, LPRECT pRectArray ) const;
\r
92 BOOL SetBkColor( COLORREF clrBk ) const;
\r
93 BOOL SetBkImage( LVBKIMAGE& plvbkImage ) const;
\r
94 BOOL SetCallbackMask( UINT nMask ) const;
\r
95 void SetCheckState( int iItem, BOOL fCheck = TRUE ) const;
\r
96 BOOL SetColumn( int iCol, const LVCOLUMN& pColumn ) const;
\r
97 BOOL SetColumnOrderArray( int iCount, LPINT piArray ) const;
\r
98 BOOL SetColumnWidth( int iCol, int cx ) const;
\r
99 DWORD SetExtendedStyle( DWORD dwNewStyle ) const;
\r
100 HCURSOR SetHotCursor( HCURSOR hCursor ) const;
\r
101 int SetHotItem( int nIndex ) const;
\r
102 DWORD SetHoverTime( DWORD dwHoverTime = (DWORD)-1 ) const;
\r
103 CSize SetIconSpacing( int cx, int cy ) const;
\r
104 CSize SetIconSpacing( CSize sz ) const;
\r
105 HIMAGELIST SetImageList( HIMAGELIST himl, int iImageListType ) const;
\r
106 BOOL SetItem( LVITEM& pItem ) const;
\r
107 BOOL SetItem( int iItem, int iSubItem, UINT nMask, LPCTSTR pszText, int iImage,
\r
108 UINT nState, UINT nStateMask, LPARAM lParam, int iIndent ) const;
\r
109 void SetItemCount( int iCount ) const;
\r
110 void SetItemCountEx( int iCount, DWORD dwFlags = LVSICF_NOINVALIDATEALL ) const;
\r
111 BOOL SetItemData( int iItem, DWORD_PTR dwData ) const;
\r
112 BOOL SetItemPosition( int iItem, CPoint& pt ) const;
\r
113 BOOL SetItemState( int iItem, LVITEM& Item ) const;
\r
114 void SetItemState( int iItem, UINT nState, UINT nMask ) const;
\r
115 void SetItemText( int iItem, int iSubItem, LPCTSTR pszText ) const;
\r
116 int SetSelectionMark( int iIndex ) const;
\r
117 BOOL SetTextBkColor( COLORREF clrBkText ) const;
\r
118 BOOL SetTextColor( COLORREF clrText ) const;
\r
119 CToolTip* SetToolTips ( CToolTip* pToolTip ) const;
\r
120 void SetWorkAreas( int nWorkAreas, CRect& pRectArray ) const;
\r
121 int SubItemHitTest( LVHITTESTINFO& htInfo ) const;
\r
124 BOOL Arrange( UINT nCode ) const;
\r
125 HIMAGELIST CreateDragImage( int iItem, CPoint& pt ) const;
\r
126 BOOL DeleteAllItems( ) const;
\r
127 BOOL DeleteColumn( int iCol ) const;
\r
128 BOOL DeleteItem( int iItem ) const;
\r
129 CEdit* EditLabel( int iItem ) const;
\r
130 BOOL EnsureVisible( int iItem, BOOL fPartialOK ) const;
\r
131 int FindItem( LVFINDINFO& FindInfo, int iStart = -1 ) const;
\r
132 int HitTest( LVHITTESTINFO& HitTestInfo ) const;
\r
133 int HitTest( CPoint pt, UINT* pFlags = NULL ) const;
\r
134 int InsertColumn( int iCol, const LVCOLUMN& pColumn ) const;
\r
135 int InsertColumn( int iCol, LPCTSTR pszColumnHeading, int iFormat = LVCFMT_LEFT,
\r
136 int iWidth = -1, int iSubItem = -1 ) const;
\r
137 int InsertItem( const LVITEM& pItem ) const;
\r
138 int InsertItem( int iItem, LPCTSTR pszText ) const;
\r
139 int InsertItem( int iItem, LPCTSTR pszText, int iImage ) const;
\r
140 BOOL RedrawItems( int iFirst, int iLast ) const;
\r
141 BOOL Scroll( CSize sz ) const;
\r
142 BOOL SortItems( PFNLVCOMPARE pfnCompare, DWORD_PTR dwData ) const;
\r
143 BOOL Update( int iItem ) const;
\r
146 CListView(const CListView&); // Disable copy construction
\r
147 CListView& operator = (const CListView&); // Disable assignment operator
\r
152 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
\r
157 inline void CListView::PreRegisterClass(WNDCLASS &wc)
\r
159 // Set the Window Class
\r
160 wc.lpszClassName = WC_LISTVIEW;
\r
163 inline CSize CListView::ApproximateViewRect(CSize sz /*= CSize(-1, -1)*/, int iCount /* = -1*/) const
\r
164 // Calculates the approximate width and height required to display a given number of items.
\r
166 assert(::IsWindow(m_hWnd));
\r
167 return CSize( ListView_ApproximateViewRect( m_hWnd, sz.cx, sz.cy, iCount ) );
\r
170 inline COLORREF CListView::GetBkColor( ) const
\r
171 // Retrieves the background color of a list-view control.
\r
173 assert(::IsWindow(m_hWnd));
\r
174 return ListView_GetBkColor( m_hWnd );
\r
177 inline BOOL CListView::GetBkImage( LVBKIMAGE& lvbkImage ) const
\r
178 // Retrieves the background image in a list-view control.
\r
180 assert(::IsWindow(m_hWnd));
\r
181 return ListView_GetBkImage( m_hWnd, &lvbkImage );
\r
184 inline UINT CListView::GetCallbackMask( ) const
\r
185 // Retrieves the callback mask for a list-view control.
\r
187 assert(::IsWindow(m_hWnd));
\r
188 return ListView_GetCallbackMask( m_hWnd );
\r
191 inline BOOL CListView::GetCheckState( UINT nItem ) const
\r
192 // Determines if an item in a list-view control is selected.
\r
194 assert(::IsWindow(m_hWnd));
\r
195 return ListView_GetCheckState( m_hWnd, nItem );
\r
198 inline BOOL CListView::GetColumn( int iCol, LVCOLUMN& Column ) const
\r
199 // Retrieves the attributes of a list-view control's column.
\r
201 assert(::IsWindow(m_hWnd));
\r
202 return ListView_GetColumn( m_hWnd, iCol, &Column );
\r
205 inline BOOL CListView::GetColumnOrderArray( LPINT piArray, int iCount /*= -1*/ )
\r
206 // Retrieves the current left-to-right order of columns in a list-view control.
\r
208 assert(::IsWindow(m_hWnd));
\r
209 return ListView_GetColumnOrderArray( m_hWnd, iCount, piArray );
\r
212 inline int CListView::GetColumnWidth( int iCol ) const
\r
213 // Retrieves the width of a column in report or list view.
\r
215 assert(::IsWindow(m_hWnd));
\r
216 return ListView_GetColumnWidth( m_hWnd, iCol );
\r
219 inline int CListView::GetCountPerPage( ) const
\r
220 // Calculates the number of items that can fit vertically in the visible area of a
\r
221 // list-view control when in list or report view. Only fully visible items are counted.
\r
223 assert(::IsWindow(m_hWnd));
\r
224 return ListView_GetCountPerPage( m_hWnd );
\r
227 inline CEdit* CListView::GetEditControl( ) const
\r
228 // Retrieves the handle to the edit control being used to edit a list-view item's text.
\r
230 assert(::IsWindow(m_hWnd));
\r
231 return (CEdit*)FromHandle(ListView_GetEditControl( m_hWnd ));
\r
234 inline DWORD CListView::GetExtendedStyle( ) const
\r
235 // Retrieves the extended styles that are currently in use for a given list-view control.
\r
237 assert(::IsWindow(m_hWnd));
\r
238 return ListView_GetExtendedListViewStyle( m_hWnd );
\r
241 inline CHeader* CListView::GetHeader( ) const
\r
242 // Retrieves the handle to the header control used by a list-view control.
\r
244 assert(::IsWindow(m_hWnd));
\r
245 return (CHeader*)FromHandle(ListView_GetHeader( m_hWnd ));
\r
248 inline HCURSOR CListView::GetHotCursor( )
\r
249 // Retrieves the HCURSOR used when the pointer is over an item while hot tracking is enabled.
\r
251 assert(::IsWindow(m_hWnd));
\r
252 return ListView_GetHotCursor( m_hWnd );
\r
255 inline int CListView::GetHotItem( ) const
\r
256 // Retrieves the index of the hot item.
\r
258 assert(::IsWindow(m_hWnd));
\r
259 return ListView_GetHotItem( m_hWnd );
\r
262 inline DWORD CListView::GetHoverTime( ) const
\r
263 // Retrieves the amount of time that the mouse cursor must hover over an item before it is selected.
\r
265 assert(::IsWindow(m_hWnd));
\r
266 return ListView_GetHoverTime( m_hWnd );
\r
269 inline HIMAGELIST CListView::GetImageList( int nImageType ) const
\r
270 // Retrieves the handle to an image list used for drawing list-view items.
\r
272 assert(::IsWindow(m_hWnd));
\r
273 return ListView_GetImageList( m_hWnd, nImageType );
\r
276 inline BOOL CListView::GetItem( LVITEM& Item ) const
\r
277 // Retrieves some or all of a list-view item's attributes.
\r
279 assert(::IsWindow(m_hWnd));
\r
280 return ListView_GetItem( m_hWnd, &Item );
\r
283 inline int CListView::GetItemCount( ) const
\r
284 // Retrieves the number of items in a list-view control.
\r
286 assert(::IsWindow(m_hWnd));
\r
287 return ListView_GetItemCount( m_hWnd );
\r
290 inline DWORD_PTR CListView::GetItemData( int iItem ) const
\r
291 // Retrieves the value(lParam) specific to the item.
\r
293 assert(::IsWindow(m_hWnd));
\r
297 lvi.mask = LVIF_PARAM;
\r
298 ListView_GetItem(m_hWnd, &lvi);
\r
302 inline BOOL CListView::GetItemPosition( int iItem, CPoint& pt ) const
\r
303 // Retrieves the position of a list-view item.
\r
305 assert(::IsWindow(m_hWnd));
\r
306 return ListView_GetItemPosition( m_hWnd, iItem, &pt );
\r
309 inline BOOL CListView::GetItemRect( int iItem, CRect& rc, UINT nCode ) const
\r
310 // Retrieves the bounding rectangle for all or part of an item in the current view.
\r
312 assert(::IsWindow(m_hWnd));
\r
313 return ListView_GetItemRect( m_hWnd, iItem, &rc, nCode );
\r
316 inline UINT CListView::GetItemState( int iItem, UINT nMask ) const
\r
317 // Retrieves the state of a list-view item.
\r
319 // Possible values of nMask:
\r
320 // LVIS_CUT The item is marked for a cut-and-paste operation.
\r
321 // LVIS_DROPHILITED The item is highlighted as a drag-and-drop target.
\r
322 // LVIS_FOCUSED The item has the focus, so it is surrounded by a standard focus rectangle.
\r
323 // LVIS_SELECTED The item is selected.
\r
324 // LVIS_OVERLAYMASK Use this mask to retrieve the item's overlay image index.
\r
325 // LVIS_STATEIMAGEMASK Use this mask to retrieve the item's state image index.
\r
327 assert(::IsWindow(m_hWnd));
\r
328 return ListView_GetItemState( m_hWnd, iItem, nMask );
\r
331 inline CString CListView::GetItemText( int iItem, int iSubItem, UINT nTextMax /* = 260 */ ) const
\r
332 // Retrieves the text of a list-view item.
\r
333 // Note: Although the list-view control allows any length string to be stored
\r
334 // as item text, only the first 260 characters are displayed.
\r
336 assert(::IsWindow(m_hWnd));
\r
341 std::vector<TCHAR> vTChar(nTextMax +1, _T('\0'));
\r
342 TCHAR* pszText = &vTChar.front();
\r
345 lvi.iSubItem = iSubItem;
\r
346 lvi.mask = LVIF_TEXT;
\r
347 lvi.cchTextMax = nTextMax;
\r
348 lvi.pszText = pszText;
\r
349 ListView_GetItem( m_hWnd, &lvi );
\r
355 inline int CListView::GetNextItem( int iItem, int iFlags ) const
\r
356 // Searches for a list-view item that has the specified properties and
\r
357 // bears the specified relationship to a specified item.
\r
359 assert(::IsWindow(m_hWnd));
\r
360 return ListView_GetNextItem( m_hWnd, iItem, iFlags );
\r
363 inline UINT CListView::GetNumberOfWorkAreas( ) const
\r
364 // Retrieves the working areas from a list-view control.
\r
366 assert(::IsWindow(m_hWnd));
\r
367 UINT nWorkAreas = 0;
\r
368 ListView_GetWorkAreas( m_hWnd, nWorkAreas, NULL );
\r
372 inline BOOL CListView::GetOrigin( CPoint& pt ) const
\r
373 // Retrieves the current view origin for a list-view control.
\r
375 assert(::IsWindow(m_hWnd));
\r
376 return ListView_GetOrigin( m_hWnd, &pt );
\r
379 inline UINT CListView::GetSelectedCount( ) const
\r
380 // Determines the number of selected items in a list-view control.
\r
382 assert(::IsWindow(m_hWnd));
\r
383 return (UINT)::SendMessage( m_hWnd, LVM_GETSELECTEDCOUNT, 0L, 0L );
\r
386 inline int CListView::GetSelectionMark( ) const
\r
387 // Retrieves the selection mark from a list-view control.
\r
389 assert(::IsWindow(m_hWnd));
\r
390 return (int)::SendMessage( m_hWnd, LVM_GETSELECTIONMARK, 0L, 0L );
\r
393 inline int CListView::GetStringWidth( LPCTSTR pszString ) const
\r
394 // Determines the width of a specified string using the specified list-view control's current font.
\r
396 assert(::IsWindow(m_hWnd));
\r
397 return (int)::SendMessage( m_hWnd, LVM_GETSTRINGWIDTH, 0L, (LPARAM)pszString );
\r
400 inline BOOL CListView::GetSubItemRect( int iItem, int iSubItem, int iCode, CRect& rc ) const
\r
401 // Retrieves information about the rectangle that surrounds a subitem in a list-view control.
\r
403 assert(::IsWindow(m_hWnd));
\r
404 return ListView_GetSubItemRect( m_hWnd, iItem, iSubItem, iCode, &rc );
\r
407 inline COLORREF CListView::GetTextBkColor( ) const
\r
408 // Retrieves the text background color of a list-view control.
\r
410 assert(::IsWindow(m_hWnd));
\r
411 return ListView_GetTextBkColor( m_hWnd );
\r
414 inline COLORREF CListView::GetTextColor( ) const
\r
415 // Retrieves the text color of a list-view control.
\r
417 assert(::IsWindow(m_hWnd));
\r
418 return ListView_GetTextColor( m_hWnd );
\r
421 inline CToolTip* CListView::GetToolTips( ) const
\r
422 // Retrieves the ToolTip control that the list-view control uses to display ToolTips.
\r
424 assert(::IsWindow(m_hWnd));
\r
425 return(CToolTip*)FromHandle(ListView_GetToolTips( m_hWnd ) );
\r
428 inline int CListView::GetTopIndex( ) const
\r
429 // Retrieves the index of the topmost visible item when in list or report view.
\r
431 assert(::IsWindow(m_hWnd));
\r
432 return ListView_GetTopIndex( m_hWnd );
\r
435 inline BOOL CListView::GetViewRect( CRect& rc ) const
\r
436 // Retrieves the bounding rectangle of all items in the list-view control.
\r
438 assert(::IsWindow(m_hWnd));
\r
439 return ListView_GetViewRect( m_hWnd, &rc );
\r
442 inline void CListView::GetWorkAreas( int iWorkAreas, LPRECT pRectArray ) const
\r
443 // Retrieves the working areas from a list-view control.
\r
445 assert(::IsWindow(m_hWnd));
\r
446 ListView_GetWorkAreas( m_hWnd, iWorkAreas, pRectArray );
\r
449 inline BOOL CListView::SetBkColor( COLORREF clrBk ) const
\r
450 // Sets the background color of a list-view control.
\r
452 assert(::IsWindow(m_hWnd));
\r
453 return ListView_SetBkColor( m_hWnd, clrBk );
\r
456 inline BOOL CListView::SetBkImage( LVBKIMAGE& lvbkImage ) const
\r
457 // Sets the background image in a list-view control.
\r
459 assert(::IsWindow(m_hWnd));
\r
460 return ListView_SetBkImage( m_hWnd, &lvbkImage );
\r
463 inline BOOL CListView::SetCallbackMask( UINT nMask ) const
\r
464 // Changes the callback mask for a list-view control.
\r
466 assert(::IsWindow(m_hWnd));
\r
467 return ListView_SetCallbackMask( m_hWnd, nMask );
\r
470 inline void CListView::SetCheckState( int iItem, BOOL fCheck /*= TRUE*/ ) const
\r
471 // Used to select or deselect an item in a list-view control.
\r
472 // This macro should only be used for list-view controls with the LVS_EX_CHECKBOXES style.
\r
474 assert(::IsWindow(m_hWnd));
\r
475 ListView_SetItemState(m_hWnd, iItem, INDEXTOSTATEIMAGEMASK((fCheck==TRUE)?2:1),LVIS_STATEIMAGEMASK);
\r
478 inline BOOL CListView::SetColumn( int iCol, const LVCOLUMN& Column ) const
\r
479 // Sets the attributes of a list-view column.
\r
481 assert(::IsWindow(m_hWnd));
\r
482 return ListView_SetColumn( m_hWnd, iCol, &Column );
\r
485 inline BOOL CListView::SetColumnOrderArray( int iCount, LPINT piArray ) const
\r
486 // Sets the left-to-right order of columns in a list-view control.
\r
488 assert(::IsWindow(m_hWnd));
\r
489 return ListView_SetColumnOrderArray( m_hWnd, iCount, piArray );
\r
492 inline BOOL CListView::SetColumnWidth( int iCol, int cx ) const
\r
493 // Used to change the width of a column in report view or the width of all columns in list-view mode.
\r
495 assert(::IsWindow(m_hWnd));
\r
496 return ListView_SetColumnWidth( m_hWnd, iCol, cx );
\r
499 inline DWORD CListView::SetExtendedStyle( DWORD dwNewStyle ) const
\r
500 // Sets extended styles for list-view controls.
\r
502 assert(::IsWindow(m_hWnd));
\r
503 return ListView_SetExtendedListViewStyle( m_hWnd, dwNewStyle );
\r
506 inline HCURSOR CListView::SetHotCursor( HCURSOR hCursor ) const
\r
507 // Sets the HCURSOR that the list-view control uses when the pointer is
\r
508 // over an item while hot tracking is enabled.
\r
510 assert(::IsWindow(m_hWnd));
\r
511 return ListView_SetHotCursor( m_hWnd, hCursor );
\r
514 inline int CListView::SetHotItem( int nIndex ) const
\r
515 // Sets the hot item in a list-view control.
\r
517 assert(::IsWindow(m_hWnd));
\r
518 return ListView_SetHotItem( m_hWnd, nIndex );
\r
521 inline DWORD CListView::SetHoverTime( DWORD dwHoverTime /*= (DWORD)-1*/ ) const
\r
522 // Sets the amount of time that the mouse cursor must hover over an item before it is selected.
\r
524 assert(::IsWindow(m_hWnd));
\r
525 return ListView_SetHoverTime( m_hWnd, dwHoverTime );
\r
528 inline CSize CListView::SetIconSpacing( int cx, int cy ) const
\r
529 // Sets the spacing between icons in list-view controls set to the LVS_ICON style.
\r
531 assert(::IsWindow(m_hWnd));
\r
532 return CSize( ListView_SetIconSpacing( m_hWnd, cx, cy ) );
\r
535 inline CSize CListView::SetIconSpacing( CSize sz ) const
\r
536 // Sets the spacing between icons in list-view controls set to the LVS_ICON style.
\r
538 assert(::IsWindow(m_hWnd));
\r
539 return CSize( ListView_SetIconSpacing( m_hWnd, sz.cx, sz.cy ) );
\r
542 inline HIMAGELIST CListView::SetImageList( HIMAGELIST himl, int iImageListType ) const
\r
543 // Assigns an image list to a list-view control.
\r
545 assert(::IsWindow(m_hWnd));
\r
546 return ListView_SetImageList( m_hWnd, himl, iImageListType );
\r
549 inline BOOL CListView::SetItem( LVITEM& Item ) const
\r
550 // Sets some or all of a list-view item's attributes.
\r
552 // The declaration for TVITEM:
\r
553 // typedef struct _LVITEM {
\r
563 // } LVITEM, *LVITEM&;
\r
565 assert(::IsWindow(m_hWnd));
\r
566 return ListView_SetItem( m_hWnd, &Item );
\r
569 inline BOOL CListView::SetItem( int iItem, int iSubItem, UINT nMask, LPCTSTR pszText, int iImage,
\r
570 UINT nState, UINT nStateMask, LPARAM lParam, int iIndent ) const
\r
571 // Sets some or all of a list-view item's attributes.
\r
573 assert(::IsWindow(m_hWnd));
\r
577 lvi.iSubItem = iSubItem;
\r
579 lvi.pszText = (LPTSTR)pszText;
\r
580 lvi.iImage = iImage;
\r
581 lvi.state = nState;
\r
582 lvi.stateMask = nStateMask;
\r
583 lvi.lParam = lParam;
\r
584 lvi.iIndent = iIndent;
\r
586 return ListView_SetItem( m_hWnd, &lvi);
\r
589 inline void CListView::SetItemCount( int iCount ) const
\r
590 // Causes the list-view control to allocate memory for the specified number of items.
\r
592 assert(::IsWindow(m_hWnd));
\r
593 ListView_SetItemCount( m_hWnd, iCount );
\r
596 inline void CListView::SetItemCountEx( int iCount, DWORD dwFlags /*= LVSICF_NOINVALIDATEALL*/ ) const
\r
597 // Sets the virtual number of items in a virtual list view.
\r
599 assert(::IsWindow(m_hWnd));
\r
600 ListView_SetItemCountEx( m_hWnd, iCount, dwFlags );
\r
603 inline BOOL CListView::SetItemData( int iItem, DWORD_PTR dwData ) const
\r
604 // Sets the value(lParam) specific to the item.
\r
606 assert(::IsWindow(m_hWnd));
\r
610 lvi.lParam = dwData;
\r
611 lvi.mask = LVIF_PARAM;
\r
612 return ListView_SetItem(m_hWnd, &lvi);
\r
615 inline BOOL CListView::SetItemPosition( int iItem, CPoint& pt ) const
\r
616 // Moves an item to a specified position in a list-view control (in icon or small icon view).
\r
618 assert(::IsWindow(m_hWnd));
\r
619 return ListView_SetItemPosition( m_hWnd, iItem, pt.x, pt.y );
\r
622 inline BOOL CListView::SetItemState( int iItem, LVITEM& Item ) const
\r
623 // Changes the state of an item in a list-view control.
\r
625 // Possible values of nMask:
\r
626 // LVIS_CUT The item is marked for a cut-and-paste operation.
\r
627 // LVIS_DROPHILITED The item is highlighted as a drag-and-drop target.
\r
628 // LVIS_FOCUSED The item has the focus, so it is surrounded by a standard focus rectangle.
\r
629 // LVIS_SELECTED The item is selected.
\r
630 // LVIS_OVERLAYMASK Use this mask to retrieve the item's overlay image index.
\r
631 // LVIS_STATEIMAGEMASK Use this mask to retrieve the item's state image index.
\r
633 assert(::IsWindow(m_hWnd));
\r
634 return (BOOL)::SendMessage(m_hWnd, LVM_SETITEMSTATE, (WPARAM)iItem, (LPARAM)&Item);
\r
637 inline void CListView::SetItemState( int iItem, UINT nState, UINT nMask ) const
\r
638 // Changes the state of an item in a list-view control.
\r
640 assert(::IsWindow(m_hWnd));
\r
641 ListView_SetItemState(m_hWnd, iItem, nState, nMask);
\r
644 inline void CListView::SetItemText( int iItem, int iSubItem, LPCTSTR pszText ) const
\r
645 // Sets the text color of a list-view control.
\r
647 assert(::IsWindow(m_hWnd));
\r
648 ListView_SetItemText(m_hWnd, iItem, iSubItem, (LPTSTR)pszText );
\r
651 inline int CListView::SetSelectionMark( int iIndex ) const
\r
652 // Sets the selection mark in a list-view control.
\r
654 assert(::IsWindow(m_hWnd));
\r
655 return ListView_SetSelectionMark( m_hWnd, iIndex );
\r
658 inline BOOL CListView::SetTextBkColor( COLORREF clrBkText ) const
\r
659 // Sets the background color of text in a list-view control.
\r
661 assert(::IsWindow(m_hWnd));
\r
662 return ListView_SetTextBkColor( m_hWnd, clrBkText );
\r
665 inline BOOL CListView::SetTextColor( COLORREF clrText ) const
\r
666 // Sets the text color of a list-view control.
\r
668 assert(::IsWindow(m_hWnd));
\r
669 return ListView_SetTextColor( m_hWnd, clrText );
\r
672 inline CToolTip* CListView::SetToolTips( CToolTip* pToolTip ) const
\r
673 // Sets the ToolTip control that the list-view control will use to display ToolTips.
\r
675 assert(::IsWindow(m_hWnd));
\r
678 HWND hToolTip = pToolTip? pToolTip->GetHwnd() : 0;
\r
679 return (CToolTip*) FromHandle( (HWND)::SendMessage(m_hWnd, LVM_SETTOOLTIPS, (WPARAM)hToolTip, 0L) );
\r
682 inline void CListView::SetWorkAreas( int nWorkAreas, CRect& pRectArray ) const
\r
683 // Sets the working area within a list-view control.
\r
685 assert(::IsWindow(m_hWnd));
\r
686 ListView_SetWorkAreas( m_hWnd, nWorkAreas, pRectArray );
\r
689 inline int CListView::SubItemHitTest( LVHITTESTINFO& htInfo ) const
\r
690 // Determines which list-view item or subitem is located at a given position.
\r
692 assert(::IsWindow(m_hWnd));
\r
693 return ListView_SubItemHitTest( m_hWnd, &htInfo );
\r
698 inline BOOL CListView::Arrange( UINT nCode ) const
\r
699 // Arranges items in icon view.
\r
701 assert(::IsWindow(m_hWnd));
\r
702 return ListView_Arrange( m_hWnd, nCode );
\r
705 inline HIMAGELIST CListView::CreateDragImage( int iItem, CPoint& pt ) const
\r
706 // Creates a drag image list for the specified item.
\r
708 assert(::IsWindow(m_hWnd));
\r
709 return ListView_CreateDragImage( m_hWnd, iItem, &pt );
\r
712 inline BOOL CListView::DeleteAllItems( ) const
\r
713 // ListView_DeleteAllItems
\r
715 assert(::IsWindow(m_hWnd));
\r
716 return ListView_DeleteAllItems( m_hWnd );
\r
719 inline BOOL CListView::DeleteColumn( int iCol ) const
\r
720 // Removes a column from a list-view control.
\r
722 assert(::IsWindow(m_hWnd));
\r
723 return ListView_DeleteColumn( m_hWnd, iCol );
\r
726 inline BOOL CListView::DeleteItem( int iItem ) const
\r
727 // Removes an item from a list-view control.
\r
729 assert(::IsWindow(m_hWnd));
\r
730 return ListView_DeleteItem( m_hWnd, iItem );
\r
733 inline CEdit* CListView::EditLabel( int iItem ) const
\r
734 // Begins in-place editing of the specified list-view item's text.
\r
736 assert(::IsWindow(m_hWnd));
\r
737 return (CEdit*)FromHandle( ListView_EditLabel( m_hWnd, iItem ) );
\r
740 inline BOOL CListView::EnsureVisible( int iItem, BOOL fPartialOK ) const
\r
741 // Ensures that a list-view item is either entirely or partially visible,
\r
742 // scrolling the list-view control if necessary.
\r
744 assert(::IsWindow(m_hWnd));
\r
745 return (BOOL)SendMessage(LVM_ENSUREVISIBLE, (WPARAM)iItem, (LPARAM)fPartialOK );
\r
748 inline int CListView::FindItem( LVFINDINFO& FindInfo, int iStart /*= -1*/ ) const
\r
749 // Searches for a list-view item with the specified characteristics.
\r
751 assert(::IsWindow(m_hWnd));
\r
752 return ListView_FindItem( m_hWnd, iStart, &FindInfo );
\r
755 inline int CListView::HitTest( LVHITTESTINFO& HitTestInfo ) const
\r
756 // Determines which list-view item, if any, is at a specified position.
\r
758 assert(::IsWindow(m_hWnd));
\r
759 return ListView_HitTest( m_hWnd, &HitTestInfo );
\r
762 inline int CListView::HitTest( CPoint pt, UINT* pFlags /*= NULL*/ ) const
\r
763 // Determines which list-view item, if any, is at a specified position.
\r
765 assert(::IsWindow(m_hWnd));
\r
767 LVHITTESTINFO hti = {0};
\r
768 hti.flags = *pFlags;
\r
770 return ListView_HitTest( m_hWnd, &hti );
\r
773 inline int CListView::InsertColumn( int iCol, const LVCOLUMN& Column ) const
\r
774 // Inserts a new column in a list-view control.
\r
776 assert(::IsWindow(m_hWnd));
\r
777 return ListView_InsertColumn( m_hWnd, iCol, &Column );
\r
780 inline int CListView::InsertColumn( int iCol, LPCTSTR pszColumnHeading, int iFormat /*= LVCFMT_LEFT*/,
\r
781 int iWidth /*= -1*/, int iSubItem /*= -1*/ ) const
\r
782 // Inserts a new column in a list-view control.
\r
784 assert(::IsWindow(m_hWnd));
\r
786 LVCOLUMN lvc = {0};
\r
787 lvc.mask = LVCF_TEXT|LVCF_ORDER|LVCF_FMT;
\r
790 lvc.mask |= LVCF_WIDTH;
\r
793 if (-1 != iSubItem)
\r
795 lvc.mask |= LVCF_SUBITEM;
\r
796 lvc.iSubItem = iSubItem;
\r
800 lvc.pszText = (LPTSTR)pszColumnHeading;
\r
802 lvc.iSubItem = iSubItem;
\r
803 return ListView_InsertColumn( m_hWnd, iCol, &lvc );
\r
806 inline int CListView::InsertItem( const LVITEM& Item ) const
\r
807 // Inserts a new item in a list-view control.
\r
809 assert(::IsWindow(m_hWnd));
\r
810 return ListView_InsertItem( m_hWnd, &Item );
\r
813 inline int CListView::InsertItem( int iItem, LPCTSTR pszText ) const
\r
814 // Inserts a new item in a list-view control.
\r
816 assert(::IsWindow(m_hWnd));
\r
820 lvi.pszText = (LPTSTR)pszText;
\r
821 lvi.mask = LVIF_TEXT;
\r
822 return ListView_InsertItem( m_hWnd, &lvi );
\r
825 inline int CListView::InsertItem( int iItem, LPCTSTR pszText, int iImage ) const
\r
826 // Inserts a new item in a list-view control.
\r
828 assert(::IsWindow(m_hWnd));
\r
832 lvi.pszText = (LPTSTR)pszText;
\r
833 lvi.iImage = iImage;
\r
834 lvi.mask = LVIF_TEXT | LVIF_IMAGE;
\r
835 return ListView_InsertItem( m_hWnd, &lvi );
\r
838 inline BOOL CListView::RedrawItems( int iFirst, int iLast ) const
\r
839 // Forces a list-view control to redraw a range of items.
\r
841 assert(::IsWindow(m_hWnd));
\r
842 return ListView_RedrawItems( m_hWnd, iFirst, iLast );
\r
845 inline BOOL CListView::Scroll( CSize sz ) const
\r
846 // Scrolls the content of a list-view control.
\r
848 assert(::IsWindow(m_hWnd));
\r
849 return ListView_Scroll( m_hWnd, sz.cx, sz.cy );
\r
852 inline BOOL CListView::SortItems( PFNLVCOMPARE pfnCompare, DWORD_PTR dwData ) const
\r
853 // Uses an application-defined comparison function to sort the items of a list-view control.
\r
855 assert(::IsWindow(m_hWnd));
\r
856 return ListView_SortItems( m_hWnd, pfnCompare, dwData );
\r
859 inline BOOL CListView::Update( int iItem ) const
\r
860 // Updates a list-view item. If the list-view control has the LVS_AUTOARRANGE style,
\r
861 // the list-view control is rearranged.
\r
863 assert(::IsWindow(m_hWnd));
\r
864 return ListView_Update( m_hWnd, iItem );
\r
867 } // namespace Win32xx
\r
869 #endif // #ifndef _WIN32XX_LISTVIEW_H_
\r