随笔-341  评论-2670  文章-0  trackbacks-0

    为了缓解疲劳,我网络和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) 阅读(1908) 评论(8)  编辑 收藏 引用 所属分类: C++

评论:
# re: UI库添加Edit、Static和Placement[未登录] 2008-08-03 05:51 | foxtail
老实说:很没意思  回复  更多评论
  
# re: UI库添加Edit、Static和Placement 2008-08-03 05:55 | 陈梓瀚(vczh)
当你宁可不要界面都不要MFC的时候,就有意思了。  回复  更多评论
  
# re: UI库添加Edit、Static和Placement 2008-08-03 06:48 | LOGOS
我不要MFC,我要的是wxWidget
不过,你好好干吧  回复  更多评论
  
# re: UI库添加Edit、Static和Placement 2008-08-03 07:11 | Lnn
很好啊!辛苦了啊!  回复  更多评论
  
# re: UI库添加Edit、Static和Placement 2008-08-03 18:00 | sff
主题:谁说80后没文化?!看80后写的宝塔诗!

新腔
有模样
为驴友忙
人在家中躺
门票预订网上
全国景点任你爽
折扣铿铿锵锵作响
一张门票也把优惠扛
旅游便宜就在掌门人网
  回复  更多评论
  
# re: UI库添加Edit、Static和Placement 2008-08-03 18:25 | lwan
如果单纯的封装一个form,n个comctrl控件是不难的,但是要是使之成为一个系统框架需要考虑的是:app,mainframe,以及子窗口之间的关系,modal和modalless,mdi子窗口等,如果这些都比较容易的话,那tab键,加速键,默认按钮、key clue这些就足够繁琐了,再考虑上ole之类....,可以看出目前所做的只是很小一部分,可以参考 vcl vcf wxwidget qt等封装玩玩,不断学习进步,不断发现不足。  回复  更多评论
  
# re: UI库添加Edit、Static和Placement 2008-08-03 18:48 | 陈梓瀚(vczh)
加速键完成了,tab还没做,其他api都有……不过我只做我需要的那一部分。  回复  更多评论
  
# re: UI库添加Edit、Static和Placement 2008-08-04 05:58 | megax
MFC的设计是很经典的,占用内存相对来说也不大。因为没有使用虚函数,省下了一大笔虚表的开支。UI类库,我认为最棒的仍然是VCL。不过我仍然会用MFC,经典,方便,性能高,文档齐全。对于我这种关注功能实现的人来说是最好的选择  回复  更多评论
  

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理