原来API提供的TabControl只是改改样式而已,客户区连TabPage标签也算在了里面,点击不同的TabPage也不会自动切换子控件的可见属性。这些都要封装啊囧……
在这个封装的设计里,虽然TabPage是一个普通的类,但是每一个TabPage都会自动附带一个Static Control,并在适当的时机修改大小以及修改可见属性。子控件实际上需要放在TabPage的Static Control里,不然的话其实可以连TabPage标签都挡掉。
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 class MyForm : public VL_WinForm
9 {
10 protected:
11 VL_WinTab* FTab;
12 VUnicodeString FBitmapPath;
13 VL_WinImageList* FSmallImages;
14
15 void InitControls()
16 {
17 FBitmapPath=VFileName(GetApplication()->GetAppName()).GetPath().MakeAbsolute(L"..\\..\\Views\\Bitmap\\").GetStrW();
18 FSmallImages=new VL_WinImageList(16,16);
19 for(VInt i=0;i<4;i++)
20 {
21 FSmallImages->Add(new VL_WinBitmap(FBitmapPath+L"s"+VUnicodeString(i)+L".bmp",true,true));
22 }
23
24 FTab=new VL_WinTab(this);
25 GetPlacement()->SetBorderSize(10);
26 GetPlacement()->SetControl(FTab);
27 FTab->SetImageList(FSmallImages);
28 FTab->AddPage(L"Add Table").SetImageIndex(0);
29 FTab->AddPage(L"Arrange Windows").SetImageIndex(1);
30 FTab->AddPage(L"Remove Table").SetImageIndex(2);
31 FTab->AddPage(L"Graph").SetImageIndex(3);
32
33 for(VInt i=0;i<FTab->GetPageCount();i++)
34 {
35 VL_WinTabPage Page=FTab->GetPage(i);
36 VL_WinEdit* Edit=new VL_WinEdit(Page,true);
37 Page.GetPlacement()->SetControl(Edit);
38 Edit->SetHScroll(true);
39 Edit->SetVScroll(true);
40 Edit->Move(0,0,Page.GetClientWidth(),Page.GetClientHeight());
41 Edit->SetText(L"This is a multiple line edit box in tag page "+VUnicodeString(i+1)+L".");
42 }
43 FTab->SetSelectedPage(FTab->GetPage(3));
44 }
45
46 public:
47
48 MyForm():VL_WinForm(true)
49 {
50 SetClientWidth(400);
51 SetClientHeight(400);
52 SetText(L"Vczh Form");
53 MoveCenter();
54 InitControls();
55 Show();
56 }
57
58 ~MyForm()
59 {
60 delete FSmallImages;
61 }
62 };
63
64 void main()
65 {
66 new MyForm;
67 GetApplication()->Run();
68 }
自动生成、删除和修改Static的确是比较麻烦的,不过好在API并不会对这些问题的解决施加新的困难。
1 VL_WinTabPage VL_WinTab::AddPage(VUnicodeString Text)
2 {
3 return InsertPage(GetPageCount(),Text);
4 }
5
6 VL_WinTabPage VL_WinTab::InsertPage(VInt Index , VUnicodeString Text)
7 {
8 TCITEM Item;
9 memset(&Item,0,sizeof(Item));
10 Item.mask=TCIF_TEXT;
11 Item.pszText=Text.Buffer();
12 Index=TabCtrl_InsertItem(FHandle,Index,&Item);
13 if(Index==-1)
14 {
15 return VL_WinTabPage();
16 }
17 else
18 {
19 RECT Rect;
20 GetClientArea(&Rect);
21 VL_WinStatic* Static=new VL_WinStatic(this);
22 FTabContainers.Insert(Index,Static);
23 ResetTopTabContainer();
24 ArrangeTabContainers();
25 return VL_WinTabPage(FHandle,Index,Static);
26 }
27 }
28
29 void VL_WinTab::DeletePage(VInt Index)
30 {
31 if(Index>=0 && Index<GetPageCount())
32 {
33 if(TabCtrl_DeleteItem(FHandle,Index)==TRUE)
34 {
35 delete FTabContainers.Fetch(Index);
36 ArrangeTabContainers();
37 }
38 }
39 }
40
41 VL_WinTabPage VL_WinTab::GetPage(VInt Index)
42 {
43 if(Index>=0 && Index<GetPageCount())
44 {
45 return VL_WinTabPage(FHandle,Index,FTabContainers[Index]);
46 }
47 else
48 {
49 return VL_WinTabPage();
50 }
51 }
52
53 VInt VL_WinTab::GetPageCount()
54 {
55 return TabCtrl_GetItemCount(FHandle);
56 }
posted on 2008-08-13 06:33
陈梓瀚(vczh) 阅读(1709)
评论(2) 编辑 收藏 引用 所属分类:
C++