Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I identify the Windows process that has focus?

Status
Not open for further replies.

jerrygoldring

Programmer
May 11, 2004
5
US
I am developing a VB 6 app that refreshes a display of orders every n minutes. Problem is if I open another app (like outlook or anything else) my VB app does not know that it does not have Windows focus. So when it refreshes the list, it set focus to the grid and causes the VB window to pop back to the top, overlaying the other active application. Is there a call I can make to determine if my App is on top of all others (that is, is the currently focused window)? Thanks in advance...
 

Well welcome to TT jerrygoldring. To get the most from this site please read FAQ222-2244.

The GetWindowPlacement API with the WINDOWPLACEMENT structure will contain the current state of the window in the showcmd parameter (however looking at the documentation it looks like you will have to try some tests to see what is returned.).

Good Luck

 
Well, vb5prgrmr, I am totally confused. I have never issues an API call from VB adn frankly I don;t know where to start. Do I need to include a reference to user32.DLL? How do i know what the parameters are? I am lame and lost! Please help if you have the patience...

JerryGoldring
 
Got it, thnks to your inspiration. I am using the GetForegroundWindow API call. It works like a champ.
My code does this:

Private sub TImer1_Timer()
if IAmOnTop(me) then
...
end if
exit sub

The following are placed in a Module...


' Returns Handle of OS-Level Window that has the focus
Declare Function GetForegroundWindow Lib "user32" () As Long

public function AmIOnTop(pForm as form) as boolean
' Get Handle of Calling Window
lngMyWindowHandle = pform.hWnd
' Get handle of Operating System's Focused Window
lngWindowHandle = GetForegroundWindow()
' If same, the IAmOnTop, else not
AmIOnTop = (lngwindowhandle = lngmywindowhandle)
exit function

Thanks for your help. I appreciate it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top