随笔-341  评论-2670  文章-0  trackbacks-0
    ListView实在是超级无敌复杂地难封装啊,Vista下的ListView简直是万能的,以至于我萌生了将grid和tree-grid都用ListView来实现的想法。当然这只是想一想,暂时不想做。这个ListView花了1700行代码封装完成,共有4个类,分别是item、column、group和listview,listview自己的事件16个。

    本文内容有两幅示例以及.h、.cpp以及main函数代码

    图1:初始化

    图2:点击column并排序(按照所属column的文字)

    代码1:使用
  1 #include "..\..\..\..\VL++\Library\Windows\VL_WinGUI.h"
  2 #include "..\..\..\..\VL++\Library\Data\VL_System.h"
  3 
  4 using namespace vl;
  5 using namespace vl::windows;
  6 using namespace vl::system;
  7 
  8 PWChar ListViewItemText[]={
  9     L"Add Table",
 10     L"Arrange Window",
 11     L"Delete Table",
 12     L"Graph",
 13     L"High Light",
 14     L"Home Page",
 15     L"Open",
 16     L"Paste",
 17     L"Save",
 18     L"Search"
 19 };
 20 
 21 PWChar ListViewItemText2[]={
 22     L"Add a table into the system",
 23     L"Arrange the windows of system",
 24     L"Remove a table from the system",
 25     L"Show the graph of the table relations",
 26     L"High light a table",
 27     L"Switch to home page",
 28     L"Open a table",
 29     L"Paste data from clipboard into a table",
 30     L"Save a table",
 31     L"Search information from tables"
 32 };
 33 
 34 class MyForm : public VL_WinForm
 35 {
 36 protected:
 37     VUnicodeString                FBitmapPath;
 38     VL_WinImageList*            FLargeImages;
 39     VL_WinImageList*            FSmallImages;
 40     VL_WinListView*                FListView;
 41     VL_WinComboBox*                FViewSelection;
 42 
 43     void InitControls()
 44     {
 45         FBitmapPath=VFileName(GetApplication()->GetAppName()).GetPath().MakeAbsolute(L"..\\Bitmap\\").GetStrW();
 46         FLargeImages=new VL_WinImageList(32,32);
 47         FSmallImages=new VL_WinImageList(16,16);
 48         for(VInt i=0;i<10;i++)
 49         {
 50             FLargeImages->Add(new VL_WinBitmap(FBitmapPath+L"b"+VUnicodeString(i)+L".bmp",true,true));
 51             FSmallImages->Add(new VL_WinBitmap(FBitmapPath+L"s"+VUnicodeString(i)+L".bmp",true,true));
 52         }
 53 
 54         FListView=new VL_WinListView(this);
 55         FListView->Move(10,50,380,340);
 56         FListView->SetGroupImageList(FLargeImages);
 57         FListView->SetSmallImageList(FSmallImages);
 58         FListView->SetLargeImageList(FLargeImages);
 59         FListView->AddColumn(L"Function");
 60         FListView->AddColumn(L"Description",0);
 61         FListView->GetColumn(1).SetWidth(200);
 62         FListView->GetColumn(1).SetShowSplitButton(true);
 63         VInt GroupA=FListView->AddGroup(L"Group A");
 64         FListView->GetGroupByID(GroupA).SetFooter(L"Footer of group A");
 65         FListView->GetGroupByID(GroupA).SetSubTitle(L"Title of group A");
 66         FListView->GetGroupByID(GroupA).SetTask(L"Task of group A");
 67         FListView->GetGroupByID(GroupA).SetImageIndex(0);
 68         VInt GroupB=FListView->AddGroup(L"Group B");
 69         VL_List<VInt , true> Subs;
 70         Subs.Add(0);
 71         for(VInt i=0;i<10;i++)
 72         {
 73             FListView->AddItem(ListViewItemText[i],i);
 74             FListView->GetItem(i).SetSubItem(0,ListViewItemText2[i]);
 75             FListView->GetItem(i).SetTiledSubItem(Subs);
 76             FListView->GetItem(i).EnterGroup(i<5?GroupA:GroupB);
 77         }
 78         FListView->EnableGrouping(true);
 79         FListView->SetShowCheckBoxes(true);
 80         FListView->SetAutoCheckSelect(true);
 81         FListView->OnCompareItems.Bind(this,&MyForm::ListView_OnCompareItem);
 82         FListView->OnColumnClick.Bind(this,&MyForm::ListView_OnColumnClick);
 83         FListView->OnGroupTaskClick.Bind(this,&MyForm::ListView_OnGroupTaskClick);
 84 
 85         FViewSelection=new VL_WinComboBox(this,true);
 86         FViewSelection->Move(10,10,120,30);
 87         FViewSelection->AddString(L"Large Icon");
 88         FViewSelection->AddString(L"Small Icon");
 89         FViewSelection->AddString(L"List");
 90         FViewSelection->AddString(L"Report");
 91         FViewSelection->AddString(L"Tile");
 92         FViewSelection->OnSelChange.Bind(this,&MyForm::ViewSelection_OnSelChange);
 93         FViewSelection->SetSelectedIndex(3);
 94 
 95         FListView->SetFocused();
 96     }
 97 
 98     void ViewSelection_OnSelChange(VL_Base* Sender)
 99     {
100         switch(FViewSelection->GetSelectedIndex())
101         {
102         case 0:
103             FListView->SetViewStyle(vlvsLarge);
104             break;
105         case 1:
106             FListView->SetViewStyle(vlvsSmall);
107             break;
108         case 2:
109             FListView->SetViewStyle(vlvsList);
110             break;
111         case 3:
112             FListView->SetViewStyle(vlvsReport);
113             break;
114         case 4:
115             FListView->SetViewStyle(vlvsTile);
116             break;
117         }
118     }
119 
120     void ListView_OnCompareItem(VL_Base* Sender , VInt Index1 , VInt Index2 , VPointer Param , VLE_ListViewSortResult& Result)
121     {
122         VInt ColumnIndex=*(VInt*)Param;
123         VUnicodeString Item1=FListView->GetItem(Index1).GetSubItem(ColumnIndex-1);
124         VUnicodeString Item2=FListView->GetItem(Index2).GetSubItem(ColumnIndex-1);
125         if(Item1>Item2) Result=vlvsrLarger;
126         else if(Item1<Item2) Result=vlvsrSmaller;
127         else Result=vlvsrEqual;
128     }
129 
130     void ListView_OnColumnClick(VL_Base* Sender , VInt ItemIndex , VInt SubItemIndex)
131     {
132         if(ItemIndex>=0)
133         {
134             FListView->Sort(&ItemIndex);
135         }
136     }
137 
138     void ListView_OnGroupTaskClick(VL_Base* Sender , VInt ItemIndex , VInt SubItemIndex)
139     {
140         VL_WinMsgbox(this,FListView->GetGroupByID(ItemIndex).GetHeader()+L" Clicked.",GetText(),vmbOK);
141     }
142 
143 public:
144 
145     MyForm():VL_WinForm(true)
146     {
147         SetBorder(vwfbSingle);
148         SetMaximizeBox(false);
149         SetClientWidth(400);
150         SetClientHeight(400);
151         SetText(L"Vczh ListView");
152         MoveCenter();
153         InitControls();
154         Show();
155     }
156 
157     ~MyForm()
158     {
159         delete FSmallImages;
160         delete FLargeImages;
161     }
162 };
163 
164 void main()
165 {
166     new MyForm;
167     GetApplication()->Run();
168 }

    代码2:头文件
  1 /*******************************************************************************
  2 Vczh Library++ 2.0
  3 Windows界面::View
  4 开发者:陈梓瀚
  5 
  6 接口:
  7 类:
  8   VL_WinListViewItem            :ListView项目
  9   VL_WinListViewColumn            :ListView列头
 10   VL_WinListViewGroup            :ListView组
 11   VL_WinListView                :ListView
 12 函数:
 13 *******************************************************************************/
 14 
 15 #ifndef VL_WINVIEW
 16 #define VL_WINVIEW
 17 
 18 #include "..\VL_WinClass.h"
 19 #include "commctrl.h"
 20 
 21 namespace vl
 22 {
 23     namespace windows
 24     {
 25         class VL_WinListViewItem : public VL_Base
 26         {
 27             friend class VL_WinListView;
 28         protected:
 29             HWND                    FHandle;
 30             VInt                    FIndex;
 31 
 32             VL_WinListViewItem(HWND Handle , VInt Index);
 33         public:
 34             VL_WinListViewItem();
 35             VL_WinListViewItem(const VL_WinListViewItem& Item);
 36             VL_WinListViewItem& operator=(const VL_WinListViewItem& Item);
 37             operator VBool();
 38 
 39             VUnicodeString            GetText();
 40             void                    SetText(VUnicodeString Value);
 41 
 42             VInt                    GetImageIndex();
 43             void                    SetImageIndex(VInt Value);
 44 
 45             VUnicodeString            GetSubItem(VInt Index);
 46             void                    SetSubItem(VInt Index , VUnicodeString Value);
 47 
 48             void                    GetTiledSubItem(VL_List<VInt , true>& Columns);
 49             void                    SetTiledSubItem(VL_List<VInt , true>& Columns);
 50 
 51             VBool                    GetCutState();
 52             void                    SetCutState(VBool Value);
 53 
 54             VBool                    GetDropHilitedState();
 55             void                    SetDropHilitedState(VBool Value);
 56 
 57             VBool                    GetFocusedState();
 58             void                    SetFocusedState(VBool Value);
 59 
 60             VBool                    GetSelectedState();
 61             void                    SetSelectedState(VBool Value);
 62 
 63             VInt                    GetIndent();
 64             void                    SetIndent(VInt Value);
 65 
 66             VBool                    GetChecked();
 67             void                    SetChecked(VBool Value);
 68 
 69             VPointer                GetCustomData();
 70             void                    SetCustomData(VPointer Data);
 71 
 72             void                    EnterGroup(VInt GroupID);
 73             void                    LeaveGroup();
 74             VInt                    GetOwnerGroupID();
 75             VBool                    IsInGroup();
 76         };
 77 
 78         class VL_WinListViewColumn : public VL_Base
 79         {
 80             friend class VL_WinListView;
 81         protected:
 82             HWND                    FHandle;
 83             VInt                    FIndex;
 84 
 85             VL_WinListViewColumn(HWND Handle , VInt Index);
 86         public:
 87             VL_WinListViewColumn();
 88             VL_WinListViewColumn(const VL_WinListViewColumn& Item);
 89             VL_WinListViewColumn& operator=(const VL_WinListViewColumn& Item);
 90             operator VBool();
 91 
 92             VUnicodeString            GetText();
 93             void                    SetText(VUnicodeString Value);
 94 
 95             VInt                    GetSubItemIndex();
 96             void                    SetSubItemIndex(VInt Value);
 97 
 98             VInt                    GetWidth();
 99             void                    SetWidth(VInt Value);
100 
101             VInt                    GetOrder();
102             void                    SetOrder(VInt Value);
103 
104             VInt                    GetImageIndex();
105             void                    SetImageIndex(VInt Value);
106 
107             VLE_WinHAlign            GetTextAlign();
108             void                    SetTextAlign(VLE_WinHAlign Value);
109 
110             VBool                    GetImageOnRight();
111             void                    SetImageOnRight(VBool Value);
112 
113             VBool                    GetFixedWidth();
114             void                    SetFixedWidth(VBool Value);
115 
116             VBool                    GetShowSplitButton();
117             void                    SetShowSplitButton(VBool Value);
118         };
119 
120         class VL_WinListViewGroup : public VL_Base
121         {
122             friend class VL_WinListView;
123         protected:
124             HWND                    FHandle;
125             VInt                    FID;
126 
127             VL_WinListViewGroup(HWND Handle , VInt ID);
128 
129             VUnicodeString            GetListViewGroupText(UINT Mask , LPWSTR LVGROUP::* Item , UINT LVGROUP::* Count);
130             VUnicodeString            GetListViewGroupText(UINT Mask , LPWSTR LVGROUP::* Item , int LVGROUP::* Count);
131             void                    SetListViewGroupText(UINT Mask , LPWSTR LVGROUP::* Item , VUnicodeString Text);
132         public:
133             VL_WinListViewGroup();
134             VL_WinListViewGroup(const VL_WinListViewGroup& Item);
135             VL_WinListViewGroup& operator=(const VL_WinListViewGroup& Item);
136             operator VBool();
137 
138             VInt                    GetGroupID();
139 
140             VUnicodeString            GetHeader();
141             void                    SetHeader(VUnicodeString Value);
142 
143             VUnicodeString            GetFooter();
144             void                    SetFooter(VUnicodeString Value);
145 
146             VUnicodeString            GetSubTitle();
147             void                    SetSubTitle(VUnicodeString Value);
148 
149             VUnicodeString            GetTask();
150             void                    SetTask(VUnicodeString Value);
151 
152             VUnicodeString            GetDescriptionTop();
153             void                    SetDescriptionTop(VUnicodeString Value);
154 
155             VUnicodeString            GetDescriptionBottom();
156             void                    SetDescriptionBottom(VUnicodeString Value);
157 
158             VInt                    GetImageIndex();
159             void                    SetImageIndex(VInt Value);
160 
161             VInt                    GetExtendedImageIndex();
162             void                    SetExtendedImageIndex(VInt Value);
163 
164             VLE_WinHAlign            GetHeaderAlign();
165             void                    SetHeaderAlign(VLE_WinHAlign Value);
166         };
167 
168         enum VLE_ListViewStyle
169         {
170             vlvsLarge,
171             vlvsSmall,
172             vlvsList,
173             vlvsReport,
174             vlvsTile
175         };
176 
177         enum VLE_ListViewSortResult
178         {
179             vlvsrLarger,
180             vlvsrEqual,
181             vlvsrSmaller
182         };
183         VL_DEFINE_VOID_EVENT    (VE_ListViewItemEvent    ,(Sender , ItemIndex , SubItemIndex)        ,(VL_Base* Sender , VInt ItemIndex , VInt SubItemIndex));
184         VL_DEFINE_VOID_EVENT    (VE_ListViewEditEvent    ,(Sender , ItemIndex , Accept , Text)        ,(VL_Base* Sender , VInt ItemIndex , VBool& Accept , VUnicodeString Text));
185         VL_DEFINE_VOID_EVENT    (VE_ListViewSortEvent    ,(Sender , Index1 , Index2 , Param , Result),(VL_Base* Sender , VInt Index1 , VInt Index2 , VPointer Param , VLE_ListViewSortResult& Result));
186 
187         class VL_WinListView : public VL_WinControl
188         {
189         protected:
190             VL_WinImageList*        FSmallImageList;
191             VL_WinImageList*        FLargeImageList;
192             VL_WinImageList*        FStateImageList;
193             VL_WinImageList*        FGroupImageList;
194 
195             VInt                    FColumnCount;
196             VInt                    FUsedGroupIDs;
197 
198             DWORD                    InternalGetExStyle();
199             void                    InternalSetExStyle(DWORD ExStyle);
200         public:
201             VL_WinListView(VL_WinContainer* Parent);
202             ~VL_WinListView();
203             LRESULT                    ProcessMessage(UINT Message , WPARAM& wParam , LPARAM& lParam , VBool& CallDefaultProcedure);
204 
205             VE_ListViewItemEvent    OnBeginDrag;
206             VE_ListViewItemEvent    OnBeginRightDrag;
207             VE_ListViewEditEvent    OnBeginLabelEdit;
208             VE_ListViewEditEvent    OnEndLabelEdit;
209             VE_ListViewItemEvent    OnColumnClick;
210             VE_ListViewItemEvent    OnColumnDropDown;
211             VE_ListViewItemEvent    OnItemHotTrack;
212             VE_ListViewItemEvent    OnItemActive;
213             VE_ListViewItemEvent    OnItemChanging;
214             VE_ListViewItemEvent    OnItemChanged;
215             VE_ListViewItemEvent    OnGroupTaskClick;
216             VE_ListViewItemEvent    OnItemClick;
217             VE_ListViewItemEvent    OnItemDbClick;
218             VE_ListViewItemEvent    OnItemRightClick;
219             VE_ListViewItemEvent    OnItemRightDbClick;
220             VE_ListViewSortEvent    OnCompareItems;
221 
222             VL_WinImageList*        GetSmallImageList();
223             void                    SetSmallImageList(VL_WinImageList* ImageList);
224 
225             VL_WinImageList*        GetLargeImageList();
226             void                    SetLargeImageList(VL_WinImageList* ImageList);
227 
228             VL_WinImageList*        GetStateImageList();
229             void                    SetStateImageList(VL_WinImageList* ImageList);
230 
231             VL_WinImageList*        GetGroupImageList();
232             void                    SetGroupImageList(VL_WinImageList* ImageList);
233 
234             VLE_ListViewStyle        GetViewStyle();
235             void                    SetViewStyle(VLE_ListViewStyle Style);
236 
237             COLORREF                GetOutlineColor();
238             void                    SetOutlineColor(COLORREF Value);
239 
240             COLORREF                GetTextColor();
241             void                    SetTextColor(COLORREF Value);
242 
243             COLORREF                GetTextBackColor();
244             void                    SetTextBackColor(COLORREF Value);
245 
246             COLORREF                GetBackColor();
247             void                    SetBackColor(COLORREF Value);
248 
249             /**********************************************************
250             Styles
251             **********************************************************/
252 
253             VBool                    GetAutoArrange();
254             void                    SetAutoArrange(VBool Value);
255 
256             VBool                    GetEditable();
257             void                    SetEditable(VBool Value);
258 
259             VBool                    GetColumnPushable();
260             void                    SetColumnPushable(VBool Value);
261 
262             VBool                    GetAlwaysShowSelection();
263             void                    SetAlwaysShowSelection(VBool Value);
264 
265             VBool                    GetSingleSelection();
266             void                    SetSingleSelection(VBool Value);
267 
268             VBool                    GetShowCheckBoxes();
269             void                    SetShowCheckBoxes(VBool Value);
270 
271             VBool                    GetAutoCheckSelect();
272             void                    SetAutoCheckSelect(VBool Value);
273 
274             VBool                    GetBorderSelect();
275             void                    SetBorderSelect(VBool Value);
276 
277             VBool                    GetShowGridLines();
278             void                    SetShowGridLines(VBool Value);
279 
280             VBool                    GetHeaderDragable();
281             void                    SetHeaderDragable(VBool Value);
282 
283             VBool                    GetOneClickActive();
284             void                    SetOneClickActive(VBool Value);
285 
286             VBool                    GetTwoClickActive();
287             void                    SetTwoClickActive(VBool Value);
288 
289             VBool                    GetUnderlineHot();
290             void                    SetUnderlineHot(VBool Value);
291 
292             VBool                    GetUnderlineCold();
293             void                    SetUnderlineCold(VBool Value);
294 
295             VBool                    GetAutoAutoArrange();
296             void                    SetAutoAutoArrange(VBool Value);
297 
298             VBool                    GetSnapToGrid();
299             void                    SetSnapToGrid(VBool Value);
300 
301             /**********************************************************
302             Actions
303             **********************************************************/
304 
305             void                    EditLabel(VInt Index);
306             void                    CancelEditLabel();
307             void                    Arrange();
308             void                    SnapToGrid();
309             void                    EnsureItemVisible(VInt Index , VBool AcceptPartialVisible);
310             void                    Sort(VPointer Param=0);
311 
312             /**********************************************************
313             Items
314             **********************************************************/
315 
316             VInt                    GetItemCount();
317             void                    AddItem(VUnicodeString Text , VInt ImageIndex=-1);
318             void                    InsertItem(VInt Index , VUnicodeString Text , VInt ImageIndex=-1);
319             void                    DeleteItem(VInt Index);
320             VL_WinListViewItem        GetItem(VInt Index);
321             VInt                    GetSelectedItemCount();
322             VInt                    GetSelectionItemMark();
323             void                    SetSelectionItemMark(VInt Value);
324             VInt                    GetHotItemIndex();
325             void                    SetHotItemIndex(VInt Value);
326 
327             /**********************************************************
328             Columns
329             **********************************************************/
330 
331             VInt                    GetColumnCount();
332             void                    AddColumn(VUnicodeString Text , VInt SubItemIndex=-1);
333             void                    InsertColumn(VInt Index , VUnicodeString Text , VInt SubItemIndex=-1);
334             void                    DeleteColumn(VInt Index);
335             VL_WinListViewColumn    GetColumn(VInt Index);
336             VInt                    GetSelectedColumnIndex();
337             void                    SetSelectedColumnIndex(VInt Value);
338 
339             /**********************************************************
340             Groups
341             **********************************************************/
342 
343             void                    EnableGrouping(VBool Value);
344             VInt                    GetGroupCount();
345             VInt                    AddGroup(VUnicodeString Text);
346             VInt                    InsertGroup(VInt Index , VUnicodeString Text);
347             void                    DeleteGroup(VInt Index);
348             void                    DeleteGroupByID(VInt ID);
349             VL_WinListViewGroup        GetGroup(VInt Index);
350             VL_WinListViewGroup        GetGroupByID(VInt ID);
351         };
352     }
353 }
354 
355 #endif

    代码3:实现
   1 #include "VL_WinView.h"
   2 
   3 namespace vl
   4 {
   5     namespace windows
   6     {
   7         const VInt LISTVIEW_TEXT_BUFFER_SIZE=1024;
   8 
   9         VL_IMPLEMENT_VOID_EVENT    (VE_ListViewItemEvent    ,(Sender , ItemIndex , SubItemIndex)        ,(VL_Base* Sender , VInt ItemIndex , VInt SubItemIndex));
  10         VL_IMPLEMENT_VOID_EVENT    (VE_ListViewEditEvent    ,(Sender , ItemIndex , Accept , Text)        ,(VL_Base* Sender , VInt ItemIndex , VBool& Accept , VUnicodeString Text));
  11         VL_IMPLEMENT_VOID_EVENT    (VE_ListViewSortEvent    ,(Sender , Index1 , Index2 , Param , Result),(VL_Base* Sender , VInt Index1 , VInt Index2 , VPointer Param , VLE_ListViewSortResult& Result));
  12 
  13 /*********************************************************************************************************
  14 VL_WinListViewItem
  15 *********************************************************************************************************/
  16 
  17     void FillListViewItem(LVITEM* Item , VInt Index , VInt SubItem , UINT Mask)
  18     {
  19         memset(Item,0,sizeof(*Item));
  20         Item->iItem=Index;
  21         Item->iSubItem=SubItem;
  22         Item->mask=Mask;
  23     }
  24 
  25     VL_WinListViewItem::VL_WinListViewItem(HWND Handle , VInt Index)
  26     {
  27         FHandle=Handle;
  28         FIndex=Index;
  29     }
  30 
  31     VL_WinListViewItem::VL_WinListViewItem()
  32     {
  33         FHandle=0;
  34         FIndex=0;
  35     }
  36 
  37     VL_WinListViewItem::VL_WinListViewItem(const VL_WinListViewItem& Item)
  38     {
  39         FHandle=Item.FHandle;
  40         FIndex=Item.FIndex;
  41     }
  42 
  43     VL_WinListViewItem& VL_WinListViewItem::operator=(const VL_WinListViewItem& Item)
  44     {
  45         FHandle=Item.FHandle;
  46         FIndex=Item.FIndex;
  47         return *this;
  48     }
  49 
  50     VL_WinListViewItem::operator VBool()
  51     {
  52         return FHandle!=0;
  53     }
  54 
  55     VUnicodeString VL_WinListViewItem::GetText()
  56     {
  57         return GetSubItem(-1);
  58     }
  59 
  60     void VL_WinListViewItem::SetText(VUnicodeString Value)
  61     {
  62         SetSubItem(-1,Value);
  63     }
  64 
  65     VInt VL_WinListViewItem::GetImageIndex()
  66     {
  67         LVITEM Item;
  68         FillListViewItem(&Item,FIndex,0,LVIF_IMAGE);
  69         ListView_GetItem(FHandle,&Item);
  70         return Item.iImage;
  71     }
  72 
  73     void VL_WinListViewItem::SetImageIndex(VInt Value)
  74     {
  75         LVITEM Item;
  76         FillListViewItem(&Item,FIndex,0,LVIF_IMAGE);
  77         Item.iImage=Value;
  78         ListView_SetItem(FHandle,&Item);
  79     }
  80 
  81     VUnicodeString VL_WinListViewItem::GetSubItem(VInt Index)
  82     {
  83         VWChar Buffer[LISTVIEW_TEXT_BUFFER_SIZE]={0};
  84         LVITEM Item;
  85         FillListViewItem(&Item,FIndex,Index+1,LVIF_TEXT);
  86         Item.pszText=Buffer;
  87         Item.cchTextMax=sizeof(Buffer)/sizeof(*Buffer);
  88         ListView_GetItem(FHandle,&Item);
  89         return Buffer;
  90     }
  91 
  92     void VL_WinListViewItem::SetSubItem(VInt Index , VUnicodeString Value)
  93     {
  94         LVITEM Item;
  95         FillListViewItem(&Item,FIndex,Index+1,LVIF_TEXT);
  96         Item.pszText=Value.Buffer();
  97         BOOL Result=ListView_SetItem(FHandle,&Item);
  98     }
  99 
 100     void VL_WinListViewItem::GetTiledSubItem(VL_List<VInt , true>& Columns)
 101     {
 102         UINT Buffer[20]={0};
 103         LVITEM Item;
 104         FillListViewItem(&Item,FIndex,0,LVIF_COLUMNS);
 105         Item.puColumns=Buffer;
 106         ListView_GetItem(FHandle,&Item);
 107         Columns.Clear();
 108         for(UINT i=0;i<Item.cColumns;i++)
 109         {
 110             Columns.Add(Buffer[i]-1);
 111         }
 112     }
 113 
 114     void VL_WinListViewItem::SetTiledSubItem(VL_List<VInt , true>& Columns)
 115     {
 116         UINT Buffer[20]={0};
 117         VInt Count=0;
 118         for(;Count<Columns.GetCount() && Count<20;Count++)
 119         {
 120             Buffer[Count]=Columns[Count]+1;
 121         }
 122         LVITEM Item;
 123         FillListViewItem(&Item,FIndex,0,LVIF_COLUMNS);
 124         Item.cColumns=Count;
 125         Item.puColumns=Buffer;
 126         ListView_SetItem(FHandle,&Item);
 127     }
 128 
 129     VBool VL_WinListViewItem::GetCutState()
 130     {
 131         return ListView_GetItemState(FHandle,FIndex,LVIS_CUT)!=0;
 132     }
 133 
 134     void VL_WinListViewItem::SetCutState(VBool Value)
 135     {
 136         ListView_SetItemState(FHandle,FIndex,(Value?LVIS_CUT:0),LVIS_CUT);
 137     }
 138 
 139     VBool VL_WinListViewItem::GetDropHilitedState()
 140     {
 141         return ListView_GetItemState(FHandle,FIndex,LVIS_DROPHILITED)!=0;
 142     }
 143 
 144     void VL_WinListViewItem::SetDropHilitedState(VBool Value)
 145     {
 146         ListView_SetItemState(FHandle,FIndex,(Value?LVIS_DROPHILITED:0),LVIS_DROPHILITED);
 147     }
 148 
 149     VBool VL_WinListViewItem::GetFocusedState()
 150     {
 151         return ListView_GetItemState(FHandle,FIndex,LVIS_FOCUSED)!=0;
 152     }
 153 
 154     void VL_WinListViewItem::SetFocusedState(VBool Value)
 155     {
 156         ListView_SetItemState(FHandle,FIndex,(Value?LVIS_FOCUSED:0),LVIS_FOCUSED);
 157     }
 158 
 159     VBool VL_WinListViewItem::GetSelectedState()
 160     {
 161         return ListView_GetItemState(FHandle,FIndex,LVIS_SELECTED)!=0;
 162     }
 163 
 164     void VL_WinListViewItem::SetSelectedState(VBool Value)
 165     {
 166         ListView_SetItemState(FHandle,FIndex,(Value?LVIS_SELECTED:0),LVIS_SELECTED);
 167     }
 168 
 169     VInt VL_WinListViewItem::GetIndent()
 170     {
 171         LVITEM Item;
 172         FillListViewItem(&Item,FIndex,0,LVIF_INDENT);
 173         ListView_GetItem(FHandle,&Item);
 174         return Item.iIndent;
 175     }
 176 
 177     void VL_WinListViewItem::SetIndent(VInt Value)
 178     {
 179         LVITEM Item;
 180         FillListViewItem(&Item,FIndex,0,LVIF_INDENT);
 181         Item.iIndent=Value;
 182         ListView_SetItem(FHandle,&Item);
 183     }
 184 
 185     VBool VL_WinListViewItem::GetChecked()
 186     {
 187         return ListView_GetCheckState(FHandle,FIndex)!=0;
 188     }
 189 
 190     void VL_WinListViewItem::SetChecked(VBool Value)
 191     {
 192         ListView_SetCheckState(FHandle,FIndex,(Value?TRUE:FALSE));
 193     }
 194 
 195     VPointer VL_WinListViewItem::GetCustomData()
 196     {
 197         LVITEM Item;
 198         FillListViewItem(&Item,FIndex,0,LVIF_PARAM);
 199         ListView_GetItem(FHandle,&Item);
 200         return (VPointer)Item.lParam;
 201     }
 202 
 203     void VL_WinListViewItem::SetCustomData(VPointer Data)
 204     {
 205         LVITEM Item;
 206         FillListViewItem(&Item,FIndex,0,LVIF_PARAM);
 207         Item.lParam=(LPARAM)Data;
 208         ListView_SetItem(FHandle,&Item);
 209     }
 210 
 211     void VL_WinListViewItem::EnterGroup(VInt GroupID)
 212     {
 213         LVITEM Item;
 214         FillListViewItem(&Item,FIndex,0,LVIF_GROUPID);
 215         Item.iGroupId=GroupID;
 216         ListView_SetItem(FHandle,&Item);
 217     }
 218     
 219     void VL_WinListViewItem::LeaveGroup()
 220     {
 221         EnterGroup(I_GROUPIDNONE);
 222     }
 223 
 224     VInt VL_WinListViewItem::GetOwnerGroupID()
 225     {
 226         LVITEM Item;
 227         FillListViewItem(&Item,FIndex,0,LVIF_GROUPID);
 228         ListView_GetItem(FHandle,&Item);
 229         return Item.iGroupId;
 230     }
 231 
 232     VBool VL_WinListViewItem::IsInGroup()
 233     {
 234         return GetOwnerGroupID()!=I_GROUPIDNONE;
 235     }
 236 
 237 /*********************************************************************************************************
 238 VL_WinListViewColumn
 239 *********************************************************************************************************/
 240 
 241     void FillListViewColumn(LVCOLUMN* Column , UINT Mask)
 242     {
 243         memset(Column,0,sizeof(*Column));
 244         Column->mask=Mask;
 245     }
 246 
 247     VL_WinListViewColumn::VL_WinListViewColumn(HWND Handle , VInt Index)
 248     {
 249         FHandle=Handle;
 250         FIndex=Index;
 251     }
 252 
 253     VL_WinListViewColumn::VL_WinListViewColumn()
 254     {
 255         FHandle=0;
 256         FIndex=0;
 257     }
 258 
 259     VL_WinListViewColumn::VL_WinListViewColumn(const VL_WinListViewColumn& Item)
 260     {
 261         FHandle=Item.FHandle;
 262         FIndex=Item.FIndex;
 263     }
 264 
 265     VL_WinListViewColumn& VL_WinListViewColumn::operator=(const VL_WinListViewColumn& Item)
 266     {
 267         FHandle=Item.FHandle;
 268         FIndex=Item.FIndex;
 269         return *this;
 270     }
 271 
 272     VL_WinListViewColumn::operator VBool()
 273     {
 274         return FHandle!=0;
 275     }
 276     
 277     VUnicodeString VL_WinListViewColumn::GetText()
 278     {
 279         VWChar Buffer[LISTVIEW_TEXT_BUFFER_SIZE]={0};
 280         LVCOLUMN Column;
 281         FillListViewColumn(&Column,LVCF_TEXT);
 282         Column.pszText=Buffer;
 283         Column.cchTextMax=sizeof(Buffer)/sizeof(*Buffer);
 284         ListView_GetColumn(FHandle,FIndex,&Column);
 285         return Buffer;
 286     }
 287 
 288     void VL_WinListViewColumn::SetText(VUnicodeString Value)
 289     {
 290         LVCOLUMN Column;
 291         FillListViewColumn(&Column,LVCF_TEXT);
 292         Column.pszText=Value.Buffer();
 293         ListView_SetColumn(FHandle,FIndex,&Column);
 294     }
 295 
 296     VInt VL_WinListViewColumn::GetSubItemIndex()
 297     {
 298         LVCOLUMN Column;
 299         FillListViewColumn(&Column,LVCF_SUBITEM);
 300         ListView_GetColumn(FHandle,FIndex,&Column);
 301         return Column.iSubItem-1;
 302     }
 303 
 304     void VL_WinListViewColumn::SetSubItemIndex(VInt Value)
 305     {
 306         LVCOLUMN Column;
 307         FillListViewColumn(&Column,LVCF_SUBITEM);
 308         Column.iSubItem=Value+1;
 309         ListView_SetColumn(FHandle,FIndex,&Column);
 310     }
 311 
 312     VInt VL_WinListViewColumn::GetWidth()
 313     {
 314         LVCOLUMN Column;
 315         FillListViewColumn(&Column,LVCF_WIDTH);
 316         ListView_GetColumn(FHandle,FIndex,&Column);
 317         return Column.cx;
 318     }
 319 
 320     void VL_WinListViewColumn::SetWidth(VInt Value)
 321     {
 322         LVCOLUMN Column;
 323         FillListViewColumn(&Column,LVCF_WIDTH | LVCF_DEFAULTWIDTH);
 324         Column.cx=Value;
 325         Column.cxDefault=Value;
 326         ListView_SetColumn(FHandle,FIndex,&Column);
 327     }
 328 
 329     VInt VL_WinListViewColumn::GetOrder()
 330     {
 331         LVCOLUMN Column;
 332         FillListViewColumn(&Column,LVCF_ORDER);
 333         ListView_GetColumn(FHandle,FIndex,&Column);
 334         return Column.iOrder;
 335     }
 336 
 337     void VL_WinListViewColumn::SetOrder(VInt Value)
 338     {
 339         LVCOLUMN Column;
 340         FillListViewColumn(&Column,LVCF_ORDER);
 341         Column.iOrder=Value;
 342         ListView_SetColumn(FHandle,FIndex,&Column);
 343     }
 344 
 345     VInt VL_WinListViewColumn::GetImageIndex()
 346     {
 347         LVCOLUMN Column;
 348         FillListViewColumn(&Column,LVCF_IMAGE);
 349         ListView_GetColumn(FHandle,FIndex,&Column);
 350         return Column.iImage;
 351     }
 352 
 353     void VL_WinListViewColumn::SetImageIndex(VInt Value)
 354     {
 355         LVCOLUMN Column;
 356         FillListViewColumn(&Column,LVCF_IMAGE | LVCF_FMT);
 357         ListView_GetColumn(FHandle,FIndex,&Column);
 358         if(Value>=0)
 359         {
 360             Column.fmt|=LVCFMT_COL_HAS_IMAGES;
 361         }
 362         else
 363         {
 364             Column.fmt&=~LVCFMT_COL_HAS_IMAGES;
 365         }
 366         Column.iImage=Value;
 367         ListView_SetColumn(FHandle,FIndex,&Column);
 368     }
 369 
 370     VLE_WinHAlign VL_WinListViewColumn::GetTextAlign()
 371     {
 372         LVCOLUMN Column;
 373         FillListViewColumn(&Column,LVCF_FMT);
 374         ListView_GetColumn(FHandle,FIndex,&Column);
 375         if(Column.fmt & LVCFMT_RIGHT)
 376         {
 377             return vwhaRight;
 378         }
 379         else if(Column.fmt & LVCFMT_CENTER)
 380         {
 381             return vwhaCenter;
 382         }
 383         else
 384         {
 385             return vwhaLeft;
 386         }
 387     }
 388 
 389     void VL_WinListViewColumn::SetTextAlign(VLE_WinHAlign Value)
 390     {
 391         LVCOLUMN Column;
 392         FillListViewColumn(&Column,LVCF_FMT);
 393         ListView_GetColumn(FHandle,FIndex,&Column);
 394         Column.fmt&=~LVCFMT_RIGHT;
 395         Column.fmt&=~LVCFMT_CENTER;
 396         Column.fmt&=~LVCFMT_LEFT;
 397         switch(Value)
 398         {
 399         case vwhaRight:
 400             Column.fmt|=LVCFMT_RIGHT;
 401             break;
 402         case vwhaCenter:
 403             Column.fmt|=LVCFMT_CENTER;
 404             break;
 405         case vwhaLeft:
 406             Column.fmt|=LVCFMT_LEFT;
 407             break;
 408         }
 409         ListView_SetColumn(FHandle,FIndex,&Column);
 410     }
 411 
 412     VBool VL_WinListViewColumn::GetImageOnRight()
 413     {
 414         LVCOLUMN Column;
 415         FillListViewColumn(&Column,LVCF_FMT);
 416         ListView_GetColumn(FHandle,FIndex,&Column);
 417         return (Column.fmt & LVCFMT_BITMAP_ON_RIGHT)!=0;
 418     }
 419 
 420     void VL_WinListViewColumn::SetImageOnRight(VBool Value)
 421     {
 422         LVCOLUMN Column;
 423         FillListViewColumn(&Column,LVCF_FMT);
 424         ListView_GetColumn(FHandle,FIndex,&Column);
 425         if(Value)
 426         {
 427             Column.fmt|=LVCFMT_BITMAP_ON_RIGHT;
 428         }
 429         else
 430         {
 431             Column.fmt&=~LVCFMT_BITMAP_ON_RIGHT;
 432         }
 433         ListView_SetColumn(FHandle,FIndex,&Column);
 434     }
 435 
 436     VBool VL_WinListViewColumn::GetFixedWidth()
 437     {
 438         LVCOLUMN Column;
 439         FillListViewColumn(&Column,LVCF_FMT);
 440         ListView_GetColumn(FHandle,FIndex,&Column);
 441         return (Column.fmt & LVCFMT_FIXED_WIDTH)!=0;
 442     }
 443 
 444     void VL_WinListViewColumn::SetFixedWidth(VBool Value)
 445     {
 446         LVCOLUMN Column;
 447         FillListViewColumn(&Column,LVCF_FMT);
 448         ListView_GetColumn(FHandle,FIndex,&Column);
 449         if(Value)
 450         {
 451             Column.fmt|=LVCFMT_FIXED_WIDTH;
 452         }
 453         else
 454         {
 455             Column.fmt&=~LVCFMT_FIXED_WIDTH;
 456         }
 457         ListView_SetColumn(FHandle,FIndex,&Column);
 458     }
 459 
 460     VBool VL_WinListViewColumn::GetShowSplitButton()
 461     {
 462         LVCOLUMN Column;
 463         FillListViewColumn(&Column,LVCF_FMT);
 464         ListView_GetColumn(FHandle,FIndex,&Column);
 465         return (Column.fmt & LVCFMT_SPLITBUTTON)!=0;
 466     }
 467 
 468     void VL_WinListViewColumn::SetShowSplitButton(VBool Value)
 469     {
 470         LVCOLUMN Column;
 471         FillListViewColumn(&Column,LVCF_FMT);
 472         ListView_GetColumn(FHandle,FIndex,&Column);
 473         if(Value)
 474         {
 475             Column.fmt|=LVCFMT_SPLITBUTTON;
 476         }
 477         else
 478         {
 479             Column.fmt&=~LVCFMT_SPLITBUTTON;
 480         }
 481         ListView_SetColumn(FHandle,FIndex,&Column);
 482     }
 483 
 484 /*********************************************************************************************************
 485 VL_WinListViewGroup
 486 *********************************************************************************************************/
 487 
 488     void FillListViewGroup(LVGROUP* Group , UINT Mask)
 489     {
 490         memset(Group,0,sizeof(*Group));
 491         Group->cbSize=sizeof(*Group);
 492         Group->mask=Mask;
 493     }
 494 
 495     VUnicodeString VL_WinListViewGroup::GetListViewGroupText(UINT Mask , LPWSTR LVGROUP::* Item , UINT LVGROUP::* Count)
 496     {
 497         VWChar Buffer[LISTVIEW_TEXT_BUFFER_SIZE];
 498         LVGROUP Group;
 499         FillListViewGroup(&Group,Mask);
 500         Group.*Item=Buffer;
 501         Group.*Count=LISTVIEW_TEXT_BUFFER_SIZE;
 502         ListView_GetGroupInfo(FHandle,FID,&Group);
 503         return Buffer;
 504     }
 505 
 506     VUnicodeString VL_WinListViewGroup::GetListViewGroupText(UINT Mask , LPWSTR LVGROUP::* Item , int LVGROUP::* Count)
 507     {
 508         VWChar Buffer[LISTVIEW_TEXT_BUFFER_SIZE];
 509         LVGROUP Group;
 510         FillListViewGroup(&Group,Mask);
 511         Group.*Item=Buffer;
 512         Group.*Count=LISTVIEW_TEXT_BUFFER_SIZE;
 513         ListView_GetGroupInfo(FHandle,FID,&Group);
 514         return Buffer;
 515     }
 516 
 517     void VL_WinListViewGroup::SetListViewGroupText(UINT Mask , LPWSTR LVGROUP::* Item , VUnicodeString Text)
 518     {
 519         LVGROUP Group;
 520         FillListViewGroup(&Group,Mask);
 521         Group.*Item=Text.Length()?Text.Buffer():NULL;
 522         ListView_SetGroupInfo(FHandle,FID,&Group);
 523     }
 524 
 525     VL_WinListViewGroup::VL_WinListViewGroup(HWND Handle , VInt ID)
 526     {
 527         FHandle=Handle;
 528         FID=ID;
 529     }
 530 
 531     VL_WinListViewGroup::VL_WinListViewGroup()
 532     {
 533         FHandle=0;
 534         FID=0;
 535     }
 536 
 537     VL_WinListViewGroup::VL_WinListViewGroup(const VL_WinListViewGroup& Item)
 538     {
 539         FHandle=Item.FHandle;
 540         FID=Item.FID;
 541     }
 542 
 543     VL_WinListViewGroup& VL_WinListViewGroup::operator=(const VL_WinListViewGroup& Item)
 544     {
 545         FHandle=Item.FHandle;
 546         FID=Item.FID;
 547         return *this;
 548     }
 549 
 550     VL_WinListViewGroup::operator VBool()
 551     {
 552         return FHandle!=0;
 553     }
 554 
 555     VInt VL_WinListViewGroup::GetGroupID()
 556     {
 557         return FID;
 558     }
 559 
 560     VUnicodeString VL_WinListViewGroup::GetHeader()
 561     {
 562         return GetListViewGroupText(LVGF_HEADER,&LVGROUP::pszHeader,&LVGROUP::cchHeader);
 563     }
 564 
 565     void VL_WinListViewGroup::SetHeader(VUnicodeString Value)
 566     {
 567         SetListViewGroupText(LVGF_HEADER,&LVGROUP::pszHeader,Value);
 568     }
 569 
 570     VUnicodeString VL_WinListViewGroup::GetFooter()
 571     {
 572         return GetListViewGroupText(LVGF_FOOTER,&LVGROUP::pszFooter,&LVGROUP::cchFooter);
 573     }
 574 
 575     void VL_WinListViewGroup::SetFooter(VUnicodeString Value)
 576     {
 577         SetListViewGroupText(LVGF_FOOTER,&LVGROUP::pszFooter,Value);
 578     }
 579 
 580     VUnicodeString VL_WinListViewGroup::GetSubTitle()
 581     {
 582         return GetListViewGroupText(LVGF_SUBTITLE,&LVGROUP::pszSubtitle,&LVGROUP::cchSubtitle);
 583     }
 584 
 585     void VL_WinListViewGroup::SetSubTitle(VUnicodeString Value)
 586     {
 587         SetListViewGroupText(LVGF_SUBTITLE,&LVGROUP::pszSubtitle,Value);
 588     }
 589 
 590     VUnicodeString VL_WinListViewGroup::GetTask()
 591     {
 592         return GetListViewGroupText(LVGF_TASK,&LVGROUP::pszTask,&LVGROUP::cchTask);
 593     }
 594 
 595     void VL_WinListViewGroup::SetTask(VUnicodeString Value)
 596     {
 597         SetListViewGroupText(LVGF_TASK,&LVGROUP::pszTask,Value);
 598     }
 599 
 600     VUnicodeString VL_WinListViewGroup::GetDescriptionTop()
 601     {
 602         return GetListViewGroupText(LVGF_DESCRIPTIONTOP,&LVGROUP::pszDescriptionTop,&LVGROUP::cchDescriptionTop);
 603     }
 604 
 605     void VL_WinListViewGroup::SetDescriptionTop(VUnicodeString Value)
 606     {
 607         SetListViewGroupText(LVGF_DESCRIPTIONTOP,&LVGROUP::pszDescriptionTop,Value);
 608     }
 609 
 610     VUnicodeString VL_WinListViewGroup::GetDescriptionBottom()
 611     {
 612         return GetListViewGroupText(LVGF_DESCRIPTIONBOTTOM,&LVGROUP::pszDescriptionBottom,&LVGROUP::cchDescriptionBottom);
 613     }
 614 
 615     void VL_WinListViewGroup::SetDescriptionBottom(VUnicodeString Value)
 616     {
 617         SetListViewGroupText(LVGF_DESCRIPTIONBOTTOM,&LVGROUP::pszDescriptionBottom,Value);
 618     }
 619 
 620     VInt VL_WinListViewGroup::GetImageIndex()
 621     {
 622         LVGROUP Group;
 623         FillListViewGroup(&Group,LVGF_TITLEIMAGE);
 624         ListView_GetGroupInfo(FHandle,FID,&Group);
 625         return Group.iTitleImage;
 626     }
 627 
 628     void VL_WinListViewGroup::SetImageIndex(VInt Value)
 629     {
 630         LVGROUP Group;
 631         FillListViewGroup(&Group,LVGF_TITLEIMAGE);
 632         Group.iTitleImage=Value;
 633         ListView_SetGroupInfo(FHandle,FID,&Group);
 634     }
 635 
 636     VInt VL_WinListViewGroup::GetExtendedImageIndex()
 637     {
 638         LVGROUP Group;
 639         FillListViewGroup(&Group,LVGF_EXTENDEDIMAGE);
 640         ListView_GetGroupInfo(FHandle,FID,&Group);
 641         return Group.iExtendedImage;
 642     }
 643 
 644     void VL_WinListViewGroup::SetExtendedImageIndex(VInt Value)
 645     {
 646         LVGROUP Group;
 647         FillListViewGroup(&Group,LVGF_EXTENDEDIMAGE);
 648         Group.iExtendedImage=Value;
 649         ListView_SetGroupInfo(FHandle,FID,&Group);
 650     }
 651 
 652     VLE_WinHAlign VL_WinListViewGroup::GetHeaderAlign()
 653     {
 654         LVGROUP Group;
 655         FillListViewGroup(&Group,LVGF_ALIGN);
 656         ListView_GetGroupInfo(FHandle,FID,&Group);
 657         if(Group.uAlign==LVGA_HEADER_LEFT)
 658         {
 659             return vwhaLeft;
 660         }
 661         else if(Group.uAlign==LVGA_HEADER_CENTER)
 662         {
 663             return vwhaCenter;
 664         }
 665         else
 666         {
 667             return vwhaRight;
 668         }
 669     }
 670 
 671     void VL_WinListViewGroup::SetHeaderAlign(VLE_WinHAlign Value)
 672     {
 673         LVGROUP Group;
 674         FillListViewGroup(&Group,LVGF_ALIGN);
 675         switch(Value)
 676         {
 677         case vwhaLeft:
 678             Group.uAlign=LVGA_HEADER_LEFT;
 679             break;
 680         case vwhaCenter:
 681             Group.uAlign=LVGA_HEADER_CENTER;
 682             break;
 683         case vwhaRight:
 684             Group.uAlign=LVGA_HEADER_RIGHT;
 685             break;
 686         }
 687         ListView_SetGroupInfo(FHandle,FID,&Group);
 688     }
 689 
 690 /*********************************************************************************************************
 691 VL_WinListView
 692 *********************************************************************************************************/
 693 
 694     class ListViewSortParam
 695     {
 696     public:
 697         VPointer Param;
 698         VL_WinListView* ListView;
 699     };
 700 
 701     int CALLBACK ListViewCompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
 702     {
 703         VLE_ListViewSortResult Result=vlvsrEqual;
 704         ListViewSortParam* P=(ListViewSortParam*)lParamSort;
 705         P->ListView->OnCompareItems(P->ListView,lParam1,lParam2,P->Param,Result);
 706         switch(Result)
 707         {
 708         case vlvsrLarger:
 709             return 1;
 710         case vlvsrSmaller:
 711             return -1;
 712         default:
 713             return 0;
 714         }
 715     }
 716 
 717     DWORD VL_WinListView::InternalGetExStyle()
 718     {
 719         return ListView_GetExtendedListViewStyle(FHandle);
 720     }
 721 
 722     void VL_WinListView::InternalSetExStyle(DWORD ExStyle)
 723     {
 724         ListView_SetExtendedListViewStyle(FHandle,ExStyle);
 725     }
 726 
 727     VL_WinListView::VL_WinListView(VL_WinContainer* Parent)
 728     {
 729         FSmallImageList=0;
 730         FLargeImageList=0;
 731         FStateImageList=0;
 732         FGroupImageList=0;
 733         FColumnCount=0;
 734         FUsedGroupIDs=1;
 735 
 736         _CreateWindow(
 737             0,
 738             WS_VSCROLL | WS_HSCROLL | WS_BORDER | WS_TABSTOP | WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | LVS_ALIGNTOP | LVS_SHAREIMAGELISTS | LVS_ICON,
 739             WC_LISTVIEW,
 740             Parent);
 741 
 742         SetExStyle(LVS_EX_DOUBLEBUFFER,true);
 743         SetExStyle(LVS_EX_FULLROWSELECT,true);
 744         SetExStyle(LVS_EX_TRACKSELECT,false);
 745     }
 746 
 747     VL_WinListView::~VL_WinListView()
 748     {
 749     }
 750 
 751     LRESULT VL_WinListView::ProcessMessage(UINT Message , WPARAM& wParam , LPARAM& lParam , VBool& CallDefaultProcedure)
 752     {
 753         LRESULT Result=0;
 754         switch(Message)
 755         {
 756         case WM_NOTIFY_DISPATCHED:
 757             switch(((NMHDR*)lParam)->code)
 758             {
 759             case LVN_BEGINDRAG:
 760                 {
 761                     NMLISTVIEW* Param=(NMLISTVIEW*)lParam;
 762                     OnBeginDrag(this,Param->iItem,-1);
 763                 }
 764                 break;
 765             case LVN_BEGINRDRAG:
 766                 {
 767                     NMLISTVIEW* Param=(NMLISTVIEW*)lParam;
 768                     OnBeginRightDrag(this,Param->iItem,-1);
 769                 }
 770                 break;
 771             case LVN_BEGINLABELEDIT:
 772                 {
 773                     NMLVDISPINFO* Param=(NMLVDISPINFO*)lParam;
 774                     VUnicodeString Text=Param->item.pszText?Param->item.pszText:L"";
 775                     VBool Accept=true;
 776                     OnBeginLabelEdit(this,Param->item.iItem,Accept,Text);
 777                     return Accept?FALSE:TRUE;
 778                 }
 779                 break;
 780             case LVN_ENDLABELEDIT:
 781                 {
 782                     NMLVDISPINFO* Param=(NMLVDISPINFO*)lParam;
 783                     VUnicodeString Text=Param->item.pszText?Param->item.pszText:L"";
 784                     VBool Accept=true;
 785                     OnEndLabelEdit(this,Param->item.iItem,Accept,Text);
 786                     return Accept?TRUE:FALSE;
 787                 }
 788             case LVN_COLUMNCLICK:
 789                 {
 790                     NMLISTVIEW* Param=(NMLISTVIEW*)lParam;
 791                     OnColumnClick(this,Param->iSubItem,-1);
 792                 }
 793                 break;
 794             case LVN_COLUMNDROPDOWN:
 795                 {
 796                     NMLISTVIEW* Param=(NMLISTVIEW*)lParam;
 797                     OnColumnDropDown(this,Param->iSubItem,-1);
 798                 }
 799                 break;
 800             case LVN_HOTTRACK:
 801                 {
 802                     NMLISTVIEW* Param=(NMLISTVIEW*)lParam;
 803                     OnItemHotTrack(this,Param->iItem,Param->iSubItem-1);
 804                 }
 805                 break;
 806             case LVN_ITEMACTIVATE:
 807                 {
 808                     NMITEMACTIVATE* Param=(NMITEMACTIVATE*)lParam;
 809                     OnItemActive(this,Param->iItem,-1);
 810                 }
 811                 break;
 812             case LVN_ITEMCHANGING:
 813                 {
 814                     NMLISTVIEW* Param=(NMLISTVIEW*)lParam;
 815                     OnItemChanging(this,Param->iItem,-1);
 816                 }
 817                 break;
 818             case LVN_ITEMCHANGED:
 819                 {
 820                     NMLISTVIEW* Param=(NMLISTVIEW*)lParam;
 821                     OnItemChanged(this,Param->iItem,-1);
 822                 }
 823                 break;
 824             case LVN_LINKCLICK:
 825                 {
 826                     NMLVLINK* Param=(NMLVLINK*)lParam;
 827                     if(ListView_HasGroup(FHandle,Param->iSubItem))
 828                     {
 829                         OnGroupTaskClick(this,Param->iSubItem,-1);
 830                     }
 831                 }
 832                 break;
 833             case NM_CLICK:
 834                 {
 835                     NMITEMACTIVATE* Param=(NMITEMACTIVATE*)lParam;
 836                     OnItemClick(this,Param->iItem,Param->iSubItem-1);
 837                 }
 838                 break;
 839             case NM_DBLCLK:
 840                 {
 841                     NMITEMACTIVATE* Param=(NMITEMACTIVATE*)lParam;
 842                     OnItemDbClick(this,Param->iItem,Param->iSubItem-1);
 843                 }
 844                 break;
 845             case NM_RCLICK:
 846                 {
 847                     NMITEMACTIVATE* Param=(NMITEMACTIVATE*)lParam;
 848                     OnItemRightClick(this,Param->iItem,Param->iSubItem-1);
 849                 }
 850                 break;
 851             case NM_RDBLCLK:
 852                 {
 853                     NMITEMACTIVATE* Param=(NMITEMACTIVATE*)lParam;
 854                     OnItemRightDbClick(this,Param->iItem,Param->iSubItem-1);
 855                 }
 856                 break;
 857             }
 858             Result=VL_WinControl::ProcessMessage(Message,wParam,lParam,CallDefaultProcedure);
 859             break;
 860         default:
 861             Result=VL_WinControl::ProcessMessage(Message,wParam,lParam,CallDefaultProcedure);
 862         }
 863         return Result;
 864     }
 865 
 866     VL_WinImageList* VL_WinListView::GetSmallImageList()
 867     {
 868         return FSmallImageList;
 869     }
 870 
 871     void VL_WinListView::SetSmallImageList(VL_WinImageList* ImageList)
 872     {
 873         ListView_SetImageList(FHandle,ImageList->GetHandle(),LVSIL_SMALL);
 874         FSmallImageList=ImageList;
 875     }
 876 
 877     VL_WinImageList* VL_WinListView::GetLargeImageList()
 878     {
 879         return FLargeImageList;
 880     }
 881 
 882     void VL_WinListView::SetLargeImageList(VL_WinImageList* ImageList)
 883     {
 884         ListView_SetImageList(FHandle,ImageList->GetHandle(),LVSIL_NORMAL);
 885         FLargeImageList=ImageList;
 886     }
 887 
 888     VL_WinImageList* VL_WinListView::GetStateImageList()
 889     {
 890         return FStateImageList;
 891     }
 892 
 893     void VL_WinListView::SetStateImageList(VL_WinImageList* ImageList)
 894     {
 895         ListView_SetImageList(FHandle,ImageList->GetHandle(),LVSIL_STATE);
 896         FStateImageList=ImageList;
 897     }
 898 
 899     VL_WinImageList* VL_WinListView::GetGroupImageList()
 900     {
 901         return FGroupImageList;
 902     }
 903 
 904     void VL_WinListView::SetGroupImageList(VL_WinImageList* ImageList)
 905     {
 906         ListView_SetImageList(FHandle,ImageList->GetHandle(),LVSIL_GROUPHEADER);
 907         FGroupImageList=ImageList;
 908     }
 909 
 910     VLE_ListViewStyle VL_WinListView::GetViewStyle()
 911     {
 912         switch(ListView_GetView(FHandle))
 913         {
 914         case LV_VIEW_ICON:
 915             return vlvsLarge;
 916         case LV_VIEW_SMALLICON:
 917             return vlvsSmall;
 918         case LV_VIEW_LIST:
 919             return vlvsList;
 920         case LV_VIEW_DETAILS:
 921             return vlvsReport;
 922         default:
 923             return vlvsTile;
 924         }
 925     }
 926 
 927     void VL_WinListView::SetViewStyle(VLE_ListViewStyle Style)
 928     {
 929         switch(Style)
 930         {
 931         case vlvsLarge:
 932             ListView_SetView(FHandle,LV_VIEW_ICON);
 933             break;
 934         case vlvsSmall:
 935             ListView_SetView(FHandle,LV_VIEW_SMALLICON);
 936             break;
 937         case vlvsList:
 938             ListView_SetView(FHandle,LV_VIEW_LIST);
 939             break;
 940         case vlvsReport:
 941             ListView_SetView(FHandle,LV_VIEW_DETAILS);
 942             break;
 943         case vlvsTile:
 944             ListView_SetView(FHandle,LV_VIEW_TILE);
 945             break;
 946         }
 947     }
 948 
 949     COLORREF VL_WinListView::GetOutlineColor()
 950     {
 951         return ListView_GetOutlineColor(FHandle);
 952     }
 953 
 954     void VL_WinListView::SetOutlineColor(COLORREF Value)
 955     {
 956         ListView_SetOutlineColor(FHandle,Value);
 957     }
 958 
 959     COLORREF VL_WinListView::GetTextColor()
 960     {
 961         return ListView_GetTextColor(FHandle);
 962     }
 963     
 964     void VL_WinListView::SetTextColor(COLORREF Value)
 965     {
 966         ListView_SetTextColor(FHandle,Value);
 967     }
 968 
 969     COLORREF VL_WinListView::GetTextBackColor()
 970     {
 971         return ListView_GetTextBkColor(FHandle);
 972     }
 973 
 974     void VL_WinListView::SetTextBackColor(COLORREF Value)
 975     {
 976         ListView_SetTextBkColor(FHandle,Value);
 977     }
 978 
 979     COLORREF VL_WinListView::GetBackColor()
 980     {
 981         return ListView_GetBkColor(FHandle);
 982     }
 983 
 984     void VL_WinListView::SetBackColor(COLORREF Value)
 985     {
 986         ListView_SetBkColor(FHandle,Value);
 987     }
 988 
 989     VBool VL_WinListView::GetAutoArrange()
 990     {
 991         return GetStyle(LVS_AUTOARRANGE);
 992     }
 993 
 994     void VL_WinListView::SetAutoArrange(VBool Value)
 995     {
 996         SetStyle(LVS_AUTOARRANGE,Value);
 997     }
 998 
 999     VBool VL_WinListView::GetEditable()
1000     {
1001         return GetStyle(LVS_EDITLABELS);
1002     }
1003 
1004     void VL_WinListView::SetEditable(VBool Value)
1005     {
1006         SetStyle(LVS_EDITLABELS,Value);
1007     }
1008 
1009     VBool VL_WinListView::GetColumnPushable()
1010     {
1011         return !GetStyle(LVS_NOSORTHEADER);
1012     }
1013 
1014     void VL_WinListView::SetColumnPushable(VBool Value)
1015     {
1016         SetStyle(LVS_NOSORTHEADER,!Value);
1017     }
1018 
1019     VBool VL_WinListView::GetAlwaysShowSelection()
1020     {
1021         return GetStyle(LVS_SHOWSELALWAYS);
1022     }
1023 
1024     void VL_WinListView::SetAlwaysShowSelection(VBool Value)
1025     {
1026         SetStyle(LVS_SHOWSELALWAYS,Value);
1027     }
1028 
1029     VBool VL_WinListView::GetSingleSelection()
1030     {
1031         return GetStyle(LVS_SINGLESEL);
1032     }
1033 
1034     void VL_WinListView::SetSingleSelection(VBool Value)
1035     {
1036         SetStyle(LVS_SINGLESEL,Value);
1037     }
1038 
1039     VBool VL_WinListView::GetShowCheckBoxes()
1040     {
1041         return GetExStyle(LVS_EX_CHECKBOXES);
1042     }
1043 
1044     void VL_WinListView::SetShowCheckBoxes(VBool Value)
1045     {
1046         SetExStyle(LVS_EX_CHECKBOXES,Value);
1047     }
1048 
1049     VBool VL_WinListView::GetAutoCheckSelect()
1050     {
1051         return GetExStyle(LVS_EX_AUTOCHECKSELECT);
1052     }
1053 
1054     void VL_WinListView::SetAutoCheckSelect(VBool Value)
1055     {
1056         SetExStyle(LVS_EX_AUTOCHECKSELECT,Value);
1057     }
1058 
1059     VBool VL_WinListView::GetBorderSelect()
1060     {
1061         return GetExStyle(LVS_EX_BORDERSELECT);
1062     }
1063 
1064     void VL_WinListView::SetBorderSelect(VBool Value)
1065     {
1066         SetExStyle(LVS_EX_BORDERSELECT,Value);
1067     }
1068 
1069     VBool VL_WinListView::GetShowGridLines()
1070     {
1071         return GetExStyle(LVS_EX_GRIDLINES);
1072     }
1073 
1074     void VL_WinListView::SetShowGridLines(VBool Value)
1075     {
1076         SetExStyle(LVS_EX_GRIDLINES,Value);
1077     }
1078 
1079     VBool VL_WinListView::GetHeaderDragable()
1080     {
1081         return GetExStyle(LVS_EX_HEADERDRAGDROP);
1082     }
1083 
1084     void VL_WinListView::SetHeaderDragable(VBool Value)
1085     {
1086         SetExStyle(LVS_EX_HEADERDRAGDROP,Value);
1087     }
1088 
1089     VBool VL_WinListView::GetOneClickActive()
1090     {
1091         return GetExStyle(LVS_EX_ONECLICKACTIVATE);
1092     }
1093 
1094     void VL_WinListView::SetOneClickActive(VBool Value)
1095     {
1096         SetExStyle(LVS_EX_ONECLICKACTIVATE,Value);
1097     }
1098 
1099     VBool VL_WinListView::GetTwoClickActive()
1100     {
1101         return GetExStyle(LVS_EX_TWOCLICKACTIVATE);
1102     }
1103 
1104     void VL_WinListView::SetTwoClickActive(VBool Value)
1105     {
1106         SetExStyle(LVS_EX_TWOCLICKACTIVATE,Value);
1107     }
1108 
1109     VBool VL_WinListView::GetUnderlineHot()
1110     {
1111         return GetExStyle(LVS_EX_UNDERLINEHOT);
1112     }
1113 
1114     void VL_WinListView::SetUnderlineHot(VBool Value)
1115     {
1116         SetExStyle(LVS_EX_UNDERLINEHOT,Value);
1117     }
1118 
1119     VBool VL_WinListView::GetUnderlineCold()
1120     {
1121         return GetExStyle(LVS_EX_UNDERLINECOLD);
1122     }
1123 
1124     void VL_WinListView::SetUnderlineCold(VBool Value)
1125     {
1126         SetExStyle(LVS_EX_UNDERLINECOLD,Value);
1127     }
1128 
1129     VBool VL_WinListView::GetAutoAutoArrange()
1130     {
1131         return GetExStyle(LVS_EX_AUTOAUTOARRANGE);
1132     }
1133 
1134     void VL_WinListView::SetAutoAutoArrange(VBool Value)
1135     {
1136         SetExStyle(LVS_EX_AUTOAUTOARRANGE,Value);
1137     }
1138 
1139     VBool VL_WinListView::GetSnapToGrid()
1140     {
1141         return GetExStyle(LVS_EX_SNAPTOGRID);
1142     }
1143 
1144     void VL_WinListView::SetSnapToGrid(VBool Value)
1145     {
1146         SetExStyle(LVS_EX_SNAPTOGRID,Value);
1147     }
1148 
1149     void VL_WinListView::EditLabel(VInt Index)
1150     {
1151         ListView_EditLabel(FHandle,Index);
1152     }
1153 
1154     void VL_WinListView::CancelEditLabel()
1155     {
1156         ListView_CancelEditLabel(FHandle);
1157     }
1158 
1159     void VL_WinListView::Arrange()
1160     {
1161         ListView_Arrange(FHandle,LVA_DEFAULT);
1162     }
1163 
1164     void VL_WinListView::SnapToGrid()
1165     {
1166         ListView_Arrange(FHandle,LVA_SNAPTOGRID);
1167     }
1168 
1169     void VL_WinListView::EnsureItemVisible(VInt Index , VBool AcceptPartialVisible)
1170     {
1171         ListView_EnsureVisible(FHandle,Index,(AcceptPartialVisible?TRUE:FALSE));
1172     }
1173 
1174     void VL_WinListView::Sort(VPointer Param)
1175     {
1176         ListViewSortParam P;
1177         P.Param=Param;
1178         P.ListView=this;
1179         ListView_SortItemsEx(FHandle,ListViewCompareFunc,&P);
1180     }
1181 
1182     VInt VL_WinListView::GetItemCount()
1183     {
1184         return ListView_GetItemCount(FHandle);
1185     }
1186 
1187     void VL_WinListView::AddItem(VUnicodeString Text , VInt ImageIndex)
1188     {
1189         InsertItem(GetItemCount(),Text,ImageIndex);
1190     }
1191 
1192     void VL_WinListView::InsertItem(VInt Index , VUnicodeString Text , VInt ImageIndex)
1193     {
1194         LVITEM Item;
1195         memset(&Item,0,sizeof(Item));
1196         Item.mask=LVIF_TEXT | (ImageIndex==-1?0:LVIF_IMAGE) | LVIF_PARAM;
1197         Item.pszText=Text.Buffer();
1198         Item.cchTextMax=Text.Length()+1;
1199         Item.iItem=Index;
1200         Item.iSubItem=0;
1201         Item.iImage=ImageIndex;
1202         Item.lParam=0;
1203         ListView_InsertItem(FHandle,&Item);
1204     }
1205 
1206     void VL_WinListView::DeleteItem(VInt Index)
1207     {
1208         ListView_DeleteItem(FHandle,Index);
1209     }
1210 
1211     VL_WinListViewItem VL_WinListView::GetItem(VInt Index)
1212     {
1213         if(Index>=0 && Index<GetItemCount())
1214         {
1215             return VL_WinListViewItem(FHandle,Index);
1216         }
1217         else
1218         {
1219             return VL_WinListViewItem();
1220         }
1221     }
1222 
1223     VInt VL_WinListView::GetSelectedItemCount()
1224     {
1225         return ListView_GetSelectedCount(FHandle);
1226     }
1227 
1228     VInt VL_WinListView::GetSelectionItemMark()
1229     {
1230         return ListView_GetSelectionMark(FHandle);
1231     }
1232 
1233     void VL_WinListView::SetSelectionItemMark(VInt Value)
1234     {
1235         ListView_SetSelectionMark(FHandle,Value);
1236     }
1237 
1238     VInt VL_WinListView::GetHotItemIndex()
1239     {
1240         return ListView_GetHotItem(FHandle);
1241     }
1242 
1243     void VL_WinListView::SetHotItemIndex(VInt Value)
1244     {
1245         ListView_SetHotItem(FHandle,Value);
1246     }
1247 
1248     VInt VL_WinListView::GetColumnCount()
1249     {
1250         return FColumnCount;
1251     }
1252 
1253     void VL_WinListView::AddColumn(VUnicodeString Text , VInt SubItemIndex)
1254     {
1255         InsertColumn(GetColumnCount(),Text,SubItemIndex);
1256     }
1257 
1258     void VL_WinListView::InsertColumn(VInt Index , VUnicodeString Text , VInt SubItemIndex)
1259     {
1260         LVCOLUMN Column;
1261         memset(&Column,0,sizeof(Column));
1262         Column.mask=LVCF_TEXT | LVCF_SUBITEM | LVCF_WIDTH;
1263         Column.pszText=Text.Buffer();
1264         Column.cchTextMax=Text.Length()+1;
1265         Column.iSubItem=SubItemIndex+1;
1266         Column.cx=100;
1267         if(ListView_InsertColumn(FHandle,Index,&Column)!=-1)
1268         {
1269             FColumnCount++;
1270         }
1271     }
1272 
1273     void VL_WinListView::DeleteColumn(VInt Index)
1274     {
1275         if(ListView_DeleteColumn(FHandle,Index)==TRUE)
1276         {
1277             FColumnCount--;
1278         }
1279     }
1280 
1281     VL_WinListViewColumn VL_WinListView::GetColumn(VInt Index)
1282     {
1283         if(Index>=0 && Index<GetColumnCount())
1284         {
1285             return VL_WinListViewColumn(FHandle,Index);
1286         }
1287         else
1288         {
1289             return VL_WinListViewColumn();
1290         }
1291     }
1292 
1293     VInt VL_WinListView::GetSelectedColumnIndex()
1294     {
1295         return ListView_GetSelectedColumn(FHandle);
1296     }
1297     
1298     void VL_WinListView::SetSelectedColumnIndex(VInt Value)
1299     {
1300         ListView_SetSelectedColumn(FHandle,Value);
1301     }
1302 
1303     void VL_WinListView::EnableGrouping(VBool Value)
1304     {
1305         ListView_EnableGroupView(FHandle,(Value?TRUE:FALSE));
1306     }
1307 
1308     VInt VL_WinListView::GetGroupCount()
1309     {
1310         return ListView_GetGroupCount(FHandle);
1311     }
1312 
1313     VInt VL_WinListView::AddGroup(VUnicodeString Text)
1314     {
1315         return InsertGroup(-1,Text);
1316     }
1317 
1318     VInt VL_WinListView::InsertGroup(VInt Index , VUnicodeString Text)
1319     {
1320         LVGROUP Group;
1321         memset(&Group,0,sizeof(Group));
1322         Group.cbSize=sizeof(Group);
1323         Group.mask=LVGF_HEADER | LVGF_GROUPID;
1324         Group.pszHeader=Text.Buffer();
1325         Group.iGroupId=FUsedGroupIDs;
1326         ListView_InsertGroup(FHandle,Index,&Group);
1327         return FUsedGroupIDs++;
1328     }
1329 
1330     void VL_WinListView::DeleteGroup(VInt Index)
1331     {
1332         VL_WinListViewGroup Group=GetGroup(Index);
1333         if(Group)
1334         {
1335             ListView_RemoveGroup(FHandle,Group.GetGroupID());
1336         }
1337     }
1338 
1339     void VL_WinListView::DeleteGroupByID(VInt ID)
1340     {
1341         ListView_RemoveGroup(FHandle,ID);
1342     }
1343 
1344     VL_WinListViewGroup VL_WinListView::GetGroup(VInt Index)
1345     {
1346         if(Index>=0 && Index<GetGroupCount())
1347         {
1348             LVGROUP Group;
1349             FillListViewGroup(&Group,LVGF_GROUPID);
1350             ListView_GetGroupInfoByIndex(FHandle,Index,&Group);
1351             return GetGroupByID(Group.iGroupId);
1352         }
1353         else
1354         {
1355             return VL_WinListViewGroup();
1356         }
1357     }
1358 
1359     VL_WinListViewGroup VL_WinListView::GetGroupByID(VInt ID)
1360     {
1361         if(ListView_HasGroup(FHandle,ID)==TRUE)
1362         {
1363             return VL_WinListViewGroup(FHandle,ID);
1364         }
1365         else
1366         {
1367             return VL_WinListViewGroup();
1368         }
1369     }
1370 
1371     }
1372 }
posted on 2008-08-09 02:36 陈梓瀚(vczh) 阅读(6477) 评论(27)  编辑 收藏 引用 所属分类: C++

