[help] GetWindowText - Printable Version
-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: [help] GetWindowText (/showthread.php?tid=61932)
[help] GetWindowText by cirix on 06-28-2006 at 07:17 PM
Hello could someone help me get a window text, I currentlu have this script but I cant get the window text
quote:
var sTitle;
function OnEvent_MyMediaChange (new_media) {
playerHwnd = Interop.Call('User32','FindWindowW','Winamp v1.x',0);
Interop.Call('User32','GetWindowTextW', playerHwnd, sTitle);
Debug.Trace('Media Info is :'+ new_media + playerHwnd + stitle);
}
It is getting playerHwnd correctly but I dont know whats wrong with sTitle.
I have a similiar function in VB6 that is currently working its:
quote: Public Function getWinampSong() As String
Dim lblWinamp As Object
'This function will get the song current ' ly playing on Winamp
If hWndWinAMP = 0 Then
'~~/\~~ return error code...
Exit Function
End If
Dim lRet As Integer
Dim sTitle As String * 256
If hWndWinAMP > 0 Then
lRet = GetWindowText(hWndWinAMP, sTitle, 256)
getWinampSong = Left(sTitle, InStr(1, sTitle, vbNullChar) - 10)
Else
getWinampSong = "Winamp Not Found"
End If
End Function
Hope someone can help me.
Thanks.
RE: [help] GetWindowText by Eljay on 06-28-2006 at 07:30 PM
youre missing the last parameter of GetWindowText (buffer length)
RE: [help] GetWindowText by segosa on 06-28-2006 at 07:43 PM
Use GetWindowTextLength to find out how long the buffer should be.
RE: [help] GetWindowText by cirix on 06-28-2006 at 07:45 PM
Ok, I have added the buffer
I have just tried the GetWindowTextLength but I guess Im doing something wrong, I get Error: 'stitle' no está definido with GetWindowTextLength too.
quote: sTitle = Interop.Call('User32','GetWindowTextW', playerHwnd, sTitle, 256);
But Is says 'stitle' Isnt defined.
RE: [help] GetWindowText by matty on 06-28-2006 at 08:01 PM
I am not sure if this will work as I am at work not home
code: function GetWindowText(hWnd){
var lBuffer = Interop.Call('user32', 'GetWindowTextLengthW', hWnd);
var sBuffer = Interop.Allocate(2*(lBuffer+2));
Interop.Call('user32', 'GetWindowTextW', hWnd, sBuffer, lBuffer);
Debug.Trace('sBuffer: '+sBuffer.ReadString(0));
}
quote: Originally posted by cirix
sTitle = Interop.Call('User32','GetWindowTextW', playerHwnd, sTitle, 256);
The syntax is incorrect. GetWindowTextW will return a number of the length of the string, not the string itself. That is what the sTitle parameter is for.
RE: [help] GetWindowText by cirix on 06-29-2006 at 12:12 AM
Thank you its working, here is the code in case any one cares:
quote:
function OnEvent_MyMediaChange (new_media) {
playerHwnd = Interop.Call('User32','FindWindowW','Winamp v1.x',0);
var lBuffer = Interop.Call('user32', 'GetWindowTextLengthW', playerHwnd);
var sBuffer = Interop.Allocate(2*(lBuffer+2));
var Title = Interop.Call('user32', 'GetWindowTextW', playerHwnd, sBuffer, lBuffer);
Debug.Trace('sBuffer: '+sBuffer.ReadString(0));
}
Result is:
sBuffer: 3565. Jay-Z - Aint No Nigga ft. Foxy Brown : "Reasonable Doubt" - Winam
The only problem I got now is that its cutting off the last letter but its good enough.
RE: [help] GetWindowText by matty on 06-29-2006 at 12:17 AM
quote: Originally posted by Matty
I am not sure if this will work as I am at work not home
code: function GetWindowText(hWnd){
var lBuffer = Interop.Call('user32', 'GetWindowTextLengthW', hWnd)+1;
var sBuffer = Interop.Allocate(2*(lBuffer+2));
Interop.Call('user32', 'GetWindowTextW', hWnd, sBuffer, lBuffer);
Debug.Trace('sBuffer: '+sBuffer.ReadString(0));
}
quote: Originally posted by cirix
The only problem I got now is that its cutting off the last letter but its good enough.
There is the fixed code, all you need to do is add 1 to lBuffer.
|