VB获取指定窗体上类名为Edit的句柄
网上的方法都试过了,没一个能获取到的,那个控件用【窗体探测】探测到窗体类名是Edit求大神那下面是我的代码PrivateSubCommand7_Click()tWnd1=...
网上的方法都试过了,没一个能获取到的,那个控件用【窗体探测】 探测到窗体类名是 Edit
求大神那
下面是我的代码
Private Sub Command7_Click() tWnd1 = FindWindow(vbNullString, "“万能解码器”安装 ") '找父窗口句柄(已找到) Text1 = tWnd1 If tWnd1 <> 0 Then tWnd2 = FindWindowEx(tWnd1, 0, vbNullString, "") '找首个子窗体句柄(已找到) tWnd3 = FindWindowEx(tWnd2, 0, "Edit", "vbNullString") '取得Edit文本框句柄(死活找不着) MsgBox FindWindowEx(tWnd2, 0, "Edit", "vbNullString") Text2 = tWnd2 If tWnd3 <> 0 Then SendMessage hWnd3, WM_SETTEXT, 0, ByVal "123456789"
End If Else tWnd2 = 0 tWnd1 = 0 tWnd3 = 0 End If
End Sub
这个程序是 万能解码器安装程序 下载地址
http://pan.baidu.com/s/1eQ3n0YI
如果弄好小弟感激不尽 展开
求大神那
下面是我的代码
Private Sub Command7_Click() tWnd1 = FindWindow(vbNullString, "“万能解码器”安装 ") '找父窗口句柄(已找到) Text1 = tWnd1 If tWnd1 <> 0 Then tWnd2 = FindWindowEx(tWnd1, 0, vbNullString, "") '找首个子窗体句柄(已找到) tWnd3 = FindWindowEx(tWnd2, 0, "Edit", "vbNullString") '取得Edit文本框句柄(死活找不着) MsgBox FindWindowEx(tWnd2, 0, "Edit", "vbNullString") Text2 = tWnd2 If tWnd3 <> 0 Then SendMessage hWnd3, WM_SETTEXT, 0, ByVal "123456789"
End If Else tWnd2 = 0 tWnd1 = 0 tWnd3 = 0 End If
End Sub
这个程序是 万能解码器安装程序 下载地址
http://pan.baidu.com/s/1eQ3n0YI
如果弄好小弟感激不尽 展开
3个回答
展开全部
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Const WM_SETTEXT = &HC
Private Sub Form_Load()
tWnd1 = FindWindow(vbNullString, "“万能解码器”安装 ") '找父窗口句柄(已找到)
If tWnd1 <> 0 Then
tWnd2 = FindWindowEx(tWnd1, 0, "#32770", "") '找首个子窗体句柄(已找到)
tWnd3 = FindWindowEx(tWnd2, 0, "Edit", vbNullString) '取得Edit文本框句柄(死活找不着)
If tWnd3 <> 0 Then SendMessage tWnd3, WM_SETTEXT, 0, ByVal "123456789"
End If
End Sub
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Const WM_SETTEXT = &HC
Private Sub Form_Load()
tWnd1 = FindWindow(vbNullString, "“万能解码器”安装 ") '找父窗口句柄(已找到)
If tWnd1 <> 0 Then
tWnd2 = FindWindowEx(tWnd1, 0, "#32770", "") '找首个子窗体句柄(已找到)
tWnd3 = FindWindowEx(tWnd2, 0, "Edit", vbNullString) '取得Edit文本框句柄(死活找不着)
If tWnd3 <> 0 Then SendMessage tWnd3, WM_SETTEXT, 0, ByVal "123456789"
End If
End Sub
展开全部
Private Function MyFindWindow() As Long
Dim A_szClassName(3) As String, i As Integer
A_szClassName(0) = "#32770"
A_szClassName(1) = "#32770"
A_szClassName(2) = "Edit"
Dim A_szWinName(3) As String
A_szWinName(0) = "“万能解码器”安装 "
A_szWinName(1) = ""
A_szWinName(2) = ""
Dim hLastWin As Long
hLastWin = FindWindow(A_szClassName(0), A_szWinName(0))
For i = 1 To 2
hLastWin = FindWindowEx(hLastWin, 0, A_szClassName(i), A_szWinName(i))
Next i
MyFindWindow = hLastWin
End Function
更多追问追答
追问
SendMessage MyFindWindow, WM_SETTEXT, 0, ByVal "123456789"
为什么没用?
追答
你如果使用vista及以上的操作系统,需要使用管理员权限运行VB程序才有用
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
试一下
Edit 改为 0 或者 ""
把 vbNullString 改为 TEdit
Edit 改为 0 或者 ""
把 vbNullString 改为 TEdit
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询