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

x
?
Solved

Set Focus

Posted on 2000-03-24
3
Medium Priority
?
261 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 150 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
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…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

886 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