title: send keys to a third party window from vba by hWnd
body: <p>I'm trying to send a keystroke to a third party window. Sounds simple, yes? Doesn't mean I'm getting it...</p>
  
  <p>I'm working within a fairly heavily locked down system so I'm limited as to what data I can access and what programs I can use, hence why I'm using VBA and not a stand alone compiler. </p>
  
  <p>The window in question identifies as "WindowsForms10.Window.8.app.0.33c0d9d" and it opens whenever a user attempts to send an email (to force users to include a protective marking on every email). </p>
  
  <p>I effectively need to send either a {space} or an {enter} (yes, I'm thinking sendkeys for simplicity sake) to this window to allow full automation. As it stands, the user is having to click OK on the window with each emailed report. </p>
  
  <p>The window itself does not have a visible title when it displays. </p>
  
  <p>I assume it is possible to bring this window to the front by the windows handle and then send the keystroke to it, but I'm a little stumped on how to get there. </p>
  
  <p>I've done some research and have cobbled together the following code which will provide me with the windows handle but that's about as far as I've managed to get. Tried tacking on a sendkeys which isn't doing anything and I'm out of ideas.</p>
  
  <pre><code>Dim DeskTophWnd As Long, WindowhWnd As Long
  
  Dim Buff As String * 255, WindowsCaption() As String
  
  Dim WindowsHandle() As Long
  
  Dim lngret As Long
  
  Dim strtext As String
  
  ReDim WindowsCaption(0)
  
  ReDim WindowsHandle(0)
  
  DeskTophWnd = GetDesktopWindow
  
  WindowhWnd = GetWindow(DeskTophWnd, 5)
  
  Do While (WindowhWnd &lt;&gt; 0)
  
      GetWindowText WindowhWnd, Buff, 255
  
      strtext = String$(100, Chr$(0))
  
      lngret = GetClassName(hwnd, strtext, 100)
  
      If (Trim(Buff) &lt;&gt; "") And (IsWindowVisible(WindowhWnd) &gt; False) Then
  
          'ShowWindowAsync WindowhWnd, 0
  
          ReDim Preserve WindowsCaption(UBound(WindowsCaption) + 1)
  
          ReDim Preserve WindowsHandle(UBound(WindowsHandle) + 1)
  
          WindowsCaption(UBound(WindowsCaption)) = Buff
  
          WindowsHandle(UBound(WindowsHandle)) = WindowhWnd
  
      End If
  
      WindowhWnd = GetWindow(WindowhWnd, 2)
  
      msgbox WindowhWnd
  
      if left(buff, 31)= "Protective Markings for Outlook" then sendkeys "{ENTER}", true
  
  
  Loop
  
  'The caption of window is in WindowsCaption()
  
  'The handle of window is in WindowsHandle()
  </code></pre>
  
  <p>If anyone can assist, it would be greatly appreciated. </p>
  
  <p>Regards</p>
  
  <p>M</p>