ReactOS  0.4.14-dev-317-g96040ec
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 
14 int test = 0;
15 const TCHAR* APP_NAME = "EnumWnd Test";
16 const TCHAR* CLASS_NAME = "EnumWndTestClass";
17 
19 
20 int WINAPI
22  HINSTANCE hPrevInstance,
23  LPSTR lpszCmdLine,
24  int nCmdShow)
25 {
26  WNDCLASS wc;
27  MSG msg;
28  HWND hWnd;
29 
33  wc.hInstance = hInstance;
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 
48  APP_NAME,
50  0,
51  0,
54  NULL,
55  NULL,
56  hInstance,
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 
86 void MyTextOut ( HDC hdc, int x, int y, const TCHAR* text )
87 {
88  TextOut ( hdc, x, y, text, _tcslen(text) );
89 }
90 
91 typedef struct _EnumData
92 {
94  int x;
95  int y;
96 } EnumData;
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);
121  SelectObject(hDC, tf);
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:
180  PostQuitMessage(0);
181  break;
182 
183  default:
184  return DefWindowProc(hWnd, msg, wParam, lParam);
185  }
186  return 0;
187 }
HGDIOBJ WINAPI GetStockObject(_In_ int)
BOOL WINAPI EnumChildWindows(_In_opt_ HWND, _In_ WNDENUMPROC, _In_ LPARAM)
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
BOOL WINAPI RedrawWindow(_In_opt_ HWND, _In_opt_ LPCRECT, _In_opt_ HRGN, _In_ UINT)
#define DispatchMessage
Definition: winuser.h:5666
BOOL WINAPI TranslateMessage(_In_ const MSG *)
#define TRUE
Definition: types.h:120
const CHAR * LPCTSTR
Definition: xmlstorage.h:193
int x
Definition: enumwnd.c:94
#define DEFAULT_QUALITY
Definition: wingdi.h:435
#define WM_CHAR
Definition: winuser.h:1699
#define WM_LBUTTONDOWN
Definition: winuser.h:1758
#define CreateWindow
Definition: winuser.h:5655
#define FF_DONTCARE
Definition: wingdi.h:447
const TCHAR * APP_NAME
Definition: enumwnd.c:15
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
const WCHAR * text
Definition: package.c:1827
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1827
static HDC
Definition: imagelist.c:92
HBRUSH hbrBackground
Definition: enumwnd.c:12
#define CALLBACK
Definition: compat.h:27
HWND hWnd
Definition: settings.c:17
LRESULT WINAPI MainWndProc(HWND, UINT, WPARAM, LPARAM)
Definition: enumwnd.c:109
BOOL WINAPI EnumThreadWindows(_In_ DWORD, _In_ WNDENUMPROC, _In_ LPARAM)
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1497
int cbClsExtra
Definition: winuser.h:3139
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
#define CS_HREDRAW
Definition: winuser.h:648
LPCSTR lpszMenuName
Definition: winuser.h:3145
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
#define IDI_APPLICATION
Definition: winuser.h:699
UINT_PTR WPARAM
Definition: windef.h:207
HBRUSH hbrBackground
Definition: winuser.h:3144
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
BOOL WINAPI EndPaint(_In_ HWND, _In_ const PAINTSTRUCT *)
char * LPSTR
Definition: xmlstorage.h:182
HDC hdc
Definition: enumwnd.c:93
& rect
Definition: startmenu.cpp:1413
WPARAM wParam
Definition: combotst.c:138
#define GetWindowText
Definition: winuser.h:5699
BOOL WINAPI EnumDesktopWindows(_In_opt_ HDESK, _In_ WNDENUMPROC, _In_ LPARAM)
int cbWndExtra
Definition: winuser.h:3140
HINSTANCE hInstance
Definition: charmap.c:20
unsigned int BOOL
Definition: ntddk_ex.h:94
#define FIXED_PITCH
Definition: wingdi.h:443
HDC WINAPI BeginPaint(_In_ HWND, _Out_ LPPAINTSTRUCT)
#define TA_BASELINE
Definition: wingdi.h:927
#define CLIP_DEFAULT_PRECIS
Definition: wingdi.h:425
HCURSOR hCursor
Definition: winuser.h:3143
#define CW_USEDEFAULT
Definition: winuser.h:225
#define CreateFont
Definition: wingdi.h:4438
size_t __cdecl _tcslen(const _TCHAR *str)
Definition: tcslen.h:9
smooth NULL
Definition: ftsmooth.c:416
LONG_PTR LPARAM
Definition: windef.h:208
struct _EnumData EnumData
#define GRAY_BRUSH
Definition: wingdi.h:897
#define _ftprintf
Definition: tchar.h:518
DWORD WINAPI GetCurrentThreadId(VOID)
Definition: thread.c:458
#define DefWindowProc
Definition: ros2win.h:31
#define WM_DESTROY
Definition: winuser.h:1591
#define WM_RBUTTONDOWN
Definition: winuser.h:1761
#define CS_VREDRAW
Definition: winuser.h:653
char TCHAR
Definition: xmlstorage.h:189
#define _T(x)
Definition: vfdio.h:22
#define RGB(r, g, b)
Definition: wingdi.h:2935
#define WINAPI
Definition: msvc.h:8
BOOL WINAPI EnumWindows(_In_ WNDENUMPROC, _In_ LPARAM)
#define OUT_DEFAULT_PRECIS
Definition: wingdi.h:414
#define WM_PAINT
Definition: winuser.h:1602
BOOL CALLBACK MyWindowEnumProc(HWND hwnd, LPARAM lParam)
Definition: enumwnd.c:98
HDC hdc
Definition: main.c:9
#define _sntprintf
Definition: xmlstorage.h:201
const TCHAR * CLASS_NAME
Definition: enumwnd.c:16
LPCSTR lpszClassName
Definition: winuser.h:3146
#define LoadCursor
Definition: winuser.h:5713
void MyTextOut(HDC hdc, int x, int y, const TCHAR *text)
Definition: enumwnd.c:86
HFONT tf
Definition: enumwnd.c:13
UINT style
Definition: winuser.h:3137
static HDC hDC
Definition: 3dtext.c:33
BOOL WINAPI GetClientRect(_In_ HWND, _Out_ LPRECT)
HINSTANCE hInstance
Definition: winuser.h:3141
unsigned int UINT
Definition: ndis.h:50
HBRUSH WINAPI CreateSolidBrush(_In_ COLORREF)
#define GetMessage
Definition: winuser.h:5691
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
#define FW_NORMAL
Definition: wingdi.h:372
WNDPROC lpfnWndProc
Definition: winuser.h:3138
static DWORD *static HFONT(WINAPI *pCreateFontIndirectExA)(const ENUMLOGFONTEXDVA *)
#define msg(x)
Definition: auth_time.c:54
#define IDC_ARROW
Definition: winuser.h:682
int y
Definition: enumwnd.c:95
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow)
Definition: enumwnd.c:21
#define WS_OVERLAPPEDWINDOW
Definition: pedump.c:637
#define TextOut
Definition: wingdi.h:4478
FILE * stderr
#define RegisterClass
Definition: winuser.h:5737
#define LoadIcon
Definition: winuser.h:5714
#define ANSI_CHARSET
Definition: wingdi.h:382
LONG_PTR LRESULT
Definition: windef.h:209
int test
Definition: enumwnd.c:14
int WINAPI FillRect(HDC, LPCRECT, HBRUSH)
EXTENT_DATA * ed
Definition: write.c:2818
LPARAM lParam
Definition: combotst.c:139
__analysis_noreturn void WINAPI PostQuitMessage(_In_ int)
#define RDW_INVALIDATE
Definition: winuser.h:1200
HICON hIcon
Definition: winuser.h:3142