VC对VB的优势之界面编程

来源:互联网 发布:手机日语游戏汉化软件 编辑:程序博客网 时间:2024/06/07 06:43
 
一:继承
实例一:在属性页控件中显示不同属性页
 
VB
VC
控件
TabStrip
Tab Control
VB实现原理:
           将不同的属性页设计在一个Picture控件数组中,通过对数组元素的
Visible属性值的设置来在点击一个属性页标题时显示一个属性页。控件的
初始化和属性页的处理多很麻烦。
 
VB实现代码:
Function creattabs()                         ‘创建TabStrip控件
               Dim intX As Integer
               TEST.TabStrp.Tabs.Clear
               Set reftbs 
= TEST.TabStrp.Tabs.Add(, , "Results")
               reftbs.ToolTipText 
= "The results of the test"
               Set reftbs 
= TEST.TabStrp.Tabs.Add(, , "Passed")
               reftbs.ToolTipText 
= "The report of passed products"
               Set reftbs 
= TEST.TabStrp.Tabs.Add(, , "Failed")
               reftbs.ToolTipText 
= "The report of failed products"
               For intX 
= 0 To 3
               With TEST.Picture1(intX)
                        .BorderStyle 
= 0
                        .Left 
= TEST.TabStrp.ClientLeft
                        .Top 
= TEST.TabStrp.ClientTop
                        .Width 
= TEST.TabStrp.ClientWidth
                        .Height 
= TEST.TabStrp.ClientHeight
                        .Visible 
= False
               End With
               Next intX
         End Function
         Function selecttabs()
               If tab1 Then
                          TEST.Picture1(
0).Visible = True
                          TEST.Picture1(
1).Visible = False
                          TEST.Picture1(
2).Visible = False
                          TEST.Picture1(
3).Visible = False
               End If
               If tab2 Then
                          TEST.Picture1(
0).Visible = False
                          TEST.Picture1(
1).Visible = True
                          TEST.Picture1(
2).Visible = False
                          TEST.Picture1(
3).Visible = False
              End If
              If tab3 Then
                          TEST.Picture1(
0).Visible = False
                          TEST.Picture1(
1).Visible = False
                          TEST.Picture1(
2).Visible = True
                          TEST.Picture1(
3).Visible = False
              End If
              If tab4 Then
                          TEST.Picture1(
0).Visible = False
                          TEST.Picture1(
1).Visible = False
                          TEST.Picture1(
2).Visible = False
                          TEST.Picture1(
3).Visible = True
              End If
  End Function
  
VC实现原理:
           利用面向对象编程的继承原理,将Page页从已经设计好的Dialog继
承过来,控件初始化时只需将属性页的指针指向对应的Dialog即可,属性
页的处理有Dialog自己来完成,向普通的Dialog处理一样。
 
VC实现代码:
       在头文件(.h)中声明:
               CPage1 m_Page1; // 出勤页
            CPage2 m_Page2; // 加班页
            CPage3 m_Page3; // 请假页
            CPage4 m_Page4; // 出差页
            CPropertySheet m_Sheet;

          在初始化中加入如下代码:

                m_Sheet.AddPage(&m_Page1); // 加第1页
                m_Sheet.AddPage(&m_Page2); // 加第2页
                m_Sheet.AddPage(&m_Page3); // 加第3页
                m_Sheet.AddPage(&m_Page4); // 加第4页
                m_Sheet.Create(this, WS_CHILD | WS_VISIBLE, 0); // 创建窗口
                m_Sheet.ModifyStyleEx (0, WS_EX_CONTROLPARENT); 
                m_Sheet.ModifyStyle( 
0, WS_TABSTOP ); // 修改风格
                
// 设置窗口位置
                m_Sheet.SetWindowPos( NULL, 010000
            SWP_NOZORDER 
| SWP_NOSIZE | SWP_NOACTIVATE );
原创粉丝点击