Finding child window handles using Windows API

Zeds123

New Member
Joined
Jun 6, 2020
Messages
1
Office Version
  1. 2019
Platform
  1. Windows
Hi,
I am currently trying to write a vba code that will open up an application that I use in my job and send text to the main text box in that application.
After doing that, I need to open up another application which has a child window (By that I mean a sort of text box within the application, like the ones where you enter login details in certain applications), and send text over there. The last step I need to do is press a button that is to the left of the text window inside this application.
Since the computers in my work are locked from the normal internet and are classified I cannot use apps such as SPY++ to get the window handles, so I would appreciate it if anyone could help me find a way to get the window handles names without a third party app such as SPY++.

Since I am currently using a normal computer I have tried practicing this on the Outlook app and trying to send message to the login text boxes though it has not worked for me so far, this is the code I written up to now:

VBA Code:
Sub check()
    hwnd = FindWindow(vbNullString, "Outlook")
    Dim start_doc As Long
    start_doc = ShellExecute(hwnd, vbunullstring, "Outlook", vbNullString, "C:\", SW_SHOWNORMAL)
    If start_doc = 0 Or start_doc = 2 Or start_doc = 3 Or start_doc = 5 Or start_doc = 6 Or start_doc = 8 Or start_doc = 10 Or start_doc = 11 Or start_doc = 12 Or start_doc = 13 Or start_doc = 14 Or start_doc = 15 Or start_doc = 16 Or start_doc = 19 Or start_doc = 20 Or start_doc = 21 Then
        MsgBox "Error Occured While Trying to Open The Application"
        Exit Sub
    End If
    
    Do
    DoEvents
    hwindow2 = FindWindow(vbNullString, "Outlook")
    
    Loop Until hwindow2 > 0
    
    timeout 0.3
    
    
    Dim lngHWnd As Long
    
    lngHWnd = FindWindowEx(hwindow2, 0, vbNullString, vbNullString)
    
    Do Until lngHWnd = 0
        Debug.Print lngHWnd
        lngHWnd = FindWindowEx(hwindow2, lngHWnd, vbNullString, vbNullString)
    Loop
    
    Call SendMessageByString(lngHWnd, WM_SETTEXT, 0, "Test")
    
End Sub
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.

Forum statistics

Threads
1,214,566
Messages
6,120,262
Members
448,953
Latest member
Dutchie_1

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top