The initial task is to create a run-time Textbox on a Userform, and catch the Enter and Exit events in a VBA code.
初始任务是在Userform上创建一个运行时文本框,并捕获VBA代码中的Enter和Exit事件。
Creating the form and dynamic add of controls working fine, i have stucked at the catching of events, since these are not included in the created object. For the first sight eems a relatively simple work.
创建表单和动态添加控件工作良好,我一直在捕捉事件,因为这些事件不包括在创建的对象中。乍一看,这似乎是一项相对简单的工作。
After nearly a week searching, and from several posts and documents (from EvR, Rubberduck, JonS et al.) i can get near to achieve something on which i can continue. The problem is still that while the function returns with 0 error code, no token is passed back.
经过近一周的搜索,从几篇帖子和文件(来自EvR、Rubberduck、JonS等人)中,我可以接近实现我可以继续的目标。问题仍然是,当函数返回0错误代码时,没有返回任何令牌。
The relevant part of the code
代码的相关部分
TextBoxCreator Class Module
TextBoxCreator类模块
Private Declare Function ConnectToConnectionPoint Lib "shlwapi.dll" (ByVal punk As stdole.IUnknown, ByRef riidEvent As eventguide, ByVal fConnect As Long, ByVal punkTarget As stdole.IUnknown, ByVal pdwCookie As Long, Optional ByVal ppcpOut As Long) As Long
Private oTextBox As MSForms.TextBox
Private Type eventguide
data1 As Long
data2 As Integer
data3 As Integer
data4(7) As Byte
End Type
Public Property Let SetControlEvents(ByVal TextBox As Control)
Dim conIID As eventguide
With conIID
.data1 = &H20400
.data4(0) = &HC0
.data4(7) = &H46
End With
Set oTextBox = TextBox
Dim RetVal As Long
a = StrPtr("{00020400-0000-0000-C000-000000000046}")
Debug.Print a
RetVal = IIDFromString(a, testvalue)
If RetVal = 0 Then
Debug.Print "Connection ID: ", testvalue
Else
Debug.Print "Error: ", RetVal, Hex(RetVal)
End If
conreturn = ConnectToConnectionPoint(Me, conIID, True, TextBox, cookie)
Debug.Print conreturn, Hex(conreturn), cookie
End Property
This is in UserForm1 code module
这在UserForm1代码模块中
Dim firs As TextBoxCreator
Private Sub UserForm_Activate()
Set newtextbox = UserForm1.Controls.Add("forms.textbox.1", , True)
Set demobox = UserForm1.Controls.Add("forms.textbox.1", , True)
demobox.Top = 30
End Sub
Private Sub UserForm_AddControl(ByVal Control As MSForms.Control)
Set firs = New TextBoxCreator
firs.SetControlEvents() = Control
End Sub
Tried function declaration with Alias "#168"
, same result.
尝试使用Alias“#168”进行函数声明,结果相同。
The printout:
打印输出:
29616520
Connection ID: 132096
0 0
29616520
Connection ID: 132096
0 0
How can i reach to get a valid cookie value to continue?
如何获取有效的cookie值以继续?
更多回答
我是一名优秀的程序员,十分优秀!