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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Toplevel form puzzler??? 1

Status
Not open for further replies.

BlindPete

Programmer
Jul 5, 2000
711
US
Hello All, it has been a while and I'm back with what I hope is an easy question.

I have a top level form (VFP6) that is set to be always on top. Because of this the lost focus (and got focus too) event does not fire even though the top level form may not be the current user selected application.

In other words my top level form is displayed (on top of every other application) but the user is currently in another application. I need to trap the event of lost focus or got focus. I fugure I need to access win32api but a quick browse through the api didn't reveal anything.

Anyone know an API function to tell you what the current application is? Or a foxpro function? -Pete[noevil]
 
Pete,

Perhaps GetActiveWindow coupled with GetWindowText? You can find this on the UT:- VFP Zone/Windows API functions. Then choose System information under category drop-down.

I've also put some code where I use these functions.

Hope that helps,

Stewart
Declarations:
Code:
DECLARE INTEGER GetActiveWindow IN Win32API
DECLARE INTEGER GetWindow IN Win32API INTEGER hWnd, INTEGER nType
DECLARE INTEGER GetWindowText IN Win32API INTEGER hWnd, STRING @cText, INTEGER nBuffSize && returns title bar
Code:
	hNext = GetActiveWindow()
	* iterate through the windows 
	DO WHILE hNext<>0 
		cText = REPLICATE(CHR(0),80)
		lnTextLen = GetWindowText(hNext,@cText,80) && passing by reference
		IF lnTextLen>0
			* discard any blank values
			lcCurText = LEFT(cText,lnTextLen) && strip out extra values
			FoundIt = 0<ATC(&quot;MICROSOFT WORD&quot;, lcCurText)
			IF FoundIt
				EXIT
			ENDIF
		ENDIF
		hNext = GetWindow(hNext,2)
	ENDDO
 
HI pete,

The lostFocus and gotFocus of the TopLevel form does fire correctly. If you are talking about the lost focus of the current application, which is something else and not created by you, then I dont think you can make that do something from within your programme. The maximum I can think of .. 1. Find out using API function, what is the current running application. 2. Force that to close (th reactions are depending on that applications shutdown activities).

When your application is a TopLevel one, and if you run another top level of yours, surely the lost focus of the first application will fire the moment to stray out of that. And again, the got focus will fire for sure when you click on that application.

If you are thinking about the window state getting minimised and then activated...
when minimised.. the lost control will fire..
when maximised.. the gotfocus will not fire, just by the maximising. Only click on to the form will fire the gotfocus. If this is bothering you, you can get the wanted thing done, by putting your code.. in the ActivateEvent of your form.

Hope this helps you :) ramani :)
(Subramanian.G),FoxAcc, ramani_g@yahoo.com
 
Thank you Stewart that does the trick! The snippet was very helpfull too. (A Star For You!)

738262: Sadly act/deact have the same problem as the focus events. Since it is a top level form set to always on top, those events don't fire except at initial painting just like the focus events. Thanks for trying! -Pete[noevil]
 
Ramani, Thanks for the info. It is reasonable to me that the top level application focus event fire when you switch apps. The bugger was my application is &quot;Always on Top&quot; so those events did not fire no matter what the current app was.

This &quot;On Top&quot; application is essentially an assistant linked via COM to another application(s). My problem was that I needed certain things to occur when the always on top &quot;assistant&quot; regained focus (Essentially update itself). So by using the MouseMove Event of the assitant coupled with the GetActiveWindow() API call. The problem is solved. -Pete[noevil]
 
If anyone remains curious this is how I simulated the gotFocus event for a top level form that is Always on Top

essentially if the mouse moves over my app it becomes the currently selected app. Not exactly the fix I was looking for but it works just the same

DECLARE INTEGER BringWindowToTop IN Win32API INTEGER hWind
DECLARE INTEGER GetActiveWindow IN Win32API

form.activate event
thisform.winAPIhandle = GetActiveWindow() &&Win32API

form.mousemove event
nCurrentWindow = GetActiveWindow()
if nCurrentWindow <> thisform.winAPIhandle then
nResult = BringWindowToTop(thisform.winAPIhandle)
*do my update routine
endif

-Pete[noevil]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top