评论:
# re: ListView封装完了,放代码 2008-08-09 03:57 | 沈臻豪(foxtail)
一天都不鸟人 原来忙这个  回复  更多评论
  
# re: ListView封装完了,放代码 2008-08-09 06:25 | Lnn
很牛  回复  更多评论
  
# re: ListView封装完了,放代码 2008-08-09 07:31 | feosun
平时多娱乐娱乐 不要忙坏了``  回复  更多评论
  
# re: ListView封装完了,放代码 2008-08-09 17:00 | UzStudio
再牛逼的东西也是一步步搞起来的,支持博主  回复  更多评论
  
# re: ListView封装完了,放代码 2008-08-09 21:43 | Gohan
赞啊,功能越来越强大了  回复  更多评论
  
# re: ListView封装完了,放代码 2008-08-10 09:27 | 空明流转
体力活啊,你在“忒傻逼”就干了这些啊?  回复  更多评论
  
# re: ListView封装完了,放代码 2008-08-11 05:03 | 陈梓瀚(vczh)
我能把我在“忒傻逼”里写的代码贴出来吗?  回复  更多评论
  
# re: ListView封装完了,放代码 2008-08-11 18:46 | 巫云
请问VL是什么东西啊?  回复  更多评论
  
# re: ListView封装完了,放代码 2008-08-11 19:05 | 空明流转
@陈梓瀚(vczh)
我是说你在忒傻逼都干私活了。。。  回复  更多评论
  
