LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 176
Default APIs FindWindow and GetWindowText

Hello,
I've had occasion to , given a Window Caption, to want the HWnd.
FindWindow works some of the time.
But my routine zSrch, using GetWindowText, searches all the
windows and finds some that FindWindow doesn't.
Can somebody explain this?

This is Excel97 on Win98. (Book1 is open)
The 1st Msgbox shows both methods working.
The 2nd Msgbox shows FindWindow doesn't find.

Declare Function FindWindow Lib "user32" Alias "FindWindowA" ( _
ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" ( _
ByVal hWnd As Long, ByVal lpString As String, ByVal cch As Long) As
Long
Declare Function GetWindowTextLength Lib "user32" Alias
"GetWindowTextLengthA" ( _
ByVal hWnd As Long) As Long

Sub Sub1()
Call Sub2("Microsoft Excel - Book1") ' hWnds =
Call Sub2("Worksheet Menu Bar") ' hWnds <
End Sub

Sub Sub2(WinCaption$) ' displays hWnds
Dim hWnd1&, hWnd2&
hWnd1 = zFind(WinCaption)
hWnd2 = zSrch(WinCaption)
MsgBox WinCaption & ": " & hWnd1 & ", " & hWnd2
End Sub

Function zFind&(WinCaption$)
zFind = FindWindow(vbNullString, WinCaption)
End Function

Function zSrch&(WinCaption$) ' search all windows
Dim hWnd&, iLen1%, iLen2%, sStr$
For hWnd = 0 To 9999 ' search
iLen1 = GetWindowTextLength(hWnd)
sStr = Space$(iLen1 + 1)
iLen2 = GetWindowText(hWnd, sStr, iLen1 + 1)
If iLen1 < iLen2 Then Stop ' check
sStr = Left$(sStr, iLen1)
If sStr = WinCaption Then Exit For
Next hWnd
If hWnd = 10000 Then Stop ' window not found
' at this point hWnd has a caption of WinCaption
zSrch = hWnd
End Function


----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
List of superseded APIs Paul Martin Excel Programming 3 June 1st 06 07:23 AM
____ Return file path via APIs !!!! RAFAAJ2000[_2_] Excel Programming 3 December 20th 05 01:02 AM
Where's the Documentation for the APIs? Peter Excel Programming 0 August 4th 05 06:16 PM
Are there apis that relate colour index with color? Jan Nordgreen Excel Programming 5 October 13th 03 12:37 AM
Picture Transparency/Mask/Overlay .. no APIs keepitcool Excel Programming 0 August 6th 03 11:06 PM


All times are GMT +1. The time now is 04:51 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"