sprint 1-alpha
sprint/gtl/ListView.h
Go to the documentation of this file.
00001 /******************************************************************************
00002  *  GTL: GUI Template Library 
00003  *    A Cross Platform C++ Wrapper for Win32 users
00004  *  Copyright (C) 2007-2011 Paolo Medici (www.pmx.it)
00005  *
00006  *  This library is free software; you can redistribute it and/or
00007  *  modify it under the terms of the GNU Lesser General Public
00008  *  License as published by the Free Software Foundation; either
00009  *  version 2.1 of the License, or (at your option) any later version.
00010  *
00011  *  This library is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  *  Lesser General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU Lesser General Public
00017  *  License along with this library; if not, write to the Free Software
00018  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00019  *
00020  *******************************************************************************/
00021 #ifndef _SPRINT_LISTVIEW_H
00022 #define _SPRINT_LISTVIEW_H
00023 
00027 #include <commctrl.h>
00028 #include <sprint/gtl/Window.h>
00029 #include <sprint/gtl/detail/commctrl.h>
00030 
00031 namespace sprint {
00032         namespace gtl {
00033           
00035 class ListView : public CWindow
00036 {
00037 public:
00038 // Constructors
00039         ListView(HWND hWnd = NULL) : CWindow(hWnd)
00040         { }
00041 
00042 /*
00043         HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
00044                         DWORD dwStyle = 0, DWORD dwExStyle = 0,
00045                         ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
00046         {
00047                 return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
00048         }
00049 */
00050 // Attributes
00051         static LPCTSTR GetWndClassName()
00052         {
00053                 return WC_LISTVIEW;
00054         }
00055 
00056         COLORREF GetBkColor() const
00057         {
00058                 return (COLORREF)::SendMessage(m_hwnd, LVM_GETBKCOLOR, 0, 0L);
00059         }
00060 
00061         BOOL SetBkColor(COLORREF cr)
00062         {
00063                 return (BOOL)::SendMessage(m_hwnd, LVM_SETBKCOLOR, 0, cr);
00064         }
00065 
00066         HIMAGELIST GetImageList(int nImageListType) const
00067         {
00068                 return ((HIMAGELIST)::SendMessage(m_hwnd, LVM_GETIMAGELIST, nImageListType, 0L));
00069         }
00070 
00071         HIMAGELIST SetImageList(HIMAGELIST hImageList, int nImageList)
00072         {
00073                 return ((HIMAGELIST)::SendMessage(m_hwnd, LVM_SETIMAGELIST, nImageList, (LPARAM)hImageList));
00074         }
00075 
00076         int GetItemCount() const
00077         {
00078                 return (int)::SendMessage(m_hwnd, LVM_GETITEMCOUNT, 0, 0L);
00079         }
00080 
00081         BOOL SetItemCount(int nItems)
00082         {
00083                 return (BOOL)::SendMessage(m_hwnd, LVM_SETITEMCOUNT, nItems, 0L);
00084         }
00085 
00086         BOOL GetItem(LVITEM *pItem) const
00087         {
00088                 return (BOOL)::SendMessage(m_hwnd, LVM_GETITEM, 0, (LPARAM)pItem);
00089         }
00090 
00091         BOOL SetItem(const LVITEM* pItem)
00092         {
00093                 return (BOOL)::SendMessage(m_hwnd, LVM_SETITEM, 0, (LPARAM)pItem);
00094         }
00095 
00096         BOOL SetItem(int nItem, int nSubItem, UINT nMask, LPCTSTR lpszItem,
00097                 int nImage, UINT nState, UINT nStateMask, LPARAM lParam)
00098         {
00099                 LVITEM lvi = { 0 };
00100                 lvi.mask = nMask;
00101                 lvi.iItem = nItem;
00102                 lvi.iSubItem = nSubItem;
00103                 lvi.stateMask = nStateMask;
00104                 lvi.state = nState;
00105                 lvi.pszText = (LPTSTR) lpszItem;
00106                 lvi.iImage = nImage;
00107                 lvi.lParam = lParam;
00108                 return (BOOL)::SendMessage(m_hwnd, LVM_SETITEM, 0, (LPARAM)&lvi);
00109         }
00110 
00111         UINT GetItemState(int nItem, UINT nMask) const
00112         {
00113                 return (UINT)::SendMessage(m_hwnd, LVM_GETITEMSTATE, nItem, nMask);
00114         }
00115 
00116         BOOL SetItemState(int nItem, UINT nState, UINT nStateMask)
00117         {
00118                 LVITEM lvi = { 0 };
00119                 lvi.state = nState;
00120                 lvi.stateMask = nStateMask;
00121                 return (BOOL)::SendMessage(m_hwnd, LVM_SETITEMSTATE, nItem, (LPARAM)&lvi);
00122         }
00123 
00124         BOOL SetItemState(int nItem, const LVITEM * pItem)
00125         {
00126                 return (BOOL)::SendMessage(m_hwnd, LVM_SETITEMSTATE, nItem, (LPARAM)pItem);
00127         }
00128 
00129         int GetItemText(int nItem, int nSubItem, LPTSTR lpszText, int nLen) const
00130         {
00131                 LVITEM lvi = { 0 };
00132                 lvi.iSubItem = nSubItem;
00133                 lvi.cchTextMax = nLen;
00134                 lvi.pszText = lpszText;
00135                 return (int)::SendMessage(m_hwnd, LVM_GETITEMTEXT, (WPARAM)nItem, (LPARAM)&lvi);
00136         }
00137 
00138         BOOL SetItemText(int nItem, int nSubItem, LPCTSTR lpszText)
00139         {
00140                 return SetItem(nItem, nSubItem, LVIF_TEXT, lpszText, 0, 0, 0, 0);
00141         }
00142 
00143         DWORD_PTR GetItemData(int nItem) const
00144         {
00145                 LVITEM lvi = { 0 };
00146                 lvi.iItem = nItem;
00147                 lvi.mask = LVIF_PARAM;
00148                 BOOL bRet = (BOOL)::SendMessage(m_hwnd, LVM_GETITEM, 0, (LPARAM)&lvi);
00149                 return (DWORD_PTR)(bRet ? lvi.lParam : 0);
00150         }
00151 
00152         BOOL SetItemData(int nItem, DWORD_PTR dwData)
00153         {
00154                 return SetItem(nItem, 0, LVIF_PARAM, NULL, 0, 0, 0, (LPARAM)dwData);
00155         }
00156 
00157         UINT GetCallbackMask() const
00158         {
00159                 return (UINT)::SendMessage(m_hwnd, LVM_GETCALLBACKMASK, 0, 0L);
00160         }
00161 
00162         BOOL SetCallbackMask(UINT nMask)
00163         {
00164                 return (BOOL)::SendMessage(m_hwnd, LVM_SETCALLBACKMASK, nMask, 0L);
00165         }
00166 
00167         BOOL GetItemPosition(int nItem, LPPOINT lpPoint) const
00168         {
00169                 return (BOOL)::SendMessage(m_hwnd, LVM_GETITEMPOSITION, nItem, (LPARAM)lpPoint);
00170         }
00171 
00172         BOOL SetItemPosition(int nItem, POINT pt)
00173         {
00174                 return (BOOL)::SendMessage(m_hwnd, LVM_SETITEMPOSITION32, nItem, (LPARAM)&pt);
00175         }
00176 
00177         BOOL SetItemPosition(int nItem, int x, int y)
00178         {
00179                 POINT pt = { x, y };
00180                 return (BOOL)::SendMessage(m_hwnd, LVM_SETITEMPOSITION32, nItem, (LPARAM)&pt);
00181         }
00182 
00183         int GetStringWidth(LPCTSTR lpsz) const
00184         {
00185                 return (int)::SendMessage(m_hwnd, LVM_GETSTRINGWIDTH, 0, (LPARAM)lpsz);
00186         }
00187 
00188         HWND GetEditControl() const
00189         {
00190                 return ((HWND)::SendMessage(m_hwnd, LVM_GETEDITCONTROL, 0, 0L));
00191         }
00192 
00193         BOOL GetColumn(int nCol, LVCOLUMN* pColumn) const
00194         {
00195                 return (BOOL)::SendMessage(m_hwnd, LVM_GETCOLUMN, nCol, (LPARAM)pColumn);
00196         }
00197 
00198         BOOL SetColumn(int nCol, const LVCOLUMN* pColumn)
00199         {
00200                 return (BOOL)::SendMessage(m_hwnd, LVM_SETCOLUMN, nCol, (LPARAM)pColumn);
00201         }
00202 
00203         int GetColumnWidth(int nCol) const
00204         {
00205                 return (int)::SendMessage(m_hwnd, LVM_GETCOLUMNWIDTH, nCol, 0L);
00206         }
00207 
00208         BOOL SetColumnWidth(int nCol, int cx)
00209         {
00210                 return (BOOL)::SendMessage(m_hwnd, LVM_SETCOLUMNWIDTH, nCol, MAKELPARAM(cx, 0));
00211         }
00212 
00213         BOOL GetViewRect(LPRECT lpRect) const
00214         {
00215                 return (BOOL)::SendMessage(m_hwnd, LVM_GETVIEWRECT, 0, (LPARAM)lpRect);
00216         }
00217 
00218         COLORREF GetTextColor() const
00219         {
00220                 return (COLORREF)::SendMessage(m_hwnd, LVM_GETTEXTCOLOR, 0, 0L);
00221         }
00222 
00223         BOOL SetTextColor(COLORREF cr)
00224         {
00225                 return (BOOL)::SendMessage(m_hwnd, LVM_SETTEXTCOLOR, 0, cr);
00226         }
00227 
00228         COLORREF GetTextBkColor() const
00229         {
00230                 return (COLORREF)::SendMessage(m_hwnd, LVM_GETTEXTBKCOLOR, 0, 0L);
00231         }
00232 
00233         BOOL SetTextBkColor(COLORREF cr)
00234         {
00235                 return (BOOL)::SendMessage(m_hwnd, LVM_SETTEXTBKCOLOR, 0, cr);
00236         }
00237 
00238         int GetTopIndex() const
00239         {
00240                 return (int)::SendMessage(m_hwnd, LVM_GETTOPINDEX, 0, 0L);
00241         }
00242 
00243         int GetCountPerPage() const
00244         {
00245                 return (int)::SendMessage(m_hwnd, LVM_GETCOUNTPERPAGE, 0, 0L);
00246         }
00247 
00248         BOOL GetOrigin(LPPOINT lpPoint) const
00249         {
00250                 return (BOOL)::SendMessage(m_hwnd, LVM_GETORIGIN, 0, (LPARAM)lpPoint);
00251         }
00252 
00253         UINT GetSelectedCount() const
00254         {
00255                 return (UINT)::SendMessage(m_hwnd, LVM_GETSELECTEDCOUNT, 0, 0L);
00256         }
00257 
00258         BOOL GetItemRect(int nItem, LPRECT lpRect, UINT nCode) const
00259         {
00260                 lpRect->left = nCode;
00261                 return (BOOL)::SendMessage(m_hwnd, LVM_GETITEMRECT, (WPARAM)nItem, (LPARAM)lpRect);
00262         }
00263 
00264 #ifndef _WIN32_WCE
00265         HCURSOR GetHotCursor() const
00266         {
00267                 return (HCURSOR)::SendMessage(m_hwnd, LVM_GETHOTCURSOR, 0, 0L);
00268         }
00269 
00270         HCURSOR SetHotCursor(HCURSOR hHotCursor)
00271         {
00272                 return (HCURSOR)::SendMessage(m_hwnd, LVM_SETHOTCURSOR, 0, (LPARAM)hHotCursor);
00273         }
00274 
00275         int GetHotItem() const
00276         {
00277                 return (int)::SendMessage(m_hwnd, LVM_GETHOTITEM, 0, 0L);
00278         }
00279 
00280         int SetHotItem(int nIndex)
00281         {
00282                 return (int)::SendMessage(m_hwnd, LVM_SETHOTITEM, nIndex, 0L);
00283         }
00284 #endif // !_WIN32_WCE
00285 
00286         BOOL GetColumnOrderArray(int nCount, int* lpnArray) const
00287         {
00288                 return (BOOL)::SendMessage(m_hwnd, LVM_GETCOLUMNORDERARRAY, nCount, (LPARAM)lpnArray);
00289         }
00290 
00291         BOOL SetColumnOrderArray(int nCount, int* lpnArray)
00292         {
00293                 return (BOOL)::SendMessage(m_hwnd, LVM_SETCOLUMNORDERARRAY, nCount, (LPARAM)lpnArray);
00294         }
00295 
00296         HWND GetHeader() const
00297         {
00298         return ((HWND)::SendMessage(m_hwnd, LVM_GETHEADER, 0, 0L));
00299         }
00300 
00301         BOOL GetSubItemRect(int nItem, int nSubItem, int nFlag, LPRECT lpRect) const
00302         {
00303                 lpRect->top = nSubItem;
00304                 lpRect->left = nFlag;
00305                 return (BOOL)::SendMessage(m_hwnd, LVM_GETSUBITEMRECT, nItem, (LPARAM)lpRect);
00306         }
00307 
00308         DWORD SetIconSpacing(int cx, int cy)
00309         {
00310                 return (DWORD)::SendMessage(m_hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(cx, cy));
00311         }
00312 
00313         int GetISearchString(LPTSTR lpstr) const
00314         {
00315                 return (int)::SendMessage(m_hwnd, LVM_GETISEARCHSTRING, 0, (LPARAM)lpstr);
00316         }
00317 
00318         void GetItemSpacing(SIZE& sizeSpacing, BOOL bSmallIconView = FALSE) const
00319         {
00320                 DWORD dwRet = (DWORD)::SendMessage(m_hwnd, LVM_GETITEMSPACING, bSmallIconView, 0L);
00321                 sizeSpacing.cx = LOWORD(dwRet);
00322                 sizeSpacing.cy = HIWORD(dwRet);
00323         }
00324 
00325 #if (_WIN32_WCE >= 410)
00326         void SetItemSpacing(INT cySpacing)
00327         {
00328                 ListView_SetItemSpacing(m_hwnd, cySpacing);
00329         }
00330 #endif // (_WIN32_WCE >= 410)
00331 
00332         // single-selection only
00333         int GetSelectedIndex() const
00334         {
00335                 return (int)::SendMessage(m_hwnd, LVM_GETNEXTITEM, (WPARAM)-1, MAKELPARAM(LVNI_ALL | LVNI_SELECTED, 0));
00336         }
00337 
00338         BOOL GetSelectedItem(LVITEM * pItem) const
00339         {
00340                 pItem->iItem = (int)::SendMessage(m_hwnd, LVM_GETNEXTITEM, (WPARAM)-1, MAKELPARAM(LVNI_ALL | LVNI_SELECTED, 0));
00341                 if(pItem->iItem == -1)
00342                         return FALSE;
00343                 return (BOOL)::SendMessage(m_hwnd, LVM_GETITEM, 0, (LPARAM)pItem);
00344         }
00345 
00346         // extended list view styles
00347         DWORD GetExtendedListViewStyle() const
00348         {
00349                 return (DWORD)::SendMessage(m_hwnd, LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0L);
00350         }
00351 
00352         // dwExMask = 0 means all styles
00353         DWORD SetExtendedListViewStyle(DWORD dwExStyle, DWORD dwExMask = 0)
00354         {
00355                 return (DWORD)::SendMessage(m_hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, dwExMask, dwExStyle);
00356         }
00357 
00358         // checkboxes only
00359         BOOL GetCheckState(int nIndex) const
00360         {
00361                 UINT uRet = GetItemState(nIndex, LVIS_STATEIMAGEMASK);
00362                 return (uRet >> 12) - 1;
00363         }
00364 
00365         BOOL SetCheckState(int nItem, BOOL bCheck)
00366         {
00367                 int nCheck = bCheck ? 2 : 1;   // one based index
00368                 return SetItemState(nItem, INDEXTOSTATEIMAGEMASK(nCheck), LVIS_STATEIMAGEMASK);
00369         }
00370 
00371         // view type
00372         DWORD GetViewType() const
00373         {
00374 //              return (GetStyle() & LVS_TYPEMASK);
00375         }
00376 
00377         DWORD SetViewType(DWORD dwType)
00378         {
00379 /*              DWORD dwOldType = GetViewType();
00380                 if(dwType != dwOldType)
00381                         ModifyStyle(LVS_TYPEMASK, (dwType & LVS_TYPEMASK));
00382                 return dwOldType;
00383 */              
00384         }
00385 
00386 #if (_WIN32_IE >= 0x0400)
00387 #ifndef _WIN32_WCE
00388         BOOL GetBkImage(LPLVBKIMAGE plvbki) const
00389         {
00390                 return (BOOL)::SendMessage(m_hwnd, LVM_GETBKIMAGE, 0, (LPARAM)plvbki);
00391         }
00392 
00393         BOOL SetBkImage(LPLVBKIMAGE plvbki)
00394         {
00395                 return (BOOL)::SendMessage(m_hwnd, LVM_SETBKIMAGE, 0, (LPARAM)plvbki);
00396         }
00397 #endif // !_WIN32_WCE
00398 
00399         int GetSelectionMark() const
00400         {
00401                 return (int)::SendMessage(m_hwnd, LVM_GETSELECTIONMARK, 0, 0L);
00402         }
00403 
00404         int SetSelectionMark(int nIndex)
00405         {
00406                 return (int)::SendMessage(m_hwnd, LVM_SETSELECTIONMARK, 0, nIndex);
00407         }
00408 
00409 #ifndef _WIN32_WCE
00410         BOOL GetWorkAreas(int nWorkAreas, LPRECT lpRect) const
00411         {
00412                 return (BOOL)::SendMessage(m_hwnd, LVM_GETWORKAREAS, nWorkAreas, (LPARAM)lpRect);
00413         }
00414 
00415         BOOL SetWorkAreas(int nWorkAreas, LPRECT lpRect)
00416         {
00417                 return (BOOL)::SendMessage(m_hwnd, LVM_SETWORKAREAS, nWorkAreas, (LPARAM)lpRect);
00418         }
00419 
00420         DWORD GetHoverTime() const
00421         {
00422                 return (DWORD)::SendMessage(m_hwnd, LVM_GETHOVERTIME, 0, 0L);
00423         }
00424 
00425         DWORD SetHoverTime(DWORD dwHoverTime)
00426         {
00427                 return (DWORD)::SendMessage(m_hwnd, LVM_SETHOVERTIME, 0, dwHoverTime);
00428         }
00429 
00430         BOOL GetNumberOfWorkAreas(int* pnWorkAreas) const
00431         {
00432                 return (BOOL)::SendMessage(m_hwnd, LVM_GETNUMBEROFWORKAREAS, 0, (LPARAM)pnWorkAreas);
00433         }
00434 #endif // !_WIN32_WCE
00435 
00436         BOOL SetItemCountEx(int nItems, DWORD dwFlags)
00437         {
00438                 return (BOOL)::SendMessage(m_hwnd, LVM_SETITEMCOUNT, nItems, dwFlags);
00439         }
00440 
00441 #ifndef _WIN32_WCE
00442         HWND GetToolTips() const
00443         {
00444                 return ((HWND)::SendMessage(m_hwnd, LVM_GETTOOLTIPS, 0, 0L));
00445         }
00446 
00447         HWND SetToolTips(HWND hWndTT)
00448         {
00449                 return ((HWND)::SendMessage(m_hwnd, LVM_SETTOOLTIPS, (WPARAM)hWndTT, 0L));
00450         }
00451 
00452         BOOL GetUnicodeFormat() const
00453         {
00454                 return (BOOL)::SendMessage(m_hwnd, LVM_GETUNICODEFORMAT, 0, 0L);
00455         }
00456 
00457         BOOL SetUnicodeFormat(BOOL bUnicode = TRUE)
00458         {
00459                 return (BOOL)::SendMessage(m_hwnd, LVM_SETUNICODEFORMAT, bUnicode, 0L);
00460         }
00461 #endif // !_WIN32_WCE
00462 #endif // (_WIN32_IE >= 0x0400)
00463 
00464 #if (_WIN32_WINNT >= 0x0501)
00465         int GetSelectedColumn() const
00466         {
00467                 return (int)::SendMessage(m_hwnd, LVM_GETSELECTEDCOLUMN, 0, 0L);
00468         }
00469 
00470         void SetSelectedColumn(int nColumn)
00471         {
00472                 ::SendMessage(m_hwnd, LVM_SETSELECTEDCOLUMN, nColumn, 0L);
00473         }
00474 
00475         DWORD GetView() const
00476         {
00477                 return (DWORD)::SendMessage(m_hwnd, LVM_GETVIEW, 0, 0L);
00478         }
00479 
00480         int SetView(DWORD dwView)
00481         {
00482                 return (int)::SendMessage(m_hwnd, LVM_SETVIEW, dwView, 0L);
00483         }
00484 
00485         BOOL IsGroupViewEnabled() const
00486         {
00487                 return (BOOL)::SendMessage(m_hwnd, LVM_ISGROUPVIEWENABLED, 0, 0L);
00488         }
00489 
00490         int GetGroupInfo(int nGroupID, PLVGROUP pGroup) const
00491         {
00492                 return (int)::SendMessage(m_hwnd, LVM_GETGROUPINFO, nGroupID, (LPARAM)pGroup);
00493         }
00494 
00495         int SetGroupInfo(int nGroupID, PLVGROUP pGroup)
00496         {
00497                 return (int)::SendMessage(m_hwnd, LVM_SETGROUPINFO, nGroupID, (LPARAM)pGroup);
00498         }
00499 
00500         void GetGroupMetrics(PLVGROUPMETRICS pGroupMetrics) const
00501         {
00502                 ::SendMessage(m_hwnd, LVM_GETGROUPMETRICS, 0, (LPARAM)pGroupMetrics);
00503         }
00504 
00505         void SetGroupMetrics(PLVGROUPMETRICS pGroupMetrics)
00506         {
00507                 ::SendMessage(m_hwnd, LVM_SETGROUPMETRICS, 0, (LPARAM)pGroupMetrics);
00508         }
00509 
00510         void GetTileViewInfo(PLVTILEVIEWINFO pTileViewInfo) const
00511         {
00512                 ::SendMessage(m_hwnd, LVM_GETTILEVIEWINFO, 0, (LPARAM)pTileViewInfo);
00513         }
00514 
00515         BOOL SetTileViewInfo(PLVTILEVIEWINFO pTileViewInfo)
00516         {
00517                 return (BOOL)::SendMessage(m_hwnd, LVM_SETTILEVIEWINFO, 0, (LPARAM)pTileViewInfo);
00518         }
00519 
00520         void GetTileInfo(PLVTILEINFO pTileInfo) const
00521         {
00522                 ::SendMessage(m_hwnd, LVM_GETTILEINFO, 0, (LPARAM)pTileInfo);
00523         }
00524 
00525         BOOL SetTileInfo(PLVTILEINFO pTileInfo)
00526         {
00527                 return (BOOL)::SendMessage(m_hwnd, LVM_SETTILEINFO, 0, (LPARAM)pTileInfo);
00528         }
00529 
00530         BOOL GetInsertMark(LPLVINSERTMARK pInsertMark) const
00531         {
00532                 return (BOOL)::SendMessage(m_hwnd, LVM_GETINSERTMARK, 0, (LPARAM)pInsertMark);
00533         }
00534 
00535         BOOL SetInsertMark(LPLVINSERTMARK pInsertMark)
00536         {
00537                 return (BOOL)::SendMessage(m_hwnd, LVM_SETINSERTMARK, 0, (LPARAM)pInsertMark);
00538         }
00539 
00540         int GetInsertMarkRect(LPRECT lpRect) const
00541         {
00542                 return (int)::SendMessage(m_hwnd, LVM_GETINSERTMARKRECT, 0, (LPARAM)lpRect);
00543         }
00544 
00545         COLORREF GetInsertMarkColor() const
00546         {
00547                 return (COLORREF)::SendMessage(m_hwnd, LVM_GETINSERTMARKCOLOR, 0, 0L);
00548         }
00549 
00550         COLORREF SetInsertMarkColor(COLORREF clr)
00551         {
00552                 return (COLORREF)::SendMessage(m_hwnd, LVM_SETINSERTMARKCOLOR, 0, clr);
00553         }
00554 
00555         COLORREF GetOutlineColor() const
00556         {
00557                 return (COLORREF)::SendMessage(m_hwnd, LVM_GETOUTLINECOLOR, 0, 0L);
00558         }
00559 
00560         COLORREF SetOutlineColor(COLORREF clr)
00561         {
00562                 return (COLORREF)::SendMessage(m_hwnd, LVM_SETOUTLINECOLOR, 0, clr);
00563         }
00564 #endif // (_WIN32_WINNT >= 0x0501)
00565 
00566 #if (_WIN32_WINNT >= 0x0600)
00567         int GetGroupCount() const
00568         {
00569                 return (int)::SendMessage(m_hwnd, LVM_GETGROUPCOUNT, 0, 0L);
00570         }
00571 
00572         BOOL GetGroupInfoByIndex(int nIndex, PLVGROUP pGroup) const
00573         {
00574                 return (BOOL)::SendMessage(m_hwnd, LVM_GETGROUPINFOBYINDEX, nIndex, (LPARAM)pGroup);
00575         }
00576 
00577         BOOL GetGroupRect(int nGroupID, int nType, LPRECT lpRect) const
00578         {
00579                 if(lpRect != NULL)
00580                         lpRect->top = nType;
00581                 return (BOOL)::SendMessage(m_hwnd, LVM_GETGROUPRECT, nGroupID, (LPARAM)lpRect);
00582         }
00583 
00584         UINT GetGroupState(int nGroupID, UINT uMask) const
00585         {
00586                 return (UINT)::SendMessage(m_hwnd, LVM_GETGROUPSTATE, nGroupID, (LPARAM)uMask);
00587         }
00588 
00589         int GetFocusedGroup() const
00590         {
00591                 return (int)::SendMessage(m_hwnd, LVM_GETFOCUSEDGROUP, 0, 0L);
00592         }
00593 
00594         BOOL GetEmptyText(LPWSTR lpstrText, int cchText) const
00595         {
00596                 return (BOOL)::SendMessage(m_hwnd, LVM_GETEMPTYTEXT, cchText, (LPARAM)lpstrText);
00597         }
00598 
00599         BOOL GetFooterRect(LPRECT lpRect) const
00600         {
00601                 return (BOOL)::SendMessage(m_hwnd, LVM_GETFOOTERRECT, 0, (LPARAM)lpRect);
00602         }
00603 
00604         BOOL GetFooterInfo(LPLVFOOTERINFO lpFooterInfo) const
00605         {
00606                 return (BOOL)::SendMessage(m_hwnd, LVM_GETFOOTERINFO, 0, (LPARAM)lpFooterInfo);
00607         }
00608 
00609         BOOL GetFooterItemRect(int nItem, LPRECT lpRect) const
00610         {
00611                 return (BOOL)::SendMessage(m_hwnd, LVM_GETFOOTERITEMRECT, nItem, (LPARAM)lpRect);
00612         }
00613 
00614         BOOL GetFooterItem(int nItem, LPLVFOOTERITEM lpFooterItem) const
00615         {
00616                 return (BOOL)::SendMessage(m_hwnd, LVM_GETFOOTERITEM, nItem, (LPARAM)lpFooterItem);
00617         }
00618 
00619         BOOL GetItemIndexRect(PLVITEMINDEX pItemIndex, int nSubItem, int nType, LPRECT lpRect) const
00620         {
00621                 if(lpRect != NULL)
00622                 {
00623                         lpRect->top = nSubItem;
00624                         lpRect->left = nType;
00625                 }
00626                 return (BOOL)::SendMessage(m_hwnd, LVM_GETITEMINDEXRECT, (WPARAM)pItemIndex, (LPARAM)lpRect);
00627         }
00628 
00629         BOOL SetItemIndexState(PLVITEMINDEX pItemIndex, UINT uState, UINT dwMask)
00630         {
00631                 LVITEM lvi = { 0 };
00632                 lvi.state = uState;
00633                 lvi.stateMask = dwMask;
00634                 return (BOOL)::SendMessage(m_hwnd, LVM_SETITEMINDEXSTATE, (WPARAM)pItemIndex, (LPARAM)&lvi);
00635         }
00636 
00637         BOOL GetNextItemIndex(PLVITEMINDEX pItemIndex, WORD wFlags) const
00638         {
00639                 return (BOOL)::SendMessage(m_hwnd, LVM_GETNEXTITEMINDEX, (WPARAM)pItemIndex, MAKELPARAM(wFlags, 0));
00640         }
00641 #endif // (_WIN32_WINNT >= 0x0600)
00642 
00643 // Operations
00644         int InsertColumn(int nCol, const LVCOLUMN* pColumn)
00645         {
00646                 return (int)::SendMessage(m_hwnd, LVM_INSERTCOLUMN, nCol, (LPARAM)pColumn);
00647         }
00648 
00649         int InsertColumn(int nCol, LPCTSTR lpszColumnHeading, int nFormat = LVCFMT_LEFT, 
00650                         int nWidth = -1, int nSubItem = -1, int iImage = -1, int iOrder = -1)
00651         {
00652                 LVCOLUMN column = { 0 };
00653                 column.mask = LVCF_TEXT|LVCF_FMT;
00654                 column.pszText = (LPTSTR)lpszColumnHeading;
00655                 column.fmt = nFormat;
00656                 if (nWidth != -1)
00657                 {
00658                         column.mask |= LVCF_WIDTH;
00659                         column.cx = nWidth;
00660                 }
00661                 if (nSubItem != -1)
00662                 {
00663                         column.mask |= LVCF_SUBITEM;
00664                         column.iSubItem = nSubItem;
00665                 }
00666                 if (iImage != -1)
00667                 {
00668                         column.mask |= LVCF_IMAGE;
00669                         column.iImage = iImage;
00670                 }
00671                 if (iOrder != -1)
00672                 {
00673                         column.mask |= LVCF_ORDER;
00674                         column.iOrder = iOrder;
00675                 }
00676                 return InsertColumn(nCol, &column);
00677         }
00678 
00679         BOOL DeleteColumn(int nCol)
00680         {
00681                 return (BOOL)::SendMessage(m_hwnd, LVM_DELETECOLUMN, nCol, 0L);
00682         }
00683 
00684         int InsertItem(UINT nMask, int nItem, LPCTSTR lpszItem, UINT nState, UINT nStateMask, int nImage, LPARAM lParam)
00685         {
00686                 LVITEM item = { 0 };
00687                 item.mask = nMask;
00688                 item.iItem = nItem;
00689                 item.iSubItem = 0;
00690                 item.pszText = (LPTSTR)lpszItem;
00691                 item.state = nState;
00692                 item.stateMask = nStateMask;
00693                 item.iImage = nImage;
00694                 item.lParam = lParam;
00695                 return InsertItem(&item);
00696         }
00697 
00698         int InsertItem(const LVITEM* pItem)
00699         {
00700                 return (int)::SendMessage(m_hwnd, LVM_INSERTITEM, 0, (LPARAM)pItem);
00701         }
00702 
00703         int InsertItem(int nItem, LPCTSTR lpszItem)
00704         {
00705                 return InsertItem(LVIF_TEXT, nItem, lpszItem, 0, 0, 0, 0);
00706         }
00707 
00708         int InsertItem(int nItem, LPCTSTR lpszItem, int nImage)
00709         {
00710                 return InsertItem(LVIF_TEXT|LVIF_IMAGE, nItem, lpszItem, 0, 0, nImage, 0);
00711         }
00712 
00713         int GetNextItem(int nItem, int nFlags) const
00714         {
00715                 return (int)::SendMessage(m_hwnd, LVM_GETNEXTITEM, nItem, MAKELPARAM(nFlags, 0));
00716         }
00717 
00718         BOOL DeleteItem(int nItem)
00719         {
00720                 return (BOOL)::SendMessage(m_hwnd, LVM_DELETEITEM, nItem, 0L);
00721         }
00722 
00724         BOOL DeleteAllItems()
00725         {
00726                 return (BOOL)::SendMessage(m_hwnd, LVM_DELETEALLITEMS, 0, 0L);
00727         }
00728 
00729         int FindItem(LVFINDINFO* pFindInfo, int nStart) const
00730         {
00731                 return (int)::SendMessage(m_hwnd, LVM_FINDITEM, nStart, (LPARAM)pFindInfo);
00732         }
00733 
00734         int HitTest(LVHITTESTINFO* pHitTestInfo) const
00735         {
00736                 return (int)::SendMessage(m_hwnd, LVM_HITTEST, 0, (LPARAM)pHitTestInfo);
00737         }
00738 
00739         int HitTest(POINT pt, UINT* pFlags) const
00740         {
00741                 LVHITTESTINFO hti = { 0 };
00742                 hti.pt = pt;
00743                 int nRes = (int)::SendMessage(m_hwnd, LVM_HITTEST, 0, (LPARAM)&hti);
00744                 if (pFlags != NULL)
00745                         *pFlags = hti.flags;
00746                 return nRes;
00747         }
00748 
00749         BOOL EnsureVisible(int nItem, BOOL bPartialOK)
00750         {
00751                 return (BOOL)::SendMessage(m_hwnd, LVM_ENSUREVISIBLE, nItem, MAKELPARAM(bPartialOK, 0));
00752         }
00753 
00754         BOOL Scroll(SIZE size)
00755         {
00756                 return (BOOL)::SendMessage(m_hwnd, LVM_SCROLL, size.cx, size.cy);
00757         }
00758 
00759         BOOL RedrawItems(int nFirst, int nLast)
00760         {
00761                 return (BOOL)::SendMessage(m_hwnd, LVM_REDRAWITEMS, nFirst, nLast);
00762         }
00763 
00764         BOOL Arrange(UINT nCode)
00765         {
00766                 return (BOOL)::SendMessage(m_hwnd, LVM_ARRANGE, nCode, 0L);
00767         }
00768 
00769         HWND EditLabel(int nItem)
00770         {
00771                 return ((HWND)::SendMessage(m_hwnd, LVM_EDITLABEL, nItem, 0L));
00772         }
00773 
00774         BOOL Update(int nItem)
00775         {
00776                 return (BOOL)::SendMessage(m_hwnd, LVM_UPDATE, nItem, 0L);
00777         }
00778 
00779         BOOL SortItems(PFNLVCOMPARE pfnCompare, LPARAM lParamSort)
00780         {
00781                 return (BOOL)::SendMessage(m_hwnd, LVM_SORTITEMS, (WPARAM)lParamSort, (LPARAM)pfnCompare);
00782         }
00783 
00784         HIMAGELIST RemoveImageList(int nImageList)
00785         {
00786                 return ((HIMAGELIST)::SendMessage(m_hwnd, LVM_SETIMAGELIST, (WPARAM)nImageList, 0));
00787         }
00788 
00789         HIMAGELIST CreateDragImage(int nItem, LPPOINT lpPoint)
00790         {
00791                 return ((HIMAGELIST)::SendMessage(m_hwnd, LVM_CREATEDRAGIMAGE, nItem, (LPARAM)lpPoint));
00792         }
00793 
00794         DWORD ApproximateViewRect(int cx = -1, int cy = -1, int nCount = -1)
00795         {
00796                 return (DWORD)::SendMessage(m_hwnd, LVM_APPROXIMATEVIEWRECT, nCount, MAKELPARAM(cx, cy));
00797         }
00798 
00799         int SubItemHitTest(LPLVHITTESTINFO lpInfo) const
00800         {
00801                 return (int)::SendMessage(m_hwnd, LVM_SUBITEMHITTEST, 0, (LPARAM)lpInfo);
00802         }
00803 
00804         int AddColumn(LPCTSTR strItem, int nItem, int nSubItem = -1,
00805                         int nMask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM,
00806                         int nFmt = LVCFMT_LEFT)
00807         {
00808                 const int cxOffset = 15;
00809                 LVCOLUMN lvc = { 0 };
00810                 lvc.mask = nMask;
00811                 lvc.fmt = nFmt;
00812                 lvc.pszText = (LPTSTR)strItem;
00813                 lvc.cx = GetStringWidth(lvc.pszText) + cxOffset;
00814                 if(nMask & LVCF_SUBITEM)
00815                         lvc.iSubItem = (nSubItem != -1) ? nSubItem : nItem;
00816                 return InsertColumn(nItem, &lvc);
00817         }
00818 
00819         int AddItem(int nItem, int nSubItem, LPCTSTR strItem, int nImageIndex = -1)
00820         {
00821                 LVITEM lvItem = { 0 };
00822                 lvItem.mask = LVIF_TEXT;
00823                 lvItem.iItem = nItem;
00824                 lvItem.iSubItem = nSubItem;
00825                 lvItem.pszText = (LPTSTR)strItem;
00826                 if(nImageIndex != -1)
00827                 {
00828                         lvItem.mask |= LVIF_IMAGE;
00829                         lvItem.iImage = nImageIndex;
00830                 }
00831                 if(nSubItem == 0)
00832                         return InsertItem(&lvItem);
00833                 return SetItem(&lvItem) ? nItem : -1;
00834         }
00835 
00836 #if (_WIN32_IE >= 0x0500) && !defined(_WIN32_WCE)
00837         BOOL SortItemsEx(PFNLVCOMPARE pfnCompare, LPARAM lParamSort)
00838         {
00839                 return (BOOL)::SendMessage(m_hwnd, LVM_SORTITEMSEX, (WPARAM)lParamSort, (LPARAM)pfnCompare);
00840         }
00841 #endif // (_WIN32_IE >= 0x0500) && !defined(_WIN32_WCE)
00842 
00843 #if (_WIN32_WINNT >= 0x0501)
00844         int InsertGroup(int nItem, PLVGROUP pGroup)
00845         {
00846                 return (int)::SendMessage(m_hwnd, LVM_INSERTGROUP, nItem, (LPARAM)pGroup);
00847         }
00848 
00849         int AddGroup(PLVGROUP pGroup)
00850         {
00851                 return InsertGroup(-1, pGroup);
00852         }
00853 
00854         int RemoveGroup(int nGroupID)
00855         {
00856                 return (int)::SendMessage(m_hwnd, LVM_REMOVEGROUP, nGroupID, 0L);
00857         }
00858 
00859         void MoveGroup(int nGroupID, int nItem)
00860         {
00861                 ::SendMessage(m_hwnd, LVM_MOVEGROUP, nGroupID, nItem);
00862         }
00863 
00864         void MoveItemToGroup(int nItem, int nGroupID)
00865         {
00866                 ::SendMessage(m_hwnd, LVM_MOVEITEMTOGROUP, nItem, nGroupID);
00867         }
00868 
00869         int EnableGroupView(BOOL bEnable)
00870         {
00871                 return (int)::SendMessage(m_hwnd, LVM_ENABLEGROUPVIEW, bEnable, 0L);
00872         }
00873 
00874         int SortGroups(PFNLVGROUPCOMPARE pCompareFunc, LPVOID lpVoid = NULL)
00875         {
00876                 return (int)::SendMessage(m_hwnd, LVM_SORTGROUPS, (WPARAM)pCompareFunc, (LPARAM)lpVoid);
00877         }
00878 
00879         void InsertGroupSorted(PLVINSERTGROUPSORTED pInsertGroupSorted)
00880         {
00881                 ::SendMessage(m_hwnd, LVM_INSERTGROUPSORTED, (WPARAM)pInsertGroupSorted, 0L);
00882         }
00883 
00884         void RemoveAllGroups()
00885         {
00886                 ::SendMessage(m_hwnd, LVM_REMOVEALLGROUPS, 0, 0L);
00887         }
00888 
00889         BOOL HasGroup(int nGroupID)
00890         {
00891                 return (BOOL)::SendMessage(m_hwnd, LVM_HASGROUP, nGroupID, 0L);
00892         }
00893 
00894         BOOL InsertMarkHitTest(LPPOINT lpPoint, LPLVINSERTMARK pInsertMark) const
00895         {
00896                 return (BOOL)::SendMessage(m_hwnd, LVM_INSERTMARKHITTEST, (WPARAM)lpPoint, (LPARAM)pInsertMark);
00897         }
00898 
00899         BOOL SetInfoTip(PLVSETINFOTIP pSetInfoTip)
00900         {
00901                 return (BOOL)::SendMessage(m_hwnd, LVM_SETINFOTIP, 0, (LPARAM)pSetInfoTip);
00902         }
00903 
00904         void CancelEditLabel()
00905         {
00906                 ::SendMessage(m_hwnd, LVM_CANCELEDITLABEL, 0, 0L);
00907         }
00908 
00909         UINT MapIndexToID(int nIndex) const
00910         {
00911                 return (UINT)::SendMessage(m_hwnd, LVM_MAPINDEXTOID, nIndex, 0L);
00912         }
00913 
00914         int MapIDToIndex(UINT uID) const
00915         {
00916                 return (int)::SendMessage(m_hwnd, LVM_MAPIDTOINDEX, uID, 0L);
00917         }
00918 #endif // (_WIN32_WINNT >= 0x0501)
00919 
00920 #if (_WIN32_WINNT >= 0x0600)
00921         int HitTestEx(LPLVHITTESTINFO lpHitTestInfo) const
00922         {
00923                 return (int)::SendMessage(m_hwnd, LVM_HITTEST, (WPARAM)-1, (LPARAM)lpHitTestInfo);
00924         }
00925 
00926         int HitTestEx(POINT pt, UINT* pFlags) const
00927         {
00928                 LVHITTESTINFO hti = { 0 };
00929                 hti.pt = pt;
00930                 int nRes = (int)::SendMessage(m_hwnd, LVM_HITTEST, (WPARAM)-1, (LPARAM)&hti);
00931                 if (pFlags != NULL)
00932                         *pFlags = hti.flags;
00933                 return nRes;
00934         }
00935 
00936         int SubItemHitTestEx(LPLVHITTESTINFO lpHitTestInfo) const
00937         {
00938                 return (int)::SendMessage(m_hwnd, LVM_SUBITEMHITTEST, (WPARAM)-1, (LPARAM)lpHitTestInfo);
00939         }
00940 #endif // (_WIN32_WINNT >= 0x0600)
00941 
00942         // single-selection only
00943         BOOL SelectItem(int nIndex)
00944         {
00945                 BOOL bRet = SetItemState(nIndex, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
00946                 if(bRet)
00947                         bRet = EnsureVisible(nIndex, FALSE);
00948                 return bRet;
00949         }
00950 };
00951 
00952 }
00953 }
00954 
00955 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines