4 * application to test the various Window Enumeration functions
7 //#define WIN32_LEAN_AND_MEAN
15 const TCHAR* APP_NAME = "EnumWnd Test";
16 const TCHAR* CLASS_NAME = "EnumWndTestClass";
18 LRESULT WINAPI MainWndProc(HWND, UINT, WPARAM, LPARAM);
21 WinMain(HINSTANCE hInstance,
22 HINSTANCE hPrevInstance,
30 wc.lpszClassName = CLASS_NAME;
31 wc.lpfnWndProc = MainWndProc;
32 wc.style = CS_VREDRAW | CS_HREDRAW;
33 wc.hInstance = hInstance;
34 wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
35 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
36 wc.hbrBackground = (HBRUSH)GetStockObject(GRAY_BRUSH);
37 wc.lpszMenuName = NULL;
40 if (RegisterClass(&wc) == 0)
42 _ftprintf ( stderr, _T("RegisterClass failed (last error 0x%X)\n"),
47 hWnd = CreateWindow(CLASS_NAME,
60 _ftprintf ( stderr, _T("CreateWindow failed (last error 0x%X)\n"),
65 tf = CreateFont (14, 0, 0, TA_BASELINE, FW_NORMAL, FALSE, FALSE, FALSE,
66 ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
67 DEFAULT_QUALITY, FIXED_PITCH|FF_DONTCARE, _T("Timmons"));
69 hbrBackground = CreateSolidBrush ( RGB(192,192,192) );
71 ShowWindow ( hWnd, nCmdShow );
73 while(GetMessage(&msg, NULL, 0, 0))
75 TranslateMessage(&msg);
76 DispatchMessage(&msg);
79 DeleteObject(hbrBackground);
86 void MyTextOut ( HDC hdc, int x, int y, const TCHAR* text )
88 TextOut ( hdc, x, y, text, _tcslen(text) );
91 typedef struct _EnumData
98 BOOL CALLBACK MyWindowEnumProc ( HWND hwnd, LPARAM lParam )
100 TCHAR wndcaption[1024], buf[1024];
101 EnumData* ped = (EnumData*)lParam;
102 GetWindowText ( hwnd, wndcaption, sizeof(wndcaption)/sizeof(*wndcaption) );
103 _sntprintf ( buf, sizeof(buf)/sizeof(*buf), _T("%x - %s"), hwnd, wndcaption );
104 MyTextOut ( ped->hdc, ped->x, ped->y, buf );
109 LRESULT CALLBACK MainWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
120 hDC = BeginPaint(hWnd, &ps);
121 SelectObject(hDC, tf);
123 GetClientRect ( hWnd, &rect );
124 FillRect ( hDC, &rect, hbrBackground );
126 MyTextOut ( hDC, 10, 10, "EnumWnd Test" );
128 _sntprintf ( buf, sizeof(buf)/sizeof(*buf), _T("My HWND: %x"), hWnd );
129 MyTextOut ( hDC, 10, 30, buf );
138 MyTextOut ( hDC, 10, 50, _T("Test #1: EnumWindows()") );
139 EnumWindows ( MyWindowEnumProc, (LPARAM)&ed );
142 MyTextOut ( hDC, 10, 50, _T("Test #2: EnumChildWindows()") );
143 EnumChildWindows ( hWnd, MyWindowEnumProc, (LPARAM)&ed );
146 MyTextOut ( hDC, 10, 50, _T("Test #3: EnumDesktopWindows") );
147 EnumDesktopWindows ( NULL, MyWindowEnumProc, (LPARAM)&ed );
150 MyTextOut ( hDC, 10, 50, _T("Test #4: EnumThreadWindows") );
151 EnumThreadWindows ( GetCurrentThreadId(), MyWindowEnumProc, (LPARAM)&ed );
154 MyTextOut ( hDC, 10, 50, _T("Press any of the number keys from 1 to 4 to run a test") );
155 MyTextOut ( hDC, 10, 70, _T("Press the left and right mouse buttons to cycle through the tests") );
163 test = (TCHAR)wParam - '1' + 1;
164 RedrawWindow ( hWnd, NULL, NULL, RDW_INVALIDATE );
170 RedrawWindow ( hWnd, NULL, NULL, RDW_INVALIDATE );
176 RedrawWindow ( hWnd, NULL, NULL, RDW_INVALIDATE );
184 return DefWindowProc(hWnd, msg, wParam, lParam);