Solved

Which app has the focus??

Posted on 1998-06-04
4
165 Views
Last Modified: 2010-05-03
Hi,

Can anyone send me the API example of how to find the current application that has the focus, I tried the other way around, ie: does my VB app still have the focus using the event lostfocus but it does not quite work the way I want.

Some help will be greatly appreciated.

Cheers
0
Comment
Question by:mmahdi
  • 3
4 Comments
 
LVL 1

Accepted Solution

by:
Sekans earned 80 total points
ID: 1462539
mmahdi,
Try this:

Dim hWndCURR As Long
Dim WNDTEXT As String
hWndCURR = GetForegroundWindow()
TXTLEN = GetWindowTextLength(hWndCURR)
WNDTEXT = Space$(TXTLEN + 1)
TXTLEN = GetWindowText(hWndCURR, WNDTEXT, TXTLEN + 1)
MsgBox WNDTEXT

WNDTEXT is the window text of the current application

Regards,
Sekans
0
 
LVL 1

Expert Comment

by:Sekans
ID: 1462540
mmahdi,
I apologize, the code I submitted will return the foreground window, perhaps a more appropriate code would be:
    hWndCURR = GetFocus()
this would go in place of:
    hWndCURR = GetForegroundWindow()

Regards,
Sekans
0
 
LVL 1

Author Comment

by:mmahdi
ID: 1462541
Sekans,

Thanks for the code, the first answer somehow work, however I had to edit the code:

from: WNDTEXT = Space$(TXTLEN + 1)
to: WNDTEXT = Space$(TXTLEN)

the first line returned a string length of whatever the caption of the window is + 1 extra character. I am using the procedure in a timer control. If my app has not got the focus then activate some process.

Thanks
MMAHDI

0
 
LVL 1

Expert Comment

by:Sekans
ID: 1462542
Glad I could help.
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

813 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now