# re: ListView封装完了,放代码 2008-08-12 04:43 | 陈梓瀚(vczh)
囧了,难道我白天给公司写代码,晚上就不能给我自己写代码?  回复  更多评论
  
# re: ListView封装完了,放代码 2008-08-12 04:43 | 陈梓瀚(vczh)
VL是我看别的库的函数名称跟我的习惯不一样之后的结果  回复  更多评论
  
# re: ListView封装完了,放代码[未登录] 2008-08-12 12:42 | Yock.W
囧rz...陈同学果然很囧....  回复  更多评论
  
# re: ListView封装完了,放代码 2008-08-14 00:51 | brent
你的目标:没有MFC?  回复  更多评论
  
# re: ListView封装完了,放代码 2008-08-14 03:29 | 陈梓瀚(vczh)
被你发现了  回复  更多评论
  
# re: ListView封装完了,放代码 2008-08-22 03:20 | Condor
很好,不知有没有完整的源码提供.  回复  更多评论
  
# re: ListView封装完了,放代码 2011-05-26 01:25 | Reader
前几天用VB6 SDK做了一个具有Grouping功能的Listview. 在XP下,GroupHeader是不能展开。在Vista/Win7 above支持,但有Repaint的问题,解决的办法是Subclass相关消息。  回复  更多评论
  
