0

I'm using EnumDesktopWindows() to get the window handles of running applications, then using GetWindowText() to get the title of each window.

The user picks a window and I then use FindWindow() to locate it and activate it. This all works fine, and has done for several years until I moved to Windows 10. It still works fine for everything except Microsoft Edge. When passed the window text of the Edge Browser the API returns a zero value (IntPtr.Zero).

I'm working in VB.NET, but this is really about the Win32 API and Edge. I've included the definitions of the API functions I am calling below:

Private Declare Auto Function EnumDesktopWindows Lib "user32" (ByVal hDesktop As Integer, ByVal lpfn As EnumDesktopWindowsDelegate, ByVal param As Integer) As Integer
Private Delegate Function EnumDesktopWindowsDelegate(hWnd As IntPtr, lParam As Integer) As Boolean

Private Shared Function GetWindowText(ByVal hwnd As IntPtr, ByVal lpString As Text.StringBuilder, ByVal cch As Integer) As Integer

Private Shared Function FindWindow(ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
Darren
  • 4,408
  • 4
  • 39
  • 57
  • Microsoft Edge (or any Windows Store App) doesn't want you to throw random API calls at it. Now would be a good time to introduce yourself to [UI Automation](https://msdn.microsoft.com/en-us/library/ms747327.aspx). – IInspectable Jan 21 '16 at 16:11
  • The enumeration gives you the actual `HWND`s, so if you keep track of them along with the text then you won't need to use `FindWindow()` afterwards. In any case, use a tool like Spy++ or Winspector to see details about active `HWND`s and how they relate to each other, and that should give you a clue why `FindWindow()` is not working. You are likely not giving it the correct input values. – Remy Lebeau Jan 21 '16 at 18:49
  • Thanks @RemyLebeau, My Plan B is to use the `hWnd` from `EnumDesktopWindows()`, but that is going to require a lot more changes to the code than if I can find the window from its title. – Darren Jan 22 '16 at 11:12
  • Have you seen this? https://stackoverflow.com/questions/65308197/windows-console-app-stops-printing-when-i-switch-to-edge/65312170#65312170. Maybe you can't find "Microsoft Edge" because there's a `ZERO-WIDTH SPACE` (U+8203) char after the `t` in Microsoft. – Thiago Villa Dec 16 '20 at 17:28

0 Answers0