|
-
Feb 19th, 2001, 03:58 AM
#1
Thread Starter
Lively Member
Is there a way to find out the class name of active window & then use this class name & findwindowex api to obtain the handles of the child windows of the active window ?
-
Feb 19th, 2001, 04:14 AM
#2
If it is just the active window you are interested in, then Declare Function GetActiveWindow& Lib "user32" ()
dim hwnd as long
hwnd = GetActiveWindow()
will give you the handle of the active window. Use this instead of the class name in the findwindowex function. It will accept either.
-
Feb 19th, 2001, 07:19 AM
#3
Thread Starter
Lively Member
Hi Orwell , my code is shown below whereby i only used
the caption to find the child handles using findwindowex api . But the returned value is 0 . Can you guide me why this is so ?
fish = GetForegroundWindow()
x = GetActiveWindowTitle(True)
hWnd_MD = FindWindowEx(0, 0, vbNullString, x)
' in module
Public Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
Public sClassname As String
Public r As String
Public fish As Long
Public j As Long
Public Declare Function FindWindowEx _
Lib "user32" Alias "FindWindowExA" _
(ByVal hWnd1 As Long, _
ByVal hWnd2 As Long, _
ByVal lpsz1 As String, _
ByVal lpsz2 As String) As Long
Public Declare Function GetForegroundWindow Lib "user32.dll" () As Long
' Returns the title of the active window.
' if GetParent = true then the parent window is
' returned.
Public Function GetActiveWindowTitle(ByVal ReturnParent As Boolean) As String
fish = GetForegroundWindow
If ReturnParent Then
Do While fish <> 0
j = fish
fish = GetParent(fish)
Loop
fish = j
End If
GetActiveWindowTitle = GetWindowTitle(fish)
End Function
Public Function GetWindowTitle(ByVal hwnd As Long) As String
Dim l As Long
Dim s As String
l = GetWindowTextLength(hwnd)
s = Space(l + 1)
GetWindowText hwnd, s, l + 1
GetWindowTitle = Left$(s, l)
End Function
-
Feb 20th, 2001, 03:13 AM
#4
fish = GetForegroundWindow()
minnow = findwindowex(fish, 0, vbnullstring, vbnullstring)
will store the handle to a child window in minnow.
I am not sure why you were using the caption, but in your code sample, it is not necessary.
This code will find all of the child windows:
fish = GetForegroundWindow()
minnow = 0
do
minnow = findwindowex(fish, minnow, vbnullstring, vbnullstring)
debug.print minnow
loop until minnow = 0
Last edited by Lord Orwell; Feb 20th, 2001 at 04:25 AM.
-
Feb 20th, 2001, 04:47 AM
#5
Fanatic Member
Lord Orwell
Can you really use the hWnd instead of the classname? Thanks for that - tip of the day!! I never saw that documented anywhere - cool - that makes my life a lot easier.
Crispin
VB6 ENT SP5
VB.NET
W2K ADV SVR SP3
WWW.BLOCKSOFT.CO.UK
[Microsoft Basic: 1976-2001, RIP]
-
Feb 20th, 2001, 03:52 PM
#6
Why not just use the EnumChildWindows API function.
-
Feb 21st, 2001, 12:11 AM
#7
[edited to correct my errors )
How about a code sample? I have never needed that api call, and would like to see an example of it used.
Last edited by Lord Orwell; Feb 21st, 2001 at 12:16 AM.
-
Feb 21st, 2001, 04:37 AM
#8
Thread Starter
Lively Member
Hi Orwell , my code which i want to save all the child handles to a dynamic array cannot work saying subscript out of range , can you help me ?
Public lHwnd() As long
Public iCount As Integer
iCount = 0
ReDim Preserve lHwnd(iCount)
fish = GetForegroundWindow()
hWnd_MD = FindWindowEx(fish, 0, vbNullString, vbNullString)
Do
hWnd_MD = FindWindowEx(fish, hWnd_MD, vbNullString, vbNullString)
lHwnd(iCount) = hWnd_MD
iCount = iCount + 1
Loop Until hWnd_MD = 0
------------------------------------------------------------------------
Originally posted by Lord Orwell
fish = GetForegroundWindow()
minnow = findwindowex(fish, 0, vbnullstring, vbnullstring)
will store the handle to a child window in minnow.
I am not sure why you were using the caption, but in your code sample, it is not necessary.
This code will find all of the child windows:
fish = GetForegroundWindow()
minnow = 0
do
minnow = findwindowex(fish, minnow, vbnullstring, vbnullstring)
debug.print minnow
loop until minnow = 0
-
Feb 21st, 2001, 03:29 PM
#9
Here's an example of using EnumChildWindows.
Add to a Module.
Code:
Declare Function EnumChildWindows Lib "user32" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Public lHwnd() As Long
Public iCount As Integer
Function EnumChildProc(ByVal hwnd As Long, ByVal lParam As Long) As Long
iCount = iCount + 1
ReDim Preserve lHwnd(iCount)
lHwnd(iCount) = hwnd
EnumChildProc = 1
End Function
Add to a Form
Code:
Private Sub Command1_Click()
EnumChildWindows hwnd, AddressOf EnumChildProc, 0
For i = 0 To UBound(lHwnd)
Debug.Print lHwnd(i)
Next i
End Sub
-
Feb 21st, 2001, 09:10 PM
#10
Megatron thanks for the code sample. It answers a question or two i had 
Eng70640 The problem with your code is you are redimming the size of the array to zero. I can see what you were trying to do. You should have put the redim inside of the loop.
Working code(i hope ):
Public lHwnd(0) As long
Public iCount As Integer
iCount = 0
ReDim Preserve lHwnd(iCount)
fish = GetForegroundWindow()
hWnd_MD = FindWindowEx(fish, 0, vbNullString, vbNullString)
Do
iCount = iCount + 1
hWnd_MD = FindWindowEx(fish, hWnd_MD,
vbNullString, vbNullString)
if hWnd_MD > 0 then
Redim Preserve lHwnd(iCount)
lHwnd(iCount) = hWnd_MD
end if
Loop Until hWnd_MD = 0
-
Feb 22nd, 2001, 02:37 AM
#11
Thread Starter
Lively Member
-
Feb 22nd, 2001, 02:39 AM
#12
Thread Starter
Lively Member
Moreover , i have deleted the line 'icount = 0' & there is still error .
-
Feb 23rd, 2001, 12:06 AM
#13
heh i declared the array incorrectly.
To be able to resize an array, lHwnd has to be declared
like this:
dim lHwnd() as long
not like this:
dim lHwnd(0) as long
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|