# re: ListView封装完了,放代码 2011-05-26 01:33 | Reader
看起来MFC比VB6简单,有很多现成的功能。


VUnicodeString VL_WinListViewColumn::GetText()
 278     {
 279         VWChar Buffer[LISTVIEW_TEXT_BUFFER_SIZE]={0};
 280         LVCOLUMN Column;
 281         FillListViewColumn(&Column,LVCF_TEXT);
 282         Column.pszText=Buffer;
 283         Column.cchTextMax=sizeof(Buffer)/sizeof(*Buffer);
 284         ListView_GetColumn(FHandle,FIndex,&Column);
 285         return Buffer;
 286     }
 287 
 288     void VL_WinListViewColumn::SetText(VUnicodeString Value)
 289     {
 290         LVCOLUMN Column;
 291         FillListViewColumn(&Column,LVCF_TEXT);
 292         Column.pszText=Value.Buffer();
 293         ListView_SetColumn(FHandle,FIndex,&Column);
 294     }

VB6:

Public Property Get ColumnText(ByVal Column As Long) As String

Dim uLVC As LVCOLUMNW
Dim a(260) As Byte

If (m_hListView And m_hHeader) Then
With uLVC
.pszText = VarPtr(a(0))
.cchTextMax = UBound(a)
.mask = LVIF_TEXT
End With
If m_bIsNT Then
Call SendMessage(m_hListView, LVM_GETCOLUMNW, Column, uLVC)
Else
Call SendMessage(m_hListView, LVM_GETCOLUMN, Column, uLVC)
End If
If uLVC.cchTextMax > 0 Then
If m_bIsNT Then
ColumnText = a
Else
ColumnText = left$(StrConv(a(), vbUnicode), uLVC.cchTextMax)
End If
Else
ColumnText = ""
End If
End If

