What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » [help] GetWindowText

[help] GetWindowText
Author: Message:
cirix
New Member
*


Posts: 10
Joined: Jun 2006
O.P. [help] GetWindowText

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.
06-28-2006 07:17 PM
Profile E-Mail PM Find Quote Report
Eljay
Elite Member
*****

Avatar
:O

Posts: 2949
Reputation: 77
– / Male / –
Joined: May 2004
RE: [help] GetWindowText
youre missing the last parameter of GetWindowText (buffer length)
06-28-2006 07:30 PM
Profile PM Find Quote Report
segosa
Community's Choice
*****


Posts: 1407
Reputation: 92
Joined: Feb 2003
RE: [help] GetWindowText
Use GetWindowTextLength to find out how long the buffer should be.
The previous sentence is false. The following sentence is true.
06-28-2006 07:43 PM
Profile PM Find Quote Report
cirix
New Member
*


Posts: 10
Joined: Jun 2006
O.P. RE: [help] GetWindowText
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.

This post was edited on 06-28-2006 at 07:49 PM by cirix.
06-28-2006 07:45 PM
Profile E-Mail PM Find Quote Report
matty
Scripting Guru
*****


Posts: 8336
Reputation: 109
39 / Male / Flag
Joined: Dec 2002
Status: Away
RE: [help] GetWindowText
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.

This post was edited on 06-28-2006 at 08:13 PM by matty.
06-28-2006 08:01 PM
Profile E-Mail PM Find Quote Report
cirix
New Member
*


Posts: 10
Joined: Jun 2006
O.P. RE: [help] GetWindowText
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.

This post was edited on 06-29-2006 at 12:12 AM by cirix.
06-29-2006 12:12 AM
Profile E-Mail PM Find Quote Report
matty
Scripting Guru
*****


Posts: 8336
Reputation: 109
39 / Male / Flag
Joined: Dec 2002
Status: Away
RE: [help] GetWindowText
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.

This post was edited on 06-29-2006 at 12:19 AM by matty.
06-29-2006 12:17 AM
Profile E-Mail PM Find Quote Report
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On