On Sat, 15 Nov 2003 09:54:44 -0500, "Mike C." <
noname@nonet.net>
wrote:
Quote
That's a good idea, but when that Top form unloads, sometimes the owner form
gets the focus, and when that happens I don't have a clue who's on top.
That's why I was hoping an API call would be of some benefit.
Thanks Tom... I'll keep plugging away.
If it helps, here's what I was thinking of with GetWindow. The
App.ThreadID test isn't strictly necessary, but it does eliminate
iterating the forms collection for windows that don't belong to the
app.
'declares...
Public Const GW_HWNDFIRST = 0
Public Const GW_HWNDNEXT = 2
Public Declare Function GetWindow Lib "user32" _
(ByVal hwnd As Long, ByVal wCmd As Long) As Long
Public Declare Function GetWindowThreadProcessId Lib "user32" _
(ByVal hwnd As Long, lpdwProcessId As Any) As Long
'implementation...
Public Function GetLastActiveOwnedForm(Owner As Form) As Form
Dim hwndTop As Long
Dim F As Form
hwndTop = GetWindow(Owner.hwnd, GW_HWNDFIRST)
Do While (hwndTop <>0) And (hwndTop <>Owner.hwnd)
If App.ThreadID = GetWindowThreadProcessId(hwndTop, _
ByVal 0&) Then
For Each F In Forms
If F.hwnd = hwndTop Then
Set GetLastActiveOwnedForm = F
Exit Function '======>>>
End If
Next
End If
hwndTop = GetWindow(hwndTop, GW_HWNDNEXT)
Loop
End Function
'ex usage...
Dim F As Form
Set F = GetLastActiveOwnedForm(Me)
If Not (F Is Nothing) Then
Debug.Print F.Name
End If
-Tom
MVP - Visual Basic
(please post replies to the newsgroup)
-