get my winamp HWND

i trey to use

 hwnd_winamp:=FindWindow('Winamp v5.x', nil);  /// have 5.52 version

but allways return 0.

What to to to get my opne winamp hwnd ??
LVL 9
ginsonicAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

tammozCommented:
you just need to switch the parameters of the findwindow function:
hwnd_winamp:=FindWindow(nil, 'Winamp v5.x');  /// have 5.52 version
0
CodedKCommented:
Hi GinSonic

The right command is :
FindWindow('Winamp v1.x',nil);

So do this :
hwnd_winamp:=FindWindow('Winamp v1.x',nil);
0
tammozCommented:
have a look here:

HWND FindWindow(

    LPCTSTR lpClassName,      // pointer to class name
    LPCTSTR lpWindowName       // pointer to window name
   );      
 

Parameters

lpClassName

Points to a null-terminated string that specifies the class name or is an atom that identifies the class-name string. If this parameter is an atom, it must be a global atom created by a previous call to the GlobalAddAtom function. The atom, a 16-bit value, must be placed in the low-order word of lpClassName; the high-order word must be zero.

lpWindowName

Points to a null-terminated string that specifies <B> the window name (the window's title)</B>. If this parameter is NULL, all window names match.

 I think that the window title (window caption) is the second parameter
0
Angular Fundamentals

Learn the fundamentals of Angular 2, a JavaScript framework for developing dynamic single page applications.

CodedKCommented:
Tammoz i bet GinSonic knows the structure of FindWindow.
He asks the right class name or a valid caption.

If you check your code ... it doesnt work !
'Winamp v1.x' is the right handle to search so you can find the handle and talk to winamp without worrying about the version.
And 'Winamp v5.x' is not the caption... So...
0
tammozCommented:
ok I've got it,  I was talking about the general case because I do not use winamp, so I do not know about its class name

regards codedk
0
ginsonicAuthor Commented:
i use :
 
  WinExec(PChar(FPath2Winamp), SW_NORMAL{HIDE});
   hwnd_winamp:=FindWindow('Winamp v1.x',nil);

  hwnd_winamp is 0 :(
0
ginsonicAuthor Commented:
try with 2.x,3.x,4.x,5.x... same result
0
CodedKCommented:
Ginsonic what do you want to do with winamp handle.
(Except from executing), i will give you the code,
0
CodedKCommented:
Here is some working code :


function GetWinampSongTitle(Index: Integer): String;
var
  hWndWinamp, TempHandle : THandle;
  dat2: array[0..500] of Char;
  TrackPos: Integer;
  temp, MPointer: Cardinal;
begin
  hwndWinamp := FindWindow('Winamp v1.x',nil);
  if (Index < 0) then TrackPos := SendMessage(hWndWinamp, WM_USER, 0, 125) else TrackPos := Index;
  MPointer := SendMessage(hWndWinamp, WM_USER, TrackPos, 212);
  GetWindowThreadProcessId(hwndWinamp, @TempHandle);
  hwndWinamp := OpenProcess(PROCESS_ALL_ACCESS, false, TempHandle);
  ReadProcessMemory(hWndWinamp, Pointer(MPointer), @dat2, 500, temp);
  CloseHandle(hWndWinamp);
  Result := dat2;
end;


procedure TForm1.Button1Click(Sender: TObject);
var
  FPath2Winamp : String;
  LeHandle:  THandle;
begin
  FPath2Winamp:='C:\Program Files\Winamp\Winamp.exe';
  WinExec(PChar(FPath2Winamp), SW_NORMAL{HIDE});
  LeHandle:= FindWindow('Winamp v1.x',nil);
  While LeHandle=0 do
    begin
     LeHandle:= FindWindow('Winamp v1.x',nil);
     Application.ProcessMessages;
    end;
  ShowMessage('Winamp handle is :'+IntToStr(LeHandle));
  ShowMessage('The 1st song is :'+GetWinampSongTitle(0));
end;
0
CodedKCommented:
I guess you didnt wait the window to get a handle first...
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ginsonicAuthor Commented:
yes CodedK, this is the problem :) found me mysellf last night.

If try to get the hwnd a little latter is ok with 1.x

I will force my application to wait to be created the window.
0
ginsonicAuthor Commented:
thx to all for support!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.