Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to activate the previous instance of an application Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
04-Oct-02
Category
System
Language
Delphi All Versions
Views
91
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			 Author: Jonas Bilinkevicius

How to activate the previous instance of an application

Answer:

Place the following at the start of your project file:
1   
2   begin
3     if HPrevInst < > 0 then
4     begin
5       ActivatePreviousInstance;
6       Exit;
7     end;
8     { ... }
9   
10  and include the following unit:
11  
12  unit PrevInst;
13  
14  interface
15  
16  uses
17    WinProcs, WinTypes, SysUtils;
18  
19  type
20    PHWnd = ^HWnd;
21  
22  {function EnumFunc(Wnd: HWnd; TargetWindow: PHWnd): Bool; export;
23  procedure ActivatePreviousInstance;}
24  
25  implementation
26  
27  function EnumFunc(Wnd: HWnd; TargetWindow: PHWnd): Bool;
28  var
29    ClassName: array[0..30] of char;
30  begin
31    Result := True;
32    if GetWindowWord(Wnd, GWW_HINSTANCE) = HPrevInst then
33    begin
34      GetClassName(Wnd, ClassName, 30);
35      if StrIComp(ClassName, 'TApplication') = 0 then
36      begin
37        TargetWindow^ := Wnd;
38        Result := False;
39      end;
40    end;
41  end;
42  
43  procedure ActivatePreviousInstance;
44  var
45    PrevInstWnd: HWnd;
46  begin
47    PrevInstWnd := 0;
48    EnumWindows(@EnumFunc, Longint(@PrevInstWnd));
49    if PrevInstWnd <> 0 then
50      if IsIconic(PrevInstWnd) then
51        ShowWindow(PrevInstWnd, SW_RESTORE)
52      else
53        BringWindowToTop(PrevInstWnd);
54  end;
55  
56  end.


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC