|
-
Mar 17th, 2000, 01:11 AM
#1
Thread Starter
Member
Hi, thank you for enter, i need help on how to use the API EnumWindows [Public Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long]
Please help me understand what is the lpEnumFunc and lParam .
Thank you very much,
Kiron.
-
Mar 17th, 2000, 01:26 AM
#2
EnumWindows does what the name suggests, it Enumerates all Windows, (Top Level), and passes the Window Handle to the specified Callback Function, (lpEnumFunc), along with a user defined value, (lParam).
You can use the Function to obtain a list of currently active Windows, ie.
Code:
'---[In a Module]---
Private Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hWnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private sWindows() As String
Private iWindows As Long
Private Function EnumWindowsProc(ByVal hWnd As Long, ByVal lParam As Long) As Long
Dim sCaption As String * 255
If hWnd Then
'A Valid Window Handle
'Add Window Caption to Array
ReDim Preserve sWindows(iWindows)
sWindows(iWindows) = Left$(sCaption, GetWindowText(hWnd, sCaption, 255))
iWindows = iWindows + 1
End If
'Continue Enumeration whilst there is a Valid Window Handle
EnumWindowsProc = hWnd
End Function
Public Function ListWindows() As Variant
'Initialise the Temporary Array
'Used to Store a List of Open Windows
ReDim sWindows(0)
iWindows = 0
'Call the Enumeration Function
Call EnumWindows(AddressOf EnumWindowsProc, 0&)
'Pass back the Array of Enumerated Windows
ListWindows = sWindows
End Function
Code:
---[In a Form with a Listbox and Command Button]---
Private Sub Command1_Click()
Dim vWins As Variant
Dim iIndex As Long
List1.Clear
vWins = ListWindows
'Add Retrieved Window Captions to a Listbox
'Exclude those with No Caption
For iIndex = 0 To UBound(vWins)
If Len(Trim(vWins(iIndex))) Then List1.AddItem vWins(iIndex)
Next
End Sub
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
|