[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Controlling An External Windows Program From A Delphi App

Posted on 2004-08-05
7
Medium Priority
?
247 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Technology Partners: 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

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…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

650 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