Something went wrong. Try again.
Reactos
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188/* * enumwnd.c * * application to test the various Window Enumeration functions */
//#define WIN32_LEAN_AND_MEAN#include <windows.h>#include <tchar.h>#include <stdio.h>
HBRUSH hbrBackground;HFONT tf;int test = 0;const TCHAR* APP_NAME = "EnumWnd Test";const TCHAR* CLASS_NAME = "EnumWndTestClass";
LRESULT WINAPI MainWndProc(HWND, UINT, WPARAM, LPARAM);
int WINAPIWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow){ WNDCLASS wc; MSG msg; HWND hWnd;
wc.lpszClassName = CLASS_NAME; wc.lpfnWndProc = MainWndProc; wc.style = CS_VREDRAW | CS_HREDRAW; wc.hInstance = hInstance; wc.hIcon = LoadIcon(NULL, (LPCTSTR)IDI_APPLICATION); wc.hCursor = LoadCursor(NULL, (LPCTSTR)IDC_ARROW); wc.hbrBackground = (HBRUSH)GetStockObject(GRAY_BRUSH); wc.lpszMenuName = NULL; wc.cbClsExtra = 0; wc.cbWndExtra = 0; if (RegisterClass(&wc) == 0) { _ftprintf ( stderr, _T("RegisterClass failed (last error 0x%lX)\n"), GetLastError()); return(1); }
hWnd = CreateWindow(CLASS_NAME, APP_NAME, WS_OVERLAPPEDWINDOW, 0, 0, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL); if (hWnd == NULL) { _ftprintf ( stderr, _T("CreateWindow failed (last error 0x%lX)\n"), GetLastError()); return(1); }
tf = CreateFont (14, 0, 0, TA_BASELINE, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, FIXED_PITCH|FF_DONTCARE, _T("Timmons"));
hbrBackground = CreateSolidBrush ( RGB(192,192,192) );
ShowWindow ( hWnd, nCmdShow );
while(GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); }
DeleteObject(hbrBackground);
DeleteObject(tf);
return msg.wParam;}
void MyTextOut ( HDC hdc, int x, int y, const TCHAR* text ){ TextOut ( hdc, x, y, text, _tcslen(text) );}
typedef struct _EnumData{ HDC hdc; int x; int y;} EnumData;
BOOL CALLBACK MyWindowEnumProc ( HWND hwnd, LPARAM lParam ){ TCHAR wndcaption[1024], buf[1024]; EnumData* ped = (EnumData*)lParam; GetWindowText ( hwnd, wndcaption, sizeof(wndcaption)/sizeof(*wndcaption) ); _sntprintf ( buf, sizeof(buf)/sizeof(*buf), _T("%x - %s"), hwnd, wndcaption ); MyTextOut ( ped->hdc, ped->x, ped->y, buf ); ped->y += 13; return TRUE;}
LRESULT CALLBACK MainWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam){ PAINTSTRUCT ps; HDC hDC; RECT rect; TCHAR buf[100]; EnumData ed;
switch(msg) { case WM_PAINT: hDC = BeginPaint(hWnd, &ps); SelectObject(hDC, tf);
GetClientRect ( hWnd, &rect ); FillRect ( hDC, &rect, hbrBackground );
MyTextOut ( hDC, 10, 10, "EnumWnd Test" );
_sntprintf ( buf, sizeof(buf)/sizeof(*buf), _T("My HWND: %x"), hWnd ); MyTextOut ( hDC, 10, 30, buf );
ed.hdc = hDC; ed.x = 10; ed.y = 70;
switch ( test ) { case 1: MyTextOut ( hDC, 10, 50, _T("Test #1: EnumWindows()") ); EnumWindows ( MyWindowEnumProc, (LPARAM)&ed ); break; case 2: MyTextOut ( hDC, 10, 50, _T("Test #2: EnumChildWindows()") ); EnumChildWindows ( hWnd, MyWindowEnumProc, (LPARAM)&ed ); break; case 3: MyTextOut ( hDC, 10, 50, _T("Test #3: EnumDesktopWindows") ); EnumDesktopWindows ( NULL, MyWindowEnumProc, (LPARAM)&ed ); break; case 4: MyTextOut ( hDC, 10, 50, _T("Test #4: EnumThreadWindows") ); EnumThreadWindows ( GetCurrentThreadId(), MyWindowEnumProc, (LPARAM)&ed ); break; default: MyTextOut ( hDC, 10, 50, _T("Press any of the number keys from 1 to 4 to run a test") ); MyTextOut ( hDC, 10, 70, _T("Press the left and right mouse buttons to cycle through the tests") ); break; }
EndPaint(hWnd, &ps); break;
case WM_CHAR: test = (TCHAR)wParam - '1' + 1; RedrawWindow ( hWnd, NULL, NULL, RDW_INVALIDATE ); break;
case WM_LBUTTONDOWN: if ( ++test > 4 ) test = 1; RedrawWindow ( hWnd, NULL, NULL, RDW_INVALIDATE ); break;
case WM_RBUTTONDOWN: if ( !--test ) test = 4; RedrawWindow ( hWnd, NULL, NULL, RDW_INVALIDATE ); break;
case WM_DESTROY: PostQuitMessage(0); break;
default: return DefWindowProc(hWnd, msg, wParam, lParam); } return 0;}