怎么枚举Textbox的事件名称,如Click,Change...

一如既往哈 2016-06-16 10:56:45
如题。其实是在练习用interfaceinfo枚举/设置对象的属性时突发奇想,因为既然属性,方法都能列出来,那么事件也应该可以的,不过很遗憾,没有列出事件的名称。
哪位大侠知道,吱一声........
...全文
246 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
一如既往哈 2016-06-22
  • 打赏
  • 举报
回复
谢谢Chen8013 ,#7代码。 我找到了一个读文件的方法。就是TLI.TypeLibInfoFromFile。 爽翻了,总结一下: 对于VB内部的控件,只要读 vb6.olb文件即可; 对于添加的其它控件,读取相应的dll、ocx即可。 .......... 不过,发现一个小问题: 对于多数情况下,一个coclass下只有2个interface,第1个是属性,第2个是事件。 发现一个特例Webbrowser,有4个interface IWebBrowser2 IWebBrowser IWebBrowserEvents2 IWebBrowserEvents 怎么区分?VB会自动使用IWebBrowser2,IWebBrowserEvents2,VB是咋知道的?通过使用interface.typekind等不能判断。会不会是这么配对【1,interface.count\2+1】,【2,interface.count\2+2】.....然后第1组是默认的?
舉杯邀明月 2016-06-21
  • 打赏
  • 举报
回复
我好像记得那个interfaceinfo只能在IDE中用的,编译成exe后运行就没效果了。
一如既往哈 2016-06-21
  • 打赏
  • 举报
回复
引用 4 楼 zhao4zhong1 的回复:
自己读文件VB6.IDL分析。里面“诸如Label,Commandbutton,PictureBox等控件”的相关信息都有。
谢谢赵4老师。我还以为能像属性和方法那样直接列出来呢,感情还得自己动手,,也好,丰衣足食
赵4老师 2016-06-21
  • 打赏
  • 举报
回复
Chen8013
舉杯邀明月 2016-06-21
  • 打赏
  • 举报
回复
编译成 .exe居然也能正常运行。 记得以前写的是“列举属性”,编译成 .exe后不能运行。不知道会不会跟操作系统有关。
舉杯邀明月 2016-06-21
  • 打赏
  • 举报
回复
刚才“研究”了一下,发现还是可以实现的。

先上张效果图:


窗口内两个列表控件,左边的是List1,右边的是List2。
全部代码如下:
Option Explicit

Private objApp As Object
Private objTI As Object

Private Sub EnumVBObjectEvents(ClassName As String)
Dim cci As Object
Dim mi As Object
Dim i As Long

For Each cci In objTI.CoClasses
If (ClassName = cci.Name) Then
For i = 1 To cci.Interfaces(2).Members.Count
Set mi = cci.Interfaces(2).Members(i)
List2.AddItem mi.Name
Set mi = Nothing
Next
End If
Next
End Sub

Private Sub EnumControls()
Dim cci As Object

For Each cci In objTI.CoClasses
If (2 = cci.Interfaces.Count) Then
If (cci.Interfaces(2).Members.Count) Then List1.AddItem cci.Name
End If
Next
Set cci = Nothing
End Sub


Private Sub cmdDispEvents_Click()
List2.Clear
Call EnumVBObjectEvents(List1.Text)
End Sub

Private Sub Form_Load()
List1.Clear
Set objApp = CreateObject("TLI.TLIApplication")
Set objTI = objApp.TypeLibInfoFromRegistry( _
"{FCFB3D2E-A0FA-1068-A738-08002B3371B5}", 6, 0, 9)
Call EnumControls
List1.Selected(0) = True ' 先把第1个选上再说
End Sub

Private Sub Form_Unload(Cancel As Integer)
Set objTI = Nothing
Set objApp = Nothing
End Sub
赵4老师 2016-06-20
  • 打赏
  • 举报
回复
自己读文件VB6.IDL分析。里面“诸如Label,Commandbutton,PictureBox等控件”的相关信息都有。
赵4老师 2016-06-17
  • 打赏
  • 举报
回复
吱——
赵4老师 2016-06-17
  • 打赏
  • 举报
