Solved

Set Focus

Posted on 2000-03-24
3
252 Views
Last Modified: 2010-04-04
How can i give focus to other application ?
ex:
Running Application :
1. IE
2. Windows Explorer
3. My Application

Now Focus in My Application, How can i set the focus to IE or Windows Explorer from my application ?
0
Comment
Question by:crazydragonx
  • 2
3 Comments
 
LVL 6

Accepted Solution

by:
Jaymol earned 50 total points
ID: 2652500
If you know the window title (caption bar text) you can use the following

Function SetWindowFocused(wTitle: String): Boolean;
var
  Hndl : Boolean;
begin
  Result:=False;
  Hndl:=FindWindow(nil, PChar(wTitle));
  If Hndl>0 then begin
    SetForegroundWindow(Hndl);
    Result:=True;
  end;
end;

....
....
....
  if not SetWindowFocused('Microsoft Internet Explorer') then
    ShowMessage('Couldn't find window.');

or, if you don't know the Window Title, you'll have to enumerate the open windows to find the closest.  (This can be done using a unit I wrote - GetApps.  If you need it, let me know your email and I'll send it.)  It's a bit easier to get the titles and find one with your selected text within one of them.  (Internet explorer always says something like "web site you're on - microsoft internet explorer".  FindWindow will not find that if you ask it to find "Internet Explorer".  See what I mean?)

Hope this helps,

John.
0
 

Author Comment

by:crazydragonx
ID: 2652643
Thank You, I got the point now...

May you send me the getapps code, so i can compare it with my app. Thx before
0
 
LVL 6

Expert Comment

by:Jaymol
ID: 2652691
Go to my web site and download it from there.

  www.geocities.com/jaymol

Thanks,

John.
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.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

829 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