End Property

Public Property Let ColumnText(ByVal Column As Long, ByVal Text As String)

Dim uLVC As LVCOLUMNW

If (m_hListView And m_hHeader) Then

With uLVC
If m_bIsNT Then
.pszText = StrPtr(Text)
Else
.pszText = StrPtr(StrConv(Text & vbNullChar, vbFromUnicode))
End If
.cchTextMax = Len(Text) + 1
.mask = LVCF_TEXT
End With
If m_bIsNT Then
Call SendMessage(m_hListView, LVM_SETCOLUMNW, Column, uLVC)
Else
Call SendMessage(m_hListView, LVM_SETCOLUMN, Column, uLVC)
End If
End If

End Property
  回复  更多评论
  
# re: ListView封装完了,放代码 2011-05-27 07:49 | 陈梓瀚(vczh)
@Reader
VB6有垃圾收集,当然要简单……  回复  更多评论
  
# re: ListView封装完了,放代码 2011-06-14 22:30 | Reader
请问怎样MoveItem和InsertItem?  回复  更多评论
  
# re: ListView封装完了,放代码 2011-06-14 22:43 | Reader
@陈梓瀚(vczh)

在VB6中,SetHeader Text在XP中好像不行,需要骗,参考http://users.skynet.be/oleole/Listview_grouping_feature.htm,Vista/Win7可以。

  回复  更多评论
  
