Solved

Controlling An External Windows Program From A Delphi App

Posted on 2004-08-05
7
230 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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

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 The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

743 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now