Enumerating Windows on Taskbar

$SAMPLECODE$

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60

#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

Comments