# re: ListView封装完了,放代码 2011-06-14 22:53 | Reader
@陈梓瀚(vczh)
C真是好,VB6,Subclass本身还需要自己编写,C中已经有了:
LRESULT VL_WinListView::ProcessMessage(UINT Message , WPARAM& wParam , LPARAM& lParam , VBool& CallDefaultProcedure)  回复  更多评论
  
# re: ListView封装完了,放代码 2011-06-15 02:26 | Reader
你测试过
FListView->GetGroupByID(GroupA).SetExtendedImageIndex(0);
在VB6好像不行。  回复  更多评论
  
# re: ListView封装完了,放代码 2011-06-15 02:39 | Reader
FStateImageList用在什么地方(在什么情况下用)?  回复  更多评论
  
# re: ListView封装完了,放代码 2011-06-16 21:43 | Reader
149 VBool VL_WinListViewItem::GetFocusedState()
150 {
151 return ListView_GetItemState(FHandle,FIndex,LVIS_FOCUSED)!=0;
152 }
153
154 void VL_WinListViewItem::SetFocusedState(VBool Value)
155 {
156 ListView_SetItemState(FHandle,FIndex,(Value?LVIS_FOCUSED:0),LVIS_FOCUSED);
157 }

I am not sure whether you did a test for function GetFocusedState.
In VB6,I can't use LVM_GETITEMSTATE to check the item is focused or not. I believe SendMessage of LVM_GETITEMSTATE in VB6 is equal to C++ ListView_GetItemState.

