Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Look for multiple openings of a program

Posted on 1997-12-11
3
Medium Priority
?
163 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 200 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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

963 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