test case for EnumWindows, EnumChildWindows, etc... all functions that make use of NtUserBuildHwndList

svn path=/trunk/; revision=5263
This commit is contained in:
Royce Mitchell III 2003-07-25 19:13:14 +00:00
parent a5abfe745b
commit 1e85120647
4 changed files with 308 additions and 0 deletions

View file

@ -0,0 +1,6 @@
*.exe
*.sym
*.coff
*.d
*.o
*.map

View file

@ -0,0 +1,191 @@
/*
* 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 WINAPI
WinMain(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, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, 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%X)\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%X)\n"),
GetLastError());
return(1);
}
tf = CreateFont (13, 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("%i - %s"), hwnd, wndcaption );
MyTextOut ( ped->hdc, ped->x, ped->y, buf );
ped->y += 12;
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("%d,%d,%d,%d"), rect.left, rect.top, rect.right, rect.bottom );
MyTextOut ( hDC, 10, 30, buf );
GetWindowRect(hWnd, &rect );
_sntprintf ( buf, sizeof(buf)/sizeof(*buf), _T("%d,%d,%d,%d"), rect.left, rect.top, rect.right, rect.bottom );
MyTextOut ( hDC, 10, 50, buf );
ed.hdc = hDC;
ed.x = 10;
ed.y = 90;
switch ( test )
{
case 1:
MyTextOut ( hDC, 10, 70, _T("Test #1: EnumWindows()") );
EnumWindows ( MyWindowEnumProc, (LPARAM)&ed );
break;
case 2:
MyTextOut ( hDC, 10, 70, _T("Test #2: EnumChildWindows()") );
EnumChildWindows ( hWnd, MyWindowEnumProc, (LPARAM)&ed );
break;
case 3:
MyTextOut ( hDC, 10, 70, _T("Test #3: EnumDesktopWindows") );
EnumDesktopWindows ( NULL, MyWindowEnumProc, (LPARAM)&ed );
break;
case 4:
MyTextOut ( hDC, 10, 70, _T("Test #4: EnumThreadWindows") );
EnumThreadWindows ( GetCurrentThreadId(), MyWindowEnumProc, (LPARAM)&ed );
break;
default:
MyTextOut ( hDC, 10, 70, _T("Press any of the number keys from 1 to 4 to run a test") );
MyTextOut ( hDC, 10, 90, _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;
}

View file

@ -0,0 +1,90 @@
# Microsoft Developer Studio Project File - Name="enumwnd" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Console Application" 0x0103
CFG=enumwnd - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "enumwnd.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "enumwnd.mak" CFG="enumwnd - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "enumwnd - Win32 Release" (based on "Win32 (x86) Console Application")
!MESSAGE "enumwnd - Win32 Debug" (based on "Win32 (x86) Console Application")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
RSC=rc.exe
!IF "$(CFG)" == "enumwnd - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "Release"
# PROP Intermediate_Dir "Release"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
!ELSEIF "$(CFG)" == "enumwnd - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "Debug"
# PROP Intermediate_Dir "Debug"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /debug /machine:I386 /pdbtype:sept
# SUBTRACT LINK32 /pdb:none
!ENDIF
# Begin Target
# Name "enumwnd - Win32 Release"
# Name "enumwnd - Win32 Debug"
# Begin Source File
SOURCE=.\enumwnd.c
# End Source File
# End Target
# End Project

View file

@ -0,0 +1,21 @@
# $Id: makefile,v 1.1 2003/07/25 19:13:14 royce Exp $
PATH_TO_TOP = ../../..
TARGET_NORC = yes
TARGET_TYPE = program
TARGET_APPTYPE = windows
TARGET_NAME = enumwnd
TARGET_SDKLIBS = kernel32.a gdi32.a
TARGET_OBJECTS = $(TARGET_NAME).o
include $(PATH_TO_TOP)/rules.mak
include $(TOOLS_PATH)/helper.mk
# EOF