title: GetWindow API VB
body: <p>I usually write scripts in the VBE of Excel because they all tend to involve Excel. This time I wrote a script which has nothing to do with Excel, so I want to make it an executable file.</p>
  
  <p>Note:
   - Below code is a part of the actual script
   - I tested this part also separately in the VBE and it works
   - I tried it now in Visual Studio 2015</p>
  
  <p>Problem:
   - The code returns the handle of lWindow, but always returns 0 voor lChild</p>
  
  <pre><code>Module Module1
  Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
      (ByVal lpClassName As String,
      ByVal lpWindowName As String) As Long
  Declare Function GetWindow Lib "user32.dll" (
       ByVal hwnd As Long,
       ByVal wCmd As Long) As Long
  
  Private Const GW_CHILD = 5
  Private Const GW_HWNDNEXT = 2
  Private Const BM_CLICK = &amp;HF5&amp;
  
  Sub Main()
      Dim lWindow As Long
      Dim lChild As Long
  
      lWindow = FindWindow(vbNullString, "Untitled - Notepad")
      Debug.Print(lWindow)
      lChild = GetWindow(lWindow, GW_CHILD)
      Debug.Print(lChild)
  End Sub
  </code></pre>
  
  <p>End Module</p>
  
  <p>Thanks.</p>