Search code examples
winapivb6

Find window by class name


I want to close a certain window.

Spy++ tells me that the window is of class name "ad_win#2":

enter image description here

However, when I use FindWindow like that...

Public Declare Function FindWindow Lib "USER32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

 Dim lRet&
 lRet = FindWindow("ad_win#2", vbNullString)

.... lRet is 0, meaning that it didn't find any window.

What am I doing wrong?

Thank you!


Solution

  • It works when I add a ChrW(10) to the name like this:

    Dim lRet&
    lRet = FindWindow("ad_win#2" & ChrW(10), vbNullString)