INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

How to enumerate active windows in Win7 with VFP 9.0

How to enumerate active windows in Win7 with VFP 9.0

(OP)
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

RE: How to enumerate active windows in Win7 with VFP 9.0

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.

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 

RE: How to enumerate active windows in Win7 with VFP 9.0

(OP)
Tore Bleken

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

I get a count of zero when I test it

CODE --> VFP

?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 --> VFP

oShellWindows = oShell.Windows 
.

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


Dennis Kean

Simplicity is the extreme degree of sophistication.
Leonardo da Vinci

RE: How to enumerate active windows in Win7 with VFP 9.0

(OP)
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 --> VFP

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))
 	
 	IF nVisible = 1
	    INSERT INTO csResult VALUES (hCurrent, nVisible,;
	        nLeft, nTop, nRight, nBottom, cWinCap, cWinClass)
	ENDIF 
    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

RE: How to enumerate active windows in Win7 with VFP 9.0

Well, to find a single Window by title, still FindWindow is the one API call to make.

Bye, Olaf.

RE: How to enumerate active windows in Win7 with VFP 9.0

(OP)
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

RE: How to enumerate active windows in Win7 with VFP 9.0

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.








Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close