回复
用OleView.exe的File、View TypeLib... 打开文件:C:\Program Files\Microsoft Visual Studio\VB98\VB6.OLB 保存VB6.IDL:

    1187:     interface TextBoxEvents : IUnknown {
    1188:         [helpstring("Occurs when the contents of a control have changed."), helpcontext(0x000dfb4d)]
    1189:         HRESULT _stdcall Change();
    1190:         [helpstring("Occurs when a drag-and-drop operation is completed."), helpcontext(0x000dfb50)]
    1191:         HRESULT _stdcall DragDrop(
    1192:                         [in, out] Control** Source,
    1193:                         [in, out] single* X,
    1194:                         [in, out] single* Y);
    1195:         [helpstring("Occurs when a drag-and-drop operation is in progress."), helpcontext(0x000dfb51)]
    1196:         HRESULT _stdcall DragOver(
    1197:                         [in, out] Control** Source,
    1198:                         [in, out] single* X,
    1199:                         [in, out] single* Y,
    1200:                         [in, out] short* State);
    1201:         [helpstring("Occurs when an object receives the focus."), helpcontext(0x000dfb53)]
    1202:         HRESULT _stdcall GotFocus();
    1203:         [helpstring("Occurs when the user presses a key while an object has the focus."), helpcontext(0x000dfb55)]
    1204:         HRESULT _stdcall KeyDown(
    1205:                         [in, out] short* KeyCode,
    1206:                         [in, out] short* Shift);
    1207:         [helpstring("Occurs when the user presses and releases an ANSI key."), helpcontext(0x000dfb56)]
    1208:         HRESULT _stdcall KeyPress([in, out] short* KeyAscii);
    1209:         [helpstring("Occurs when the user releases a key while an object has the focus."), helpcontext(0x000dfb57)]
    1210:         HRESULT _stdcall KeyUp(
    1211:                         [in, out] short* KeyCode,
    1212:                         [in, out] short* Shift);
    1213:         [helpstring("Occurs when a DDE conversation terminates."), helpcontext(0x000dfb58)]
    1214:         HRESULT _stdcall LinkClose();
    1215:         [helpstring("Occurs when there is an error during a DDE conversation."), helpcontext(0x000dfb59)]
    1216:         HRESULT _stdcall LinkError([in, out] short* LinkErr);
    1217:         [helpstring("Occurs when a DDE conversation is being initiated."), helpcontext(0x000dfb5c)]
    1218:         HRESULT _stdcall LinkOpen([in, out] short* Cancel);
    1219:         [helpstring("Occurs when an object loses the focus."), helpcontext(0x000dfb5e)]
    1220:         HRESULT _stdcall LostFocus();
    1221:         [helpstring("Occurs when the source has changed the DDE data if the LinkMode property of the destination control is Notify."), helpcontext(0x000dfb5b)]
    1222:         HRESULT _stdcall LinkNotify();
    1223:         [helpstring("Occurs when the user presses the mouse button while an object has the focus."), helpcontext(0x000dfb5f)]
    1224:         HRESULT _stdcall MouseDown(
    1225:                         [in, out] short* Button,
    1226:                         [in, out] short* Shift,
    1227:                         [in, out] single* X,
    1228:                         [in, out] single* Y);
    1229:         [helpstring("Occurs when the user moves the mouse."), helpcontext(0x000dfb60)]
    1230:         HRESULT _stdcall MouseMove(
    1231:                         [in, out] short* Button,
    1232:                         [in, out] short* Shift,
    1233:                         [in, out] single* X,
    1234:                         [in, out] single* Y);
    1235:         [helpstring("Occurs when the user releases the mouse button while an object has the focus."), helpcontext(0x000dfb61)]
    1236:         HRESULT _stdcall MouseUp(
    1237:                         [in, out] short* Button,
    1238:                         [in, out] short* Shift,
    1239:                         [in, out] single* X,
    1240:                         [in, out] single* Y);
    1241:         [helpstring("Occurs when the user presses and then releases a mouse button over an object."), helpcontext(0x000dfb4e)]
    1242:         HRESULT _stdcall Click();
    1243:         [helpstring("Occurs when the user presses and releases a mouse button and then presses and releases it again over an object."), helpcontext(0x000dfb4f)]
    1244:         HRESULT _stdcall DblClick();
    1245:         [helpstring("Occurs when the mouse is moved over the control during an OLE drag/drop operation, if its OLEDropMode property is set to manual."), helpcontext(0x000dfb76)]
    1246:         HRESULT _stdcall OLEDragOver(
    1247:                         [in, out] DataObject** Data,
    1248:                         [in, out] long* Effect,
    1249:                         [in, out] short* Button,
    1250:                         [in, out] short* Shift,
    1251:                         [in, out] single* X,
    1252:                         [in, out] single* Y,
    1253:                         [in, out] short* State);
    1254:         [helpstring("Occurs when data is dropped onto the control via an OLE drag/drop operation, and OLEDropMode is set to manual."), helpcontext(0x000dfb77)]
    1255:         HRESULT _stdcall OLEDragDrop(
    1256:                         [in, out] DataObject** Data,
    1257:                         [in, out] long* Effect,
    1258:                         [in, out] short* Button,
    1259:                         [in, out] short* Shift,
    1260:                         [in, out] single* X,
    1261:                         [in, out] single* Y);
    1262:         [helpstring("Occurs at the source control of an OLE drag/drop operation when the mouse cursor needs to be changed."), helpcontext(0x000dfb78)]
    1263:         HRESULT _stdcall OLEGiveFeedback(
    1264:                         [in, out] long* Effect,
    1265:                         [in, out] VARIANT_BOOL* DefaultCursors);
    1266:         [helpstring("Occurs when an OLE drag/drop operation is initiated either manually or automatically."), helpcontext(0x000dfb79)]
    1267:         HRESULT _stdcall OLEStartDrag(
    1268:                         [in, out] DataObject** Data,
    1269:                         [in, out] long* AllowedEffects);
    1270:         [helpstring("Occurs at the OLE drag/drop source control when the drop target requests data that was not provided to the DataObject during the OLEDragStart event."), helpcontext(0x000dfb7a)]
    1271:         HRESULT _stdcall OLESetData(
    1272:                         [in, out] DataObject** Data,
    1273:                         [in, out] short* DataFormat);
    1274:         [helpstring("Occurs at the OLE drag/drop source control after a manual or automatic drag/drop has been completed or canceled."), helpcontext(0x000dfb7b)]
    1275:         HRESULT _stdcall OLECompleteDrag([in, out] long* Effect);
    1276:         [helpstring("Occurs when a control loses focus to a control that causes validation."), helpcontext(0x000dfb87)]
    1277:         HRESULT _stdcall Validate([in, out] VARIANT_BOOL* Cancel);
    1278:     };
一如既往哈 2016-06-17
  • 打赏
  • 举报
回复
呵呵,谢谢zhao4zhong1 TypeLib已经引用,Textbox只是示例,还有诸如Label,Commandbutton,PictureBox等控件 TypeLib中难道没有一个现成的方法来获取那些控件的事件名称? 最像的是有一个ClassInfoFromObject不知道怎么用,仿照InterfaceInfoFromObject报接口错误....... 继续等待

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