2010-03-19 94 views
0

注意:这可能是一个在黑暗中拍摄,它纯粹出于好奇心,我问。VB6 ImageList Frm代码生成

当使用来自Microsoft公共控制库(mscomctl.ocx)的ImageList控件时,我发现VB6生成的FRM代码无法解析为真实的属性/方法名称,我很好奇如何解析制作。所生成的FRM代码的一个例子在下面给出用含3个图像一个ImageList:

Begin MSComctlLib.ImageList ImageList1 
     BackColor  = -2147483643 
     ImageWidth  = 100 
     ImageHeight  = 45 
     MaskColor  = 12632256 
     BeginProperty Images {2C247F25-8591-11D1-B16A-00C0F0283628} 
     NumListImages = 3 
     BeginProperty ListImage1 {2C247F27-8591-11D1-B16A-00C0F0283628} 
      Picture   = "Form1.frx":0054 
      Key    = "" 
     EndProperty 
     BeginProperty ListImage2 {2C247F27-8591-11D1-B16A-00C0F0283628} 
      Picture   = "Form1.frx":3562 
      Key    = "" 
     EndProperty 
     BeginProperty ListImage3 {2C247F27-8591-11D1-B16A-00C0F0283628} 
      Picture   = "Form1.frx":6A70 
      Key    = "" 
     EndProperty 
     EndProperty 
    End 

从我的经验,一BeginProperty标签通常是指一个化合物属性(一个对象)被分配到诸如字体对象例如:

Begin VB.Form Form1 
    Caption   = "Form1" 
    ClientHeight = 10950 
    ClientLeft  = 60 
    ClientTop  = 450 
    ClientWidth  = 7215 
    BeginProperty Font 
     Name   = "MS Serif" 
     Size   = 8.25 
     Charset   = 0 
     Weight   = 400 
     Underline  = 0 'False 
     Italic   = -1 'True 
     Strikethrough = 0 'False 
    EndProperty 
End 

可以很容易地看到解析为VB.Form.Font。 <房源名称>。

使用ImageList,没有名为Images的属性。与属性Images关联的GUID表示实现接口IImages的类型ListImages。这种类型是有道理的,因为ImageList控件具有一个名为ListImages的属性,它的类型为IImages。其次,类型IImages中不存在属性ListImage1,ListImage2和ListImage3,但与这些属性关联的GUID表示实现接口IImage的ListImage类型。这种类型也是有道理的,因为IImages实际上是IImage的集合。

对我来说没有意义的是VB6如何使这些关联。 VB6如何知道名称图像 - > ListImages之间的关联纯粹是因为关联类型(由GUID提供) - 也许是因为它是该类型的唯一属性?其次,它如何将ListImage1,ListImage2和ListImage3解析为集合IImages的添加,并且它是否使用Add方法?或者可能是ControlDefault属性?

也许VB6具有此控件的特定知识,并且不存在逻辑分辨率?

回答

2

你可以看到这个相当人为的例子发生了什么。启动与ActiveX项目并添加Class1并将其标记为Persistable = 1

' Class1 
Option Explicit 

Private m_sText As String 

Property Get Text() As String 
    Text = m_sText 
End Property 

Property Let Text(sValue As String) 
    m_sText = sValue 
End Property 

Private Sub Class_ReadProperties(PropBag As PropertyBag) 
    With PropBag 
     m_sText = .ReadProperty("txt", "") 
    End With 
End Sub 

Private Sub Class_WriteProperties(PropBag As PropertyBag) 
    With PropBag 
     .WriteProperty "txt", m_sText, "" 
    End With 
End Sub 

添加的UserControl1

' UserControl1 
Option Explicit 

Private m_oData As Class1 

Property Get Data() As Class1 
    Set Data = m_oData 
End Property 

Private Sub UserControl_Initialize() 
    Set m_oData = New Class1 
    m_oData.Text = "this is a test" 
End Sub 

Private Sub UserControl_ReadProperties(PropBag As PropertyBag) 
    With PropBag 
     Set m_oData = .ReadProperty("rs", Nothing) 
    End With 
End Sub 

Private Sub UserControl_WriteProperties(PropBag As PropertyBag) 
    With PropBag 
     .WriteProperty "rs", m_oData, Nothing 
    End With 
End Sub 

添加Form1并放置的UserControl1上它保存。你可能湾添加模块1的子主

' Module1 
Sub Main() 
    With New Form1 
     .Show 
    End With 
End Sub 

这里是我的Form1.frm文件

VERSION 5.00 
Begin VB.Form Form1 
    Caption   = "Form1" 
    ClientHeight = 2400 
    ClientLeft  = 48 
    ClientTop  = 432 
    ClientWidth  = 3744 
    LinkTopic  = "Form1" 
    ScaleHeight  = 2400 
    ScaleWidth  = 3744 
    StartUpPosition = 3 'Windows Default 
    Begin Project1.UserControl1 UserControl11 
     Height   = 516 
     Left   = 924 
     TabIndex  = 0 
     Top    = 588 
     Width   = 1020 
     _ExtentX  = 1799 
     _ExtentY  = 910 
     BeginProperty rs {326250A4-CA0D-4F88-8F20-DAA391CF8E79} 
     txt    = "this is a test" 
     EndProperty 
    End 
End 
Attribute VB_Name = "Form1" 
Attribute VB_GlobalNameSpace = False 
Attribute VB_Creatable = False 
Attribute VB_PredeclaredId = True 
Attribute VB_Exposed = False 
Option Explicit 

所以UserControl1确定对象m_oData是坚持在其WriteProperty过载性能rsClass1确定它的m_sText成员变量(或Text公共属性)在012m成员IPropertyBag中保持为frm通过。没有什么要求公共财产名称与内部财产包名称匹配。我个人使用短ID来减少膨胀(如果可能的话,使用VB6)。

+0

+1。它全部记录在VB6手册中关于创作您自己的控件的部分。它建议你“应该在财产包中使用财产的名称,因为它会出现在frm文本文件中,并且可能会被控制的用户看到”,但是你并没有被迫这么做。相同的原则适用于使用其他编程语言编写的COM控件。 http://msdn.microsoft.com/en-us/library/aa261321(v=VS.60).aspx – MarkJ 2010-03-23 13:46:17

+0

@MarkJ:完美,感谢您的额外信息 – DAC 2010-04-02 10:57:05

0

我在猜测GUID({2C247F25-8591-11D1-B16A-00C0F0283628})指向关联的ImageList控件,而ListImage1,ListImage2等...就在这里枚举所有的图像。

它有点像WPF关联控件的早期版本(例如TextBox可以引用它的封闭网格来放置)。