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 keep your application focused at all times 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
30-Aug-02
Category
Win API
Language
Delphi 2.x
Views
61
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			 Author: Tomas Rutkauskas

I want my application to keep focus at any time. So, if someone clicks another 
window, I want my application to retrieve back focus.

Answer:

Solve 1:

To get your application into the foreground in W98, ME, W2K and XP, instead of 
using SetForegroundWindow, try this:

1   procedure ShowMe;
2   var
3     Th1, Th2: Cardinal;
4   begin
5     Th1 := GetCurrentThreadId;
6     Th2 := GetWindowThreadProcessId(GetForegroundWindow, nil);
7     AttachThreadInput(Th2, Th1, true);
8     try
9       SetForegroundWindow(Application.Handle);
10    finally
11      AttachThreadInput(Th2, Th1, false);
12    end;
13  end;



Solve 2:

As well as the SetForegroundWindow (if you are using Win9X and not WinNT/2000), you 
could trick the system that your application is a running screensaver. In this case 
it will not loose focus, for screensavers by design maintain focus.

14  { ... }
15  var
16    old: Bool;
17  begin
18    {Make it a Screensaver}
19    SystemParametersInfo(SPI_SCREENSAVERRUNNING, Word(True), @old, 0);
20  
21  or
22  
23  {Make it not a Screensaver}
24  SystemParametersInfo(SPI_SCREENSAVERRUNNING, Word(False), @old, 0);


			
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