We can always enumerate all windows with 'EnumWindows'.
But how can we filter it to show the windows that taskbar shows
Printable View
We can always enumerate all windows with 'EnumWindows'.
But how can we filter it to show the windows that taskbar shows
I recently got this working myself, its more complex than I thought it would be...
In a module :
VB Code:
Public Function EnumWindowsProc(ByVal hwnd As Long, ByVal lParam As Long) As Boolean Dim lReturn As Long Dim lExStyle As Long Dim bNoOwner As Boolean Dim sWindowText As String Dim sWin As String ' ' This callback function is called by Windows (from ' the EnumWindows API call) for EVERY window that exists. ' It populates the combobox with a list of windows that we ' are interested in. ' ' Windows to display are those that: ' - are not this app's ' - are visible ' - do not have a parent ' - have no owner and are not Tool windows OR ' have an owner and are App windows ' sWin = Space$(256) sWin = GetClassName(hwnd, sWin, Len(sWin)) If IsWindowVisible(hwnd) Then If GetParent(hwnd) = 0 Then bNoOwner = (GetWindow(hwnd, GW_OWNER) = 0) lExStyle = GetWindowLong(hwnd, GWL_EXSTYLE) If (((lExStyle And WS_EX_TOOLWINDOW) = 0) And bNoOwner) Or _ ((lExStyle And WS_EX_APPWINDOW) And Not bNoOwner) Then ' ' Get the window's caption. ' sWindowText = Space$(256) lReturn = GetWindowText(hwnd, sWindowText, Len(sWindowText)) If lReturn Then ' ' Add it to our list. ' WindCount = WindCount + 1 sWindowText = Left$(sWindowText, lReturn) frmFindWindow.cboWindows.AddItem sWindowText End If End If End If End If EnumWindowsProc = True End Function
In your form :
VB Code:
Private Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Boolean Call EnumWindows(AddressOf EnumWindowsProc, frmFindWindow.cboWindows.hwnd)
Could you please include your declares and constants. It is a little bit tedious to go through your code to find what needs to be declared and what does not. Thank you.
Joe
You mean these ones ?
VB Code:
Public Const WS_EX_TOOLWINDOW = &H80 Public Const WS_EX_APPWINDOW = &H40000 Public Const GW_OWNER = 4 Public Const GWL_EXSTYLE = (-20)
:D