专注于互联网--专注于架构

最新标签
网站地图
文章索引
Rss订阅

首页 »C 教程 » listview:ListView封装完以后的代码 »正文

listview:ListView封装完以后的代码

来源: 发布时间:星期四, 2008年9月25日 浏览:178次 评论: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);

如果本文没有解决您的问题,请进老妖怪开发者社区提问

相关文章

读者评论

  • 共0条 分0页

发表评论

  • 昵称:
  • 内容: