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

x
?
Solved

Which app has the focus??

Posted on 1998-06-04
4
Medium Priority
?
196 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 240 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

783 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