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 switch focus to an existing 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 2.x
Views
98
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			 Author: Jonas Bilinkevicius

How can I switch focus to an existing instance of an application instead of 
creating a new instance (HPrevInst)?

Answer:
1   
2   {usual stuff at the top of the project source file}
3   
4   var
5     hwnd: Word;
6   begin
7     if hPrevInst = 0 then
8     begin
9       Application.CreateForm(TForm1, Form1);
10      Application.Run;
11    end
12    else
13    begin
14      hwnd := FindWindow('TForm1', nil);
15      if (not IsWindowVisible(hwnd)) then
16      begin
17        ShowWindow(hwnd, sw_ShowNormal);
18        PostMessage(hwnd, wm_User, 0, 0);
19      end
20      else
21        SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE or SWP_NOMOVE);
22    end;
23  end.


in the form's PAS file add a message response function for the wm_User message.
24  
25  {in the form declaration}
26  public
27  
28  procedure WMUser(var msg: TMessage); message wm_User;
29  
30  {in the implementation section}
31  
32  procedure TForm1.WMUser(var msg: TMessage);
33  begin
34    Application.Restore;
35  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