為了緩解疲勞,我網絡和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) 閱讀(1925)
評論(8) 編輯 收藏 引用 所屬分類:
C++