Solved

Look for multiple openings of a program

Posted on 1997-12-11
3
157 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
[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
  • 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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

Suggested Solutions

Title # Comments Views Activity
Error E2158 compiling with Delphi XE10 Seattle 2 138
Create a path if not exists 7 124
control image tags in a string ? 12 167
FMX TEdit KeyUp handler detecting  "enter" key 4 62
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…
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…

732 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