Getting window handle for a window with UNICODE title?
Posted on 2014-10-17
How to get window handle of a window, knowing its title, but that will work even if the title is a Unicode text?
The obvious FindWindow API
hWnd = FindWindow(vbNullString, "Window Title")
works fine if the title of the window is ASCII, but if it is apparently Unicode, it just returns zero…
Namely, I need to get handle to MS Word window, for which I use
hWnd = FindWindow(vbNullString, WrdDoc.ActiveWindow.Caption & " - " & "Microsoft Word")
which works just fine, unless the Word window Caption contains Unicode characters, which can easily happen if the document is saved to with a file name containing Unicode, which is often; in that case the FindWindow fails to work, and returns zero…