Enumerating Windows on Taskbar

This is sample code. Add error handling and adjust to your requirements as necessary.

#define GW_HWNDFIRST        0
#define GW_HWNDLAST         1
#define GW_HWNDNEXT         2
#define GW_HWNDPREV         3
#define GW_OWNER            4
#define GW_CHILD            5
 
DECLARE Long GetWindow IN WIN32API Long hWnd, Long uCmd
DECLARE Long GetWindowText IN WIN32API Long hWnd, String @lpString, Long nMaxCount
DECLARE INTEGER GetDesktopWindow IN Win32API
DECLARE LONG GetWindowLong IN WIN32API Long hWnd, Long nIndex
 
#define GWL_EXSTYLE 		-20
#define GWL_STYLE 			-16
 
#define WS_EX_APPWINDOW  	0x00040000
 
#define WS_VISIBLE 			0x10000000
#define WS_POPUP   			0x80000000
 
CREATE CURSOR crsWindows ( ;
	hwnd I, WindTitle C(50))
 
lhWnd = GetDesktopWindow()
lhWnd = GetWindow(lhwnd, GW_CHILD) 
 
* Itterate through all TOP-Level windows
DO WHILE lhWnd > 0
	m.WindTitle = GetTitle(lhWnd)
	IF NOT EMPTY(m.WindTitle)
		m.hwnd 	= lhWnd
		m.Style = GetWindowLong(lhWnd, GWL_STYLE)
		m.hex 	= TRANSFORM(m.Style, "@0")
 
		* Check if window is visible and isn't WS_POPUP style
		IF  BITAND(m.Style, WS_VISIBLE) > 0 ;
				AND BITAND(m.Style, WS_POPUP) = 0
			INSERT INTO crsWindows FROM MEMVAR
		ENDIF
	ENDIF
	* Get next window in Z order
	lhWnd = GetWindow(lhWnd, GW_HWNDNEXT )
ENDDO
 
*BROWSE NOWAIT
RETURN
 
FUNCTION GetTitle(lhWnd)
LOCAL lcTitle
lcTitle = Space(512)
lnTitle = GetWindowText(lhWnd , @lcTitle, 256)
IF lnTitle > 0
	lcTitle = Left(lcTitle, lnTitle )
ELSE
	lcTitle = ""
ENDIF
RETURN lcTitle
Your rating: None Average: 2 (1 vote)