获取其它运行程序的按钮的句柄的API函数是什么?怎么使用?
【lc_mtt】:
不仅仅是一个api可以解决问
题
快递公司问题件快递公司问题件货款处理关于圆的周长面积重点题型关于解方程组的题及答案关于南海问题
。
【plsandslp】:
麻烦具体说一下,谢了
【IORI915189】:
获取当前焦点句柄 getfocus
查找窗口句柄 findwindow
枚举子窗口 enumchildwindows
你可以枚举子窗口获取按钮内容对比
【dabie】:
findwindow '找到窗口句柄
findwindowex '找到窗体上按钮句柄
dim wnd as long
wnd = FindWindow("窗体类名", "窗体名")
wnd = FindWindowEx(wnd, 0, "控件类名", "控件名")
最后的wnd就是你要的控件的句柄了。
【chenhui530】:
最简单的是: FindWindowEx(FindWindow(VbNullString,"Form1"),VbNullString,"确定")
如果这个不行用下面这个。
Private Const GW_HWNDNEXT = 2
Private Const GW_CHILD = 5
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Function FindControlHwnd(ByVal nHwnd As Long,ByVal findStr As String) As Long
Dim fHwnd As Long, myStr As String, sHwnd As Long
fHwnd = GetWindow(nHwnd, GW_CHILD)
If fHwnd = 0 Then Exit Function
Do While fHwnd > 0
myStr = String(100, Chr$(0))
GetWindowText fHwnd, myStr, 100
If Left(myStr,InStr(myStr, Chr$(0))-1)=findStr Then FindControlHwnd=fHwnd:Exit Function
sHwnd = GetWindow(fHwnd, GW_CHILD)
If sHwnd > 0 Then
SearchAllControl fHwnd
End If
fHwnd = GetWindow(fHwnd, GW_HWNDNEXT)
Loop
End Function
Private Sub Form_Load()
FindControlHwnd FindWindow(vbNullString, "Form1"),"确定"
End Sub
如果上面这个方法不行再试这个其实应该是差不多的
新建一个窗体用下面代码
EnumChildWindows FindWindow(vbNullString, "Form1"), AddressOf EnumChildWindowsProc, ByVal 0&
再建个模块用下面代码
Public Declare Function EnumChildWindows Lib "user32" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Public findHwnd As Long
Public Function EnumChildWindowsProc(ByVal hwnd As Long, ByVal lParam As Long) As Boolean
Dim str As String * 255,hLen As Long
hLen = GetWindowTextLength(hwnd)+1
GetWindowText hwnd, str, 255
if Left(str, hLen) = "确定" Then findHwnd=hwnd : EnumChildWindowsProc=False
EnumChildWindowsProc = True
End Function
【sxycgxj】:
SearchAllControl
是什么,不是API函数,也没有找到这个过程的定义
【chenhui530】:
错了改成FindControlHwnd就行了