Solved

Which app has the focus??

Posted on 1998-06-04
4
178 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Suggested Solutions

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

739 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