classic_gaming
asked on
getting text from another program
hi,
on thw winamp site it says you can get the current song playing
e.g this c++ code:
char this_title[2048],*p;
GetWindowText(hwndWinamp,t his_title, sizeof(thi s_title));
p = this_title+strlen(this_tit le)-8;
while (p >= this_title)
{
if (!strnicmp(p,"- Winamp",8)) break;
p--;
}
if (p >= this_title) p--;
while (p >= this_title && *p == ' ') p--;
*++p=0;
i'm trying to convert that code to delphi and this is what i got so far:
const CustRec: pchar = '';
procedure TForm1.Button1Click(Sender : TObject);
var
ino: pchar;
begin
hwndwinamp := FindWindow('Winamp v1.x', nil);
getwindowtext(hwndwinamp,c ustrec,siz eof(custre c));
ino := custrec;
showmessage(ino);
end;
anyone know where i'm going wrong?
cheers
classic_gaming
on thw winamp site it says you can get the current song playing
e.g this c++ code:
char this_title[2048],*p;
GetWindowText(hwndWinamp,t
p = this_title+strlen(this_tit
while (p >= this_title)
{
if (!strnicmp(p,"- Winamp",8)) break;
p--;
}
if (p >= this_title) p--;
while (p >= this_title && *p == ' ') p--;
*++p=0;
i'm trying to convert that code to delphi and this is what i got so far:
const CustRec: pchar = '';
procedure TForm1.Button1Click(Sender
var
ino: pchar;
begin
hwndwinamp := FindWindow('Winamp v1.x', nil);
getwindowtext(hwndwinamp,c
ino := custrec;
showmessage(ino);
end;
anyone know where i'm going wrong?
cheers
classic_gaming
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
it looks like the WinAmp uses a 2k buffer (Pchar) for the Title of the window
char this_title[2048]
so the Array of Char should be
Ttext:array[0..2048]of Char;
or use a String var for the Text variable
var
TitleText: String;
SetLength(TitleText, 2048);
GetWindowText(hWnd, @TitleText[1],2048);
it also appears to remove the "- Winamp" from the title
if (!strnicmp(p,"- Winamp",8)) break;
you might use Ps := Pos('- Winamp',Titleext) to find it and
Delete(TitleText, Ps, 8); to remove it
and it looks like it removes the extra spaces, you might use
TitleText := Trim(TitleText);
char this_title[2048]
so the Array of Char should be
Ttext:array[0..2048]of Char;
or use a String var for the Text variable
var
TitleText: String;
SetLength(TitleText, 2048);
GetWindowText(hWnd, @TitleText[1],2048);
it also appears to remove the "- Winamp" from the title
if (!strnicmp(p,"- Winamp",8)) break;
you might use Ps := Pos('- Winamp',Titleext) to find it and
Delete(TitleText, Ps, 8); to remove it
and it looks like it removes the extra spaces, you might use
TitleText := Trim(TitleText);
ASKER
you posted exactly what i want :)
points go to you
cheers
classic_gaming
points go to you
cheers
classic_gaming
use wm_getText message heres an example , it works ok:
Function ReadWinAmpSongName:string;
var h:hwnd;
Text:string;
NumChars:integer;
begin
h:=FindWindow('Winamp v1.x',nil);
if h<>0 then begin
NumChars:=SendMessage(h,wm
setlength(text,NumChars);
SendMessage(h,wm_getText,N
result:=text;
end
else result:='no winamp found';
end;
procedure TForm1.Button1Click(Sender
begin
edit1.text := ReadWinAmpSongName;
end;