ReactOS 0.4.15-dev-7693-gd0e2924
enumwnd.c
Go to the documentation of this file.
1/*
2 * enumwnd.c
3 *
4 * application to test the various Window Enumeration functions
5 */
6
7//#define WIN32_LEAN_AND_MEAN
8#include <windows.h>
9#include <tchar.h>
10#include <stdio.h>
11
14int test = 0;
15const TCHAR* APP_NAME = "EnumWnd Test";
16const TCHAR* CLASS_NAME = "EnumWndTestClass";
17
19
20int WINAPI
22 HINSTANCE hPrevInstance,
23 LPSTR lpszCmdLine,
24 int nCmdShow)
25{
26 WNDCLASS wc;
27 MSG msg;
28 HWND hWnd;
29
37 wc.lpszMenuName = NULL;
38 wc.cbClsExtra = 0;
39 wc.cbWndExtra = 0;
40 if (RegisterClass(&wc) == 0)
41 {
42 _ftprintf ( stderr, _T("RegisterClass failed (last error 0x%lX)\n"),
43 GetLastError());
44 return(1);
45 }
46
50 0,
51 0,
54 NULL,
55 NULL,
57 NULL);
58 if (hWnd == NULL)
59 {
60 _ftprintf ( stderr, _T("CreateWindow failed (last error 0x%lX)\n"),
61 GetLastError());
62 return(1);
63 }
64
68
69 hbrBackground = CreateSolidBrush ( RGB(192,192,192) );
70
71 ShowWindow ( hWnd, nCmdShow );
72
73 while(GetMessage(&msg, NULL, 0, 0))
74 {
77 }
78
80
82
83 return msg.wParam;
84}
85
86void MyTextOut ( HDC hdc, int x, int y, const TCHAR* text )
87{
88 TextOut ( hdc, x, y, text, _tcslen(text) );
89}
90
91typedef struct _EnumData
92{
94 int x;
95 int y;
97
99{
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 );
105 ped->y += 13;
106 return TRUE;
107}
108
110{
111 PAINTSTRUCT ps;
112 HDC hDC;
113 RECT rect;
114 TCHAR buf[100];
115 EnumData ed;
116
117 switch(msg)
118 {
119 case WM_PAINT:
120 hDC = BeginPaint(hWnd, &ps);
122
123 GetClientRect ( hWnd, &rect );
125
126 MyTextOut ( hDC, 10, 10, "EnumWnd Test" );
127
128 _sntprintf ( buf, sizeof(buf)/sizeof(*buf), _T("My HWND: %x"), hWnd );
129 MyTextOut ( hDC, 10, 30, buf );
130
131 ed.hdc = hDC;
132 ed.x = 10;
133 ed.y = 70;
134
135 switch ( test )
136 {
137 case 1:
138 MyTextOut ( hDC, 10, 50, _T("Test #1: EnumWindows()") );
140 break;
141 case 2:
142 MyTextOut ( hDC, 10, 50, _T("Test #2: EnumChildWindows()") );
144 break;
145 case 3:
146 MyTextOut ( hDC, 10, 50, _T("Test #3: EnumDesktopWindows") );
148 break;
149 case 4:
150 MyTextOut ( hDC, 10, 50, _T("Test #4: EnumThreadWindows") );
152 break;
153 default:
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") );
156 break;
157 }
158
159 EndPaint(hWnd, &ps);
160 break;
161
162 case WM_CHAR:
163 test = (TCHAR)wParam - '1' + 1;
165 break;
166
167 case WM_LBUTTONDOWN:
168 if ( ++test > 4 )
169 test = 1;
171 break;
172
173 case WM_RBUTTONDOWN:
174 if ( !--test )
175 test = 4;
177 break;
178
179 case WM_DESTROY:
181 break;
182
183 default:
185 }
186 return 0;
187}
static HDC hDC
Definition: 3dtext.c:33
#define msg(x)
Definition: auth_time.c:54
HWND hWnd
Definition: settings.c:17
HINSTANCE hInstance
Definition: charmap.c:19
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define CALLBACK
Definition: compat.h:35
const WCHAR * text
Definition: package.c:1799
#define RGB(r, g, b)
Definition: precomp.h:62
const TCHAR * CLASS_NAME
Definition: enumwnd.c:16
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow)
Definition: enumwnd.c:21
int test
Definition: enumwnd.c:14
HBRUSH hbrBackground
Definition: enumwnd.c:12
LRESULT WINAPI MainWndProc(HWND, UINT, WPARAM, LPARAM)
Definition: enumwnd.c:109
BOOL CALLBACK MyWindowEnumProc(HWND hwnd, LPARAM lParam)
Definition: enumwnd.c:98
HFONT tf
Definition: enumwnd.c:13
struct _EnumData EnumData
void MyTextOut(HDC hdc, int x, int y, const TCHAR *text)
Definition: enumwnd.c:86
const TCHAR * APP_NAME
Definition: enumwnd.c:15
unsigned int BOOL
Definition: ntddk_ex.h:94
pKey DeleteObject()
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define stderr
Definition: stdio.h:100
#define _ftprintf
Definition: tchar.h:518
HDC hdc
Definition: main.c:9
static HDC
Definition: imagelist.c:92
static DWORD *static HFONT(WINAPI *pCreateFontIndirectExA)(const ENUMLOGFONTEXDVA *)
unsigned int UINT
Definition: ndis.h:50
#define WS_OVERLAPPEDWINDOW
Definition: pedump.c:637
#define DefWindowProc
Definition: ros2win.h:31
& rect
Definition: startmenu.cpp:1413
int x
Definition: enumwnd.c:94
HDC hdc
Definition: enumwnd.c:93
int y
Definition: enumwnd.c:95
HBRUSH hbrBackground
Definition: winuser.h:3169
HICON hIcon
Definition: winuser.h:3167
HINSTANCE hInstance
Definition: winuser.h:3166
HCURSOR hCursor
Definition: winuser.h:3168
int cbWndExtra
Definition: winuser.h:3165
UINT style
Definition: winuser.h:3162
LPCSTR lpszMenuName
Definition: winuser.h:3170
LPCSTR lpszClassName
Definition: winuser.h:3171
WNDPROC lpfnWndProc
Definition: winuser.h:3163
int cbClsExtra
Definition: winuser.h:3164
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1829
#define _T(x)
Definition: vfdio.h:22
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
DWORD WINAPI GetCurrentThreadId(void)
Definition: thread.c:459
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023
LONG_PTR LPARAM
Definition: windef.h:208
LONG_PTR LRESULT
Definition: windef.h:209
UINT_PTR WPARAM
Definition: windef.h:207
#define WINAPI
Definition: msvc.h:6
#define FIXED_PITCH
Definition: wingdi.h:444
HGDIOBJ WINAPI GetStockObject(_In_ int)
#define DEFAULT_QUALITY
Definition: wingdi.h:436
#define FF_DONTCARE
Definition: wingdi.h:448
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1539
#define GRAY_BRUSH
Definition: wingdi.h:898
#define OUT_DEFAULT_PRECIS
Definition: wingdi.h:415
#define CreateFont
Definition: wingdi.h:4443
#define ANSI_CHARSET
Definition: wingdi.h:383
#define CLIP_DEFAULT_PRECIS
Definition: wingdi.h:426
#define FW_NORMAL
Definition: wingdi.h:373
#define TA_BASELINE
Definition: wingdi.h:928
int WINAPI FillRect(HDC, LPCRECT, HBRUSH)
HBRUSH WINAPI CreateSolidBrush(_In_ COLORREF)
#define TextOut
Definition: wingdi.h:4483
#define WM_PAINT
Definition: winuser.h:1619
#define CS_VREDRAW
Definition: winuser.h:658
BOOL WINAPI RedrawWindow(_In_opt_ HWND, _In_opt_ LPCRECT, _In_opt_ HRGN, _In_ UINT)
BOOL WINAPI TranslateMessage(_In_ const MSG *)
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
__analysis_noreturn void WINAPI PostQuitMessage(_In_ int)
#define CS_HREDRAW
Definition: winuser.h:653
#define IDC_ARROW
Definition: winuser.h:687
#define WM_LBUTTONDOWN
Definition: winuser.h:1775
BOOL WINAPI EnumChildWindows(_In_opt_ HWND, _In_ WNDENUMPROC, _In_ LPARAM)
#define IDI_APPLICATION
Definition: winuser.h:704
#define CreateWindow
Definition: winuser.h:5753
#define WM_RBUTTONDOWN
Definition: winuser.h:1778
#define GetMessage
Definition: winuser.h:5789
BOOL WINAPI GetClientRect(_In_ HWND, _Out_ LPRECT)
BOOL WINAPI EnumWindows(_In_ WNDENUMPROC lpEnumFunc, _In_ LPARAM lParam)
BOOL WINAPI EndPaint(_In_ HWND, _In_ const PAINTSTRUCT *)
#define LoadIcon
Definition: winuser.h:5812
#define LoadCursor
Definition: winuser.h:5811
#define WM_CHAR
Definition: winuser.h:1716
#define GetWindowText
Definition: winuser.h:5797
#define CW_USEDEFAULT
Definition: winuser.h:225
BOOL WINAPI EnumDesktopWindows(_In_opt_ HDESK, _In_ WNDENUMPROC, _In_ LPARAM)
#define RegisterClass
Definition: winuser.h:5835
#define WM_DESTROY
Definition: winuser.h:1608
#define DispatchMessage
Definition: winuser.h:5764
HDC WINAPI BeginPaint(_In_ HWND, _Out_ LPPAINTSTRUCT)
BOOL WINAPI EnumThreadWindows(_In_ DWORD, _In_ WNDENUMPROC, _In_ LPARAM)
#define RDW_INVALIDATE
Definition: winuser.h:1213
char TCHAR
Definition: xmlstorage.h:189
char * LPSTR
Definition: xmlstorage.h:182
const CHAR * LPCTSTR
Definition: xmlstorage.h:193
#define _sntprintf
Definition: xmlstorage.h:201
#define _tcslen
Definition: xmlstorage.h:198