Solved

Set Focus

Posted on 2000-03-24
3
251 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

770 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