我正在尝试找到“& Yes”按钮的子窗口句柄,因此我可以发送单击消息并按下它。 该窗口是确认另存为窗口,因为我正在尝试将文件保存到已存在同名文件的位置,因此我必须处理该确认弹出窗口。 “确认”窗口的结构包含几个子窗口,具有相同的父窗口(CtrlNotifySink)。 一些滚动,似乎是不活动的,& Yes,& No Button。
Public Declare PtrSafe Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare PtrSafe Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByRef lParam As Any) As Long
Public Declare PtrSafe Function FindWindowEx Lib "user32.dll" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Public Declare PtrSafe Function SendMessageByString Lib "user32.dll" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Any) As Long
Public Declare PtrSafe Function SetActiveWindow Lib "user32.dll" (ByVal hWnd As Long) As Long
Public Declare PtrSafe Function ShowWindow Lib "user32" (ByVal hWnd As Long, ByVal nCmdSHow As Long) As Long
Public Declare PtrSafe Function BringWindowToTop Lib "user32" (ByVal lngHWnd As Long) As Long
Public Declare PtrSafe Function EnableWindow Lib "user32.dll" (ByVal hWnd As Long, ByVal fEnable As Long) As Long
Public Declare PtrSafe Function GetActiveWindow Lib "user32" () As Long
Public Declare PtrSafe Function GetFocus Lib "user32.dll" () As Long
Public Const WM_CLOSE As Long = &H10
Public Const SW_SHOW As Integer = 5
Public Const WM_SETTEXT As Long = &HC
Public Const BM_CLICK As Long = &HF5&
Sub PulseAutomation()
CCPUlse = FindWindow("Afx:00E80000:8:00010005:00000000:5DF82B2F", vbNullString)
MDIClient = FindWindowEx(CCPUlse, 0&, "MDIClient", vbNullString)
view13844 = FindWindowEx(MDIClient, 0&, vbNullString, "Inbound 13844 Queues")
view13845 = FindWindowEx(MDIClient, 0&, vbNullString, "Inbound 13845 Queues")
viewTSUMDL = FindWindowEx(MDIClient, 0&, vbNullString, "TSU MDL Queue")
viewOutSource = FindWindowEx(MDIClient, 0&, vbNullString, "OUTSOURCE")
viewAgentGroup = FindWindowEx(MDIClient, 0&, vbNullString, "Agent Group")
If view13844 = 0 Or view13845 = 0 Or viewTSUMDL = 0 Or viewOutSource = 0 Or viewAgentGroup = 0 Then
MsgBox "Check CCPulse Views. Views :Inbound 13844 Queues, Inbound 13845 Queues, TSU MDL Queue, OUTSOURCE, Agent Group, must be enabled)"
Else
view13844BringWindowToTop = BringWindowToTop(view13844)
DoEvents
SendKeys "%", True
SendKeys "{DOWN}", True
SendKeys "{DOWN}", True
SendKeys "{DOWN}", True
SendKeys "{DOWN}", True
SendKeys "{DOWN}", True
SendKeys "{DOWN}", True
SendKeys "~", True
Application.Wait (Now + #12:00:01 AM#)
SaveAsWindow = FindWindow(vbNullString, "Save as HTML")
TextComboBox = FindWindowEx(SaveAsWindow, 0&, "ComboBoxEx32", vbNullString)
ComboBox = FindWindowEx(TextComboBox, 0&, "ComboBox", vbNullString)
EditComboBox = FindWindowEx(ComboBox, 0&, "Edit", vbNullString)
Application.Wait (Now + #12:00:01 AM#)
Call SendMessageByString(EditComboBox, WM_SETTEXT, 0, "http://inhol/Inbound 13844 Queues.html")
DoEvents
SaveButton = FindWindowEx(SaveAsWindow, 0&, "Button", "&Save")
Call EnableWindow(SaveButton, True)
Call SendMessage(SaveButton, BM_CLICK, 0&, ByVal 0&)
DoEvents
Application.Wait (Now + #12:00:02 AM#)
hWnd = FindWindow(vbNullString, "Confirm Save As")
If SaveasConfirmationButton <> 0 Then
hWnd1 = FindWindowEx(hWnd, 0&, "DirectUIHWND", vbNullString)
hWnd2 = FindWindowEx(hWnd1, 0&, "CtrlNotifySink", vbNullString)
hwnd3 = FindWindowEx(hWnd2, 0&, "Button", "&Yes")
Call SendMessage(hwnd3, BM_CLICK, 0&, ByVal 0&)
Application.Wait (Now + #12:00:01 AM#)
DoEvents
End If
End Sub
窗口结构是这样的:
12519822 #32770 Confirm Save As
148708704 DirectUIHWND N/A
62856910 CtrlNotifySink N/A
65934476 ScrollBar N/A
84414422 CtrlNotifySink N/A
46533118 ScrollBar N/A
51578040 CtrlNotifySink N/A
56371342 ScrollBar N/A
204155690 CtrlNotifySink N/A
103359250 ScrollBar N/A
79695992 CtrlNotifySink N/A
70715476 SysLink N/A
25107220 CtrlNotifySink N/A
120982920 SysLink N/A
**31656246 CtrlNotifySink N/A
73013478 Button &Yes
29561694 CtrlNotifySink N/A
82250158 Button &No**
有多个CtrNotifySink具有自己的Button子窗口或其他子窗口。如何通过不同的CtrNotifySink窗口搜索找到包含Yes按钮的窗口,以便我可以发送一个点击它? 虽然我找到了hwnd,hwnd1,hwnd2,但我找不到hwnd3。它总是包含零。
我确实需要在发送点击之前找到它,对吗?因为我尝试用sendmessage将它发送到主窗口,没有任何反应。 你能帮帮我吗? 提前谢谢!
答案 0 :(得分:1)
使用MS Spy ++(随Win32 SDK一起提供)查看窗口及其子窗口。如果找到弹出窗口,可以通过ID向按钮发送消息 - 无需找到按钮的HWND。即SendDlgItemMessage( hwnd, ID_BTN, BM_CLICK, 0, 0);
。您将从Spy ++中看到ID_BTN。
答案 1 :(得分:0)
我终于使用了它:
hWndFind = GetNextWindow(hWnd, GW_HWNDNEXT)