-
Apr 19th, 2006, 09:03 PM
#1
Thread Starter
Lively Member
Handle from Part Caption
How is this done? I have a sub for it but it just returns true or false.. it doesn't give the handle.
-
Apr 19th, 2006, 09:10 PM
#2
Hyperactive Member
Re: Handle from Part Caption
Please post your code.
We can't answer your question without codes.
-
Apr 19th, 2006, 09:12 PM
#3
Re: Handle from Part Caption
If you're using RobDog's Code then the handle is being passed By Reference:
VB Code:
Private Sub Command1_Click()
Dim lhWndP As Long
' lhWndP is equal to 0
If GetHandleFromPartialCaption(lhWndP, " - Microsoft Outlook") = True Then
' lhWndP is modified by function and is now the value for the handle of the window
MsgBox "Found Window Handle: " & lhWndP, vbOKOnly + vbInformation
Else
' handle wasn't found so lhWndP is equal to 0
MsgBox "Window ' - Microsoft Outlook' not found!", vbOKOnly + vbExclamation
End If
End Sub
-
Apr 19th, 2006, 09:16 PM
#4
Thread Starter
Lively Member
Re: Handle from Part Caption
VB Code:
Private Function AIM_Username()
Dim Handle as long, Username as String
Handle = GetHandleFromPartialCaption(vbNull, "Buddy List Window")
Username = GetWindowCaption(Handle)
Username = Username - Right$(Username, "20")
AIM_Username = Username
End Function
Private Function GetHandleFromPartialCaption(ByRef lWnd As Long, ByVal sCaption As String) As Boolean
Dim lhWndP As Long
Dim sStr As String
GetHandleFromPartialCaption = False
lhWndP = FindWindow(vbNullString, vbNullString)
Do While lhWndP <> 0
sStr = String(GetWindowTextLength(lhWndP) + 1, Chr$(0))
GetWindowText lhWndP, sStr, Len(sStr)
sStr = Left$(sStr, Len(sStr) - 1)
If InStr(1, sStr, sCaption) > 0 Then
GetHandleFromPartialCaption = True
lWnd = lhWndP
Exit Do
End If
handle = GetWindow(lhWndP, GW_HWNDNEXT)
Loop
End Function
Public Function GetWindowCaption(wHWnd As Long) As String
Dim TxtLen As Long
Dim WinTxt As String * 255
TxtLen = GetWindowTextLength(wHWnd) + 1
Call GetWindowText(wHWnd, WinTxt, TxtLen)
GetWindowCaption = WinTxt
End Function
I'm essentially trying to create a variable as the person's AIM Screen name which I would like to grab from the title of their Buddy list.
Last edited by SC I VeNoM I; Apr 19th, 2006 at 09:23 PM.
-
Apr 19th, 2006, 09:19 PM
#5
Thread Starter
Lively Member
Re: Handle from Part Caption
VB Code:
Private Function AIM_Username()
Dim AIMHandle As Long, AIMName As String
AIMHandle = FindWindow(vbNullString, "MedinaSoccaStar's Buddy List Window")
AIMName = GetWindowCaption(AIMHandle)
AIMName = AIMName - Right$(AIMName, "20")
AIM_Username = AIMName
End Function
That how I'm trying to do it with my screen name directly, but It can vary so I would like to just use "Buddy List Window"
-
Apr 19th, 2006, 09:23 PM
#6
Re: Handle from Part Caption
in that case you can modify the function a little:
VB Code:
Private Sub Command1_Click()
Dim sUsername As String
sUsername = GetAIMUserName("Buddy List Window")
End Sub
Private Function GetAIMUserName(ByVal sCaption As String) As String
Dim lhWndP As Long, Dim sStr As String
lhWndP = FindWindow(vbNullString, vbNullString)
Do While lhWndP <> 0
sStr = String(GetWindowTextLength(lhWndP) + 1, Chr$(0))
GetWindowText lhWndP, sStr, Len(sStr)
sStr = Left$(sStr, Len(sStr) - 1)
If InStr(1, sStr, sCaption) > 0 Then
GetUserName = Trim$(Left$(sStr, Len(sStr) - Len(sCaption)))
Exit Do
End If
lhWndP = GetWindow(lhWndP, GW_HWNDNEXT)
Loop
End Function
-
Apr 19th, 2006, 09:36 PM
#7
Thread Starter
Lively Member
Re: Handle from Part Caption
Would that function just grab the handle to it? It returns "" for me.
-
Apr 19th, 2006, 09:41 PM
#8
Thread Starter
Lively Member
Re: Handle from Part Caption
VB Code:
Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, _
ByVal cch As Long) As Long
Private Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Private Const GW_HWNDNEXT = 2
Private Sub Command1_Click()
Dim Handle As Long, Username As String
Handle = GetAIMUserName("Buddy List Window")
Username = GetWindowCaption(Handle)
Username = Username - Right$(Username, "20")
MsgBox Username
End Sub
Private Function GetAIMUserName(ByVal sCaption As String) As String
Dim lhWndP As Long, sStr As String, GetUserName As String
lhWndP = FindWindow(vbNullString, vbNullString)
Do While lhWndP <> 0
sStr = String(GetWindowTextLength(lhWndP) + 1, Chr$(0))
GetWindowText lhWndP, sStr, Len(sStr)
sStr = Left$(sStr, Len(sStr) - 1)
If InStr(1, sStr, sCaption) > 0 Then
GetUserName = Trim$(Left$(sStr, Len(sStr) - Len(sCaption)))
Exit Do
End If
lhWndP = GetWindow(lhWndP, GW_HWNDNEXT)
Loop
End Function
Public Function GetWindowCaption(wHWnd As Long) As String
Dim TxtLen As Long
Dim WinTxt As String * 255
TxtLen = GetWindowTextLength(wHWnd) + 1
Call GetWindowText(wHWnd, WinTxt, TxtLen)
GetWindowCaption = WinTxt
End Function
There is all my code. It is not working.
Thank you for the help!
-
Apr 19th, 2006, 09:43 PM
#9
Re: Handle from Part Caption
I gave you an example of how to use the function. It 'should' just return the persons name all by itself:
VB Code:
Private Sub Command1_Click()
Dim sUsername As String
sUsername = GetAIMUserName("Buddy List Window")
End Sub
I've tested it with skype and it works
VB Code:
Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" ( _
ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" ( _
ByVal hwnd As Long, _
ByVal lpString As String, _
ByVal cch As Long) As Long
Private Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" ( _
ByVal hwnd As Long) As Long
Private Declare Function GetWindow Lib "user32" ( _
ByVal hwnd As Long, _
ByVal wCmd As Long) As Long
Private Const GW_HWNDNEXT = 2
Private Sub Command1_Click()
Dim sUsername As String
sUsername = GetAIMUserName("Buddy List Window")
Debug.Print sUsername
End Sub
Private Function GetAIMUserName(ByVal sCaption As String) As String
Dim lhWndP As Long, sStr As String, GetUserName As String
lhWndP = FindWindow(vbNullString, vbNullString)
Do While lhWndP <> 0
sStr = String(GetWindowTextLength(lhWndP) + 1, Chr$(0))
GetWindowText lhWndP, sStr, Len(sStr)
sStr = Left$(sStr, Len(sStr) - 1)
If InStr(1, sStr, sCaption) > 0 Then
GetUserName = Trim$(Left$(sStr, Len(sStr) - Len(sCaption)))
Exit Do
End If
lhWndP = GetWindow(lhWndP, GW_HWNDNEXT)
Loop
End Function
Last edited by bushmobile; Apr 19th, 2006 at 09:47 PM.
-
Apr 19th, 2006, 09:50 PM
#10
Thread Starter
Lively Member
Re: Handle from Part Caption
How would I tell it to grab the whole title minus the last 20 charachters? Cuz with AIM it has Usernames 's Buddy List Window and i want 's Buddy List Window gone
EDIT:: Your code still isn't working. Here is a screenshot of what happens with AIM. Do you have AIM 5.9?
http://i3.tinypic.com/vyxr7s.jpg
Last edited by SC I VeNoM I; Apr 19th, 2006 at 09:53 PM.
-
Apr 19th, 2006, 09:53 PM
#11
Re: Handle from Part Caption
that's what it does.
if the window's caption is "Bushmobile's Buddy List Window" then GetAIMUserName("Buddy List Window") will return "Bushmobile's"
-
Apr 19th, 2006, 09:59 PM
#12
Thread Starter
Lively Member
Re: Handle from Part Caption
-
Apr 19th, 2006, 10:05 PM
#13
Re: Handle from Part Caption
Does the window caption contain the exact text "Buddy List Window".
Try sUsername = GetAIMUserName("Buddy List")
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|