[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 165
  • Last Modified:

Look for multiple openings of a program

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
keithcsl
Asked:
keithcsl
  • 2
1 Solution
 
JimBob091197Commented:
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
 
JimBob091197Commented:
P.S.  You'll need to declare a variable:

var
    hWnd: Integer;

0
 
keithcslAuthor Commented:
I tried it and it works perfectly!!

Thanks!!!
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now