vb.net如何通过窗口句柄 vb.net显示窗口

怎样在VB.NET中获取窗口句柄HWND?
[问题点数:20分,结帖人hwshws123]
本版专家分:38
结帖率 92.52%
CSDN今日推荐
本版专家分:139101
2010年 总版技术专家分年内排行榜第五
2010年11月 总版技术专家分月排行榜第二2010年9月 总版技术专家分月排行榜第二2010年8月 总版技术专家分月排行榜第二
2010年7月 总版技术专家分月排行榜第三
2012年1月 荣获微软MVP称号2011年1月 荣获微软MVP称号
本版专家分:38
本版专家分:34
本版专家分:41480
本版专家分:139101
2010年 总版技术专家分年内排行榜第五
2010年11月 总版技术专家分月排行榜第二2010年9月 总版技术专家分月排行榜第二2010年8月 总版技术专家分月排行榜第二
2010年7月 总版技术专家分月排行榜第三
2012年1月 荣获微软MVP称号2011年1月 荣获微软MVP称号
匿名用户不能发表回复!|
其他相关推荐VB里面怎么用简单的办法枚举父窗口下所有的子窗口句柄_百度知道
VB里面怎么用简单的办法枚举父窗口下所有的子窗口句柄
答题抽奖
首次认真答题后
即可获得3次抽奖机会,100%中奖。
Private Sub Command1_Click()Dim h&Doh = FindWindowEx(Me.hWnd, h, vbNullString, vbNullString)If h && 0 ThenList1.AddItem hEnd IfLoop Until h = 0End Sub比如这样,就是枚举了当前窗体的所有子窗体(控件),如果需要获得其他窗体的子窗体句柄,把Me.hwnd改成父窗体句柄就行了
采纳率:51%
为您推荐:
其他类似问题
窗口句柄的相关知识
换一换
回答问题,赢新手礼包
个人、企业类
违法有害信息,请在下方选择后提交
色情、暴力
我们会通过消息、邮箱等方式尽快将举报结果通知您。在VB.NET中使用 FindWindow 查找窗口和获得句柄
我的图书馆
在VB.NET中使用 FindWindow 查找窗口和获得句柄
windows窗口句柄是32位,在VB.NET中,Integer表示32位,Long表示64位。这是调用API函数时需要注意的地方。下面是正确的函数声明和设定一个参数为空的例子:
Private Declare Auto Function FindWindow Lib "user32" ( _
ByVal lpClassName As String, _
ByVal lpWindowName As String) As Integer
Private Sub Button2_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles Button2.Click
Dim hWnd As Integer
hWnd = FindWindow(vbNullString, "收件箱 - Outlook Express")
If hWnd Then
MsgBox("找到Outlook Express窗口!")
MsgBox("未找到Outlook Express窗口!")
FindWindow函数是比较容易调用的,因为两个参数都是只读的,不会被API修改,所以在VB6和VB.NET中的差别只在于数据类型的不同。而对于GetSystemDirectory这样的函数就不同了,因为参数是可修改的,而在VB.NET中String是不可以修改的,所以必须借助于StringBuilder类才能调用。
喜欢该文的人也喜欢文章 - 0&评论 - 0&trackbacks - 0
4.1、捕获其他程序窗口句柄要对其他程序进行操作,首先要捕获其他程序的窗口句柄。&查找标题栏包含&inWindowText&&&&&的窗口,窗口标题内容不确定的可以使用,例如动态变化标题的窗口,如果标题固定,直接用FindWindowEx()就可以了。Public&Function&MyFindWindow(ByVal&className&As&String,&ByVal&inWindowText&As&String)&As&Integer&&&'查找标题栏包含&inWindowText&的窗口&& & & &&Dim&hMyWindow&As&Integer&& & & &&Dim&sss&As&New&String("", 256)&& & & & hMyWindow = FindWindowEx(0, 0, className,&Nothing) & &'以desktop window为父,按照Z order查找第一个子窗口&& & & &&'hMyButton = FindWindowEx(hMyWindow, 0&, Nothing, Nothing) & & & '为遍历所有类型窗口,将第三个参数设为&Nothing&&&&&&&&& MyFindWindow = 0&& & & &&While&hMyWindow&& & & & & & GetWindowText(hMyWindow, sss, 256)&&&&&'获取窗口标题&&&&&&&&&&&&If&InStr(sss, inWindowText) & 0&Then&&&&&&&&&&'进行比较&&&&&&&&&&&&&&&& MyFindWindow = hMyWindow&&&&&&&&&&&&&&&&&Exit Function&&&&&&&&&找到退出&&&&&&&&&&&&&End&If&& & & & & & hMyWindow = FindWindowEx(0, hMyWindow, className,&Nothing) & &'以desktop window为父,按照Z order查找在hMyWindow后的下一个子窗口&& & & &&End&While&& &&End&Function&4.2、单击其他程序的菜单&'点击级菜单的第个子项(从0算起)&&&&Public&Function&ClickMenu(ByVal&hMyWindow&As&Integer,ByVal&nSubMenu&As&Integer,&ByVal&nMenuItemID&As&Integer)&As&Integer&&&&&&&&&Dim&hMyWindow&As&Integer&& & & &&Dim&MyMenu&As&Integer&& & & &&Dim&MyGetMenuItemID&As&Integer&& & & &&Dim&nReturn&As&Integer&&&&&&&&&If&hMyWindow = 0&Then&& & & & & & MsgBox("没有找到相应窗口!")&& & & &&Else&& & & & & & MyMenu = GetMenu(hMyWindow)&& & & & & & MyMenu = GetSubMenu(MyMenu, nSubMenu)&& & & & & & MyGetMenuItemID = GetMenuItemID(MyMenu, nMenuItemID) & & &'&按条件选择设备&菜单&& & & & & & BringWindowToTop(hMyWindow)&& & & & & & nReturn = PostMessage(hMyWindow, WM_SYSCOMMAND, MyGetMenuItemID, 0)&& & & & & & nReturn = PostMessage(hMyWindow, WM_COMMAND, MyGetMenuItemID, 0)&& & & &&End&If&&&End&Function&&4.3、ListView相关操作见另文。&4.4.1、'读COMBOBOX&& &&Private&Sub&Button9_Click(ByVal&sender&As&System.Object,&ByVal&e&As&System.EventArgs)&Handles&Button9.Click&& & & &&Dim&hMyWindow, hMyButton&As&Integer&& & & & hMyWindow = FindWindow("WindowsForms10.Window.8.app3",&"远程浏览")&& & & & hMyButton = FindWindowEx(hMyWindow, 0,&"WindowsForms10.COMBOBOX.app3",&Nothing)&'获取第二个WindowsForms10.COMBOBOX.app3窗口:ATMID 下拉选择框&& & & & hMyButton = FindWindowEx(hMyWindow, hMyButton,&"WindowsForms10.COMBOBOX.app3",&Nothing)&'获取第二个WindowsForms10.COMBOBOX.app3窗口:ATMID 下拉选择框&& & & & MsgBox(hMyButton)&& & & &&Dim&i&As&Integer&= SendMessage(hMyButton, CB_GETCURSEL, 0, 0) &&'读取当前COMBOBOX索引值,&&第三个参数为列表框的索引&& & & & MsgBox(i)&& & & &&Dim&k&As&Integer&= SendMessage(hMyButton, CB_GETLBTEXTLEN, i, 0)&&' 读取索引位置文本长度&&&&&&& MsgBox(k)&& & & &&Dim&ptr&As&IntPtr = Marshal.AllocHGlobal(256)&& & & & i = SendMessage(hMyButton, CB_GETLBTEXT, i, ptr)&&&&&' 读取索引位置文本&&&&&&& MsgBox(i)&& & & & MsgBox(IntPtrToStr(ptr))&& &&End&Sub&&4.4.2、设置其他程序的下拉框的选择Private&Sub&Button3_Click(ByVal&sender&As&System.Object,&ByVal&e&As&System.EventArgs)&Handles&Button3.Click&& & & &&Dim&hMyWindow, hMyButton&As&Integer&& & & & hMyWindow = FindWindow("WindowsForms10.Window.8.app3",&"远程浏览")&& & & & hMyButton = FindWindowEx(hMyWindow, 0,&"WindowsForms10.COMBOBOX.app3",&Nothing)&'获取第二个WindowsForms10.COMBOBOX.app3窗口:ATMID 下拉选择框&& & & & MsgBox(hMyButton)&& & & & hMyButton = FindWindowEx(hMyWindow, hMyButton,&"WindowsForms10.COMBOBOX.app3",&Nothing)&'获取第二个WindowsForms10.COMBOBOX.app3窗口:ATMID 下拉选择框&& & & & MsgBox(hMyButton)&& & & & SendMessage(hMyButton, CB_SETCURSEL, 1, 0) &'第三个参数为列表框的索引&&&End&Sub&4.5.1、读Edit&& &&Private&Sub&Button7_Click(ByVal&sender&As&System.Object,&ByVal&e&As&System.EventArgs)&Handles&Button7.Click&& & & &&Dim&processId&As&Integer&& & & & hwnd = FindWindow("WindowsForms10.Window.8.app3",&"远程浏览")&& & & & hwnd = FindWindowEx(hwnd, 0,&"WindowsForms10.COMBOBOX.app3",&Nothing)&'获取第一个WindowsForms10.COMBOBOX.app3窗口:&& & & & hwnd = FindWindowEx(hwnd, 0,&"Edit",&Nothing)&& & & &&Dim&ptr&As&IntPtr = Marshal.AllocHGlobal(256)&& & & & SendMessage(hwnd, WM_GETTEXT, 255, ptr)&& & & & MsgBox(IntPtrToStr(ptr))&& & & & MsgBox(Marshal.PtrToStringAnsi(ptr))&& &&End&Sub&&4.5.2、设置其他程序Edit框的值'浏览路径&& &&Private&Sub&Button4_Click(ByVal&sender&As&System.Object,&ByVal&e&As&System.EventArgs)&Handles&Button4.Click&& & & &&Dim&hMyWindow, hMyButton, MyEditbox&As&Integer&& & & &&Dim&processId&As&Integer&& & & & hMyWindow = FindWindow("WindowsForms10.Window.8.app3",&"远程浏览")&& & & & hMyButton = FindWindowEx(hMyWindow, 0,&"WindowsForms10.COMBOBOX.app3",&Nothing)&'获取第一个WindowsForms10.COMBOBOX.app3窗口:&& & & & MyEditbox = GetDlgItem(hMyButton, 1001)&&&&&&&&&&'获&&&&&&& hMyButton = FindWindowEx(hMyButton, 0,&"Edit",&Nothing) & & & & & & & & & & & &&'获取&浏览路径&输入框&& & & &&Dim&str&As&String&=&"D:\Image\"&& & & & SendMessage(hMyButton, WM_SETTEXT, 0, StrToIntPtr(str))&&&&&End&Sub&&&&&'将字符串存储到IntPtr 指针中。&& &&'Dim ptr As IntPtr = Marshal.StringToHGlobalAuto("1234")&& &&'指针ptr 存放内容格式为:1个数据,1个结束符0,例如上面数据,存放如下:49、0,50、0,51、0,52、0&& &&'而很多时,传递字符指针,要求数据是连续存放的,最后才是结束符0,例如SendMessage(hMyButton, WM_SETTEXT, 0, StrToIntPtr(str))。&& &&Public&Function&StrToIntPtr(ByVal&inStrText&As&String)&As&IntPtr&&&&&&&&&Dim&nLen&As&Integer&= Len(inStrText)&&&&&&&&&'分配内存,以免内存区域给其他进程改写。&& & & &&Dim&ptr&As&IntPtr = Marshal.AllocHGlobal(nLen + 1)&&&&&&&&&Dim&mstr&As&Byte() = Encoding.Unicode.GetBytes(inStrText)&&&&&&&&&For&i = 0&To&nLen - 1&& & & & & & Marshal.WriteByte(ptr, i, mstr(i * 2))&& & & &&Next&&&&&&&& Marshal.WriteByte(ptr, nLen, 0)&&&&&&&&&Return&ptr&& &&End&Function&4.6、单击其他程序按钮Private&Sub&Button5_Click(ByVal&sender&As&System.Object,&ByVal&e&As&System.EventArgs)&Handles&Button5.Click&& & & &&Dim&hMyWindow, hMyButton&As&Integer&& & & & hMyWindow = FindWindow("WindowsForms10.Window.8.app3",&"远程浏览")&& & & & hMyButton = FindWindowEx(hMyWindow, 0,&"WindowsForms10.BUTTON.app3",&"远程浏览(&B)") & &'&远程浏览(&B)&按钮&& & & & MsgBox(hMyButton)&& & & & SendMessage(hMyButton, BM_CLICK, 0, 0)&&End&Sub&
阅读(...) 评论()求vb.net句柄实例,实现操作其他程序窗口
[问题点数:100分,结帖人goodkenneth2]
本版专家分:0
结帖率 100%
CSDN今日推荐
本版专家分:0
本版专家分:0
本版专家分:50
本版专家分:6563
本版专家分:3404
本版专家分:870
本版专家分:171
本版专家分:76
本版专家分:0
匿名用户不能发表回复!|
其他相关推荐

我要回帖

更多关于 vb 选项卡句柄 的文章

 

随机推荐