为了缓解疲劳,我网络和UI同时做。封装UI真是麻烦啊,一大堆习惯的东西原来是没有的,什么tab转移焦点,什么控件对齐,都要自己做。后来就囧了,干脆实现一个Placement来自动调整控件的位置。
Placement写起来还是比较麻烦的,不过为了以后GUI Editor的开发方便,我还是做成了这个样子。
1 #include "..\..\..\..\VL++\Library\Windows\VL_WinMain.h"
2 #include "..\..\..\..\VL++\Library\Windows\Commctrl\VL_WinText.h"
3 #include "..\..\..\..\VL++\Library\Windows\Commctrl\VL_WinButton.h"
4
5 using namespace vl;
6 using namespace vl::windows;
7
8 class MyForm : public VL_WinForm
9 {
10 protected:
11 VL_WinEdit* FSingleLine;
12 VL_WinEdit* FMultiLine;
13 VL_WinButton* FButton;
14 VL_WinStatic* FStatic;
15
16 void InitControls()
17 {
18 FStatic=new VL_WinStatic(this);
19 FStatic->SetText(L"Name:");
20
21 FButton=new VL_WinButton(this);
22 FButton->SetText(L"Button");
23
24 FSingleLine=new VL_WinEdit(this,false);
25 FSingleLine->SetText(VUnicodeString(FSingleLine->GetTextLimit()));
26 FSingleLine->SetTextLimit(20);
27 FSingleLine->SelectAll();
28
29 FMultiLine=new VL_WinEdit(this,true);
30 FMultiLine->SetHScroll(true);
31 FMultiLine->SetVScroll(true);
32 FMultiLine->SetText(L"Line1\r\nLine2\r\nLine3\r\nLine4\r\nLine5");
33
34 GetPlacement()->SetBorderSize(10);
35 GetPlacement()->SetSpliterSize(10);
36 GetPlacement()->SetBehavior(vpbFixPlacement1);
37 GetPlacement()->SetSpliterPosition(20);
38 GetPlacement()->SetMinClientWidth(200);
39 GetPlacement()->SetMinClientHeight(200);
40
41 GetPlacement()->GetPlacement1()->SetSpliterDirection(vpdVertical);
42 GetPlacement()->GetPlacement1()->SetSpliterSize(10);
43 GetPlacement()->GetPlacement1()->SetBehavior(vpbFixPlacement1);
44 GetPlacement()->GetPlacement1()->SetSpliterPosition(40);
45
46 GetPlacement()->GetPlacement1()->GetPlacement2()->SetSpliterDirection(vpdVertical);
47 GetPlacement()->GetPlacement1()->GetPlacement2()->SetSpliterSize(10);
48 GetPlacement()->GetPlacement1()->GetPlacement2()->SetBehavior(vpbFixPlacement2);
49 GetPlacement()->GetPlacement1()->GetPlacement2()->SetSpliterPosition(80);
50
51 GetPlacement()->GetPlacement2()->SetControl(FMultiLine);
52 GetPlacement()->GetPlacement1()->GetPlacement1()->SetControl(FStatic);
53 GetPlacement()->GetPlacement1()->GetPlacement2()->GetPlacement1()->SetControl(FSingleLine);
54 GetPlacement()->GetPlacement1()->GetPlacement2()->GetPlacement2()->SetControl(FButton);
55 }
56
57 public:
58
59 MyForm():VL_WinForm(true)
60 {
61 SetClientWidth(400);
62 SetClientHeight(400);
63 SetText(L"Vczh Form");
64 MoveCenter();
65 InitControls();
66 Show();
67 }
68 };
69
70 void main()
71 {
72 new MyForm;
73 GetApplication()->Run();
74 }
posted on 2008-08-03 04:54
陈梓瀚(vczh) 阅读(1918)
评论(8) 编辑 收藏 引用 所属分类:
C++