
正文
vb.net枚举窗口 vb枚举类型enum用法
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
VB.net如何枚举字符串?
Enum Week
周日 = 0
周一 = 1
周二 = 2
周三 = 3
周四 = 4
周五 = 5
周六 = 6
End Enum
Sub Main()
Dim myType As Type = GetType(Week)
MsgBox(Week.GetName(myType, Week.周二))
End Sub
相关问答
Q1: 在vb.net中,如何枚举一个注册的组件其开放的COM类的接口函数。
为什么增加的回答这么久还没显示。
我想知道你为什么要枚举这些方法,是需要打印出来还是只是为了查看和调用?
1,如果只是为了查看和调用的话,不需要用代码就能知道了。
打开VS,视图-》对象浏览器。然后开了后,点浏览右边的“。。。”,开了后。选COM活页,再在里面选ThunderAgent 1.0 Type Library。再点添加。
添加好之后。在左边的浏览窗口内就有了,展开THUNDERAGENTLib下面有几个类和接口,展开类就有方法了。
2,如果是需要用代码枚举并打印。网上有相关的代码,C#写的。我就不帖了。自己搜一下。改成vb.net相信应该不会太难。
祝你好运。
Q2: VB中Enumchildwindow函数怎么用?
Private Declare Function EnumChildWindows Lib "user32" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
【说明】
为指定的父窗口枚举子窗口
【返回值】
Long,非零表示成功,零表示失败
【参数表】
hWndParent ----- Long,欲枚举子窗口的父窗口的句柄
lpEnumFunc ----- Long,为每个子窗口调用的函数的指针。用AddressOf运算符获得函数在一个标准模块中的地址
lParam --------- Long,在枚举期间,传递给dwcbkd32.ocx定制控件之EnumWindows事件的值。这个值的含义是由程序员规定的。
示例
'Example Name:EnumChildWindows
'in a form
Private Sub Form_Load()
'KPD-Team 2000
'URL:
'E-Mail: KPDTeam@Allapi.net
Me.AutoRedraw = True
EnumChildWindows GetDesktopWindow, AddressOf EnumChildProc, ByVal 0
End Sub
'in a module
Declare Function GetDesktopWindow Lib "user32" () As Long
Declare Function EnumChildWindows Lib "user32" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Public Function EnumChildProc(ByVal hwnd As Long, ByVal lParam As Long) As Long
Dim sSave As String
'Get the windowtext length
sSave = Space$(GetWindowTextLength(hwnd) + 1)
'get the window text
GetWindowText hwnd, sSave, Len(sSave)
'remove the last Chr$(0)
sSave = Left$(sSave, Len(sSave) - 1)
If sSave "" Then Form1.Print sSave
'continue enumeration
EnumChildProc = 1
End Function
Q3: vb.net实例化窗口后如何区分打开的窗口
If App.PrevInstance = True Then
End
End If
如果程序正在运行,结束程序。
在模块中加入每个窗口的标题变量。
然后用if then 来判断是否有相同窗口。
如果你事先不知道有哪些窗口的话,那你就用枚举 FindWindow来查找子窗口句柄。再用SendMessage 获得窗口标题再进行判断。
Q4: VB.NET的枚举求教解决方法
这个功能实现起来其实也很简单,就是通过反射去读取 DescriptionAttribute 的 Description 属性的值,代码如下所示:
/// summary
/// 返回枚举项的描述信息。
/// /summary
/// param name="value"要获取描述信息的枚举项。/param
/// returns枚举想的描述信息。/returns
public static string GetDescription(Enum value)
{
Type enumType = value.GetType();
// 获取枚举常数名称。
string name = Enum.GetName(enumType, value);
if (name != null)
{
// 获取枚举字段。
FieldInfo fieldInfo = enumType.GetField(name);
if (fieldInfo != null)
{
// 获取描述的属性。
DescriptionAttribute attr = Attribute.GetCustomAttribute(fieldInfo,
typeof(DescriptionAttribute), false) as DescriptionAttribute;
if (attr != null)
{
return attr.Description;
}
}
}
return null;
}
这段代码还是很容易看懂的,这里取得枚举常数的名称使用的是 Enum.GetName() 而不是 ToString(),因为前者更快,而且对于不是枚举常数的值会返回 null,不用进行额外的反射。
当然,这段代码仅是一个简单的示例,接下来会进行更详细的分析。
Q5: vb.net怎么枚举父窗口下所有子窗口
Dim HanStr As String = ""
For Each Form In Me.MdiChildren
HanStr += Form.Handle.ToString
Next
MsgBox(HanStr)
关于vb.net枚举窗口和vb枚举类型enum用法的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。






