How to find a window by FindWindowW from the unicode window title text?

181 views Asked by At

I have tried to use GetWindowTextW to extract the window title text successfully, and it is a unicode text. When I use FindWindowW to find the window, it failed and the returned Hwnd is 0.

The window with the unicode title:

enter image description here

The code on VB6 is below. the currentHwnd is the window Hwnd I captured already and it works well during my test:

Private Declare Function FindWindowW Lib "user32" (ByVal lpClassName As Long, ByVal lpWindowName As Long) As Long
Private Declare Function GetWindowTextW Lib "user32" (ByVal hWnd As Long, ByVal lpString As Long, ByVal cch As Long) As Long
Private Declare Function GetWindowTextLengthW Lib "user32" (ByVal hWnd As Long) As Long

Private Sub cmdOK_Click()

Dim titleString  As String
dim newHwnd as Long
dim Class as string
Class = Space(500)
GetClassName currentHwnd, Class, Len(Class)
titleString = String$(256, 0)
GetWindowTextW currentHwnd, StrPtr(titleString), GetWindowTextLengthW(currentHwnd)


newHwnd = FindWindowW(StrPtr(Class), StrPtr(titleString))

End Sub
0

There are 0 answers