Option Explicit
Private Declare Function SendMessageSTRING Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
Private Declare Function SendMessageLong Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Declare Function SendMessageByString Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
Public Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Public Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Public Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Public Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Boolean
Public Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Public Const WM_GETTEXT = &HD
Public Const WM_GETTEXTLENGTH = &HE
Public Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Global lngRhWnd As Long ' global to store handle
Global strWindowTitle As String ' global to store title
Global strClassname As String ' global to store class
'searches through all windows for the partial caption "- Conversation"
'it will return the hwnd and caption :D
Public Function EnumWindowsProc(ByVal hwnd As Long, ByVal lParam As Long) As Boolean
Dim sSave As String, Ret As Long
Ret = GetWindowTextLength(hwnd)
sSave = Space(Ret)
GetWindowText hwnd, sSave, Ret + 1
If InStr(sSave, "- Create a Profile - More Info") Then
lngRhWnd = Str$(hwnd)
strClassname = GetClass(lngRhWnd)
strWindowTitle = GetWinTitle(lngRhWnd)
MsgBox "ok"
End If
EnumWindowsProc = True
End Function
Public Function GetTheWindow(Optional strClassname As String) As Long
Dim retval As Boolean
retval = EnumWindows(AddressOf EnumWindowsProc, 0)
strClassname = GetClass(lngRhWnd)
GetTheWindow = lngRhWnd
End Function
Private Function GetClass(hwnd As Long)
Dim sSave As String, intLenRet As Integer
sSave = Space(256)
intLenRet = GetClassName(hwnd, sSave, 256)
GetClass = Left$(sSave, intLenRet)
End Function
Private Function GetWinTitle(hwnd As Long) As String
GetWinTitle = GetText(hwnd)
End Function
Public Function GetText(WinHandle As Long) As String
Dim abc As String, TxtLength As Long
TxtLength& = SendMessage(WinHandle&, WM_GETTEXTLENGTH, 0&, 0&)
abc$ = String(TxtLength&, 0&)
Call SendMessageByString(WinHandle&, WM_GETTEXT, TxtLength& + 1, abc$)
GetText$ = abc$
End Function