Solved

Look for multiple openings of a program

Posted on 1997-12-11
3
144 Views
Last Modified: 2010-04-04
When I open a delphi application, how do I check if it is not already opened. If it is already opened, how do I divert to that application instead of opening a new one?

Keith
0
Comment
Question by:keithcsl
  • 2
3 Comments
 
LVL 5

Accepted Solution

by:
JimBob091197 earned 50 total points
ID: 1353357
Hi.  If you make the following changes to your project unit, it should work.  This code assumes your main form is TForm1 with caption Form1.  Make sure that the form's unit is NOT open in the Delphi designer...

(Add Windows to the project's uses clause.)

begin
  Application.Initialize;
  hWnd := FindWindow(PChar('TForm1'), PChar('Form1'));
  Application.CreateForm(TForm1, Form1);
  if (hWnd > 0) then begin
    SetForegroundWindow(hWnd);
    hWnd := GetWindow(hWnd, GW_OWNER);
    if (hWnd > 0) and (IsIconic(hWnd)) then
      ShowWindow(hWnd, SW_SHOWNORMAL);
  end else
    Application.Run;
end.

Regards,
JB
0
 
LVL 5

Expert Comment

by:JimBob091197
ID: 1353358
P.S.  You'll need to declare a variable:

var
    hWnd: Integer;

0
 
LVL 1

Author Comment

by:keithcsl
ID: 1353359
I tried it and it works perfectly!!

Thanks!!!
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

707 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

15 Experts available now in Live!

Get 1:1 Help Now