我对此非常陌生,并且一直在努力创建一个与我们的外部应用程序通信的Excel文档。
我已经完成了使用FindWindowEX查找此应用程序的特定按钮/框的教程,并设法成功地将文本插入其中一个表单。
我试图点击"点击"一个按钮,我认为问题是我尝试与之通信的应用程序没有唯一的类名。
从图片中可以看出,几乎所有东西都被称为" WindowsForms10.Window.8.app.0.2004eee"
这意味着我可以将文本插入到第一个也是唯一的文本框中但不能深入挖掘以获取我需要的按钮"单击"为了搜索。
目前的代码如下:我不需要打开应用程序,因为它始终是从启动时开始的。
Sub Runapplication()
DoEvents
Hwindow2 = FindWindow(vbNullString, "General Account Enquiry")
'Account Number
Account_Number = FindWindowEx(Hwindow2, 0&, "WindowsForms10.EDIT.app.0.2004eee", vbNullString)
Accountnumber = ThisWorkbook.Sheets("Sheet1").Range("A1")
Call SendMessageByString(Account_Number, WM_SETTEXT, 0, Accountnumber)
DoEvents
Account1 = FindWindow(vbNullString, "csEditAccount")
Account = FindWindowEx(Hwindow2, 0&, "WindowsForms10.Window.8.app.0.2004eee", vbNullString)
'Call EnableWindow(Account, True)
Call SendMessage(Account, WM_LBUTTONDOWN, 0, ByVal 0&)
End Sub
我有所有常数/解除
Public Declare PtrSafe Function FindWindow Lib "user32" Alias "FindWindowA" ( _
ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare PtrSafe Function CloseWindow Lib "user32" (ByVal hWnd As Long) As Long
Public Declare PtrSafe Function SendMessage Lib "user32" Alias "SendMessageA" ( _
ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _
lParam As Any) As Long
Public Declare PtrSafe Function SendMessageByString Lib "user32" Alias "SendMessageA" ( _
ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _
ByVal lParam As String) As Long
Public Declare PtrSafe Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" ( _
ByVal hWnd As Long, ByVal lpOperation As String, ByVal lpFile As String, _
ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Public Declare PtrSafe Function FindWindowEx Lib "user32" _
Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, _
ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Public Declare PtrSafe Function EnableWindow Lib "USER32.dll" ( _
ByVal hWnd As Long, _
ByVal fEnable As Long) As Long
Public Const SW_NORMAL As Long = 1
Public Const WM_CLOSE As Long = &H10
Public Const BM_CLICK As Long = &HF5
Public Const WM_KEYUP As Long = &H101
Public Const WM_SETTEXT = &HC
Public Const LB_FINDSTRING = &H18F
Public Const WM_LBUTTONDOWN = &H201
任何帮助都会非常感激,我几乎疯了昨天在网上搜索试图找到这个问题的答案,
谢谢!
答案 0 :(得分:1)
虽然我同情许多窗口具有相同的类,但是不希望您想要操作的窗口(模仿单击)将始终出现在序列中的相同位置。因此,如果您想要点击第三个按钮,那么它将永远不会是第三个按钮。即使按钮与文本框具有相同的类别,所以实际上你想要的是按钮和文本框的超集中的第8个,那么它仍将是第8个。
所以只需枚举(使用EnumChildWindows),直到找到目标。