?
Solved

Controlling An External Windows Program From A Delphi App

Posted on 2004-08-05
7
Medium Priority
?
252 Views
Last Modified: 2010-04-05
Not sure if this is possible, but if you don't ask... :)

I want to call Winamp from my application and play some music while my app waits for Winamp to finish. This I have already done.

When the music ends and Winamp closes, control passes back to my app. This is OK, but what I want to do is to be able to press say the X key and close Winamp before the music has finished.

First thoughts suggest that it's not possible as my app loses focus when Winamp (set to Always On Top) is running, so there's nothing to process keystrokes. Am I right in thinking that pressing X would be intercepted by Winamp? If so, there doesn't appear to be a keyboard shortcut to exit Winamp (in the version I'm using anyway).

Any suggestions?

TDK_Man
0
Comment
Question by:tdk_man
7 Comments
 
LVL 1

Author Comment

by:tdk_man
ID: 11732484
Oops, sorry - forgot to mention that the Winamp video screen is also open (full screen) at the same time, so both Winamp and my app are hidden behind it and using the mouse to close it isn't an option.

TDK_Man
0
 
LVL 3

Expert Comment

by:philly_tee
ID: 11732741
Hi tdk_man,

Why don't you use Winamp's SDK?  It has commands for doing all sorts of stuff in it.

Regards,

Philip
0
 
LVL 5

Expert Comment

by:Hypoviax
ID: 11733021
What you are talking about is keyboard hooking. A simple way to do this is to assign using the following component libary, a hotkey (ctrl-x etc) so that no matter where you are when you press those keys an event is triggered in your application - you can get this component libary from:

http://homepages.borland.com/jedi/jvcl/

Use the hotkey component to assign a hotkey. Assign an event so you can close winamp or perform whatever action

Regards,

Hypoviax
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 12

Expert Comment

by:Ivanov_G
ID: 11733249
0
 
LVL 1

Author Comment

by:tdk_man
ID: 11735320
Thanks for the info everyone, but the common problem seems to be that once Winamp has started, focus has been lost from my program and I cannot detect that a key has been pressed.

Once I can detect that I've pressed say the 'Q' key I can tell Winamp to close sending a message using FindWindow... I hope! :)

TDK_Man
0
 
LVL 17

Accepted Solution

by:
geobul earned 2000 total points
ID: 11736164
Hi,

1. Add a timer on your form, set its Interval to 50 and Enabled to False.
2. Before running Winamp set
  Timer1.Enabled := true;
3. Add the code below in OnTimer event:

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  if ((GetAsyncKeyState($51) and 1) = 1) then begin // 'Q' has been pressed
      // do whatever you want here to close Winamp
      Timer1.Enabled := false; // stop the timer
  end;
end;

Regards, Geo
0
 
LVL 1

Author Comment

by:tdk_man
ID: 11740660
Thanks for that geobul - just what I was after!

Info on closing the Winamp program itself I got after a quick search of past answers on EE and was amazed to find that the accepted answer was posted by my own son back in January 2000!

For anyone interested, it's done without the SDK with:

Sendmessage(hwndParent, WM_Close,0,0);

TDK_Man
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

839 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