Golemic
Golemic

Reputation: 40

Find Child window

I am trying to find the handle of child window for the "&Yes" button, so i can send click message and press it. The window is a Confirm Save as window, because i am trying to save a file to a location where a file with same name already exists, so i have to handle that confirmation pop up window. The Confirm window has a structure with a few child windows, with the same parent(CtrlNotifySink). Some scroll, that seems to be inactive, and &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

Window structure is somthing like that:

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**

There are multiple CtrNotifySink with its own Button child window or other child windows. How do i search thru the different CtrNotifySink window to find the one that contain the Yes button so i can send a click to it? although i find hwnd, hwnd1, hwnd2, i can't find hwnd3. It always contains zero.

I do need to find it before i can send a click, right? because i try just sending it to the main window with sendmessage and nothing happen. Can you help me with that? Thanks in advance!

Upvotes: 0

Views: 3035

Answers (2)

Golemic
Golemic

Reputation: 40

I finally got it using:

hWndFind = GetNextWindow(hWnd, GW_HWNDNEXT)

Upvotes: 0

i486
i486

Reputation: 6564

Use MS Spy++ (coming with Win32 SDK) to look at window and its child windows. If you find the popup window, you can send message to button by its ID - no need to find the HWND of button. I.e. SendDlgItemMessage( hwnd, ID_BTN, BM_CLICK, 0, 0);. ID_BTN you will see from Spy++.

Upvotes: 2

Related Questions