Public Property Get ItemFocused(ByVal Item As Long) As Boolean

Dim lFlag As Long
If (m_hListView) Then
lFlag = LVIS_FOCUSED
ItemFocused = CBool(SendMessage(m_hListView, LVM_GETITEMSTATE, item, Byval lFlag ))
End If

End Property

I have to use Message LVM_GETNEXTITEM to retrieve item's focus state.

Public Property Get ItemFocused(ByVal Item As Long) As Boolean

Dim lFlags As Long
Dim RowInFocus As Long

If m_hListView Then
lFlags = LVNI_SELECTED
If GetFocus() = m_hListView Then lFlags = lFlags Or LVNI_FOCUSED
RowInFocus = SendMessage(m_hListView, LVM_GETNEXTITEM, &HFFFF, ByVal lFlags) 'don't use LVM_GETITEMSTATE
If RowInFocus = Item Then ItemFocused = True
End If

End Property  回复  更多评论
  
# re: ListView封装完了,放代码 2011-06-17 05:03 | 陈梓瀚(vczh)
@Reader
我猜应该是有些api是vista和win7才管用的。我的库并没有分开他们。  回复  更多评论
  
# re: ListView封装完了,放代码 2011-06-17 06:15 | Reader
@陈梓瀚(vczh)
我测试的平台是Win7.Vista支持很多新的功能而XP是不支持。
请你在Win7下测试一下GetFocusedState和FListView->GetGroupByID(GroupA).SetExtendedImageIndex(0);  回复  更多评论
  

只有注册用户登录后才能发表评论。
【推荐】超50万行VC++源码: 大型组态工控、电力仿真CAD与GIS源码库
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理