Solved

Controlling An External Windows Program From A Delphi App

Posted on 2004-08-05
7
234 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
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 500 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Machine not responding during CopyFile() 3 103
Create a path if not exists 7 86
How to convert memory stream to PDF file 6 103
Firemonkey android show image from resource ? 1 46
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

789 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