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

How to enumerate active windows in Win7 with VFP 9.0 1

Status
Not open for further replies.

dkean4

Programmer
Feb 15, 2015
282
US
I seem to have some problems getting a list of active windows in Windows 7.0, (not forms in vfp). I used to do it in XP and, (using my old method), I am now only getting a reference to the Task switching window, because of the way I was doing it in Windows XP, from VFP.

I need to get the handle of a specific Active window directly, based on the title of the window, if there is a way to do that directly. If not, then how can I enumerate the active windows into a list?

TIA..



Dennis Kean

Simplicity is the extreme degree of sophistication.
Leonardo da Vinci
 
I don't have the complete code for you, but I am sure you can modify this code to get what you want. I use it to find get a reference to IE if it's active and has a specific page opened.

[pre]llAlredyup=.F.
oShell = Createobject("Shell.Application")
&& A collection of the open windows that belong to the Shell
oShellWindows = oShell.Windows
For Each oIE In oShellWindows
*!* Wait 'a '+Upper(oIE.FullName) Window
*!* Wait 'b '+Justfname(Upper(oIE.LocationName)) Window
If "IEXPLORE.EXE" $ Justfname(Upper(oIE.FullName))
If 'MYWEBSITE'$Upper(oIE.LocationName) && Fake data!!
lox=oIE
*!* Wait 'success ' Window Timeout 1
llAlredyup=.T.
Exit
Endif
Endif
Endfor
oShellWindows = Null
oShell = Null[/pre]
 
Tore Bleken

Very interesting solution, if I could get it to work.

I get a count of zero when I test it

Code:
?oShellWindows.Count    &&  = 0  ... It gives me zero here

I fought with it for a while, but to no avail. oShell instantiates into an object and so does this:

Code:
oShellWindows = oShell.Windows
.

But no items come up... The list is empty.




Dennis Kean

Simplicity is the extreme degree of sophistication.
Leonardo da Vinci
 
Olaf you rascal...

That is the ultimate. But it does give you all visible and not visible bunch of windows and what not. So I modified it as follows and it works great.

Code:
DO WHILE .T.
    cWinCap = GetWinText(hCurrent)
    cWinClass= GetClsName(hCurrent)
    nVisible = IsWindowVisible(hCurrent)
 
    rc = Repli(Chr(0),16)
    = GetWindowRect(hCurrent, @rc)
    nLeft = buf2dword(SUBSTR(rc, 1,4))
    nTop = buf2dword(SUBSTR(rc, 5,4))
    nRight = buf2dword(SUBSTR(rc, 9,4))
    nBottom = buf2dword(SUBSTR(rc, 13,4))
 	
 	[b][COLOR=#FF0000]IF nVisible = 1[/color][/b]
	    INSERT INTO csResult VALUES (hCurrent, nVisible,;
	        nLeft, nTop, nRight, nBottom, cWinCap, cWinClass)
	[b][COLOR=#FF0000]ENDIF[/color] [/b]
    IF hCurrent = hLastChild
        EXIT
    ENDIF
    hCurrent = GetWindow(hCurrent, GW_HWNDNEXT)
ENDDO

I found it on my own, after I posted it on the forum, but it does not take away from your astute skill of finding the best solutions. And it is lightning fast...

Thanks...

Dennis Kean

Simplicity is the extreme degree of sophistication.
Leonardo da Vinci
 
Well, to find a single Window by title, still FindWindow is the one API call to make.

Bye, Olaf.
 
Olaf,

The FindWindow function requires the exact spelling of the Title and the titles I encounter may have various fields embedded in the Title. Does FindWindow function allow for fractional Title content searches? I could not figure out a way to do that, but by including the entire string perfectly. Here are a few examples

"60T0419: LMXQ- Server 197 - Account ABJ - [GUOKN,M1]"
"74W0498: LMXQ- Server 501 - Account HIZ - [LOSUI,T4]"
"30Y0715: LMXQ- Server 449 - Account AB0 - [COKNI,BW]"

"LMXQ" is the main fraction of the Title used to isolate the windows which could be operated on. After that the square bracket contents allow me to choose from among the 4 candidates.

So, enumeration isolates the set and the brackets resolve the next detail. In fact the second field in the brackets is important on the next level of this cascade, as well. You found the right stuff, Olaf... Good show!

Merci beaucoup!

Dennis Kean

Simplicity is the extreme degree of sophistication.
Leonardo da Vinci
 
Yes, that's the problematic part of FindWindow, even when you know Word always uses caption "Document1" for the first new document, it's not the case, if it's the second new document in the current session, and it's not the case in another language. But you can often reach the goal by knowing the Window Class, eg a notepad window can be found by FindWindow("Notepad",0) instead of FindWindow(0,"Title - Editor") and FindWindow("OpusApp",0) for Microsoft Word document windows - Googling OpusApp you find also Outlook windows are based on that class.

It's, of course, easy to cope with the list of all windows, as it's retrieved fast and can be filtered.

Bye, Olaf.








 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top