Solved

Look for multiple openings of a program

Posted on 1997-12-11
3
154 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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
code issue 8 156
How to debug For loops? 3 57
Delphi problems to abort a printjob 9 25
Browsing a TTreeView in Delphi 5 9
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…
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…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

830 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