Solved

getting text from another program

Posted on 2002-03-16
4
1,635 Views
Last Modified: 2010-08-05
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,this_title,sizeof(this_title));
p = this_title+strlen(this_title)-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,custrec,sizeof(custrec));
ino := custrec;
showmessage(ino);
end;

anyone know where i'm going wrong?

cheers
classic_gaming
0
Comment
Question by:classic_gaming
  • 2
4 Comments
 
LVL 17

Expert Comment

by:inthe
ID: 6872597
hi,
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_getTextLength,0,0);
setlength(text,NumChars);
SendMessage(h,wm_getText,NumChars+1,Integer(text));
result:=text;
end
else result:='no winamp found';
end;


procedure TForm1.Button1Click(Sender: TObject);
begin
edit1.text := ReadWinAmpSongName;
end;
0
 
LVL 17

Accepted Solution

by:
inthe earned 100 total points
ID: 6872629
heres the GetWindowText example,you need to use an array of char instead of pchar

function ReadWinampSongName2:String;
var
wind:HWND;
Windtext:array[0..255]of Char;
begin
Wind:=FindWindow('Winamp v1.x',nil);
GetWindowText(Wind,WindText,255);
result := WindText;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
edit1.text :=  ReadWinampSongName2;
end;
0
 
LVL 34

Expert Comment

by:Slick812
ID: 6873468
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);
0
 

Author Comment

by:classic_gaming
ID: 6873713
you posted exactly what i want :)

points go to you

cheers
classic_gaming
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Delphi cmd execution 6 67
FMX StringGrid1->Canvas->FillRect Problem 3 170
Delphi 2 69
How to insert .png images to TClientDataSet .cds file? 2 31
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question