diff --git a/rosapps/tests/Makefile b/rosapps/tests/Makefile new file mode 100644 index 00000000000..5dbb14956ff --- /dev/null +++ b/rosapps/tests/Makefile @@ -0,0 +1,113 @@ +# +# ReactOS test applications makefile +# + +PATH_TO_TOP = ../../reactos + +include $(PATH_TO_TOP)/rules.mak + +TEST_APPS = \ + accelerator \ + alive \ + alphablend \ + apc \ + apc2 \ + args \ + atomtest \ + bench \ + bitblt \ + button \ + button2 \ + capclock \ + carets \ + combo \ + consume \ + copymove \ + count \ + dibtest \ + dirdlg \ + dump_shared_data \ + edit \ + enhmetafile \ + enumwnd \ + enumws \ + event \ + eventpair \ + fiber \ + global_mem \ + gradient \ + guithreadinfo \ + hello \ + mdi \ + hivetest \ + icontest \ + isotest \ + lineclip \ + linetest \ + lpc \ + map_dup_inherit \ + mktime \ + mstest \ + multithrdwin \ + multiwin \ + mutex \ + nptest \ + patblt \ + popupmenu \ + primitives \ + pteb \ + p_dup_handle \ + regtest \ + sectest \ + sertest \ + shaptest \ + shm \ + statst \ + statst2 \ + stretchblt \ + suspend \ + tcpsvr \ + terminate \ + txtscale \ + thread \ + thread_msg \ + threadwait \ + tokentest \ + vmtest \ + winhello \ + wm_erasebkgnd \ + wm_paint + +all: $(TEST_APPS) + +depends: + +implib: $(TEST_APPS:%=%_implib) + +clean: $(TEST_APPS:%=%_clean) + +install: $(TEST_APPS:%=%_install) + +.PHONY: all depends implib clean install + +# +# Test Applications +# +$(TEST_APPS): %: + $(MAKE) -C $* + +$(TEST_APPS:%=%_implib): %_implib: + $(MAKE) -C $* implib + +$(TEST_APPS:%=%_clean): %_clean: + $(MAKE) -C $* clean + +$(TEST_APPS:%=%_install): %_install: + $(MAKE) -C $* install + +.PHONY: $(TEST_APPS) $(TEST_APPS:%=%_implib) $(TEST_APPS:%=%_clean) $(TEST_APPS:%=%_install) + +etags: + find . -name "*.[ch]" -print | etags --language=c - + +# EOF diff --git a/rosapps/tests/README.txt b/rosapps/tests/README.txt new file mode 100644 index 00000000000..8dbc5d61b2d --- /dev/null +++ b/rosapps/tests/README.txt @@ -0,0 +1,3 @@ +This folder contains tests that are not merged in to the new regression system. + +Please DO NOT add new tests here. \ No newline at end of file diff --git a/rosapps/tests/accelerator/.cvsignore b/rosapps/tests/accelerator/.cvsignore new file mode 100644 index 00000000000..060f7fa87a2 --- /dev/null +++ b/rosapps/tests/accelerator/.cvsignore @@ -0,0 +1,7 @@ +*.o +*.d +*.a +*.exe +*.coff +*.sym +*.map \ No newline at end of file diff --git a/rosapps/tests/accelerator/Makefile b/rosapps/tests/accelerator/Makefile new file mode 100644 index 00000000000..38d05e890c8 --- /dev/null +++ b/rosapps/tests/accelerator/Makefile @@ -0,0 +1,19 @@ +PATH_TO_TOP = ../../../reactos + +TARGET_NORC = yes + +TARGET_TYPE = program + +TARGET_APPTYPE = windows + +TARGET_NAME = accelerator + +#TARGET_SDKLIBS = kernel32.a user32.a + +TARGET_OBJECTS = accelerator.o + +TARGET_CFLAGS = -Wall -Werror + +include $(PATH_TO_TOP)/rules.mak + +include $(TOOLS_PATH)/helper.mk diff --git a/rosapps/tests/accelerator/accelerator.c b/rosapps/tests/accelerator/accelerator.c new file mode 100644 index 00000000000..0b7aca65ef1 --- /dev/null +++ b/rosapps/tests/accelerator/accelerator.c @@ -0,0 +1,161 @@ +#include +#include +#include + +#define ID_ACCEL1 0x100 +#define ID_ACCEL2 0x101 +#define ID_ACCEL3 0x102 +#define ID_ACCEL4 0x103 + +/* + * {fVirt, key, cmd} + * fVirt |= FVIRTKEY | FCONTROL | FALT | FSHIFT + */ +//static HFONT tf; +static ACCEL Accelerators[4] = { + { FVIRTKEY, VK_A, ID_ACCEL1}, + { FVIRTKEY | FSHIFT, VK_A, ID_ACCEL2}, + { FVIRTKEY | FCONTROL, VK_A, ID_ACCEL3}, + { FVIRTKEY | FALT, VK_A, ID_ACCEL4}}; +static HACCEL hAcceleratorTable; +static char Event[200]; + +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 = "AcceleratorTest"; + 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) + { + fprintf(stderr, "RegisterClass failed (last error 0x%lX)\n", + GetLastError()); + return(1); + } + + hWnd = CreateWindow("AcceleratorTest", + "Accelerator Test", + WS_OVERLAPPEDWINDOW, + 0, + 0, + CW_USEDEFAULT, + CW_USEDEFAULT, + NULL, + NULL, + hInstance, + NULL); + if (hWnd == NULL) + { + fprintf(stderr, "CreateWindow failed (last error 0x%lX)\n", + GetLastError()); + return(1); + } + + /*tf = CreateFontA(14, 0, 0, TA_BASELINE, FW_NORMAL, FALSE, FALSE, FALSE, + ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, + DEFAULT_QUALITY, FIXED_PITCH|FF_DONTCARE, "Timmons");*/ + + Event[0] = 0; + + ShowWindow(hWnd, nCmdShow); + + hAcceleratorTable = CreateAcceleratorTable(Accelerators, + sizeof(Accelerators)/sizeof(Accelerators[1])); + if (hAcceleratorTable == NULL) + { + fprintf(stderr, "CreateAcceleratorTable failed (last error 0x%lX)\n", + GetLastError()); + return(1); + } + + while(GetMessage(&msg, NULL, 0, 0)) + { + if (!TranslateAccelerator(hWnd, hAcceleratorTable, &msg)) + { + TranslateMessage(&msg); + DispatchMessage(&msg); + } + } + + if (!DestroyAcceleratorTable(hAcceleratorTable)) + { + fprintf(stderr, "DestroyAcceleratorTable failed (last error 0x%lX)\n", + GetLastError()); + return(1); + } + + //DeleteObject(tf); + + return msg.wParam; +} + +LRESULT CALLBACK MainWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) +{ + PAINTSTRUCT ps; + HDC hDC; + char buf[200]; + + switch(msg) + { + case WM_PAINT: + hDC = BeginPaint(hWnd, &ps); + //SelectObject(hDC, tf); + sprintf(buf, "Event: '%s'", Event); + TextOut(hDC, 10, 10, buf, strlen(buf)); + EndPaint(hWnd, &ps); + break; + + case WM_DESTROY: + PostQuitMessage(0); + break; + + case WM_COMMAND: + + switch (LOWORD(wParam)) + { + case ID_ACCEL1: + strcpy(Event, "A"); + break; + + case ID_ACCEL2: + strcpy(Event, "SHIFT+A"); + break; + + case ID_ACCEL3: + strcpy(Event, "CTRL+A"); + break; + + case ID_ACCEL4: + strcpy(Event, "ALT+A"); + break; + + default: + sprintf(Event, "%d", LOWORD(wParam)); + break; + } + + InvalidateRect(hWnd, NULL, TRUE); + UpdateWindow(hWnd); + break; + + default: + return DefWindowProc(hWnd, msg, wParam, lParam); + } + return 0; +} diff --git a/rosapps/tests/alive/.cvsignore b/rosapps/tests/alive/.cvsignore new file mode 100644 index 00000000000..060f7fa87a2 --- /dev/null +++ b/rosapps/tests/alive/.cvsignore @@ -0,0 +1,7 @@ +*.o +*.d +*.a +*.exe +*.coff +*.sym +*.map \ No newline at end of file diff --git a/rosapps/tests/alive/Makefile b/rosapps/tests/alive/Makefile new file mode 100644 index 00000000000..73c8a7e7fa1 --- /dev/null +++ b/rosapps/tests/alive/Makefile @@ -0,0 +1,23 @@ +# $Id: Makefile,v 1.1 2004/10/21 04:48:44 sedwards Exp $ + +PATH_TO_TOP = ../../../reactos + +TARGET_NORC = yes + +TARGET_TYPE = program + +TARGET_APPTYPE = console + +TARGET_NAME = alive + +TARGET_SDKLIBS = kernel32.a user32.a + +TARGET_OBJECTS = $(TARGET_NAME).o + +TARGET_CFLAGS = -Wall -Werror + +include $(PATH_TO_TOP)/rules.mak + +include $(TOOLS_PATH)/helper.mk + +# EOF diff --git a/rosapps/tests/alive/alive.c b/rosapps/tests/alive/alive.c new file mode 100644 index 00000000000..4cfeca872ef --- /dev/null +++ b/rosapps/tests/alive/alive.c @@ -0,0 +1,48 @@ +/* $Id: alive.c,v 1.1 2004/10/21 04:48:44 sedwards Exp $ + * + */ +#include +#include + +HANDLE StandardOutput = INVALID_HANDLE_VALUE; +CHAR Message [80]; +DWORD CharactersToWrite = 0; +DWORD WrittenCharacters = 0; +INT d = 0, h = 0, m = 0, s = 0; + +int +main (int argc, char * argv []) +{ + StandardOutput = GetStdHandle (STD_OUTPUT_HANDLE); + if (INVALID_HANDLE_VALUE == StandardOutput) + { + return (EXIT_FAILURE); + } + while (TRUE) + { + /* Prepare the message and update it */ + CharactersToWrite = + wsprintf ( + Message, + "Alive for %dd %dh %d' %d\" \r", + d, h, m, s + ); + WriteConsole ( + StandardOutput, + Message, + CharactersToWrite, + & WrittenCharacters, + NULL + ); + /* suspend the execution for 1s */ + Sleep (1000); + /* increment seconds */ + ++ s; + if (60 == s) { s = 0; ++ m; } + if (60 == m) { m = 0; ++ h; } + if (24 == h) { h = 0; ++ d; } + } + return (EXIT_SUCCESS); +} + +/* EOF */ diff --git a/rosapps/tests/alphablend/.cvsignore b/rosapps/tests/alphablend/.cvsignore new file mode 100644 index 00000000000..060f7fa87a2 --- /dev/null +++ b/rosapps/tests/alphablend/.cvsignore @@ -0,0 +1,7 @@ +*.o +*.d +*.a +*.exe +*.coff +*.sym +*.map \ No newline at end of file diff --git a/rosapps/tests/alphablend/alphablend.c b/rosapps/tests/alphablend/alphablend.c new file mode 100644 index 00000000000..ee3942d8992 --- /dev/null +++ b/rosapps/tests/alphablend/alphablend.c @@ -0,0 +1,213 @@ +#include +#include + +#ifndef AC_SRC_ALPHA +#define AC_SRC_ALPHA (0x1) +#endif + +HINSTANCE HInst; +const char* WndClassName = "GMainWnd"; +LRESULT CALLBACK MainWndProc(HWND HWnd, UINT Msg, WPARAM WParam, + LPARAM LParam); + +WINBOOL +STDCALL +GdiAlphaBlend(HDC hdcDst,LONG DstX,LONG DstY,LONG DstCx,LONG DstCy,HDC hdcSrc,LONG SrcX,LONG SrcY,LONG SrcCx,LONG SrcCy,BLENDFUNCTION BlendFunction); + + +int APIENTRY WinMain(HINSTANCE HInstance, HINSTANCE HPrevInstance, + LPTSTR lpCmdLine, int nCmdShow) +{ + WNDCLASS wc; + MSG msg; + + HInst = HInstance; + + memset(&wc, 0, sizeof(WNDCLASS)); + + wc.style = CS_VREDRAW | CS_HREDRAW | CS_DBLCLKS; + wc.lpfnWndProc = MainWndProc; + wc.hInstance = HInstance; + wc.hCursor = LoadCursor(NULL, (LPCTSTR)IDC_ARROW); + /* wc.hbrBackground = reinterpret_cast(COLOR_BTNFACE + 1); */ + wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1); + wc.lpszClassName = WndClassName; + + if (RegisterClass(&wc)) + { + HWND HWnd = + CreateWindow( + WndClassName, TEXT("AlphaBlend Rendering Demo"), + WS_OVERLAPPED | WS_SYSMENU | WS_CAPTION | + WS_VISIBLE | WS_CLIPSIBLINGS, + 0, 0, 320, 430, + NULL, NULL, HInst, NULL + ); + + if (HWnd) + { + ShowWindow(HWnd, nCmdShow); + UpdateWindow(HWnd); + + while (GetMessage(&msg, NULL, 0, 0)) + { + TranslateMessage(&msg); + DispatchMessage(&msg); + } + } + } + return 0; +} + +/* image related */ +BITMAP bmp; +LPCSTR filename = TEXT("lena.bmp"); +HDC HMemDC = NULL, HMemDC2 = NULL; +HBITMAP HOldBmp = NULL; +PVOID pBmpBits = NULL; +HBITMAP H32BppBitmap = NULL; +BITMAPINFO bmpi; + +BOOL ConvertBitmapTo32Bpp(HDC hDC, BITMAP *bmp) +{ + ZeroMemory(&bmpi, sizeof(BITMAPINFO)); + bmpi.bmiHeader.biSize = sizeof(BITMAPINFO); + bmpi.bmiHeader.biWidth = bmp->bmWidth; + bmpi.bmiHeader.biHeight = bmp->bmHeight; + bmpi.bmiHeader.biPlanes = 1; + bmpi.bmiHeader.biBitCount = 32; + bmpi.bmiHeader.biCompression = BI_RGB; + bmpi.bmiHeader.biSizeImage = 4 * bmpi.bmiHeader.biWidth * bmpi.bmiHeader.biHeight; + H32BppBitmap = CreateDIBSection(hDC, &bmpi, DIB_RGB_COLORS, &pBmpBits, 0, 0); + if(H32BppBitmap) + { + HBITMAP bmpalpha; + SelectObject(hDC, H32BppBitmap); + BitBlt(hDC, 0, 0, bmp->bmWidth, bmp->bmHeight, HMemDC, 0, 0, SRCCOPY); + + /* load and apply alpha channel */ + bmpalpha = LoadImage(HInst, TEXT("lenaalpha.bmp"), IMAGE_BITMAP, + 0, 0, LR_LOADFROMFILE); + if(bmpalpha) + { + COLORREF *col = pBmpBits; + int x, y; + HDC hdcTemp = CreateCompatibleDC(NULL); + if(!hdcTemp) + { + DeleteObject(bmpalpha); + return FALSE; + } + SelectObject(hdcTemp, bmpalpha); + + for(y = 0; y < bmp->bmHeight; y++) + { + for(x = 0; x < bmp->bmWidth; x++) + { + COLORREF Color = (COLORREF)GetRValue(GetPixel(hdcTemp, x, y)) << 24; + *col++ |= Color; + } + } + + DeleteObject(bmpalpha); + DeleteDC(hdcTemp); + return TRUE; + } + return FALSE; + } + return FALSE; +} + +LRESULT CALLBACK MainWndProc(HWND HWnd, UINT Msg, WPARAM WParam, + LPARAM LParam) +{ + switch (Msg) + { + case WM_CREATE: + { + /* create a memory DC */ + HMemDC = CreateCompatibleDC(NULL); + if (HMemDC) + { + /* load a bitmap from file */ + HBITMAP HBmp = + /* static_cast */( + LoadImage(HInst, filename, IMAGE_BITMAP, + 0, 0, LR_LOADFROMFILE) + ); + if (HBmp) + { + /* extract dimensions of the bitmap */ + GetObject(HBmp, sizeof(BITMAP), &bmp); + + /* associate the bitmap with the memory DC */ + /* HOldBmp = static_cast */ + (SelectObject(HMemDC, HBmp) + ); + HMemDC2 = CreateCompatibleDC(NULL); + if(!ConvertBitmapTo32Bpp(HMemDC2, &bmp)) + { + PostQuitMessage(0); + return 0; + } + } + } + } + case WM_PAINT: + { + PAINTSTRUCT ps; + BLENDFUNCTION BlendFunc; + HDC Hdc = BeginPaint(HWnd, &ps); +#if 0 + try +#endif + { + + BlendFunc.BlendOp = AC_SRC_OVER; + BlendFunc.BlendFlags = 0; + BlendFunc.SourceConstantAlpha = 128; + BlendFunc.AlphaFormat = 0; + + BitBlt(Hdc, 100, 90, + bmp.bmWidth, bmp.bmHeight, + HMemDC2, 0, 0, + SRCCOPY); + GdiAlphaBlend(Hdc, 0, 0, bmp.bmWidth, bmp.bmHeight, + HMemDC2, 0, 0, bmp.bmWidth, bmp.bmHeight, + BlendFunc); + GdiAlphaBlend(Hdc, bmp.bmWidth - 15, 10, bmp.bmWidth / 2, bmp.bmHeight / 2, + HMemDC2, 0, 0, bmp.bmWidth, bmp.bmHeight, + BlendFunc); + + BlendFunc.SourceConstantAlpha = 255; + BlendFunc.AlphaFormat = AC_SRC_ALPHA; + + GdiAlphaBlend(Hdc, 140, 200, bmp.bmWidth, bmp.bmHeight, + HMemDC2, 0, 0, bmp.bmWidth, bmp.bmHeight, + BlendFunc); + GdiAlphaBlend(Hdc, 20, 210, (bmp.bmWidth / 3) * 2, (bmp.bmHeight / 3) * 2, + HMemDC2, 0, 0, bmp.bmWidth, bmp.bmHeight, + BlendFunc); + } +#if 0 + catch (...) + { + EndPaint(HWnd, &ps); + } +#endif + EndPaint(HWnd, &ps); + break; + } + case WM_DESTROY: + { + /* clean up */ + DeleteObject(SelectObject(HMemDC, HOldBmp)); + DeleteDC(HMemDC); + DeleteDC(HMemDC2); + + PostQuitMessage(0); + return 0; + } + } + return DefWindowProc(HWnd, Msg, WParam, LParam); +} diff --git a/rosapps/tests/alphablend/lena.bmp b/rosapps/tests/alphablend/lena.bmp new file mode 100644 index 00000000000..e9916963852 Binary files /dev/null and b/rosapps/tests/alphablend/lena.bmp differ diff --git a/rosapps/tests/alphablend/lenaalpha.bmp b/rosapps/tests/alphablend/lenaalpha.bmp new file mode 100644 index 00000000000..71982ce8b06 Binary files /dev/null and b/rosapps/tests/alphablend/lenaalpha.bmp differ diff --git a/rosapps/tests/alphablend/makefile b/rosapps/tests/alphablend/makefile new file mode 100644 index 00000000000..c2bf775c1aa --- /dev/null +++ b/rosapps/tests/alphablend/makefile @@ -0,0 +1,22 @@ + +PATH_TO_TOP = ../../../reactos + +TARGET_NORC = yes + +TARGET_TYPE = program + +TARGET_APPTYPE = windows + +TARGET_NAME = alphablend + +TARGET_SDKLIBS = kernel32.a gdi32.a + +TARGET_OBJECTS = $(TARGET_NAME).o + +TARGET_CFLAGS = -Wall -Werror -D__USE_W32API + +include $(PATH_TO_TOP)/rules.mak + +include $(TOOLS_PATH)/helper.mk + +# EOF diff --git a/rosapps/tests/apc/.cvsignore b/rosapps/tests/apc/.cvsignore new file mode 100644 index 00000000000..060f7fa87a2 --- /dev/null +++ b/rosapps/tests/apc/.cvsignore @@ -0,0 +1,7 @@ +*.o +*.d +*.a +*.exe +*.coff +*.sym +*.map \ No newline at end of file diff --git a/rosapps/tests/apc/apc.c b/rosapps/tests/apc/apc.c new file mode 100644 index 00000000000..d33da633d69 --- /dev/null +++ b/rosapps/tests/apc/apc.c @@ -0,0 +1,94 @@ +#include +#include +#include +#include +#include +#include + +HANDLE OutputHandle; +HANDLE InputHandle; + +VOID STDCALL +ApcRoutine(PVOID Context, + PIO_STATUS_BLOCK IoStatus, + ULONG Reserved) +{ + printf("(apc.exe) ApcRoutine(Context %p)\n", Context); +} + + +int main(int argc, char* argv[]) +{ + NTSTATUS Status; + HANDLE FileHandle; + OBJECT_ATTRIBUTES ObjectAttributes; + UNICODE_STRING FileName = ROS_STRING_INITIALIZER(L"\\C:\\a.txt"); + IO_STATUS_BLOCK IoStatus; + CHAR Buffer[256]; + HANDLE EventHandle; + LARGE_INTEGER off; + + AllocConsole(); + InputHandle = GetStdHandle(STD_INPUT_HANDLE); + OutputHandle = GetStdHandle(STD_OUTPUT_HANDLE); + + printf("APC test program\n"); + + EventHandle = CreateEventW(NULL, + FALSE, + FALSE, + NULL); + if (EventHandle == INVALID_HANDLE_VALUE) + { + printf("Failed to create event\n"); + return 0; + } + + printf("Opening file\n"); + InitializeObjectAttributes(&ObjectAttributes, + &FileName, + 0, + NULL, + NULL); + + printf("Creating file\n"); + FileHandle = CreateFileW(L"C:\\a.txt", + FILE_GENERIC_READ | FILE_GENERIC_WRITE, + 0, + NULL, + OPEN_EXISTING, + FILE_FLAG_OVERLAPPED, + NULL); + + if (FileHandle == INVALID_HANDLE_VALUE) + { + + printf("Open failed last err 0x%lu\n",GetLastError()); + return 0; + } + + off.QuadPart = 0; + + printf("Reading file\n"); + Status = ZwReadFile(FileHandle, + NULL, + (PIO_APC_ROUTINE)ApcRoutine, + (PVOID) 0xdeadbeef, + &IoStatus, + Buffer, + 256,//len + &off ,//offset must exist if file was opened for asynch. i/o aka. OVERLAPPED + NULL); + + if (!NT_SUCCESS(Status)) + { + printf("Read failed status 0x%lu\n",Status); + } + printf("Waiting\n"); + WaitForSingleObjectEx(EventHandle, INFINITE, TRUE); + printf("Returned from wait\n"); + ZwClose(FileHandle); + printf("Program finished\n"); + return 0; +} + diff --git a/rosapps/tests/apc/makefile b/rosapps/tests/apc/makefile new file mode 100644 index 00000000000..072d5f94d78 --- /dev/null +++ b/rosapps/tests/apc/makefile @@ -0,0 +1,23 @@ +# $Id: makefile,v 1.1 2004/10/21 04:48:44 sedwards Exp $ + +PATH_TO_TOP = ../../../reactos + +TARGET_NORC = yes + +TARGET_TYPE = program + +TARGET_APPTYPE = console + +TARGET_NAME = apc + +TARGET_SDKLIBS = ntdll.a kernel32.a + +TARGET_OBJECTS = $(TARGET_NAME).o + +TARGET_CFLAGS = -Wall -Werror + +include $(PATH_TO_TOP)/rules.mak + +include $(TOOLS_PATH)/helper.mk + +# EOF diff --git a/rosapps/tests/apc2/.cvsignore b/rosapps/tests/apc2/.cvsignore new file mode 100644 index 00000000000..060f7fa87a2 --- /dev/null +++ b/rosapps/tests/apc2/.cvsignore @@ -0,0 +1,7 @@ +*.o +*.d +*.a +*.exe +*.coff +*.sym +*.map \ No newline at end of file diff --git a/rosapps/tests/apc2/apc2.c b/rosapps/tests/apc2/apc2.c new file mode 100644 index 00000000000..ca3699cca58 --- /dev/null +++ b/rosapps/tests/apc2/apc2.c @@ -0,0 +1,53 @@ + +#include +#include + +VOID CALLBACK TimerApcProc( + LPVOID lpArg, + DWORD dwTimerLowValue, + DWORD dwTimerHighValue ) +{ + printf("APC Callback %lu\n", *(PDWORD)lpArg); +} + + +int main() +{ + HANDLE hTimer; + BOOL bSuccess; + LARGE_INTEGER DueTime; + DWORD value = 1; + + hTimer = CreateWaitableTimer(NULL, FALSE, NULL ); + + if (!hTimer) + { + printf("CreateWaitableTimer failed!\n"); + return 0; + } + + DueTime.QuadPart = -(LONGLONG)(5 * 10000000); + + bSuccess = SetWaitableTimer( + hTimer, + &DueTime, + 2001 /*interval (using an odd number to be able to find it easy in kmode) */, + TimerApcProc, + &value /*callback argument*/, + FALSE ); + + if (!bSuccess) + { + printf("SetWaitableTimer failed!\n"); + return 0; + } + + for (;value <= 10; value++ ) + { + SleepEx(INFINITE, TRUE /*alertable*/ ); + } + + CloseHandle( hTimer ); + return 0; +} + diff --git a/rosapps/tests/apc2/makefile b/rosapps/tests/apc2/makefile new file mode 100644 index 00000000000..2a5640c60a4 --- /dev/null +++ b/rosapps/tests/apc2/makefile @@ -0,0 +1,23 @@ + + +PATH_TO_TOP = ../../../reactos + +TARGET_NORC = yes + +TARGET_TYPE = program + +TARGET_APPTYPE = console + +TARGET_NAME = apc2 + +TARGET_SDKLIBS = ntdll.a kernel32.a + +TARGET_CFLAGS = -Wall -Werror + +TARGET_OBJECTS = $(TARGET_NAME).o + +include $(PATH_TO_TOP)/rules.mak + +include $(TOOLS_PATH)/helper.mk + +# EOF diff --git a/rosapps/tests/args/.cvsignore b/rosapps/tests/args/.cvsignore new file mode 100644 index 00000000000..060f7fa87a2 --- /dev/null +++ b/rosapps/tests/args/.cvsignore @@ -0,0 +1,7 @@ +*.o +*.d +*.a +*.exe +*.coff +*.sym +*.map \ No newline at end of file diff --git a/rosapps/tests/args/args.c b/rosapps/tests/args/args.c new file mode 100644 index 00000000000..91b0d0eb406 --- /dev/null +++ b/rosapps/tests/args/args.c @@ -0,0 +1,39 @@ +#include +#include +#include +#include + +HANDLE OutputHandle; +HANDLE InputHandle; + +void debug_printf(char* fmt, ...) +{ + va_list args; + char buffer[255]; + + va_start(args,fmt); + vsprintf(buffer,fmt,args); + WriteConsoleA(OutputHandle, buffer, strlen(buffer), NULL, NULL); + va_end(args); +} + + +int main(int argc, char* argv[]) +{ + int i; + + AllocConsole(); + InputHandle = GetStdHandle(STD_INPUT_HANDLE); + OutputHandle = GetStdHandle(STD_OUTPUT_HANDLE); + + printf("GetCommandLineA() %s\n",GetCommandLineA()); + debug_printf("GetCommandLineA() %s\n",GetCommandLineA()); + debug_printf("argc %d\n", argc); + for (i=0; i +#include +#include +#include + +#define BUFFER_SIZE 256 + +int main(int argc, char* argv[]) +{ + PRTL_ATOM_TABLE AtomTable = NULL; + RTL_ATOM AtomA = -1, AtomB = -1, AtomC = -1; + NTSTATUS Status; + WCHAR Buffer[BUFFER_SIZE]; + ULONG NameLength, Data1, Data2; + + printf("Atom table test app\n\n"); + + printf("RtlCreateAtomTable()\n"); + Status = RtlCreateAtomTable(37, + &AtomTable); + printf(" Status 0x%08lx\n", Status); + + if (NT_SUCCESS(Status)) + { + printf(" AtomTable %p\n", AtomTable); + + printf("RtlAddAtomToAtomTable()\n"); + Status = RtlAddAtomToAtomTable(AtomTable, + L"TestAtomA", + &AtomA); + printf(" Status 0x%08lx\n", Status); + if (NT_SUCCESS(Status)) + { + printf(" AtomA 0x%x\n", AtomA); + } + + printf("RtlAddAtomToAtomTable()\n"); + Status = RtlAddAtomToAtomTable(AtomTable, + L"TestAtomB", + &AtomB); + printf(" Status 0x%08lx\n", Status); + if (NT_SUCCESS(Status)) + { + printf(" AtomB 0x%x\n", AtomB); + } + + + printf("RtlLookupAtomInAtomTable()\n"); + Status = RtlLookupAtomInAtomTable(AtomTable, + L"TestAtomA", + &AtomC); + printf(" Status 0x%08lx\n", Status); + if (NT_SUCCESS(Status)) + { + printf(" AtomC 0x%x\n", AtomC); + } + + + printf("RtlPinAtomInAtomTable()\n"); + Status = RtlPinAtomInAtomTable(AtomTable, + AtomC); + printf(" Status 0x%08lx\n", Status); + + printf("RtlPinAtomInAtomTable()\n"); + Status = RtlPinAtomInAtomTable(AtomTable, + AtomC); + printf(" Status 0x%08lx\n", Status); + + +// printf("RtlDeleteAtomFromAtomTable()\n"); +// Status = RtlDeleteAtomFromAtomTable(AtomTable, +// AtomC); +// printf(" Status 0x%08lx\n", Status); + + +// printf("RtlEmptyAtomTable()\n"); +// Status = RtlEmptyAtomTable(AtomTable, +// TRUE); +// printf(" Status 0x%08lx\n", Status); + + +// printf("RtlLookupAtomInAtomTable()\n"); +// Status = RtlLookupAtomInAtomTable(AtomTable, +// L"TestAtomA", +// &AtomC); +// printf(" Status 0x%08lx\n", Status); + + + printf("RtlQueryAtomInAtomTable()\n"); + NameLength = sizeof(WCHAR) * BUFFER_SIZE; + Status = RtlQueryAtomInAtomTable(AtomTable, + AtomC, + &Data1, + &Data2, + Buffer, + &NameLength); + printf(" Status 0x%08lx\n", Status); + if (NT_SUCCESS(Status)) + { + printf(" RefCount %ld\n", Data1); + printf(" PinCount %ld\n", Data2); + printf(" NameLength %lu\n", NameLength); + printf(" AtomName: %S\n", Buffer); + } + + printf("RtlDestroyAtomTable()\n"); + RtlDestroyAtomTable(AtomTable); + + + printf("Atom table test app finished\n"); + } + + return(0); +} diff --git a/rosapps/tests/atomtest/makefile b/rosapps/tests/atomtest/makefile new file mode 100644 index 00000000000..b1458c4f21c --- /dev/null +++ b/rosapps/tests/atomtest/makefile @@ -0,0 +1,22 @@ +# $Id: makefile,v 1.1 2004/10/21 04:48:44 sedwards Exp $ +PATH_TO_TOP = ../../../reactos + +TARGET_NORC = yes + +TARGET_TYPE = program + +TARGET_APPTYPE = console + +TARGET_NAME = atomtest + +TARGET_SDKLIBS = ntdll.a kernel32.a + +TARGET_OBJECTS = $(TARGET_NAME).o + +TARGET_CFLAGS = -Wall -Werror + +include $(PATH_TO_TOP)/rules.mak + +include $(TOOLS_PATH)/helper.mk + +# EOF diff --git a/rosapps/tests/stretchblt/.cvsignore b/rosapps/tests/stretchblt/.cvsignore new file mode 100644 index 00000000000..060f7fa87a2 --- /dev/null +++ b/rosapps/tests/stretchblt/.cvsignore @@ -0,0 +1,7 @@ +*.o +*.d +*.a +*.exe +*.coff +*.sym +*.map \ No newline at end of file diff --git a/rosapps/tests/stretchblt/makefile b/rosapps/tests/stretchblt/makefile new file mode 100644 index 00000000000..d972293424c --- /dev/null +++ b/rosapps/tests/stretchblt/makefile @@ -0,0 +1,31 @@ + +PATH_TO_TOP = ../../../reactos + +TARGET_TYPE = program + +TARGET_APPTYPE = windows + +TARGET_NAME = stretchblt + +TARGET_NORC = yes + +TARGET_CFLAGS = -fexceptions -g -O0 -DWIN32 -D_DEBUG -D_WINDOWS -D_MBCS -W -D__USE_W32API -Wall -Werror + +TARGET_CPPFLAGS = -fexceptions -g -O0 -DWIN32 -D_DEBUG -D_WINDOWS -D_MBCS -W -D__USE_W32API -Wall -Werror + +TARGET_SDKLIBS = \ + kernel32.a \ + user32.a \ + gdi32.a + +TARGET_OBJECTS = \ +stretchblt.o + +include $(PATH_TO_TOP)/rules.mak + +include $(TOOLS_PATH)/helper.mk + +# overide LD_CC to use g++ for linking of the executable +LD_CC = $(CXX) + +# EOF diff --git a/rosapps/tests/stretchblt/stretchblt.cpp b/rosapps/tests/stretchblt/stretchblt.cpp new file mode 100644 index 00000000000..dec7dd56a71 --- /dev/null +++ b/rosapps/tests/stretchblt/stretchblt.cpp @@ -0,0 +1,380 @@ + +// ------------------------------------------------------------------ +// Windows 2000 Graphics API Black Book +// Chapter 1 - Listing 1.5 (StretchBlt Zooming Demo) +// +// Created by Damon Chandler +// Updates can be downloaded at: +// +// Please do not hesistate to e-mail me at dmc27@ee.cornell.edu +// if you have any questions about this code. +// ------------------------------------------------------------------ + +// Modified by Aleksey Bragin (aleksey at studiocerebral.com) +// to support non-uniform scaling, and output via sretchdibits +// (type something in the command line to invoke this mode, +// in future it will be source BPP) + +//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> +#include +#include +//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + + +HWND HListBox = NULL; +HWND VListBox = NULL; +const int ID_LISTBOX = 101; +const int ID_LISTBOX2 = 102; +BOOL useDIBits=FALSE; // How to display the image - via StretchDIBits + +HINSTANCE HInst; +HINSTANCE HPrevInst; +TCHAR *cmdline; +const char* WndClassName = "GMainWnd"; +LRESULT CALLBACK MainWndProc(HWND HWnd, UINT Msg, WPARAM WParam, + LPARAM LParam); + + +int APIENTRY WinMain(HINSTANCE HInstance, HINSTANCE HPrevInstance, + LPTSTR lpCmdLine, int nCmdShow) +{ + HInst = HInstance; + HPrevInst = HPrevInstance; + cmdline = lpCmdLine; + + WNDCLASS wc; + memset(&wc, 0, sizeof(WNDCLASS)); + + wc.style = CS_VREDRAW | CS_HREDRAW | CS_DBLCLKS; + wc.lpfnWndProc = MainWndProc; + wc.hInstance = HInstance; + wc.hCursor = LoadCursor(NULL, IDC_ARROW); + wc.hbrBackground = reinterpret_cast(COLOR_BTNFACE + 1); + wc.lpszClassName = WndClassName; + + if (RegisterClass(&wc)) + { + HWND HWnd = + CreateWindow(WndClassName, TEXT("StretchBlt NonUniform Zooming Demo"), + WS_OVERLAPPEDWINDOW | WS_CAPTION | + WS_VISIBLE | WS_CLIPSIBLINGS, + 0, 0, 675, 560, + NULL, NULL, HInst, NULL); + + if (HWnd) + { + HListBox = + CreateWindowEx(WS_EX_CLIENTEDGE, "LISTBOX", "", + LBS_NOTIFY | WS_CHILD | WS_VISIBLE, + 530, 5, 130, 150, HWnd, + reinterpret_cast(ID_LISTBOX), + HInst, NULL); + VListBox = + CreateWindowEx(WS_EX_CLIENTEDGE, "LISTBOX", "", + LBS_NOTIFY | WS_CHILD | WS_VISIBLE, + 530, 5+170, 130, 150, HWnd, + reinterpret_cast(ID_LISTBOX2), + HInst, NULL); + + if (HListBox && VListBox) + { +// horizontal zoom + SNDMSG(HListBox, LB_ADDSTRING, 0, + reinterpret_cast("Zoom 25%")); + SNDMSG(HListBox, LB_ADDSTRING, 0, + reinterpret_cast("Zoom 50%")); + SNDMSG(HListBox, LB_ADDSTRING, 0, + reinterpret_cast("Zoom 75%")); + SNDMSG(HListBox, LB_ADDSTRING, 0, + reinterpret_cast("Zoom 100%")); + SNDMSG(HListBox, LB_ADDSTRING, 0, + reinterpret_cast("Zoom 125%")); + SNDMSG(HListBox, LB_ADDSTRING, 0, + reinterpret_cast("Zoom 150%")); + SNDMSG(HListBox, LB_ADDSTRING, 0, + reinterpret_cast("Zoom 200%")); + SNDMSG(HListBox, LB_ADDSTRING, 0, + reinterpret_cast("Zoom 300%")); +// vertical zoom + SNDMSG(VListBox, LB_ADDSTRING, 0, + reinterpret_cast("Zoom 25%")); + SNDMSG(VListBox, LB_ADDSTRING, 0, + reinterpret_cast("Zoom 50%")); + SNDMSG(VListBox, LB_ADDSTRING, 0, + reinterpret_cast("Zoom 75%")); + SNDMSG(VListBox, LB_ADDSTRING, 0, + reinterpret_cast("Zoom 100%")); + SNDMSG(VListBox, LB_ADDSTRING, 0, + reinterpret_cast("Zoom 125%")); + SNDMSG(VListBox, LB_ADDSTRING, 0, + reinterpret_cast("Zoom 150%")); + SNDMSG(VListBox, LB_ADDSTRING, 0, + reinterpret_cast("Zoom 200%")); + SNDMSG(VListBox, LB_ADDSTRING, 0, + reinterpret_cast("Zoom 300%")); + + } + + ShowWindow(HWnd, nCmdShow); + UpdateWindow(HWnd); + + MSG msg; + while (GetMessage(&msg, NULL, 0, 0)) + { + TranslateMessage(&msg); + DispatchMessage(&msg); + } + } + } + return 0; +} +//------------------------------------------------------------------ + + +// image related +BITMAP bmp; +BITMAPINFO bmInfo; +char *bbits = NULL; // bitmap bits +const char* filename = "LENA.BMP"; +HDC HMemDC = NULL; +HBITMAP HOldBmp = NULL; + +// zooming related +float zoom_factor_h = 0.5; +float zoom_factor_v = 0.5; +RECT RDest = {5, 5, 0, 0}; +enum {ID_ZOOM25, ID_ZOOM50, ID_ZOOM75, ID_ZOOM100, + ID_ZOOM125, ID_ZOOM150, ID_ZOOM200, ID_ZOOM300}; + +LRESULT CALLBACK MainWndProc(HWND HWnd, UINT Msg, WPARAM WParam, + LPARAM LParam) +{ + switch (Msg) + { + case WM_CREATE: + { + // check commandline + if (strlen(cmdline) != 0) + { + + useDIBits = TRUE; + } + else + useDIBits = FALSE; + + // create a memory DC + HMemDC = CreateCompatibleDC(NULL); + if (HMemDC) + { + // load a bitmap from file + HBITMAP HBmp = + static_cast( + LoadImage(HInst, filename, IMAGE_BITMAP, + 0, 0, LR_LOADFROMFILE) + ); + if (HBmp) + { + // extract dimensions of the bitmap + GetObject(HBmp, sizeof(BITMAP), &bmp); + + // fill the BITMAPINFO stucture for further use by StretchDIBits + bmInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); + bmInfo.bmiHeader.biWidth = bmp.bmWidth; + bmInfo.bmiHeader.biHeight = bmp.bmHeight; + bmInfo.bmiHeader.biPlanes = 1;//bmp.bmPlanes; + bmInfo.bmiHeader.biBitCount = bmp.bmBitsPixel; + bmInfo.bmiHeader.biCompression = BI_RGB; + bmInfo.bmiHeader.biSizeImage = 0; + bmInfo.bmiHeader.biXPelsPerMeter = 0; + bmInfo.bmiHeader.biClrImportant = 0; + bmInfo.bmiHeader.biClrUsed = 0; + + // associate the bitmap with the memory DC + HOldBmp = static_cast( + SelectObject(HMemDC, HBmp) + ); + + if (useDIBits) + { + bbits = new char[bmp.bmHeight*bmp.bmWidthBytes*(bmp.bmBitsPixel / 8)]; + //GetDIBits(HMemDC, HBmp, 0, bmp.bmHeight, bbits, &bmInfo, DIB_RGB_COLORS); + + // Here goes a temp hack, since GetDIBits doesn't exist in ReactOS yet + FILE *f = fopen(filename, "rb"); + BITMAPFILEHEADER bmpHeader; + + fread(&bmpHeader, sizeof(BITMAPFILEHEADER), 1, f); + fread(&bmInfo, sizeof(BITMAPINFO), 1, f); + fseek(f, bmpHeader.bfOffBits, SEEK_SET); + fread(bbits, bmp.bmHeight*bmp.bmWidthBytes*(bmp.bmBitsPixel / 8), 1, f); + + fclose(f); + } + } + } + } + case WM_COMMAND: + { + if (WParam == MAKEWPARAM(ID_LISTBOX, LBN_SELCHANGE) || + WParam == MAKEWPARAM(ID_LISTBOX2, LBN_SELCHANGE)) + { + switch (SNDMSG(HListBox, LB_GETCURSEL, 0, 0)) + { + case ID_ZOOM25: zoom_factor_h = 0.25; break; + case ID_ZOOM50: zoom_factor_h = 0.50; break; + case ID_ZOOM75: zoom_factor_h = 0.75; break; + case ID_ZOOM100: zoom_factor_h = 1.00; break; + case ID_ZOOM125: zoom_factor_h = 1.25; break; + case ID_ZOOM150: zoom_factor_h = 1.50; break; + case ID_ZOOM200: zoom_factor_h = 2.00; break; + case ID_ZOOM300: zoom_factor_h = 3.00; break; + } + + switch (SNDMSG(VListBox, LB_GETCURSEL, 0, 0)) + { + case ID_ZOOM25: zoom_factor_v = 0.25; break; + case ID_ZOOM50: zoom_factor_v = 0.50; break; + case ID_ZOOM75: zoom_factor_v = 0.75; break; + case ID_ZOOM100: zoom_factor_v = 1.00; break; + case ID_ZOOM125: zoom_factor_v = 1.25; break; + case ID_ZOOM150: zoom_factor_v = 1.50; break; + case ID_ZOOM200: zoom_factor_v = 2.00; break; + case ID_ZOOM300: zoom_factor_v = 3.00; break; + } + + // calculate the new width and height + const int new_width = + static_cast(zoom_factor_h * bmp.bmWidth); + const int new_height = + static_cast(zoom_factor_v * bmp.bmHeight); + + // is zooming in? + bool zoom_in = (new_width > RDest.right - RDest.left); + + // caculate the area that needs to be updated + RECT RUpdate = { + RDest.left, RDest.top, + RDest.left + max(new_width, RDest.right - RDest.left), + RDest.top + max(new_height, RDest.bottom - RDest.top) + }; + + // adjust the dimenstions of the + // destination rectangle + RDest.right = RDest.left + new_width; + RDest.bottom = RDest.top + new_height; + + // create an update region from the XOR combination + // of the update and destination rectangles + HRGN HUpdateRgn = CreateRectRgnIndirect(&RUpdate); + HRGN HDestRgn = CreateRectRgnIndirect(&RDest); + int result = + CombineRgn(HUpdateRgn, HUpdateRgn, HDestRgn, RGN_XOR); + + // incite a repaint + if (result != NULLREGION && result != ERROR) + { + InvalidateRgn(HWnd, HUpdateRgn, true); + RedrawWindow(HWnd, &RDest, NULL, RDW_NOERASE | RDW_INVALIDATE); + } + else if (result == NULLREGION) + { + InvalidateRect(HWnd, &RUpdate, zoom_in ? false : true); + } + + // clean up + DeleteObject(HUpdateRgn); + DeleteObject(HDestRgn); + } + break; + } + case WM_PAINT: + { + PAINTSTRUCT ps; + const HDC Hdc = BeginPaint(HWnd, &ps); +#if 0 + try +#endif + { + // + // TODO: add palette support (see Chapter 9)... + // + if (useDIBits) + { + if (RDest.right - RDest.left > 0) + { + if (zoom_factor_h < 1.0 || zoom_factor_v < 1.0) + { + SetStretchBltMode(Hdc, COLORONCOLOR); + } + + // render the zoomed image + StretchDIBits(Hdc, RDest.left, RDest.top, + RDest.right - RDest.left, + RDest.bottom - RDest.top, + 0, 0, + bmp.bmWidth, bmp.bmHeight, + bbits, &bmInfo, + DIB_RGB_COLORS, + SRCCOPY); + } + } + else + { + if (RDest.right - RDest.left > 0) + { + + // use BitBlt when not zooming + if (zoom_factor_h == 1.0 && zoom_factor_v == 1.0) + { + BitBlt(Hdc, RDest.left, RDest.top, + RDest.right - RDest.left, + RDest.bottom - RDest.top, + HMemDC, 0, 0, + SRCCOPY); + } + else + { + if (zoom_factor_h < 1.0 || zoom_factor_v < 1.0) + { + SetStretchBltMode(Hdc, COLORONCOLOR); + } + + // render the zoomed image + StretchBlt(Hdc, RDest.left, RDest.top, + RDest.right - RDest.left, + RDest.bottom - RDest.top, + HMemDC, 0, 0, + bmp.bmWidth, bmp.bmHeight, + SRCCOPY); + } + } + } + } +#if 0 + catch (...) +#endif + { + EndPaint(HWnd, &ps); + } + EndPaint(HWnd, &ps); + break; + } + case WM_DESTROY: + { + // clean up + DeleteObject(SelectObject(HMemDC, HOldBmp)); + DeleteDC(HMemDC); + + if (bbits) + delete bbits; + + PostQuitMessage(0); + return 0; + } + } + return DefWindowProc(HWnd, Msg, WParam, LParam); +} +//------------------------------------------------------------------ + + + diff --git a/rosapps/tests/subclass/.cvsignore b/rosapps/tests/subclass/.cvsignore new file mode 100644 index 00000000000..060f7fa87a2 --- /dev/null +++ b/rosapps/tests/subclass/.cvsignore @@ -0,0 +1,7 @@ +*.o +*.d +*.a +*.exe +*.coff +*.sym +*.map \ No newline at end of file diff --git a/rosapps/tests/subclass/makefile b/rosapps/tests/subclass/makefile new file mode 100644 index 00000000000..5acc805e69f --- /dev/null +++ b/rosapps/tests/subclass/makefile @@ -0,0 +1,23 @@ +# $Id: makefile,v 1.1 2004/10/21 04:48:45 sedwards Exp $ + +PATH_TO_TOP = ../../../reactos + +TARGET_NORC = yes + +TARGET_TYPE = program + +TARGET_APPTYPE = console + +TARGET_NAME = subclass + +TARGET_SDKLIBS = kernel32.a gdi32.a + +TARGET_OBJECTS = $(TARGET_NAME).o + +TARGET_CFLAGS += -D_DISABLE_TIDENTS -Werror -Wall + +include $(PATH_TO_TOP)/rules.mak + +include $(TOOLS_PATH)/helper.mk + +# EOF diff --git a/rosapps/tests/subclass/subclass.c b/rosapps/tests/subclass/subclass.c new file mode 100644 index 00000000000..9340e74844c --- /dev/null +++ b/rosapps/tests/subclass/subclass.c @@ -0,0 +1,173 @@ +#include +#include + +LRESULT WINAPI UnicodeWndProc(HWND, UINT, WPARAM, LPARAM); +LRESULT WINAPI UnicodeSubclassProc(HWND, UINT, WPARAM, LPARAM); +LRESULT WINAPI AnsiSubclassProc(HWND, UINT, WPARAM, LPARAM); + +static WNDPROC SavedWndProcW; +static WNDPROC SavedWndProcA; + +int WINAPI +WinMain(HINSTANCE hInstance, + HINSTANCE hPrevInstance, + LPSTR lpszCmdLine, + int nCmdShow) +{ + WNDCLASSW wc; + MSG msg; + HWND hWnd; + WCHAR WindowTextW[256]; + char WindowTextA[256]; + + wc.lpszClassName = L"UnicodeClass"; + wc.lpfnWndProc = UnicodeWndProc; + wc.style = 0; + wc.hInstance = hInstance; + wc.hIcon = NULL; + wc.hCursor = NULL; + wc.hbrBackground = NULL; + wc.lpszMenuName = NULL; + wc.cbClsExtra = 0; + wc.cbWndExtra = 0; + if (RegisterClassW(&wc) == 0) + { + fprintf(stderr, "RegisterClassW failed (last error 0x%X)\n", + GetLastError()); + return 1; + } + printf("Unicode class registered, WndProc = 0x%08x\n", wc.lpfnWndProc); + + hWnd = CreateWindowA("UnicodeClass", + "Unicode Window", + WS_OVERLAPPEDWINDOW, + 0, + 0, + CW_USEDEFAULT, + CW_USEDEFAULT, + NULL, + NULL, + hInstance, + NULL); + if (hWnd == NULL) + { + fprintf(stderr, "CreateWindowA failed (last error 0x%X)\n", + GetLastError()); + return 1; + } + + printf("Window created, IsWindowUnicode returns %s\n", IsWindowUnicode(hWnd) ? "TRUE" : "FALSE"); + + printf("Calling GetWindowTextW\n"); + if (! GetWindowTextW(hWnd, WindowTextW, sizeof(WindowTextW) / sizeof(WindowTextW[0]))) + { + fprintf(stderr, "GetWindowTextW failed (last error 0x%X)\n", GetLastError()); + return 1; + } + printf("GetWindowTextW returned Unicode string \"%S\"\n", WindowTextW); + + printf("Calling GetWindowTextA\n"); + if (! GetWindowTextA(hWnd, WindowTextA, sizeof(WindowTextA) / sizeof(WindowTextA[0]))) + { + fprintf(stderr, "GetWindowTextA failed (last error 0x%X)\n", GetLastError()); + return 1; + } + printf("GetWindowTextA returned Ansi string \"%s\"\n", WindowTextA); + printf("\n"); + + SavedWndProcW = (WNDPROC) GetWindowLongW(hWnd, GWL_WNDPROC); + printf("GetWindowLongW returned 0x%08x\n", SavedWndProcW); + SavedWndProcA = (WNDPROC) GetWindowLongA(hWnd, GWL_WNDPROC); + printf("GetWindowLongA returned 0x%08x\n", SavedWndProcA); + printf("\n"); + + printf("Subclassing window using SetWindowLongW, new WndProc 0x%08x\n", UnicodeSubclassProc); + SetWindowLongW(hWnd, GWL_WNDPROC, (LONG) UnicodeSubclassProc); + printf("After subclass, IsWindowUnicode %s, WndProcA 0x%08x, WndProcW 0x%08x\n", + IsWindowUnicode(hWnd) ? "TRUE" : "FALSE", GetWindowLongA(hWnd, GWL_WNDPROC), + GetWindowLongW(hWnd, GWL_WNDPROC)); + + printf("Calling GetWindowTextW\n"); + if (! GetWindowTextW(hWnd, WindowTextW, sizeof(WindowTextW) / sizeof(WindowTextW[0]))) + { + fprintf(stderr, "GetWindowTextW failed (last error 0x%X)\n", GetLastError()); + return 1; + } + printf("GetWindowTextW returned Unicode string \"%S\"\n", WindowTextW); + printf("\n"); + + printf("Subclassing window using SetWindowLongA, new WndProc 0x%08x\n", AnsiSubclassProc); + SetWindowLongA(hWnd, GWL_WNDPROC, (LONG) AnsiSubclassProc); + printf("After subclass, IsWindowUnicode %s, WndProcA 0x%08x, WndProcW 0x%08x\n", + IsWindowUnicode(hWnd) ? "TRUE" : "FALSE", GetWindowLongA(hWnd, GWL_WNDPROC), + GetWindowLongW(hWnd, GWL_WNDPROC)); + + printf("Calling GetWindowTextW\n"); + if (! GetWindowTextW(hWnd, WindowTextW, sizeof(WindowTextW) / sizeof(WindowTextW[0]))) + { + fprintf(stderr, "GetWindowTextW failed (last error 0x%X)\n", GetLastError()); + return 1; + } + printf("GetWindowTextW returned Unicode string \"%S\"\n", WindowTextW); + + DestroyWindow(hWnd); + + return 0; +} + +LRESULT CALLBACK UnicodeWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) +{ + LRESULT Result; + + switch(msg) + { + case WM_GETTEXT: + printf("UnicodeWndProc calling DefWindowProcW\n"); + Result = DefWindowProcW(hWnd, msg, wParam, lParam); + printf("UnicodeWndProc Unicode window text \"%S\"\n", (LPWSTR) lParam); + break; + default: + Result = DefWindowProcW(hWnd, msg, wParam, lParam); + break; + } + + return Result; +} + +LRESULT CALLBACK UnicodeSubclassProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) +{ + LRESULT Result; + + switch(msg) + { + case WM_GETTEXT: + printf("UnicodeSubclassProc calling SavedWindowProc\n"); + Result = CallWindowProcW(SavedWndProcW, hWnd, msg, wParam, lParam); + printf("UnicodeSubclassProc Unicode window text \"%S\"\n", (LPWSTR) lParam); + break; + default: + Result = CallWindowProcW(SavedWndProcW, hWnd, msg, wParam, lParam); + break; + } + + return Result; +} + +LRESULT CALLBACK AnsiSubclassProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) +{ + LRESULT Result; + + switch(msg) + { + case WM_GETTEXT: + printf("AnsiSubclassProc calling SavedWindowProcA\n"); + Result = CallWindowProcA(SavedWndProcA, hWnd, msg, wParam, lParam); + printf("AnsiSubclassProc Ansi window text \"%s\"\n", (LPSTR) lParam); + break; + default: + Result = CallWindowProcA(SavedWndProcA, hWnd, msg, wParam, lParam); + break; + } + + return Result; +} diff --git a/rosapps/tests/suspend/.cvsignore b/rosapps/tests/suspend/.cvsignore new file mode 100644 index 00000000000..060f7fa87a2 --- /dev/null +++ b/rosapps/tests/suspend/.cvsignore @@ -0,0 +1,7 @@ +*.o +*.d +*.a +*.exe +*.coff +*.sym +*.map \ No newline at end of file diff --git a/rosapps/tests/suspend/Makefile b/rosapps/tests/suspend/Makefile new file mode 100644 index 00000000000..5b44717c6ca --- /dev/null +++ b/rosapps/tests/suspend/Makefile @@ -0,0 +1,21 @@ +# $Id: Makefile,v 1.1 2004/10/21 04:48:45 sedwards Exp $ + +PATH_TO_TOP = ../../../reactos + +TARGET_NORC = yes + +TARGET_TYPE = program + +TARGET_APPTYPE = console + +TARGET_NAME = suspend + +TARGET_OBJECTS = $(TARGET_NAME).o + +TARGET_CFLAGS = -Wall -Werror + +include $(PATH_TO_TOP)/rules.mak + +include $(TOOLS_PATH)/helper.mk + +# EOF diff --git a/rosapps/tests/suspend/suspend.c b/rosapps/tests/suspend/suspend.c new file mode 100644 index 00000000000..15a245fdbb0 --- /dev/null +++ b/rosapps/tests/suspend/suspend.c @@ -0,0 +1,74 @@ +#define UNICODE + +#define NTOS_MODE_USER +#include +#include +#include + +#define DBG +#define NDEBUG +#include + +static volatile DWORD z; +static volatile DWORD x=0; + +static NTSTATUS STDCALL +thread_1(PVOID Param) +{ + DWORD y=0; + + for(;;) + { + z++; + if(x>50) + { + printf("I should have been suspended for years :-)\n"); + Sleep(100); + x=0;y++; + if(y==3) ExitProcess(0); + } + } +} + +int +main(int argc, char *argv[]) +{ + HANDLE thread; + DWORD thread_id; + CONTEXT context; + + context.ContextFlags=CONTEXT_CONTROL; + + z=0; + thread=CreateThread(NULL, + 0x1000, + (LPTHREAD_START_ROUTINE)thread_1, + NULL, + 0, + &thread_id); + + if(!thread) + { + printf("Error: could not create thread ...\n"); + ExitProcess(0); + } + + Sleep(1000); + + SuspendThread(thread); + + for(;;) + { + printf("%lx ", z); + Sleep(100);x++; + if(x>100 && GetThreadContext(thread, &context)) + { + printf("EIP: %lx\n", context.Eip); + printf("Calling resumethread ... \n"); + ResumeThread(thread); + } + } + + ExitProcess(0); + return(0); +} diff --git a/rosapps/tests/tcpsvr/.cvsignore b/rosapps/tests/tcpsvr/.cvsignore new file mode 100644 index 00000000000..060f7fa87a2 --- /dev/null +++ b/rosapps/tests/tcpsvr/.cvsignore @@ -0,0 +1,7 @@ +*.o +*.d +*.a +*.exe +*.coff +*.sym +*.map \ No newline at end of file diff --git a/rosapps/tests/tcpsvr/makefile b/rosapps/tests/tcpsvr/makefile new file mode 100644 index 00000000000..4321c11586b --- /dev/null +++ b/rosapps/tests/tcpsvr/makefile @@ -0,0 +1,23 @@ +# $Id: makefile,v 1.1 2004/10/21 04:48:45 sedwards Exp $ + +PATH_TO_TOP = ../../../reactos + +TARGET_NORC = yes + +TARGET_TYPE = program + +TARGET_APPTYPE = console + +TARGET_NAME = tcpsvr + +TARGET_SDKLIBS = kernel32.a ws2_32.a + +TARGET_OBJECTS = $(TARGET_NAME).o + +TARGET_CFLAGS = -D__USE_W32API -Wall -Werror + +include $(PATH_TO_TOP)/rules.mak + +include $(TOOLS_PATH)/helper.mk + +# EOF diff --git a/rosapps/tests/tcpsvr/tcpsvr.c b/rosapps/tests/tcpsvr/tcpsvr.c new file mode 100644 index 00000000000..10eda654a8a --- /dev/null +++ b/rosapps/tests/tcpsvr/tcpsvr.c @@ -0,0 +1,175 @@ +/* tcpServer.c + * + * Simple Winsock TCP server test. + * Later will be used as base for ReactOS telnetd + * + * HISTORY: + * 6-15-02 - Added Winsock support to UNIX tcp test + * 6-16-02 - Removed Unix support + * 6-17-02 - Added extra comments to code + * + */ + +#include +#include +#include +#include + +#undef ERROR +#define SUCCESS 0 +#define ERROR 1 + +#define END_LINE 0x0A +#define SERVER_PORT 23 +#define MAX_MSG 100 + +/* function readline */ +int read_line(); + +int main (int argc, char *argv[]) { + + WORD wVersionRequested; + WSADATA WsaData; + INT Status; + int sd, newSd, cliLen; + + struct sockaddr_in cliAddr, servAddr; + char line[MAX_MSG]; + + wVersionRequested = MAKEWORD(2, 2); + + Status = WSAStartup(wVersionRequested, &WsaData); + if (Status != 0) { + printf("Could not initialize winsock dll.\n"); + return FALSE; + } + + /* create socket */ + sd = socket(AF_INET, SOCK_STREAM, 0); + if(sd<0) { + perror("cannot open socket "); + WSACleanup(); + return ERROR; + } + + /* bind server port */ + servAddr.sin_family = AF_INET; + servAddr.sin_addr.s_addr = htonl(INADDR_ANY); + servAddr.sin_port = htons(SERVER_PORT); + + if(bind(sd, (struct sockaddr *) &servAddr, sizeof(servAddr))<0) { + perror("cannot bind port "); + WSACleanup(); + return ERROR; + } + + listen(sd,5); + + while(1) { + + printf("%s: \n" + "To start test, Please telnet to localhost (127.0.0.1) port 23 \n" + "When connected input raw data followed by End of Line\n" + "Test is now running on TCP port %u\n",argv[0],SERVER_PORT); + + cliLen = sizeof(cliAddr); + newSd = accept(sd, (struct sockaddr *) &cliAddr, &cliLen); + if(newSd<0) { + perror("cannot accept connection "); + WSACleanup(); + return ERROR; + } + + /* init line */ + memset(line,0x0,MAX_MSG); + + /* receive segments */ + while(read_line(newSd,line)!=ERROR) { + + printf("%s: received from %s:TCP%d : %s\n", argv[0], + inet_ntoa(cliAddr.sin_addr), + ntohs(cliAddr.sin_port), line); + /* init line */ + memset(line,0x0,MAX_MSG); + + } /* while(read_line) */ + + } /* while (1) */ + +} + + +/* WARNING WARNING WARNING WARNING WARNING WARNING WARNING */ +/* this function is experimental.. I don't know yet if it works */ +/* correctly or not. Use Steven's readline() function to have */ +/* something robust. */ +/* WARNING WARNING WARNING WARNING WARNING WARNING WARNING */ + +/* rcv_line is my function readline(). Data is read from the socket when */ +/* needed, but not byte after bytes. All the received data is read. */ +/* This means only one call to recv(), instead of one call for */ +/* each received byte. */ +/* You can set END_CHAR to whatever means endofline for you. (0x0A is \n)*/ +/* read_lin returns the number of bytes returned in line_to_return */ +int read_line(int newSd, char *line_to_return) { + + static int rcv_ptr=0; + static char rcv_msg[MAX_MSG]; + static int n; + int offset; + + offset=0; + + while(1) { + if(rcv_ptr==0) { + /* read data from socket */ + memset(rcv_msg,0x0,MAX_MSG); /* init buffer */ + n = recv(newSd, rcv_msg, MAX_MSG, 0); /* wait for data */ + if (n<0) { + perror(" cannot receive data "); + return ERROR; + } else if (n==0) { + printf(" connection closed by client\n"); + close(newSd); + WSACleanup(); + return ERROR; + } + } + + /* if new data read on socket */ + /* OR */ + /* if another line is still in buffer */ + + /* copy line into 'line_to_return' */ + while(*(rcv_msg+rcv_ptr)!=END_LINE && rcv_ptr return line */ + if(rcv_ptr==n-1) { + /* set last byte to END_LINE */ + *(line_to_return+offset)=END_LINE; + rcv_ptr=0; + return ++offset; + } + + /* end of line but still some data in buffer => return line */ + if(rcv_ptr */ + /* wait for more data to arrive on socket */ + if(rcv_ptr == n) { + rcv_ptr = 0; + } + + } /* while */ +} + + diff --git a/rosapps/tests/terminate/.cvsignore b/rosapps/tests/terminate/.cvsignore new file mode 100644 index 00000000000..060f7fa87a2 --- /dev/null +++ b/rosapps/tests/terminate/.cvsignore @@ -0,0 +1,7 @@ +*.o +*.d +*.a +*.exe +*.coff +*.sym +*.map \ No newline at end of file diff --git a/rosapps/tests/terminate/Makefile b/rosapps/tests/terminate/Makefile new file mode 100644 index 00000000000..3d3fe965130 --- /dev/null +++ b/rosapps/tests/terminate/Makefile @@ -0,0 +1,21 @@ +# $Id: Makefile,v 1.1 2004/10/21 04:48:45 sedwards Exp $ + +PATH_TO_TOP = ../../../reactos + +TARGET_NORC = yes + +TARGET_TYPE = program + +TARGET_APPTYPE = console + +TARGET_NAME = terminate + +TARGET_OBJECTS = $(TARGET_NAME).o + +TARGET_CFLAGS = -Wall -Werror + +include $(PATH_TO_TOP)/rules.mak + +include $(TOOLS_PATH)/helper.mk + +# EOF diff --git a/rosapps/tests/terminate/terminate.c b/rosapps/tests/terminate/terminate.c new file mode 100644 index 00000000000..986de455800 --- /dev/null +++ b/rosapps/tests/terminate/terminate.c @@ -0,0 +1,76 @@ +#define UNICODE + +#define NTOS_MODE_USER +#include +#include +#include + +#define DBG +#define NDEBUG +#include + +static volatile DWORD z; +static volatile DWORD x=0; + +static NTSTATUS STDCALL +thread_1(PVOID Param) +{ + DWORD y=0; + + for(;;) + { + z++; + if(x>50) + { + Sleep(100); + x=0;y++; + if(y==3) return(0); + } + } +} + +int +main(int argc, char *argv[]) +{ + HANDLE thread; + DWORD thread_id; + CONTEXT context; + DWORD z = 0; + + context.ContextFlags=CONTEXT_CONTROL; + + while (z < 50) + { + z++; + thread=CreateThread(NULL, + 0x1000, + (LPTHREAD_START_ROUTINE)thread_1, + NULL, + 0, + &thread_id); + + if(!thread) + { + printf("Error: could not create thread ...\n"); + ExitProcess(0); + } + + Sleep(1000); + + printf("T"); + if ((z % 5) == 0) + { + TerminateThread(thread, 0); + } + printf("C"); + GetThreadContext(thread, &context); + printf("S"); + SuspendThread(thread); + printf("R"); + ResumeThread(thread); + TerminateThread(thread, 0); + } + + ExitProcess(0); + return(0); +} diff --git a/rosapps/tests/thread/.cvsignore b/rosapps/tests/thread/.cvsignore new file mode 100644 index 00000000000..060f7fa87a2 --- /dev/null +++ b/rosapps/tests/thread/.cvsignore @@ -0,0 +1,7 @@ +*.o +*.d +*.a +*.exe +*.coff +*.sym +*.map \ No newline at end of file diff --git a/rosapps/tests/thread/makefile b/rosapps/tests/thread/makefile new file mode 100644 index 00000000000..656a78da358 --- /dev/null +++ b/rosapps/tests/thread/makefile @@ -0,0 +1,23 @@ +# $Id: makefile,v 1.1 2004/10/21 04:48:45 sedwards Exp $ + +PATH_TO_TOP = ../../../reactos + +TARGET_NORC = yes + +TARGET_TYPE = program + +TARGET_APPTYPE = console + +TARGET_NAME = thread + +TARGET_SDKLIBS = kernel32.a + +TARGET_OBJECTS = $(TARGET_NAME).o + +TARGET_CFLAGS = -Wall -Werror + +include $(PATH_TO_TOP)/rules.mak + +include $(TOOLS_PATH)/helper.mk + +# EOF diff --git a/rosapps/tests/thread/thread.c b/rosapps/tests/thread/thread.c new file mode 100644 index 00000000000..38df7a2fe2d --- /dev/null +++ b/rosapps/tests/thread/thread.c @@ -0,0 +1,88 @@ +/* $Id: thread.c,v 1.1 2004/10/21 04:48:45 sedwards Exp $ + * + * + * + * + */ + +#include +#include +#include + +#define NR_THREADS (10) + +ULONG nr; + +DWORD WINAPI thread_main1(LPVOID param) +{ + ULONG s; + + printf("Thread %ld running\n", (DWORD)param); + s = nr = ((nr * 1103515245) + 12345) & 0x7fffffff; + s = s % 10; + printf("s %ld\n", s); + Sleep(s); + printf("Thread %ld finished\n", (DWORD)param); + return 0; +} + +// Shows the help on how to use these program to the user +void showHelp(void) +{ + +printf("\nReactOS threads test program (built on %s).\n\n", __DATE__); +printf("syntax:\tthread.exe \n"); +printf("\twhere is an integer number\n"); +printf("\texample: thread.exe 100\n"); + + +} + +int main (int argc, char* argv[]) +{ + DWORD i=0; + DWORD id; + ULONG nr; + HANDLE ThreadHandle[NR_THREADS]; + + // The user must supply one argument (the seed). if he/she doesn't + // then we show the help. + // if(argc < 2) { + // showHelp(); + // return 1; + // } + + // nr = atoi(argv[1]); + nr = 500; + printf("Seed %ld\n", nr); + + printf("Creating %d threads...\n",NR_THREADS*2); + for (i=0;i +#include +#include + +HANDLE hWaitForFailure; +HANDLE hOkToPostThreadMessage; +HANDLE hOkToTerminate; + +DWORD WINAPI thread( LPVOID crap ) +{ + MSG msg; + + /* Failure case ... Wait for the parent to try to post a message + before queue creation */ + printf( "Waiting to create the message queue.\n" ); + + WaitForSingleObject(hWaitForFailure,INFINITE); + + printf( "Creating message queue.\n" ); + + /* "Create" a message queue */ + PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE ); + + printf( "Signalling the parent that we're ready.\n" ); + + /* Signal that it's ok to post */ + SetEvent( hOkToPostThreadMessage ); + + printf( "Listening messages.\n" ); + + /* Now read some messages */ + while( GetMessage( &msg, 0,0,0 ) ) { + printf( "Received message: %04x %04x %08lx\n", + (msg.message & 0xffff), + (msg.wParam & 0xffff), + msg.lParam ); + assert( !msg.hwnd ); + } + + printf( "Finished receiving messages.\n" ); + SetEvent( hOkToTerminate ); + + return 0; +} + +int main( int argc, char **argv ) +{ + DWORD id; + + printf( "Creating events\n" ); + + hOkToPostThreadMessage = CreateEvent( NULL, FALSE, FALSE, NULL ); + hOkToTerminate = CreateEvent( NULL, FALSE, FALSE, NULL ); + hWaitForFailure = CreateEvent( NULL, FALSE, FALSE, NULL ); + + printf( "Created events\n" ); + + if( CreateThread( 0, 0, thread, 0, 0, &id ) == NULL ) { + printf( "Couldn't create one thread.\n" ); + return 0; + } + + printf( "Posting to non-existent queue\n" ); + + /* Check failure case */ + assert( PostThreadMessage( id, WM_USER + 0, 1, 2 ) == FALSE ); + + printf( "Signalling thread to advance.\n" ); + + SetEvent( hWaitForFailure ); + + printf( "Waiting for signal from thread.\n" ); + WaitForSingleObject( hOkToPostThreadMessage, INFINITE ); + + printf( "Sending three messages, then quit.\n" ); + assert( PostThreadMessage( id, WM_USER + 0, 1, 2 ) ); + assert( PostThreadMessage( id, WM_USER + 1, 3, 4 ) ); + Sleep( 500 ); /* Sleep a bit, so that the queue is empty for a bit. */ + assert( PostThreadMessage( id, WM_USER + 2, 5, 6 ) ); + assert( PostThreadMessage( id, WM_QUIT, 0,0 ) ); + + WaitForSingleObject( hOkToTerminate, INFINITE ); + printf( "Test complete.\n" ); + + return 0; +} diff --git a/rosapps/tests/threadwait/.cvsignore b/rosapps/tests/threadwait/.cvsignore new file mode 100644 index 00000000000..060f7fa87a2 --- /dev/null +++ b/rosapps/tests/threadwait/.cvsignore @@ -0,0 +1,7 @@ +*.o +*.d +*.a +*.exe +*.coff +*.sym +*.map \ No newline at end of file diff --git a/rosapps/tests/threadwait/makefile b/rosapps/tests/threadwait/makefile new file mode 100644 index 00000000000..720fc224b8d --- /dev/null +++ b/rosapps/tests/threadwait/makefile @@ -0,0 +1,23 @@ +# $Id: makefile,v 1.1 2004/10/21 04:48:45 sedwards Exp $ + +PATH_TO_TOP = ../../../reactos + +TARGET_NORC = yes + +TARGET_TYPE = program + +TARGET_APPTYPE = console + +TARGET_NAME = threadwait + +TARGET_SDKLIBS = ntdll.a + +TARGET_OBJECTS = $(TARGET_NAME).o + +TARGET_CFLAGS = -Wall -Werror + +include $(PATH_TO_TOP)/rules.mak + +include $(TOOLS_PATH)/helper.mk + +# EOF diff --git a/rosapps/tests/threadwait/threadwait.c b/rosapps/tests/threadwait/threadwait.c new file mode 100644 index 00000000000..683bcc0d04f --- /dev/null +++ b/rosapps/tests/threadwait/threadwait.c @@ -0,0 +1,31 @@ +/* + * Author: Skywing (skywing@valhallalegends.com) + * Date: 09/09/2003 + * Purpose: Probe for PsUnblockThread crash due to double-acquire spin lock. + */ + +#include +#include + +DWORD __stdcall threadfunc(void* UNREFERENCED) +{ + printf("Thread: Initialized\n"); + Sleep(2500); + printf("Thread: Terminating...\n"); + return 0; +} + +int main(int ac, char **av) +{ + DWORD id; + HANDLE Thread; + + Thread = CreateThread(0, 0, threadfunc, 0, 0, &id); + printf("Main: ThreadId for new thread is %08lx\n", id); + printf("Main: Waiting on thread...\n"); + WaitForSingleObject(Thread, INFINITE); + printf("Main: OK, somebody fixed the PsUnblockThread spinlock double-acquire crash\n"); + NtClose(Thread); + printf("Main: Terminating...\n"); + return 0; +} diff --git a/rosapps/tests/tmrqueue/.cvsignore b/rosapps/tests/tmrqueue/.cvsignore new file mode 100644 index 00000000000..060f7fa87a2 --- /dev/null +++ b/rosapps/tests/tmrqueue/.cvsignore @@ -0,0 +1,7 @@ +*.o +*.d +*.a +*.exe +*.coff +*.sym +*.map \ No newline at end of file diff --git a/rosapps/tests/tmrqueue/makefile b/rosapps/tests/tmrqueue/makefile new file mode 100644 index 00000000000..5a3ea8fd3c1 --- /dev/null +++ b/rosapps/tests/tmrqueue/makefile @@ -0,0 +1,23 @@ +# $Id: makefile,v 1.1 2004/10/21 04:48:45 sedwards Exp $ + +PATH_TO_TOP = ../../../reactos + +TARGET_NORC = yes + +TARGET_TYPE = program + +TARGET_APPTYPE = console + +TARGET_NAME = tmrqueue + +TARGET_SDKLIBS = kernel32.a + +TARGET_OBJECTS = $(TARGET_NAME).o + +TARGET_CFLAGS = -Wall -Werror + +include $(PATH_TO_TOP)/rules.mak + +include $(TOOLS_PATH)/helper.mk + +# EOF diff --git a/rosapps/tests/tmrqueue/tmrqueue.c b/rosapps/tests/tmrqueue/tmrqueue.c new file mode 100644 index 00000000000..5dd2df7f005 --- /dev/null +++ b/rosapps/tests/tmrqueue/tmrqueue.c @@ -0,0 +1,365 @@ +#include +#include +#include + +#define N_TIMEOUT 3 + +/*******************************************************************************/ + +typedef struct _TEST *PTEST; + +typedef VOID (*PFNTEST)(PTEST Test, HANDLE hEvent); + +typedef struct _TEST +{ + TCHAR *description; + BOOL Result; + PFNTEST Routine; + int id; +} TEST; + +static TEST Tests[3]; + +VOID RunTests(VOID) +{ + int i, nTests; + static HANDLE hEvent; + + hEvent = CreateEvent(NULL, FALSE, FALSE, NULL); + if(hEvent == NULL) + { + _tprintf(_T("Unable to create event!")); + return; + } + + nTests = sizeof(Tests) / sizeof(TEST); + + for(i = 0; i < nTests; i++) + { + Tests[i].id = i + 1; + + if(Tests[i].Routine == NULL) + { + continue; + } + + _tprintf(_T("+++ TEST %d: %s\n"), Tests[i].id, Tests[i].description); + + Tests[i].Routine(&Tests[i], hEvent); + + WaitForSingleObject(hEvent, INFINITE); + + _tprintf(_T("\n\n")); + } + + CloseHandle(hEvent); +} + +VOID PrintTestResults(VOID) +{ + int i, nTests, nsuccess = 0, nfailed = 0; + TCHAR *status; + + nTests = sizeof(Tests) / sizeof(TEST); + + for(i = 0; i < nTests; i++) + { + if(Tests[i].Routine == NULL) + { + status = _T("SKIPPED"); + } + else if(Tests[i].Result == TRUE) + { + status = _T("SUCCESS"); + nsuccess++; + } + else + { + status = _T("FAILED "); + nfailed++; + } + + _tprintf(_T("Test %d: %s %s\n"), i, status, Tests[i].description); + } + + _tprintf(_T("\nTests succeeded: %d, failed: %d\n"), nsuccess, nfailed); + if(nfailed == 0) + { + _tprintf(_T(" ALL TESTS SUCCESSFUL!\n")); + } +} + +/*******************************************************************************/ + +typedef struct _TESTINFO +{ + PTEST Test; + int secsleft; + HANDLE hTimer; + HANDLE hEvent; + /* additional stuff */ + union + { + struct + { + /* nothing */ + } Test1; + struct + { + HANDLE hWaitEvent; + } Test2; + struct + { + HANDLE hWaitEvent; + HANDLE hNotification; + } Test3; + }; +} TESTINFO, *PTESTINFO; + +VOID CALLBACK TimerCallback1(PVOID Param, BOOLEAN Fired) +{ + PTESTINFO Info = (PTESTINFO)Param; + + _tprintf(_T("[%d]TimerCallback(0x%x, %d) called (%d)\n"), (int)Info->Test->id, (int)Info->hTimer, (int)Fired, --Info->secsleft); + + if(Info->secsleft == 0) + { + BOOL stat; + + _tprintf(_T("[%d]Timout finished, delete timer queue..."), (int)Info->Test->id); + stat = DeleteTimerQueueTimer(NULL, Info->hTimer, NULL); + if(stat) + _tprintf(_T("returned OK -> test FAILED!\n")); + else + { + int error = GetLastError(); + + switch(error) + { + case ERROR_IO_PENDING: + _tprintf(_T("OK, Overlapped I/O operation in progress\n")); + /* this test is only successful in this case */ + Info->Test->Result = TRUE; + break; + default: + _tprintf(_T("Failed, LastError: %d\n"), (int)GetLastError()); + break; + } + } + + /* set the event to continue tests */ + SetEvent(Info->hEvent); + } +} + +VOID Test1(PTEST Test, HANDLE hEvent) +{ + static TESTINFO Info; + + Info.Test = Test; + Info.hEvent = hEvent; + Info.secsleft = N_TIMEOUT; + + if(!CreateTimerQueueTimer(&Info.hTimer, NULL, TimerCallback1, &Info, 1000, 1000, 0)) + { + _tprintf(_T("[%d]CreateTimerQueueTimer() failed, LastError: %d!"), (int)Info.Test->id, (int)GetLastError()); + /* we failed, set the event to continue tests */ + SetEvent(hEvent); + return; + } + + _tprintf(_T("[%d]CreateTimerQueueTimer() created timer 0x%x, countdown (%d sec)...\n"), (int)Info.Test->id, (int)Info.hTimer, (int)Info.secsleft); +} + +/*******************************************************************************/ + +VOID CALLBACK TimerCallback2(PVOID Param, BOOLEAN Fired) +{ + PTESTINFO Info = (PTESTINFO)Param; + + _tprintf(_T("[%d]TimerCallback(0x%x, %d) called (%d)\n"), (int)Info->Test->id, (int)Info->hTimer, (int)Fired, --Info->secsleft); + + if(Info->secsleft == 0) + { + /* set the event to continue tests */ + SetEvent(Info->Test2.hWaitEvent); + + /* sleep a bit */ + Sleep(1500); + } +} + +VOID Test2(PTEST Test, HANDLE hEvent) +{ + static TESTINFO Info; + BOOL stat; + + Info.Test = Test; + Info.hEvent = hEvent; + Info.secsleft = N_TIMEOUT; + + Info.Test2.hWaitEvent = CreateEvent(NULL, FALSE, FALSE, NULL); + if(Info.Test2.hWaitEvent == NULL) + { + _tprintf(_T("[%d]Unable to create event!\n"), (int)Info.Test->id); + return; + } + + if(!CreateTimerQueueTimer(&Info.hTimer, NULL, TimerCallback2, &Info, 1000, 1000, 0)) + { + _tprintf(_T("[%d]CreateTimerQueueTimer() failed, LastError: %d!"), (int)Info.Test->id, (int)GetLastError()); + + CloseHandle(Info.Test2.hWaitEvent); + /* we failed, set the event to continue tests */ + SetEvent(hEvent); + return; + } + + _tprintf(_T("[%d]CreateTimerQueueTimer() created timer 0x%x, countdown (%d sec)...\n"), (int)Test->id, (int)Info.hTimer, (int)Info.secsleft); + + WaitForSingleObject(Info.Test2.hWaitEvent, INFINITE); + + _tprintf(_T("[%d]Timout finished, delete timer queue..."), (int)Test->id); + stat = DeleteTimerQueueTimer(NULL, Info.hTimer, INVALID_HANDLE_VALUE); + if(stat) + { + _tprintf(_T("OK\n")); + /* this test is only successful in this case */ + Test->Result = TRUE; + } + else + { + int error = GetLastError(); + + switch(error) + { + case ERROR_IO_PENDING: + _tprintf(_T("FAILED, Overlapped I/O operation in progress\n")); + break; + default: + _tprintf(_T("Failed, LastError: %d\n"), (int)GetLastError()); + break; + } + } + + SetEvent(Info.hEvent); +} + +/*******************************************************************************/ + +VOID CALLBACK TimerCallback3(PVOID Param, BOOLEAN Fired) +{ + PTESTINFO Info = (PTESTINFO)Param; + + _tprintf(_T("[%d]TimerCallback(0x%x, %d) called (%d)\n"), (int)Info->Test->id, (int)Info->hTimer, (int)Fired, --Info->secsleft); + + if(Info->secsleft == 0) + { + /* set the event to continue tests */ + SetEvent(Info->Test3.hWaitEvent); + + /* sleep a bit */ + Sleep(1500); + } +} + +VOID Test3(PTEST Test, HANDLE hEvent) +{ + static TESTINFO Info; + BOOL stat; + + Info.Test = Test; + Info.hEvent = hEvent; + Info.secsleft = N_TIMEOUT; + + Info.Test3.hWaitEvent = CreateEvent(NULL, FALSE, FALSE, NULL); + if(Info.Test3.hWaitEvent == NULL) + { + _tprintf(_T("[%d]Unable to create event!\n"), (int)Info.Test->id); + return; + } + + Info.Test3.hNotification = CreateEvent(NULL, FALSE, FALSE, NULL); + if(Info.Test3.hNotification == NULL) + { + _tprintf(_T("[%d]Unable to create notification event!\n"), (int)Info.Test->id); + return; + } + + if(!CreateTimerQueueTimer(&Info.hTimer, NULL, TimerCallback3, &Info, 1000, 1000, 0)) + { + _tprintf(_T("[%d]CreateTimerQueueTimer() failed, LastError: %d!"), (int)Info.Test->id, (int)GetLastError()); + + CloseHandle(Info.Test3.hWaitEvent); + CloseHandle(Info.Test3.hNotification); + /* we failed, set the event to continue tests */ + SetEvent(hEvent); + return; + } + + _tprintf(_T("[%d]CreateTimerQueueTimer() created timer 0x%x, countdown (%d sec)...\n"), (int)Test->id, (int)Info.hTimer, (int)Info.secsleft); + + WaitForSingleObject(Info.Test3.hWaitEvent, INFINITE); + + _tprintf(_T("[%d]Timout finished, delete timer queue..."), (int)Test->id); + stat = DeleteTimerQueueTimer(NULL, Info.hTimer, Info.Test3.hNotification); + if(stat) + { + _tprintf(_T("returned OK -> test FAILED!\n")); + } + else + { + int error = GetLastError(); + + switch(error) + { + case ERROR_IO_PENDING: + _tprintf(_T("OK, Overlapped I/O operation in progress\n")); + /* this test is only successful in this case */ + Test->Result = TRUE; + break; + default: + _tprintf(_T("Failed, LastError: %d\n"), (int)GetLastError()); + break; + } + } + + WaitForSingleObject(Info.Test3.hNotification, INFINITE); + + CloseHandle(Info.Test3.hWaitEvent); + CloseHandle(Info.Test3.hNotification); + + SetEvent(Info.hEvent); +} + +/*******************************************************************************/ + +VOID +InitTests(VOID) +{ + ZeroMemory(Tests, sizeof(Tests)); + + Tests[0].description = _T("non-blocking DeleteTimerQueueTimer() call from callback"); + Tests[0].Routine = Test1; + + Tests[1].description = _T("blocking DeleteTimerQueueTimer() call"); + Tests[1].Routine = Test2; + + Tests[2].description = _T("blocking DeleteTimerQueueTimer() call with specified event"); + Tests[2].Routine = Test3; +} + +int main(int argc, char* argv[]) +{ + _tprintf(_T("+++ TimerQueue test running +++\n\n")); + + InitTests(); + + RunTests(); + + _tprintf(_T("\n+++ RESULTS +++\n")); + + PrintTestResults(); + + return 0; +} diff --git a/rosapps/tests/tokentest/.cvsignore b/rosapps/tests/tokentest/.cvsignore new file mode 100644 index 00000000000..060f7fa87a2 --- /dev/null +++ b/rosapps/tests/tokentest/.cvsignore @@ -0,0 +1,7 @@ +*.o +*.d +*.a +*.exe +*.coff +*.sym +*.map \ No newline at end of file diff --git a/rosapps/tests/tokentest/makefile b/rosapps/tests/tokentest/makefile new file mode 100644 index 00000000000..65ad7825fb0 --- /dev/null +++ b/rosapps/tests/tokentest/makefile @@ -0,0 +1,23 @@ +# $Id: makefile,v 1.1 2004/10/21 04:48:46 sedwards Exp $ + +PATH_TO_TOP = ../../../reactos + +TARGET_NORC = yes + +TARGET_TYPE = program + +TARGET_APPTYPE = console + +TARGET_NAME = tokentst + +TARGET_SDKLIBS = ntdll.a kernel32.a + +TARGET_OBJECTS = tokentest.o + +TARGET_CFLAGS = -Wall -Werror -Wno-format + +include $(PATH_TO_TOP)/rules.mak + +include $(TOOLS_PATH)/helper.mk + +# EOF diff --git a/rosapps/tests/tokentest/tokentest.c b/rosapps/tests/tokentest/tokentest.c new file mode 100644 index 00000000000..6578f522d72 --- /dev/null +++ b/rosapps/tests/tokentest/tokentest.c @@ -0,0 +1,529 @@ +#define UNICODE +#define _UNICODE + +#define ANONYMOUSUNIONS +#include +#include + +#define INCLUDE_THE_DDK_HEADERS +#ifdef INCLUDE_THE_DDK_HEADERS +#include +#define ROS_ACE_HEADER ACE_HEADER +#define ROS_ACE ACE + +// +// Allocate the System Luid. The first 1000 LUIDs are reserved. +// Use #999 here (0x3E7 = 999) +// + +#define SYSTEM_LUID { 0x3E7, 0x0 } +#define ANONYMOUS_LOGON_LUID { 0x3e6, 0x0 } +#define LOCALSERVICE_LUID { 0x3e5, 0x0 } +#define NETWORKSERVICE_LUID { 0x3e4, 0x0 } + +#else +typedef LONG NTSTATUS, *PNTSTATUS; + +typedef struct _UNICODE_STRING +{ + USHORT Length; + USHORT MaximumLength; + PWSTR Buffer; +} UNICODE_STRING, *PUNICODE_STRING; + +typedef struct _OBJECT_ATTRIBUTES { + ULONG Length; + HANDLE RootDirectory; + PUNICODE_STRING ObjectName; + ULONG Attributes; + PVOID SecurityDescriptor; // Points to type SECURITY_DESCRIPTOR + PVOID SecurityQualityOfService; // Points to type SECURITY_QUALITY_OF_SERVICE +} OBJECT_ATTRIBUTES; +typedef OBJECT_ATTRIBUTES *POBJECT_ATTRIBUTES; + +typedef struct _ROS_ACE_HEADER +{ + CHAR AceType; + CHAR AceFlags; + USHORT AceSize; +} ROS_ACE_HEADER, *PROS_ACE_HEADER; + +typedef struct +{ + ACE_HEADER Header; + ACCESS_MASK AccessMask; +} ROS_ACE, *PROS_ACE; + +NTSYSAPI +NTSTATUS +NTAPI +RtlConvertSidToUnicodeString ( + IN OUT PUNICODE_STRING String, + IN PSID Sid, + IN BOOLEAN AllocateString + ); + +NTSYSAPI +NTSTATUS +NTAPI +RtlCreateAcl( + PACL Acl, + ULONG AclSize, + ULONG AclRevision); + +NTSYSAPI +NTSTATUS +NTAPI +RtlAddAccessAllowedAce ( + PACL Acl, + ULONG Revision, + ACCESS_MASK AccessMask, + PSID Sid + ); + +NTSYSAPI +NTSTATUS +NTAPI +RtlGetAce ( + PACL Acl, + ULONG AceIndex, + PROS_ACE *Ace + ); + +NTSYSAPI +NTSTATUS +NTAPI +ZwAllocateLocallyUniqueId( + OUT PLUID Luid + ); + +NTSYSAPI +NTSTATUS +NTAPI +ZwCreateToken( + OUT PHANDLE TokenHandle, + IN ACCESS_MASK DesiredAccess, + IN POBJECT_ATTRIBUTES ObjectAttributes, + IN TOKEN_TYPE TokenType, + IN PLUID AuthenticationId, + IN PLARGE_INTEGER ExpirationTime, + IN PTOKEN_USER TokenUser, + IN PTOKEN_GROUPS TokenGroups, + IN PTOKEN_PRIVILEGES TokenPrivileges, + IN PTOKEN_OWNER TokenOwner, + IN PTOKEN_PRIMARY_GROUP TokenPrimaryGroup, + IN PTOKEN_DEFAULT_DACL TokenDefaultDacl, + IN PTOKEN_SOURCE TokenSource + ); +#define NT_SUCCESS(StatCode) ((NTSTATUS)(StatCode) >= 0) +#endif +#include + +#define INITIAL_PRIV_ENABLED SE_PRIVILEGE_ENABLED_BY_DEFAULT|SE_PRIVILEGE_ENABLED +#define INITIAL_PRIV_DISABLED 0 +LUID_AND_ATTRIBUTES InitialPrivilegeSet[] = +{ + { { 0x00000007, 0x00000000 }, INITIAL_PRIV_ENABLED }, // SeTcbPrivilege + { { 0x00000002, 0x00000000 }, INITIAL_PRIV_DISABLED }, // SeCreateTokenPrivilege + { { 0x00000009, 0x00000000 }, INITIAL_PRIV_DISABLED }, // SeTakeOwnershipPrivilege + { { 0x0000000f, 0x00000000 }, INITIAL_PRIV_ENABLED }, // SeCreatePagefilePrivilege + { { 0x00000004, 0x00000000 }, INITIAL_PRIV_ENABLED }, // SeLockMemoryPrivilege + { { 0x00000003, 0x00000000 }, INITIAL_PRIV_DISABLED }, // SeAssignPrimaryTokenPrivilege + { { 0x00000005, 0x00000000 }, INITIAL_PRIV_DISABLED }, // SeIncreaseQuotaPrivilege + { { 0x0000000e, 0x00000000 }, INITIAL_PRIV_ENABLED }, // SeIncreaseBasePriorityPrivilege + { { 0x00000010, 0x00000000 }, INITIAL_PRIV_ENABLED }, // SeCreatePermanentPrivilege + { { 0x00000014, 0x00000000 }, INITIAL_PRIV_ENABLED }, // SeDebugPrivilege + { { 0x00000015, 0x00000000 }, INITIAL_PRIV_ENABLED }, // SeAuditPrivilege + { { 0x00000008, 0x00000000 }, INITIAL_PRIV_DISABLED }, // SeSecurityPrivilege + { { 0x00000016, 0x00000000 }, INITIAL_PRIV_DISABLED }, // SeSystemEnvironmentPrivilege + { { 0x00000017, 0x00000000 }, INITIAL_PRIV_ENABLED }, // SeChangeNotifyPrivilege + { { 0x00000011, 0x00000000 }, INITIAL_PRIV_DISABLED }, // SeBackupPrivilege + { { 0x00000012, 0x00000000 }, INITIAL_PRIV_DISABLED }, // SeRestorePrivilege + { { 0x00000013, 0x00000000 }, INITIAL_PRIV_DISABLED }, // SeShutdownPrivilege + { { 0x0000000a, 0x00000000 }, INITIAL_PRIV_DISABLED }, // SeLoadDriverPrivilege + { { 0x0000000d, 0x00000000 }, INITIAL_PRIV_ENABLED }, // SeProfileSingleProcessPrivilege + { { 0x0000000c, 0x00000000 }, INITIAL_PRIV_DISABLED }, // SeSystemtimePrivilege + { { 0x00000019, 0x00000000 }, INITIAL_PRIV_DISABLED }, // SeUndockPrivilege + { { 0x0000001c, 0x00000000 }, INITIAL_PRIV_DISABLED }, // SeManageVolumePrivilege +}; + +typedef struct _SID_2 +{ + UCHAR Revision; + UCHAR SubAuthorityCount; + SID_IDENTIFIER_AUTHORITY IdentifierAuthority; + ULONG SubAuthority[2]; +} SID_2; + +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +void +PrintSid(SID_AND_ATTRIBUTES* pSid, TOKEN_OWNER* pOwner, TOKEN_PRIMARY_GROUP* pPrimary) +{ + UNICODE_STRING scSid; + + RtlConvertSidToUnicodeString(&scSid, pSid->Sid, TRUE); + printf("%wZ [", &scSid); + LocalFree(scSid.Buffer); + + if ( EqualSid(pSid->Sid, pOwner->Owner) ) + printf("owner,"); + + if ( EqualSid(pSid->Sid, pPrimary->PrimaryGroup) ) + printf("primary,"); + + if ( pSid->Attributes & SE_GROUP_ENABLED ) + { + if ( pSid->Attributes & SE_GROUP_ENABLED_BY_DEFAULT ) + printf("enabled-default,"); + else + printf("enabled,"); + } + + if ( pSid->Attributes & SE_GROUP_LOGON_ID ) + printf("logon,"); + + + if ( pSid->Attributes & SE_GROUP_MANDATORY ) + printf("mandatory,"); + + printf("]\n"); +} + +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +void +DisplayTokenSids(TOKEN_USER* pUser, + TOKEN_GROUPS* pGroups, + TOKEN_OWNER* pOwner, + TOKEN_PRIMARY_GROUP* pPrimary) +{ + DWORD i; + + printf("\nSids:\n"); + PrintSid(&pUser->User, pOwner, pPrimary); + printf("\nGroups:\n"); + for (i = 0; i < pGroups->GroupCount; i++) + PrintSid(&pGroups->Groups[i], pOwner, pPrimary); +} + +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +void +DisplayTokenPrivileges(TOKEN_PRIVILEGES* pPriv) +{ + WCHAR buffer[256]; + DWORD i; + + printf("\nprivileges:\n"); + for (i = 0; i < pPriv->PrivilegeCount; i++) + { + DWORD cbName = sizeof(buffer) / sizeof(buffer[0]); + LookupPrivilegeName(0, &pPriv->Privileges[i].Luid, buffer, &cbName); + + printf("%S{0x%08x, 0x%08x} [", buffer, pPriv->Privileges[i].Luid.HighPart, pPriv->Privileges[i].Luid.LowPart); + + if ( pPriv->Privileges[i].Attributes & SE_PRIVILEGE_ENABLED ) + printf("enabled,"); + if ( pPriv->Privileges[i].Attributes & SE_PRIVILEGE_ENABLED_BY_DEFAULT ) + printf("default,"); + if ( pPriv->Privileges[i].Attributes & SE_PRIVILEGE_USED_FOR_ACCESS ) + printf("used"); + + printf("]\n"); + } +} + +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +void +DisplayDacl(PACL pAcl) +{ + DWORD i; + NTSTATUS status; + + if ( ! pAcl ) + { + printf("\nNo Default Dacl.\n"); + return; + } + + printf("\nDacl:\n"); + for (i = 0; i < pAcl->AceCount; i++) + { + UNICODE_STRING scSid; + ROS_ACE* pAce; + LPWSTR wszType = 0; + PSID pSid; + + status = RtlGetAce(pAcl, i, (ROS_ACE**) &pAce); + if ( ! NT_SUCCESS(status) ) + { + printf("RtlGetAce(): status = 0x%08x\n", status); + break; + } + + pSid = (PSID) (pAce + 1); + if ( pAce->Header.AceType == ACCESS_ALLOWED_ACE_TYPE ) + wszType = L"allow"; + if ( pAce->Header.AceType == ACCESS_DENIED_ACE_TYPE ) + wszType = L"deny "; + + status = RtlConvertSidToUnicodeString(&scSid, pSid, TRUE); + if ( ! NT_SUCCESS(status) ) + { + printf("RtlConvertSidToUnicodeString(): status = 0x%08x\n", status); + break; + } + + printf("%d.) %S %wZ 0x%08x\n", i, wszType, &scSid, pAce->AccessMask); + LocalFree(scSid.Buffer); + } +} + +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +PVOID +GetFromToken(HANDLE hToken, TOKEN_INFORMATION_CLASS tic) +{ + BOOL bResult; + DWORD n; + PBYTE p = 0; + + bResult = GetTokenInformation(hToken, tic, 0, 0, &n); + if ( ! bResult && GetLastError() != ERROR_INSUFFICIENT_BUFFER) + return 0; + + p = (PBYTE) malloc(n); + if ( ! GetTokenInformation(hToken, tic, p, n, &n) ) + { + printf("GetFromToken() failed for TOKEN_INFORMATION_CLASS(%d): %d\n", tic, GetLastError()); + free(p); + return 0; + } + + return p; +} + +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +void +DisplayToken(HANDLE hTokenSource) +{ + TOKEN_USER* pTokenUser = (PTOKEN_USER) GetFromToken(hTokenSource, TokenUser); + TOKEN_GROUPS* pTokenGroups = (PTOKEN_GROUPS) GetFromToken(hTokenSource, TokenGroups); + TOKEN_OWNER* pTokenOwner = (PTOKEN_OWNER) GetFromToken(hTokenSource, TokenOwner); + TOKEN_PRIMARY_GROUP* pTokenPrimaryGroup = (PTOKEN_PRIMARY_GROUP) GetFromToken(hTokenSource, TokenPrimaryGroup); + TOKEN_PRIVILEGES* pTokenPrivileges = (PTOKEN_PRIVILEGES) GetFromToken(hTokenSource, TokenPrivileges); + TOKEN_DEFAULT_DACL* pTokenDefaultDacl = (PTOKEN_DEFAULT_DACL) GetFromToken(hTokenSource, TokenDefaultDacl); + + DisplayTokenSids(pTokenUser, pTokenGroups, pTokenOwner, pTokenPrimaryGroup); + // DisplayTokenPrivileges(pTokenPrivileges); + DisplayDacl(pTokenDefaultDacl->DefaultDacl); + + free(pTokenUser); + free(pTokenGroups); + free(pTokenOwner); + free(pTokenPrimaryGroup); + free(pTokenPrivileges); + free(pTokenDefaultDacl); +} + +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +BOOL +EnablePrivilege(LPWSTR wszName) +{ + HANDLE hToken; + TOKEN_PRIVILEGES priv = {1, {{{0, 0}, SE_PRIVILEGE_ENABLED}}}; + BOOL bResult; + + LookupPrivilegeValue(0, wszName, &priv.Privileges[0].Luid); + + OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken); + + AdjustTokenPrivileges(hToken, FALSE, &priv, sizeof priv, 0, 0); + bResult = GetLastError() == ERROR_SUCCESS; + + CloseHandle(hToken); + return bResult; +} + +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +NTSTATUS +CreateInitialSystemToken(HANDLE* phSystemToken) +{ + static SID sidSystem = { 1, 1, {SECURITY_NT_AUTHORITY}, {SECURITY_LOCAL_SYSTEM_RID} }; + static SID sidEveryone = { 1, 1, {SECURITY_WORLD_SID_AUTHORITY}, {SECURITY_WORLD_RID} }; + static SID sidAuthenticatedUser = { 1, 1, {SECURITY_NT_AUTHORITY}, {SECURITY_AUTHENTICATED_USER_RID} }; + static SID_2 sidAdministrators = { 1, 2, {SECURITY_NT_AUTHORITY}, {SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS} }; + static const int nGroupCount = 3; + + NTSTATUS status; + ULONG uSize; + DWORD i; + + TOKEN_USER tkUser; + TOKEN_OWNER tkDefaultOwner; + TOKEN_PRIMARY_GROUP tkPrimaryGroup; + + TOKEN_GROUPS* ptkGroups = 0; + TOKEN_PRIVILEGES* ptkPrivileges = 0; + TOKEN_DEFAULT_DACL tkDefaultDacl = { 0 }; + + LARGE_INTEGER tkExpiration; + + LUID authId = SYSTEM_LUID; + + TOKEN_SOURCE source = + { + { '*', '*', 'A', 'N', 'O', 'N', '*', '*' }, + {0, 0} + }; + + SECURITY_QUALITY_OF_SERVICE sqos = + { + sizeof(sqos), + SecurityAnonymous, + SECURITY_STATIC_TRACKING, + FALSE + }; + + OBJECT_ATTRIBUTES oa = + { + sizeof(oa), + 0, + 0, + 0, + 0, + &sqos + }; + + tkExpiration.QuadPart = -1; + status = ZwAllocateLocallyUniqueId(&source.SourceIdentifier); + if ( status != 0 ) + return status; + + tkUser.User.Sid = &sidSystem; + tkUser.User.Attributes = 0; + + // Under WinXP (the only MS OS I've tested) ZwCreateToken() + // squawks if we use sidAdministrators here -- though running + // a progrem under AT and using the DisplayToken() function + // shows that the system token does default ownership to + // Administrator. + + // For now, default ownership to system, since that works + tkDefaultOwner.Owner = &sidSystem; + tkPrimaryGroup.PrimaryGroup = &sidSystem; + + uSize = sizeof(TOKEN_GROUPS) - sizeof(ptkGroups->Groups); + uSize += sizeof(SID_AND_ATTRIBUTES) * nGroupCount; + + ptkGroups = (TOKEN_GROUPS*) malloc(uSize); + ptkGroups->GroupCount = nGroupCount; + + ptkGroups->Groups[0].Sid = (SID*) &sidAdministrators; + ptkGroups->Groups[0].Attributes = SE_GROUP_ENABLED; + + ptkGroups->Groups[1].Sid = &sidEveryone; + ptkGroups->Groups[1].Attributes = SE_GROUP_ENABLED|SE_GROUP_ENABLED_BY_DEFAULT|SE_GROUP_MANDATORY; + + ptkGroups->Groups[2].Sid = &sidAuthenticatedUser; + ptkGroups->Groups[2].Attributes = SE_GROUP_ENABLED|SE_GROUP_ENABLED_BY_DEFAULT|SE_GROUP_MANDATORY; + + uSize = sizeof(TOKEN_PRIVILEGES) - sizeof(ptkPrivileges->Privileges); + uSize += sizeof(LUID_AND_ATTRIBUTES) * sizeof(InitialPrivilegeSet) / sizeof(InitialPrivilegeSet[0]); + ptkPrivileges = (TOKEN_PRIVILEGES*) malloc(uSize); + ptkPrivileges->PrivilegeCount = sizeof(InitialPrivilegeSet) / sizeof(InitialPrivilegeSet[0]); + for (i = 0; i < ptkPrivileges->PrivilegeCount; i++) + { + ptkPrivileges->Privileges[i].Luid.HighPart = InitialPrivilegeSet[i].Luid.HighPart; + ptkPrivileges->Privileges[i].Luid.LowPart = InitialPrivilegeSet[i].Luid.LowPart; + ptkPrivileges->Privileges[i].Attributes = InitialPrivilegeSet[i].Attributes; + } + + // Calculate the length needed for the ACL + uSize = sizeof(ACL); + uSize += sizeof(ACE) + sizeof(sidSystem); + uSize += sizeof(ACE) + sizeof(sidAdministrators); + uSize = (uSize & (~3)) + 8; + tkDefaultDacl.DefaultDacl = (PACL) malloc(uSize); + + status = RtlCreateAcl(tkDefaultDacl.DefaultDacl, uSize, ACL_REVISION); + if ( ! NT_SUCCESS(status) ) + printf("RtlCreateAcl() failed: 0x%08x\n", status); + + status = RtlAddAccessAllowedAce(tkDefaultDacl.DefaultDacl, ACL_REVISION, GENERIC_ALL, &sidSystem); + if ( ! NT_SUCCESS(status) ) + printf("RtlAddAccessAllowedAce() failed: 0x%08x\n", status); + + status = RtlAddAccessAllowedAce(tkDefaultDacl.DefaultDacl, ACL_REVISION, GENERIC_READ|GENERIC_EXECUTE|READ_CONTROL, (PSID) &sidAdministrators); + if ( ! NT_SUCCESS(status) ) + printf("RtlAddAccessAllowedAce() failed: 0x%08x\n", status); + + printf("Parameters being passed into ZwCreateToken:\n\n"); + DisplayTokenSids(&tkUser, ptkGroups, &tkDefaultOwner, &tkPrimaryGroup); + DisplayDacl(tkDefaultDacl.DefaultDacl); + + printf("Calling ZwCreateToken()...\n"); + status = ZwCreateToken(phSystemToken, + TOKEN_ALL_ACCESS, + &oa, + TokenPrimary, + &authId, + &tkExpiration, + &tkUser, + ptkGroups, + ptkPrivileges, + &tkDefaultOwner, + &tkPrimaryGroup, + &tkDefaultDacl, + &source); + + // Cleanup + free(ptkGroups); + free(ptkPrivileges); + free(tkDefaultDacl.DefaultDacl); + + return status; +} + +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +int +main(int argc, char* argv[]) +{ + NTSTATUS Status; + HANDLE hSystemToken; + CHAR buffer[512]; + HANDLE hOurToken; + + printf("Current process Token:\n"); + + Status=ZwOpenProcessToken(GetCurrentProcess(), TOKEN_QUERY|TOKEN_QUERY_SOURCE, &hOurToken); + if ( NT_SUCCESS(Status) ) + { + DisplayToken(hOurToken); + CloseHandle(hOurToken); + } + else + { + printf("ZwOpenProcessToken() failed: 0x%08x\n", Status); + } + +//#define ENABLE_PRIVILEGE +#ifdef ENABLE_PRIVILEGE + EnablePrivilege(SE_CREATE_TOKEN_NAME); +#endif + + // Now do the other one + Status = CreateInitialSystemToken(&hSystemToken); + if ( NT_SUCCESS(Status) ) + { + printf("System Token: 0x%08x\n", hSystemToken); + DisplayToken(hSystemToken); + CloseHandle(hSystemToken); + } + else + { + printf("CreateInitialSystemToken() return: 0x%08x\n", Status); + } + + printf("press return"); + gets(buffer); + + return 0; +} diff --git a/rosapps/tests/txtscale/.cvsignore b/rosapps/tests/txtscale/.cvsignore new file mode 100644 index 00000000000..060f7fa87a2 --- /dev/null +++ b/rosapps/tests/txtscale/.cvsignore @@ -0,0 +1,7 @@ +*.o +*.d +*.a +*.exe +*.coff +*.sym +*.map \ No newline at end of file diff --git a/rosapps/tests/txtscale/Makefile b/rosapps/tests/txtscale/Makefile new file mode 100644 index 00000000000..b4cadbd3516 --- /dev/null +++ b/rosapps/tests/txtscale/Makefile @@ -0,0 +1,33 @@ + +PATH_TO_TOP = ../../../reactos + +TARGET_TYPE = program + +TARGET_APPTYPE = windows + +TARGET_NAME = txtscale + +TARGET_NORC = yes + +TARGET_CFLAGS = -fexceptions -g -O0 -DWIN32 -D_DEBUG -D_WINDOWS -D_MBCS -W -D__USE_W32API -D_WIN32_IE=0x0501 -D_WIN32_WINNT=0x0501 -Wall -Werror + +TARGET_CPPFLAGS = -fexceptions -g -O0 -DWIN32 -D_DEBUG -D_WINDOWS -D_MBCS -W -D__USE_W32API -D_WIN32_IE=0x0501 -D_WIN32_WINNT=0x0501 -Wall -Werror + +TARGET_SDKLIBS = \ + kernel32.a \ + user32.a \ + gdi32.a \ + comctl32.a + +TARGET_OBJECTS = \ + txtscale.o \ + mk_font.o + +include $(PATH_TO_TOP)/rules.mak + +include $(TOOLS_PATH)/helper.mk + +# overide LD_CC to use g++ for linking of the executable +LD_CC = $(CXX) + +# EOF diff --git a/rosapps/tests/txtscale/mk_font.cpp b/rosapps/tests/txtscale/mk_font.cpp new file mode 100644 index 00000000000..59e3cf8ca93 --- /dev/null +++ b/rosapps/tests/txtscale/mk_font.cpp @@ -0,0 +1,69 @@ + +// ------------------------------------------------------------------ +// Windows 2000 Graphics API Black Book +// Chapter 4 - Utility functions +// +// Created by Damon Chandler +// Updates can be downloaded at: +// +// Please do not hesistate to e-mail me at dmc27@ee.cornell.edu +// if you have any questions about this code. +// ------------------------------------------------------------------ + +//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> +#include +#include + +#include "mk_font.h" +//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +namespace font { + +// creates a logical font +HFONT MakeFont( + IN HDC hDestDC, // handle to target DC + IN LPCSTR typeface_name, // font's typeface name + IN int point_size, // font's point size + IN const BYTE charset, // font's character set + IN const DWORD style // font's styles + ) +{ + // + // NOTE: On Windows 9x/Me, GetWorldTransform is not + // supported. For compatibility with these platforms you + // should initialize the XFORM::eM22 data member to 1.0. + // + XFORM xf = {0, 0, 0, 1.0, 0, 0}; + GetWorldTransform(hDestDC, &xf); + int pixels_per_inch = GetDeviceCaps(hDestDC, LOGPIXELSY); + + POINT PSize = { + 0, + -MulDiv(static_cast(xf.eM22 * point_size + 0.5), + pixels_per_inch, 72) + }; + + HFONT hResult = NULL; + if (DPtoLP(hDestDC, &PSize, 1)) + { + LOGFONT lf; + memset(&lf, 0, sizeof(LOGFONT)); + + lf.lfHeight = PSize.y; + lf.lfCharSet = charset; + lstrcpyn(reinterpret_cast(&lf.lfFaceName), + typeface_name, LF_FACESIZE); + + lf.lfWeight = (style & FS_BOLD) ? FW_BOLD : FW_DONTCARE; + lf.lfItalic = (style & FS_ITALIC) ? true : false; + lf.lfUnderline = (style & FS_UNDERLINE) ? true : false; + lf.lfStrikeOut = (style & FS_STRIKEOUT) ? true : false; + + // create the logical font + hResult = CreateFontIndirect(&lf); + } + return hResult; +} +//------------------------------------------------------------------------- + +} // namespace font diff --git a/rosapps/tests/txtscale/mk_font.h b/rosapps/tests/txtscale/mk_font.h new file mode 100644 index 00000000000..98c164c9f1d --- /dev/null +++ b/rosapps/tests/txtscale/mk_font.h @@ -0,0 +1,39 @@ + +// ------------------------------------------------------------------ +// Windows 2000 Graphics API Black Book +// Chapter 4 - Utility functions +// +// Created by Damon Chandler +// Updates can be downloaded at: +// +// Please do not hesistate to e-mail me at dmc27@ee.cornell.edu +// if you have any questions about this code. +// ------------------------------------------------------------------ + +//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> +#ifndef CH4_UTILS_H +#define CH4_UTILS_H + +#include +//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +// change namespace name appropriately to suit your needs +namespace font { + +// font options +static const ULONG FS_NONE = 0x00000000; +static const ULONG FS_BOLD = 0x00000001; +static const ULONG FS_ITALIC = 0x00000002; +static const ULONG FS_UNDERLINE = 0x00000004; +static const ULONG FS_STRIKEOUT = 0x00000008; + +// creates a logical font +HFONT MakeFont(IN HDC hDestDC, IN LPCSTR typeface_name, + IN int point_size, IN const BYTE charset = ANSI_CHARSET, + IN const DWORD style = FS_NONE); + +} + +//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> +#endif // CH4_UTILS_H +//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< diff --git a/rosapps/tests/txtscale/txtscale.cpp b/rosapps/tests/txtscale/txtscale.cpp new file mode 100644 index 00000000000..c77216b11b8 --- /dev/null +++ b/rosapps/tests/txtscale/txtscale.cpp @@ -0,0 +1,266 @@ + +// ------------------------------------------------------------------ +// Windows 2000 Graphics API Black Book +// Chapter 8 - Listing 8.1 (Scaled Text Demo) +// +// Created by Damon Chandler +// Updates can be downloaded at: +// +// Please do not hesistate to e-mail me at dmc27@ee.cornell.edu +// if you have any questions about this code. +// ------------------------------------------------------------------ + + +//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> +#include +#include +#include + +// for the MakeFont() function... +#include "mk_font.h" +//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + + +HINSTANCE hInst; +const char* WndClassName = "GMainWnd"; +LRESULT CALLBACK MainWndProc(HWND HWnd, UINT Msg, WPARAM WParam, + LPARAM LParam); + + +int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE, LPTSTR, + int nCmdShow) +{ + hInst = hInstance; + + WNDCLASS wc; + memset(&wc, 0, sizeof(WNDCLASS)); + + wc.style = CS_HREDRAW | CS_VREDRAW; + wc.lpszClassName = WndClassName; + wc.lpfnWndProc = MainWndProc; + wc.hInstance = hInst; + wc.hCursor = LoadCursor(NULL, IDC_ARROW); + wc.hbrBackground = reinterpret_cast( + COLOR_BTNFACE + 1 + ); + + if (RegisterClass(&wc)) + { + HWND hWnd = + CreateWindow( + WndClassName, TEXT("Scaled Text Demo"), + WS_OVERLAPPEDWINDOW | WS_CAPTION | + WS_VISIBLE | WS_CLIPCHILDREN, + CW_USEDEFAULT, CW_USEDEFAULT, 800, 300, + NULL, NULL, hInst, NULL + ); + + if (hWnd) + { + ShowWindow(hWnd, nCmdShow); + UpdateWindow(hWnd); + + MSG msg; + while (GetMessage(&msg, NULL, 0, 0)) + { + TranslateMessage(&msg); + DispatchMessage(&msg); + } + } + } + return 0; +} +//------------------------------------------------------------------------- + + +HWND hTrackBar = NULL; +HFONT hTTFont = NULL; +double scale = 0.0; +LPCSTR pText = TEXT("The Scaled Text!"); + +LRESULT CALLBACK MainWndProc(HWND hWnd, UINT msg, WPARAM wParam, + LPARAM lParam) +{ + switch (msg) + { + case WM_CREATE: + { + INITCOMMONCONTROLSEX icx; + icx.dwSize = sizeof(INITCOMMONCONTROLSEX); + icx.dwICC = ICC_BAR_CLASSES; + + InitCommonControlsEx(&icx); + + hTrackBar = + CreateWindow( + TRACKBAR_CLASS, "", + TBS_HORZ | TBS_BOTH | TBS_AUTOTICKS | + TBS_FIXEDLENGTH | TBS_ENABLESELRANGE | + WS_CHILD | WS_VISIBLE, + 10, 260, 375, 40, + hWnd, NULL, hInst, NULL + ); + + assert(hTrackBar != NULL); + SNDMSG(hTrackBar, TBM_SETTHUMBLENGTH, 20, 0); + SNDMSG(hTrackBar, TBM_SETRANGEMAX, TRUE, 100); + + // create the TrueType (scalable) font + HDC hDC = GetDC(hWnd); + try + { + // see Chapter 4 for the definition of MakeFont + hTTFont = font::MakeFont(hDC, "Impact", 72); + if (!hTTFont) throw; + } + catch (...) + { + ReleaseDC(hWnd, hDC); + } + ReleaseDC(hWnd, hDC); + break; + } + case WM_HSCROLL: + { + if (reinterpret_cast(lParam) == hTrackBar) + { + // + // adjust the scaling factor according to + // the position of the trackbar's slider + // + scale = static_cast( + (SNDMSG(hTrackBar, TBM_GETPOS, 0, 0) + 1) / 50.0 + ); + InvalidateRect(hWnd, NULL, true); + } + break; + } + case WM_ERASEBKGND: + { + LRESULT res = DefWindowProc(hWnd, msg, wParam, lParam); + + HDC hDC = reinterpret_cast(wParam); + HFONT hOldFont = static_cast( + SelectObject(hDC, hTTFont) + ); + try + { + SetBkMode(hDC, TRANSPARENT); + + // open a path bracket + if (!BeginPath(hDC)) throw; + + // record the text to the path + TextOut(hDC, 10, 10, pText, lstrlen(pText)); + + // close the path bracket and + // select the path into hDC + EndPath(hDC); + + // determine the number of endpoints in the path + const int num_points = GetPath(hDC, NULL, NULL, 0); + if (num_points > 0) + { + // make room for the POINTs and vertex types + POINT* pPEnds = new POINT[num_points]; + unsigned char* pTypes = new unsigned char[num_points]; + try + { + // get the path's description + int num_got = GetPath(hDC, pPEnds, pTypes, num_points); + if (num_got > 0) + { + // start a new path bracket + if (!BeginPath(hDC)) throw; + + // scale each point in the description + int iPoint; + for (iPoint = 0; iPoint < num_got; ++iPoint) + { + pPEnds[iPoint].x = static_cast( + scale * pPEnds[iPoint].x + 0.5 + ); + pPEnds[iPoint].y = static_cast( + scale * pPEnds[iPoint].y + 0.5 + ); + } + + for (iPoint = 0; iPoint < num_points; ++iPoint) + { + // handle the MoveToEx case + if (pTypes[iPoint] == PT_MOVETO) + { + MoveToEx( + hDC, pPEnds[iPoint].x, pPEnds[iPoint].y, NULL + ); + } + // handle the LineTo case + else if ( + pTypes[iPoint] == PT_LINETO || + pTypes[iPoint] == (PT_LINETO | PT_CLOSEFIGURE) + ) + { + LineTo(hDC, pPEnds[iPoint].x, pPEnds[iPoint].y); + } + // handle the PolyBezierTo case + else if ( + pTypes[iPoint] == PT_BEZIERTO || + pTypes[iPoint] == (PT_BEZIERTO | PT_CLOSEFIGURE) + ) + { + PolyBezierTo(hDC, pPEnds + iPoint, 3); + iPoint += 2; + } + } + + // close the new path bracket + EndPath(hDC); + + // stroke and fill the new path + StrokeAndFillPath(hDC); + } + } + catch (...) + { + // clean up + delete [] pTypes; + delete [] pPEnds; + throw; + } + // clean up + delete [] pTypes; + delete [] pPEnds; + } + // ... + } + catch (...) + { + SelectObject(hDC, hOldFont); + } + SelectObject(hDC, hOldFont); + return res; + } + case WM_SIZE: + { + MoveWindow( + hTrackBar, + 0, HIWORD(lParam) - 40, LOWORD(lParam), 40, + false + ); + break; + } + case WM_DESTROY: + { + // clean up + DeleteObject(hTTFont); + PostQuitMessage(0); + break; + } + } + return DefWindowProc(hWnd, msg, wParam, lParam); +} +//------------------------------------------------------------------------- + + + + diff --git a/rosapps/tests/vmtest/.cvsignore b/rosapps/tests/vmtest/.cvsignore new file mode 100644 index 00000000000..060f7fa87a2 --- /dev/null +++ b/rosapps/tests/vmtest/.cvsignore @@ -0,0 +1,7 @@ +*.o +*.d +*.a +*.exe +*.coff +*.sym +*.map \ No newline at end of file diff --git a/rosapps/tests/vmtest/Makefile b/rosapps/tests/vmtest/Makefile new file mode 100644 index 00000000000..bb5595a75c2 --- /dev/null +++ b/rosapps/tests/vmtest/Makefile @@ -0,0 +1,23 @@ +# $Id: Makefile,v 1.1 2004/10/21 04:48:46 sedwards Exp $ + +PATH_TO_TOP = ../../../reactos + +TARGET_NORC = yes + +TARGET_TYPE = program + +TARGET_APPTYPE = console + +TARGET_NAME = vmtest + +TARGET_SDKLIBS = ntdll.a kernel32.a + +TARGET_OBJECTS = $(TARGET_NAME).o + +TARGET_CFLAGS = -Wall -Werror + +include $(PATH_TO_TOP)/rules.mak + +include $(TOOLS_PATH)/helper.mk + +# EOF diff --git a/rosapps/tests/vmtest/vmtest.c b/rosapps/tests/vmtest/vmtest.c new file mode 100644 index 00000000000..ec7235ce06d --- /dev/null +++ b/rosapps/tests/vmtest/vmtest.c @@ -0,0 +1,55 @@ +#include +#include + +int main() +{ + PVOID Base; + PVOID Ret; + + Base = VirtualAlloc(NULL, + 1048576, + MEM_RESERVE, + PAGE_READWRITE); + if (Base == NULL) + { + printf("VirtualAlloc failed 1\n"); + } + + Ret = VirtualAlloc(Base + 4096, + 4096, + MEM_COMMIT, + PAGE_READWRITE); + if (Ret == NULL) + { + printf("VirtualAlloc failed 2\n"); + } + + Ret = VirtualAlloc(Base + 12288, + 4096, + MEM_COMMIT, + PAGE_READWRITE); + if (Ret == NULL) + { + printf("VirtualAlloc failed 3\n"); + } + + Ret = VirtualAlloc(Base + 20480, + 4096, + MEM_COMMIT, + PAGE_READWRITE); + if (Ret == NULL) + { + printf("VirtualAlloc failed 4\n"); + } + + Ret = VirtualAlloc(Base + 4096, + 28672, + MEM_RESERVE, + PAGE_READWRITE); + if (Ret == NULL) + { + printf("VirtualAlloc failed 5\n"); + } + return 0; +} + diff --git a/rosapps/tests/winhello/.cvsignore b/rosapps/tests/winhello/.cvsignore new file mode 100644 index 00000000000..060f7fa87a2 --- /dev/null +++ b/rosapps/tests/winhello/.cvsignore @@ -0,0 +1,7 @@ +*.o +*.d +*.a +*.exe +*.coff +*.sym +*.map \ No newline at end of file diff --git a/rosapps/tests/winhello/makefile b/rosapps/tests/winhello/makefile new file mode 100644 index 00000000000..2b47eb60752 --- /dev/null +++ b/rosapps/tests/winhello/makefile @@ -0,0 +1,23 @@ +# $Id: makefile,v 1.1 2004/10/21 04:48:46 sedwards Exp $ + +PATH_TO_TOP = ../../../reactos + +TARGET_NORC = yes + +TARGET_TYPE = program + +TARGET_APPTYPE = windows + +TARGET_NAME = winhello + +TARGET_SDKLIBS = kernel32.a gdi32.a ntdll.a + +TARGET_OBJECTS = $(TARGET_NAME).o + +TARGET_CFLAGS = -Wall -Werror + +include $(PATH_TO_TOP)/rules.mak + +include $(TOOLS_PATH)/helper.mk + +# EOF diff --git a/rosapps/tests/winhello/winhello.c b/rosapps/tests/winhello/winhello.c new file mode 100644 index 00000000000..e55df9d5446 --- /dev/null +++ b/rosapps/tests/winhello/winhello.c @@ -0,0 +1,703 @@ +/* + * ReactOS Winhello - Not So Simple Win32 Windowing test + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +/* What do we test with this app? + * - Windows and Class creation + * - A Simple Button + * - Some font rendering in the Window + * - Scrollbar support + * - Hotkeys + * - Messageboxes + * ???????? + */ + +#include +#include +#include + +HFONT tf; +LRESULT WINAPI MainWndProc(HWND, UINT, WPARAM, LPARAM); +BOOLEAN bolWM_CHAR; +BOOLEAN bolWM_KEYDOWN; + +int WINAPI +WinMain(HINSTANCE hInstance, + HINSTANCE hPrevInstance, + LPSTR lpszCmdLine, + int nCmdShow) +{ + WNDCLASS wc; + MSG msg; + HWND hWnd; + bolWM_CHAR = 0; + bolWM_KEYDOWN = 0; + + wc.lpszClassName = "HelloClass"; + 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) + { + fprintf(stderr, "RegisterClass failed (last error 0x%lX)\n", + GetLastError()); + return(1); + } + + hWnd = CreateWindow("HelloClass", + "Hello World", + WS_OVERLAPPEDWINDOW|WS_HSCROLL|WS_VSCROLL, + 0, //Position; you can use CW_USEDEFAULT, too + 0, + 600, //height + 400, + NULL, + NULL, + hInstance, + NULL); + if (hWnd == NULL) + { + fprintf(stderr, "CreateWindow failed (last error 0x%lX)\n", + GetLastError()); + return(1); + } + + tf = CreateFontA(14, 0, 0, TA_BASELINE, FW_NORMAL, FALSE, FALSE, FALSE, + ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, + DEFAULT_QUALITY, FIXED_PITCH|FF_DONTCARE, "Timmons"); + + ShowWindow(hWnd, nCmdShow); + + while(GetMessage(&msg, NULL, 0, 0)) + { + TranslateMessage(&msg); + DispatchMessage(&msg); + } + + DeleteObject(tf); + + return msg.wParam; +} + +#define CTRLC 1 /* Define our HotKeys */ +#define ALTF1 2 /* Define our HotKeys */ + +LRESULT CALLBACK MainWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) +{ + PAINTSTRUCT ps; /* Also used during window drawing */ + HDC hDC; /* A device context used for drawing */ + RECT rc, clr, wir; /* A rectangle used during drawing */ + char spr[100], sir[100]; + static HBRUSH hbrWhite=NULL, hbrGray=NULL, hbrBlack=NULL, hbrRed=NULL, hbrBlue=NULL, hbrYellow=NULL; + + /* The window handle for the "Click Me" button. */ + static HWND hwndButton = 0; + static int cx, cy; /* Height and width of our button. */ + + switch(msg) + { + + case WM_CHAR: + { + + hDC = GetDC(hWnd); + TCHAR text[2]; + text[0] = (TCHAR)wParam; + text[1] = _T('\0'); + + //Write in window + if( bolWM_KEYDOWN ) + { + TextOut(hDC, 400, 10, "WM CHAR:", strlen("WM CHAR:")); + bolWM_KEYDOWN = 0; + } + else + { + TextOut(hDC, 400, 10, "WM_CHAR:", strlen("WM_CHAR:")); + bolWM_KEYDOWN = 1; + } + TextOut(hDC, 530, 10, text, strlen(text)); + +#if 0 + // Make a line depending on the typed key + Rect.left = 10; + Rect.top = 75; + Rect.right = 610; + Rect.bottom = 85; + FillRect(hDC, &Rect, hbrWhite); + + Rect.left=308; + Rect.right=312; + FillRect(hDC, &Rect, hbrRed); + + Rect.left = 310; + Rect.top = 75; + Rect.right = 310 +text[0]*2; + Rect.bottom = 85; + HBRUSH hbrCustom = CreateSolidBrush ( RGB(text[0], text[0], text[0])); + FillRect(hDC, &Rect, hbrCustom); + DeleteObject ( hbrCustom ); + +#endif + + ReleaseDC(hWnd, hDC); + return 0; + } + + case WM_KEYDOWN: + { + + hDC = GetDC(hWnd); + RECT Rect; + TCHAR text[2]; + text[0] = (TCHAR)wParam; + text[1] = _T('\0'); + + + /* Write in window */ + Rect.left = 400; + Rect.top = 50; + Rect.right = 550; + Rect.bottom = 70; + FillRect(hDC, &Rect, hbrWhite); + if( bolWM_CHAR ) + { + TextOut(hDC, 400, 30, "WM KEYDOWN:", strlen("WM KEYDOWN:")); + bolWM_CHAR = 0; + } + else + { + TextOut(hDC, 400, 30, "WM_KEYDOWN:", strlen("WM_KEYDOWN:")); + bolWM_CHAR = 1; + } + TextOut(hDC, 530, 30, text, strlen(text)); + ReleaseDC(hWnd, hDC); + return 0; + } + + case WM_KEYUP: + { + + hDC = GetDC(hWnd); + RECT Rect; + TCHAR text[2]; + text[0] = (TCHAR)wParam; + text[1] = _T('\0'); + + + /* Write in window */ + Rect.left = 400; + Rect.top = 10; + Rect.right = 550; + Rect.bottom = 70; + FillRect(hDC, &Rect, hbrWhite); + TextOut(hDC, 400, 50, "WM_KEYUP:", strlen("WM_KEYUP:")); + TextOut(hDC, 530, 50, text, strlen(text)); + ReleaseDC(hWnd, hDC); + return 0; + } + + + case WM_LBUTTONDOWN: + { + ULONG x, y; + RECT Rect; + hDC = GetDC(hWnd); + x = LOWORD(lParam); + y = HIWORD(lParam); + + Rect.left = x - 5; + Rect.top = y - 5; + Rect.right = x + 5; + Rect.bottom = y + 5; + FillRect(hDC, &Rect, hbrRed); + + Rect.left = x - 3; + Rect.top = y - 3; + Rect.right = x + 3; + Rect.bottom = y + 3; + FillRect(hDC, &Rect, hbrBlack); + + ReleaseDC(hWnd, hDC); + break; + } + case WM_LBUTTONUP: + { + ULONG x, y; + RECT Rect; + hDC = GetDC(hWnd); + x = LOWORD(lParam); + y = HIWORD(lParam); + + Rect.left = x - 5; + Rect.top = y - 5; + Rect.right = x + 5; + Rect.bottom = y + 5; + FillRect(hDC, &Rect, hbrRed); + + Rect.left = x - 3; + Rect.top = y - 3; + Rect.right = x + 3; + Rect.bottom = y + 3; + FillRect(hDC, &Rect, hbrGray); + + ReleaseDC(hWnd, hDC); + break; + } + case WM_MBUTTONDOWN: + { + ULONG x, y; + RECT Rect; + hDC = GetDC(hWnd); + x = LOWORD(lParam); + y = HIWORD(lParam); + + Rect.left = x - 5; + Rect.top = y - 5; + Rect.right = x + 5; + Rect.bottom = y + 5; + FillRect(hDC, &Rect, hbrBlue); + + Rect.left = x - 3; + Rect.top = y - 3; + Rect.right = x + 3; + Rect.bottom = y + 3; + FillRect(hDC, &Rect, hbrBlack); + + ReleaseDC(hWnd, hDC); + break; + } + case WM_MBUTTONUP: + { + ULONG x, y; + RECT Rect; + hDC = GetDC(hWnd); + x = LOWORD(lParam); + y = HIWORD(lParam); + + Rect.left = x - 5; + Rect.top = y - 5; + Rect.right = x + 5; + Rect.bottom = y + 5; + FillRect(hDC, &Rect, hbrBlue); + + Rect.left = x - 3; + Rect.top = y - 3; + Rect.right = x + 3; + Rect.bottom = y + 3; + FillRect(hDC, &Rect, hbrGray); + + ReleaseDC(hWnd, hDC); + break; + } + case WM_RBUTTONDOWN: + { + ULONG x, y; + RECT Rect; + hDC = GetDC(hWnd); + x = LOWORD(lParam); + y = HIWORD(lParam); + + Rect.left = x - 5; + Rect.top = y - 5; + Rect.right = x + 5; + Rect.bottom = y + 5; + FillRect(hDC, &Rect, hbrYellow); + + Rect.left = x - 3; + Rect.top = y - 3; + Rect.right = x + 3; + Rect.bottom = y + 3; + FillRect(hDC, &Rect, hbrBlack); + + ReleaseDC(hWnd, hDC); + break; + } + case WM_RBUTTONUP: + { + ULONG x, y; + RECT Rect; + hDC = GetDC(hWnd); + x = LOWORD(lParam); + y = HIWORD(lParam); + + Rect.left = x - 5; + Rect.top = y - 5; + Rect.right = x + 5; + Rect.bottom = y + 5; + FillRect(hDC, &Rect, hbrYellow); + + Rect.left = x - 3; + Rect.top = y - 3; + Rect.right = x + 3; + Rect.bottom = y + 3; + FillRect(hDC, &Rect, hbrGray); + + ReleaseDC(hWnd, hDC); + break; + } + + case WM_MOUSEMOVE: + { + int fwKeys; + int x; + int y; + RECT Rect; + int temp; + TCHAR text[256]; + + hDC = GetDC(hWnd); + fwKeys = wParam; // key flags + x = LOWORD(lParam); // horizontal position of cursor + y = HIWORD(lParam); // vertical position of cursor + + Rect.left = 10; + Rect.top = 100; + Rect.right = 160; + Rect.bottom = 300; + FillRect(hDC, &Rect, hbrWhite); + + temp = _sntprintf ( text, sizeof(text)/sizeof(*text), _T("x: %d"), x ); + TextOut(hDC,10,100,text,strlen(text)); + temp = _sntprintf ( text, sizeof(text)/sizeof(*text), _T("y: %d"), y ); + TextOut(hDC,10,120,text,strlen(text)); + + Rect.left = x - 2; + Rect.top = y - 2; + Rect.right = x + 2; + Rect.bottom = y + 2; + + switch ( fwKeys ) + { + case MK_CONTROL: + TextOut(hDC,10,140,"Control",strlen("Control")); + break; + case MK_SHIFT: + TextOut(hDC,10,160,"Shift",strlen("Shift")); + break; + case MK_LBUTTON: + TextOut(hDC,10,180,"Left",strlen("Left")); + FillRect(hDC, &Rect, hbrRed); + break; + case MK_MBUTTON: + TextOut(hDC,10,200,"Middle",strlen("Middle")); + FillRect(hDC, &Rect, hbrBlue); + break; + case MK_RBUTTON: + TextOut(hDC,10,220,"Right",strlen("Right")); + FillRect(hDC, &Rect, hbrYellow); + break; + } + ReleaseDC(hWnd, hDC); + break; + } + + case WM_HSCROLL: + { + int nPos; + int temp; + RECT Rect; + int nScrollCode; + HWND hwndScrollBar; + TCHAR text[256]; + SCROLLINFO Scrollparameter; + nScrollCode = (int) LOWORD(wParam); // scroll bar value + nPos = (short int) HIWORD(wParam); // scroll box position + hwndScrollBar = (HWND) lParam; // handle to scroll bar + hDC = GetDC(hWnd); + + Scrollparameter.cbSize = sizeof(Scrollparameter); + Scrollparameter.fMask = SIF_ALL; + GetScrollInfo ( hWnd, SB_HORZ, &Scrollparameter ); + + Rect.left = 200; + Rect.top = 100; + Rect.right = 350; + Rect.bottom = 300; + FillRect(hDC, &Rect, hbrWhite); + + switch ( nScrollCode ) + { + case SB_ENDSCROLL: //Ends scroll. + TextOut(hDC,200,120,"SB_ENDSCROLL ",16); + Scrollparameter.nPos = Scrollparameter.nPos; + break; + case SB_LEFT: //Scrolls to the upper left. + TextOut(hDC,200,140,"SB_LEFT ",16); + Scrollparameter.nPos = Scrollparameter.nMin; + break; + case SB_RIGHT: //Scrolls to the lower right. + TextOut(hDC,200,160,"SB_RIGHT ",16); + Scrollparameter.nPos = Scrollparameter.nMax; + break; + case SB_LINELEFT: //Scrolls left by one unit. + TextOut(hDC,200,180,"SB_LINELEFT ",16); + Scrollparameter.nPos--; + break; + case SB_LINERIGHT: //Scrolls right by one unit. + TextOut(hDC,200,200,"SB_LINERIGHT ",16); + Scrollparameter.nPos++; + break; + case SB_PAGELEFT: //Scrolls left by the width of the window. + TextOut(hDC,200,220,"SB_PAGELEFT ",16); + Scrollparameter.nPos -= Scrollparameter.nPage; + break; + case SB_PAGERIGHT: //Scrolls right by the width of the window. + TextOut(hDC,200,240,"PAGERIGHT ",16); + Scrollparameter.nPos += Scrollparameter.nPage; + break; + case SB_THUMBPOSITION: //The user has dragged the scroll box (thumb) and released the mouse button. The nPos parameter indicates the position of the scroll box at the end of the drag operation. + TextOut(hDC,200,260,"SB_THUMBPOSITION",16); + Scrollparameter.nPos = Scrollparameter.nTrackPos; + break; + case SB_THUMBTRACK: // + TextOut(hDC,200,280,"SB_THUMBTRACK ",16); + Scrollparameter.nPos = Scrollparameter.nTrackPos; + break; + } + + SetScrollInfo( + hWnd, // handle to window with scroll bar + SB_HORZ, // scroll bar flag + &Scrollparameter, // pointer to structure with scroll parameters + 1 // redraw flag + ); + temp = _sntprintf ( text, sizeof(text)/sizeof(*text), _T("Horizontal: %d"), Scrollparameter.nPos ); + TextOut(hDC,200,100,text,strlen(text)); + ReleaseDC(hWnd, hDC); + return 0; + } + + case WM_VSCROLL: + { + int nPos; + int temp; + RECT Rect; + int nScrollCode; + HWND hwndScrollBar; + TCHAR text[256]; + SCROLLINFO Scrollparameter; + nScrollCode = (int) LOWORD(wParam); // scroll bar value + nPos = (short int) HIWORD(wParam); // scroll box position + hwndScrollBar = (HWND) lParam; // handle to scroll bar + hDC = GetDC(hWnd); + + Scrollparameter.cbSize = sizeof(Scrollparameter); + Scrollparameter.fMask = SIF_ALL; + GetScrollInfo ( hWnd, SB_VERT, &Scrollparameter ); + + Rect.left = 400; + Rect.top = 100; + Rect.right = 550; + Rect.bottom = 300; + FillRect(hDC, &Rect, hbrWhite); + + switch ( nScrollCode ) + { + case SB_ENDSCROLL: //Ends scroll. + TextOut(hDC,400,120,"SB_ENDSCROLL ",16); + Scrollparameter.nPos = Scrollparameter.nPos; + break; + case SB_LEFT: //Scrolls to the upper left. + TextOut(hDC,400,140,"SB_LEFT ",16); + Scrollparameter.nPos = Scrollparameter.nMin; + break; + case SB_RIGHT: //Scrolls to the lower right. + TextOut(hDC,400,160,"SB_RIGHT ",16); + Scrollparameter.nPos = Scrollparameter.nMax; + break; + case SB_LINELEFT: //Scrolls left by one unit. + TextOut(hDC,400,180,"SB_LINELEFT ",16); + Scrollparameter.nPos--; + break; + case SB_LINERIGHT: //Scrolls right by one unit. + TextOut(hDC,400,200,"SB_LINERIGHT ",16); + Scrollparameter.nPos++; + break; + case SB_PAGELEFT: //Scrolls left by the width of the window. + TextOut(hDC,400,220,"SB_PAGELEFT ",16); + Scrollparameter.nPos -= Scrollparameter.nPage; + break; + case SB_PAGERIGHT: //Scrolls right by the width of the window. + TextOut(hDC,400,240,"PAGERIGHT ",16); + Scrollparameter.nPos += Scrollparameter.nPage; + break; + case SB_THUMBPOSITION: //The user has dragged the scroll box (thumb) and released the mouse button. The nPos parameter indicates the position of the scroll box at the end of the drag operation. + TextOut(hDC,400,260,"SB_THUMBPOSITION",16); + Scrollparameter.nPos = Scrollparameter.nTrackPos; + break; + case SB_THUMBTRACK: // + TextOut(hDC,400,280,"SB_THUMBTRACK ",16); + Scrollparameter.nPos = Scrollparameter.nTrackPos; + break; + } + + SetScrollInfo( + hWnd, // handle to window with scroll bar + SB_VERT, // scroll bar flag + &Scrollparameter, // pointer to structure with scroll parameters + 1 // redraw flag + ); + temp = _sntprintf ( text, sizeof(text)/sizeof(*text), _T("Vertical: %d"), Scrollparameter.nPos ); + TextOut(hDC,400,100,text,strlen(text)); + ReleaseDC(hWnd, hDC); + return 0; + } + + case WM_HOTKEY: + switch(wParam) + { + case CTRLC: + MessageBox(hWnd, "You just pressed Ctrl+C", "Hotkey", MB_OK | MB_ICONINFORMATION); + break; + case ALTF1: + MessageBox(hWnd, "You just pressed Ctrl+Alt+F1", "Hotkey", MB_OK | MB_ICONINFORMATION); + break; + } + break; + + case WM_DESTROY: + UnregisterHotKey(hWnd, CTRLC); + UnregisterHotKey(hWnd, ALTF1); + PostQuitMessage(0); + DeleteObject ( hbrWhite ); + DeleteObject ( hbrGray ); + DeleteObject ( hbrBlack ); + DeleteObject ( hbrRed ); + DeleteObject ( hbrBlue ); + DeleteObject ( hbrYellow ); + break; + + case WM_CREATE: + { + /* Register a Ctrl+Alt+C hotkey*/ + RegisterHotKey(hWnd, CTRLC, MOD_CONTROL, VK_C); + RegisterHotKey(hWnd, ALTF1, MOD_CONTROL | MOD_ALT, VK_F1); + + hbrWhite = CreateSolidBrush ( RGB(0xFF, 0xFF, 0xFF)); + hbrGray = CreateSolidBrush ( RGB(0xAF, 0xAF, 0xAF)); + hbrBlack = CreateSolidBrush ( RGB(0x00, 0x00, 0x00)); + hbrRed = CreateSolidBrush ( RGB(0xFF, 0x00, 0x00)); + hbrBlue = CreateSolidBrush ( RGB(0x00, 0x00, 0xFF)); + hbrYellow = CreateSolidBrush ( RGB(0xFF, 0xFF, 0x00)); + + SCROLLINFO si; + si.cbSize = sizeof(si); + si.fMask = SIF_ALL; + si.nMin = 0; + si.nMax = 100; + si.nPage = 5; + si.nPos = 0; + + SetScrollInfo ( hWnd, SB_HORZ, &si, FALSE ); + SetScrollInfo ( hWnd, SB_VERT, &si, FALSE ); + + + /* The window is being created. Create our button + * window now. */ + TEXTMETRIC tm; + + /* First we use the system fixed font size to choose + * a nice button size. */ + hDC = GetDC (hWnd); + SelectObject (hDC, GetStockObject (SYSTEM_FIXED_FONT)); + GetTextMetrics (hDC, &tm); + cx = tm.tmAveCharWidth * 30; + cy = (tm.tmHeight + tm.tmExternalLeading) * 2; + ReleaseDC (hWnd, hDC); + + /* Now create the button */ + hwndButton = CreateWindow ( + "button", /* Builtin button class */ + "Click Here", + WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, + 0, 0, cx, cy, + hWnd, /* Parent is this window. */ + (HMENU) 1, /* Control ID: 1 */ + ((LPCREATESTRUCT) lParam)->hInstance, + NULL + ); + + return 0; + break; + } + + case WM_PAINT: + hDC = BeginPaint(hWnd, &ps); + TextOut(hDC, 10, 10, "Hello World from ReactOS!", + strlen("Hello World from ReactOS!")); + TextOut(hDC, 10, 80, "Press Ctrl+C or Ctrl+Alt+F1 to test Hotkey support.", + strlen("Press Ctrl+C or Ctrl+Alt+F1 to test Hotkey support.")); + GetClientRect(hWnd, &clr); + GetWindowRect(hWnd, &wir); + sprintf(spr, "%lu,%lu,%lu,%lu ", clr.left, clr.top, clr.right, clr.bottom); + sprintf(sir, "%lu,%lu,%lu,%lu ", wir.left, wir.top, wir.right, wir.bottom); + TextOut(hDC, 10, 30, spr, 20); + TextOut(hDC, 10, 50, sir, 20); + + /* Draw "Hello, World" in the middle of the upper + * half of the window. */ + rc.bottom = rc.bottom / 2; + DrawText (hDC, "Hello, World", -1, &rc, + DT_SINGLELINE | DT_CENTER | DT_VCENTER); + + EndPaint (hWnd, &ps); + return 0; + break; + + case WM_SIZE: + /* The window size is changing. If the button exists + * then place it in the center of the bottom half of + * the window. */ + if (hwndButton && + (wParam == SIZEFULLSCREEN || + wParam == SIZENORMAL) + ) + { + rc.left = (LOWORD(lParam) - cx) / 2; + rc.top = HIWORD(lParam) * 3 / 4 - cy / 2; + MoveWindow ( + hwndButton, + rc.left, rc.top, cx, cy, TRUE); + } + break; + + case WM_COMMAND: + /* Check the control ID, notification code and + * control handle to see if this is a button click + * message from our child button. */ + if (LOWORD(wParam) == 1 && + HIWORD(wParam) == BN_CLICKED && + (HWND) lParam == hwndButton) + { + /* Our button was clicked. Close the window. */ + DestroyWindow (hWnd); + } + return 0; + break; + + default: + return DefWindowProc(hWnd, msg, wParam, lParam); + } + return 0; +} diff --git a/rosapps/tests/wm_erasebkgnd/.cvsignore b/rosapps/tests/wm_erasebkgnd/.cvsignore new file mode 100644 index 00000000000..060f7fa87a2 --- /dev/null +++ b/rosapps/tests/wm_erasebkgnd/.cvsignore @@ -0,0 +1,7 @@ +*.o +*.d +*.a +*.exe +*.coff +*.sym +*.map \ No newline at end of file diff --git a/rosapps/tests/wm_erasebkgnd/BACKBITMAP.BMP b/rosapps/tests/wm_erasebkgnd/BACKBITMAP.BMP new file mode 100644 index 00000000000..38bc9716b64 Binary files /dev/null and b/rosapps/tests/wm_erasebkgnd/BACKBITMAP.BMP differ diff --git a/rosapps/tests/wm_erasebkgnd/makefile b/rosapps/tests/wm_erasebkgnd/makefile new file mode 100644 index 00000000000..48914ebd7af --- /dev/null +++ b/rosapps/tests/wm_erasebkgnd/makefile @@ -0,0 +1,31 @@ + +PATH_TO_TOP = ../../../reactos + +TARGET_TYPE = program + +TARGET_APPTYPE = windows + +TARGET_NAME = wm_erasebkgnd + +TARGET_NORC = yes + +TARGET_CFLAGS = -fexceptions -g -O0 -DWIN32 -D_DEBUG -D_WINDOWS -D_MBCS -W -D__USE_W32API -Wall -Werror + +TARGET_CPPFLAGS = -fexceptions -g -O0 -DWIN32 -D_DEBUG -D_WINDOWS -D_MBCS -W -D__USE_W32API -Wall -Werror + +TARGET_SDKLIBS = \ + kernel32.a \ + user32.a \ + gdi32.a + +TARGET_OBJECTS = \ + wm_erasebkgnd.o + +include $(PATH_TO_TOP)/rules.mak + +include $(TOOLS_PATH)/helper.mk + +# overide LD_CC to use g++ for linking of the executable +LD_CC = $(CXX) + +# EOF diff --git a/rosapps/tests/wm_erasebkgnd/wm_erasebkgnd.cpp b/rosapps/tests/wm_erasebkgnd/wm_erasebkgnd.cpp new file mode 100644 index 00000000000..6bfa5a37749 --- /dev/null +++ b/rosapps/tests/wm_erasebkgnd/wm_erasebkgnd.cpp @@ -0,0 +1,179 @@ + +// ------------------------------------------------------------------ +// Windows 2000 Graphics API Black Book +// Chapter 2 - CD-ROM (WM_ERASEBKGND Demo) +// +// Created by Damon Chandler +// Updates can be downloaded at: +// +// Please do not hesistate to e-mail me at dmc27@ee.cornell.edu +// if you have any questions about this code. +// ------------------------------------------------------------------ + +//*********************************************************// +// // +// SYNOPSIS: // +// This sample project demonstrates how to render // +// a background image in response to the WM_ERASEBKGND // +// message. It also shows how to create a transparent // +// static (text) control by handling the // +// WM_CTLCOLORSTATIC message. // +// // +//*********************************************************// + + +//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> +#include +//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + + +HINSTANCE HInst; +HINSTANCE HPrevInst; +TCHAR *cmdline; +const char* WndClassName = "GMainWnd"; +LRESULT CALLBACK MainWndProc(HWND HWnd, UINT Msg, WPARAM WParam, + LPARAM LParam); + + +int APIENTRY WinMain(HINSTANCE HInstance, HINSTANCE HPrevInstance, + LPTSTR lpCmdLine, int nCmdShow) +{ + HInst = HInstance; + HPrevInst = HPrevInstance; + cmdline = lpCmdLine; + + WNDCLASS wc; + memset(&wc, 0, sizeof(WNDCLASS)); + + wc.style = CS_VREDRAW | CS_HREDRAW | CS_DBLCLKS; + wc.lpfnWndProc = MainWndProc; + wc.hInstance = HInstance; + wc.hCursor = LoadCursor(NULL, IDC_ARROW); + wc.hbrBackground = + reinterpret_cast(COLOR_BTNFACE + 1); + wc.lpszClassName = WndClassName; + + if (RegisterClass(&wc)) + { + HWND HWnd = + CreateWindow(WndClassName, + TEXT("WM_ERASEBKGND Demo"), + WS_OVERLAPPEDWINDOW | WS_CAPTION | + WS_VISIBLE | WS_CLIPSIBLINGS, + CW_USEDEFAULT, CW_USEDEFAULT, 205, 85, + NULL, NULL, HInstance, NULL); + + if (HWnd) + { + ShowWindow(HWnd, nCmdShow); + UpdateWindow(HWnd); + + MSG msg; + while (GetMessage(&msg, NULL, 0, 0)) + { + TranslateMessage(&msg); + DispatchMessage(&msg); + } + } + } + return 0; +} +//------------------------------------------------------------------ + + +// static text and bitmap-related variables +HWND HStatic; +HDC HMemDC; +HBITMAP HBmp, HOldBmp; +const char* filename = "BACKBITMAP.BMP"; + +LRESULT CALLBACK MainWndProc(HWND HWnd, UINT Msg, WPARAM WParam, + LPARAM LParam) +{ + switch (Msg) + { + case WM_CREATE: + { + HStatic = + CreateWindow(TEXT("STATIC"), TEXT("Static Text"), + WS_CHILD | WS_VISIBLE | SS_CENTER, + 10, 20, 175, 30, + HWnd, NULL, HInst, NULL); + + // create a memory DC compatible with the screen + HMemDC = CreateCompatibleDC(NULL); + if (HMemDC) + { + // load a DDB from file + HBmp = static_cast( + LoadImage(HInst, filename, IMAGE_BITMAP, + 0, 0, LR_LOADFROMFILE) + ); + if (HBmp) + { + // associate the DDB with the memory DC + HOldBmp = static_cast( + SelectObject(HMemDC, HBmp) + ); + } + } + } + case WM_CTLCOLORSTATIC: + { + if (reinterpret_cast(LParam) == HStatic) + { + HDC HStaticDC = reinterpret_cast(WParam); + SetBkMode(HStaticDC, TRANSPARENT); + + return reinterpret_cast( + GetStockObject(NULL_BRUSH) + ); + } + break; + } + case WM_ERASEBKGND: + { + BITMAP bmp; + if (GetObject(HBmp, sizeof(BITMAP), &bmp)) + { + RECT RClient; + GetClientRect(HWnd, &RClient); + + HDC Hdc = reinterpret_cast(WParam); + SetStretchBltMode(Hdc, COLORONCOLOR); + + // + // TODO: add palette handling code for + // palettized displays (see Chapter 9)... + // + + // render the background image + StretchBlt(Hdc, 0, 0, + RClient.right - RClient.left, + RClient.bottom - RClient.top, + HMemDC, 0, 0, bmp.bmWidth, bmp.bmHeight, + SRCCOPY); + return TRUE; + } + break; + } + case WM_DESTROY: + { + if (HBmp) + { + // free the bitmap + DeleteObject(SelectObject(HMemDC, HOldBmp)); + } + // free the memory DC + DeleteDC(HMemDC); + + PostQuitMessage(0); + return 0; + } + } + return DefWindowProc(HWnd, Msg, WParam, LParam); +} +//------------------------------------------------------------------ + + + diff --git a/rosapps/tests/wm_paint/.cvsignore b/rosapps/tests/wm_paint/.cvsignore new file mode 100644 index 00000000000..060f7fa87a2 --- /dev/null +++ b/rosapps/tests/wm_paint/.cvsignore @@ -0,0 +1,7 @@ +*.o +*.d +*.a +*.exe +*.coff +*.sym +*.map \ No newline at end of file diff --git a/rosapps/tests/wm_paint/makefile b/rosapps/tests/wm_paint/makefile new file mode 100644 index 00000000000..85e9b44fffe --- /dev/null +++ b/rosapps/tests/wm_paint/makefile @@ -0,0 +1,22 @@ + +PATH_TO_TOP = ../../../reactos + +TARGET_NORC = yes + +TARGET_TYPE = program + +TARGET_APPTYPE = windows + +TARGET_NAME = wm_paint + +TARGET_SDKLIBS = kernel32.a gdi32.a + +TARGET_OBJECTS = $(TARGET_NAME).o + +TARGET_CFLAGS = -Wall -Werror + +include $(PATH_TO_TOP)/rules.mak + +include $(TOOLS_PATH)/helper.mk + +# EOF diff --git a/rosapps/tests/wm_paint/wm_paint.c b/rosapps/tests/wm_paint/wm_paint.c new file mode 100644 index 00000000000..7da173e9208 --- /dev/null +++ b/rosapps/tests/wm_paint/wm_paint.c @@ -0,0 +1,131 @@ + +// ------------------------------------------------------------------ +// Windows 2000 Graphics API Black Book +// Chapter 1 - Listing 1.1 (WM_PAINT Demo) +// +// Created by Damon Chandler +// Updates can be downloaded at: +// +// Please do not hesistate to e-mail me at dmc27@ee.cornell.edu +// if you have any questions about this code. +// ------------------------------------------------------------------ + + +//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> +#include +#include +//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + + +const char* WndClassName = "GMainWnd"; +LRESULT CALLBACK MainWndProc(HWND HWnd, UINT Msg, WPARAM WParam, + LPARAM LParam); + + +int APIENTRY WinMain(HINSTANCE HInstance, HINSTANCE HPrevInstance, + LPTSTR lpCmdLine, int nCmdShow) +{ + MSG msg; + WNDCLASS wc; + memset(&wc, 0, sizeof(WNDCLASS)); + + wc.style = CS_VREDRAW | CS_HREDRAW | CS_DBLCLKS; + wc.lpfnWndProc = MainWndProc; + wc.hInstance = HInstance; + wc.hCursor = LoadCursor(NULL, (LPCTSTR)IDC_ARROW); + wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1); + wc.lpszClassName = WndClassName; + + if (RegisterClass(&wc)) + { + HWND HWnd = + CreateWindow(WndClassName, TEXT("WM_PAINT Demo"), + WS_OVERLAPPEDWINDOW | WS_CAPTION | WS_VISIBLE, + CW_USEDEFAULT, CW_USEDEFAULT, 200, 150, + NULL, NULL, HInstance, NULL); + + if (HWnd) + { + ShowWindow(HWnd, nCmdShow); + UpdateWindow(HWnd); + + while (GetMessage(&msg, NULL, 0, 0)) + { + TranslateMessage(&msg); + DispatchMessage(&msg); + } + } + } + return 0; +} +//------------------------------------------------------------------ + + +LRESULT CALLBACK MainWndProc(HWND HWnd, UINT Msg, WPARAM WParam, + LPARAM LParam) +{ + const char* text = "Persistent Text"; + + switch (Msg) + { + case WM_PAINT: + { + // determine the invalidated area of the window + RECT RUpdate; + HDC Hdc; + GetUpdateRect(HWnd, &RUpdate, FALSE); + + // grab a handle to our window's + // common display device context + Hdc = GetDC(HWnd); +#if 0 + try +#endif + { + RECT RClient; + GetClientRect(HWnd, &RClient); + + // set the clipping region + IntersectClipRect(Hdc, RUpdate.left, RUpdate.top, + RUpdate.right, RUpdate.bottom); + + // fill the client area with the background brush + //HBRUSH HBrush = + //reinterpret_cast + (HBRUSH)(GetClassLong(HWnd, GCL_HBRBACKGROUND) + ); + FillRect(Hdc, &RClient, NULL); + + // render the persistent text + SetTextColor(Hdc, PALETTERGB(0, 0, 255)); + DrawText(Hdc, text, strlen(text), &RClient, + DT_CENTER | DT_VCENTER | DT_SINGLELINE); + } +#if 0 + catch (...) +#endif + { + // release the device context + ReleaseDC(HWnd, Hdc); + + // validate the update area + ValidateRect(HWnd, &RUpdate); + } + // release the device context + ReleaseDC(HWnd, Hdc); + + // validate the update area + ValidateRect(HWnd, &RUpdate); + + break; + } + case WM_DESTROY: + { + PostQuitMessage(0); + return 0; + } + } + return DefWindowProc(HWnd, Msg, WParam, LParam); +} +//------------------------------------------------------------------ + diff --git a/rosapps/tests/zwcontinue/.cvsignore b/rosapps/tests/zwcontinue/.cvsignore new file mode 100644 index 00000000000..060f7fa87a2 --- /dev/null +++ b/rosapps/tests/zwcontinue/.cvsignore @@ -0,0 +1,7 @@ +*.o +*.d +*.a +*.exe +*.coff +*.sym +*.map \ No newline at end of file diff --git a/rosapps/tests/zwcontinue/Makefile b/rosapps/tests/zwcontinue/Makefile new file mode 100644 index 00000000000..e3a207aa2dc --- /dev/null +++ b/rosapps/tests/zwcontinue/Makefile @@ -0,0 +1,23 @@ +# $Id: Makefile,v 1.1 2004/10/21 04:48:46 sedwards Exp $ + +PATH_TO_TOP = ../../../reactos + +TARGET_NORC = yes + +TARGET_TYPE = program + +TARGET_APPTYPE = console + +TARGET_NAME = zwcontinue + +TARGET_OBJECTS = $(TARGET_NAME).o i386/$(TARGET_NAME).o + +TARGET_CFLAGS = -Wall -Werror -D__USE_W32API + +TARGET_SDKLIBS = ntdll.a + +include $(PATH_TO_TOP)/rules.mak + +include $(TOOLS_PATH)/helper.mk + +# EOF diff --git a/rosapps/tests/zwcontinue/i386/.cvsignore b/rosapps/tests/zwcontinue/i386/.cvsignore new file mode 100644 index 00000000000..060f7fa87a2 --- /dev/null +++ b/rosapps/tests/zwcontinue/i386/.cvsignore @@ -0,0 +1,7 @@ +*.o +*.d +*.a +*.exe +*.coff +*.sym +*.map \ No newline at end of file diff --git a/rosapps/tests/zwcontinue/i386/zwcontinue.asm b/rosapps/tests/zwcontinue/i386/zwcontinue.asm new file mode 100644 index 00000000000..c8116412389 --- /dev/null +++ b/rosapps/tests/zwcontinue/i386/zwcontinue.asm @@ -0,0 +1,48 @@ +cpu 486 +segment .text use32 + +extern _check + +global _continuePoint +_continuePoint: + push ss + push dword 0 + pushfd + push cs + push _continuePoint + push ebp + + push eax + push ecx + push edx + push ebx + push esi + push edi + + push ds + push es + push fs + push gs + + ; TODO: floating point state + sub esp, 70h + + ; Debug registers + sub esp, 18h + + push dword 00010007h + + ; Fill the Esp field + lea eax, [esp+0CCh] + lea ecx, [esp+0C4h] + mov [ecx], eax + + ; Call the function that will compare the current context with the expected one + cld + push esp + call _check + + ; check() must not return + int 3 + +; EOF diff --git a/rosapps/tests/zwcontinue/zwcontinue.c b/rosapps/tests/zwcontinue/zwcontinue.c new file mode 100644 index 00000000000..637f0221c51 --- /dev/null +++ b/rosapps/tests/zwcontinue/zwcontinue.c @@ -0,0 +1,185 @@ +#define WIN32_LEAN_AND_MEAN +#define STRICT +#include + +#include +#include +#include +#include +#include +#include +#include + +static unsigned int nRandBytes; + +static int initrand(void) +{ + unsigned int nRandMax; + unsigned int nRandMaxBits; + time_t tLoc; + + nRandMax = RAND_MAX; + + for(nRandMaxBits = 0; nRandMax != 0; nRandMax >>= 1, ++ nRandMaxBits); + + nRandBytes = nRandMaxBits / CHAR_BIT; + + assert(nRandBytes != 0); + + srand((unsigned)(time(&tLoc) & UINT_MAX)); + + return 1; +} + +static void randbytes(void * p, size_t n) +{ + unsigned char * b; + size_t i; + int r; + + b = (unsigned char *)p; + + for(i = 0; i < n; ++ i) + { + if(i % nRandBytes == 0) + r = rand(); + + b[i] = (unsigned char)(r & UCHAR_MAX); + r >>= CHAR_BIT; + } +} + +static ULONG randULONG(void) +{ + ULONG n; + randbytes(&n, sizeof(n)); + return n; +} + +#ifdef _M_IX86 +#define ZWC_SEGMENT_BITS (0xFFFF) +#define ZWC_EFLAGS_BITS (0x3C0CD5) +#endif + +static jmp_buf jmpbuf; +static CONTEXT continueContext; + +extern void continuePoint(void); +extern void check(CONTEXT *); +extern LONG NTAPI ZwContinue(IN CONTEXT *, IN BOOLEAN); + +void check(CONTEXT * actualContext) +{ +#ifdef _M_IX86 + assert(actualContext->ContextFlags == CONTEXT_FULL); + + /* Random data segments */ + assert + ( + (actualContext->SegGs & ZWC_SEGMENT_BITS) == + (continueContext.SegGs & ZWC_SEGMENT_BITS) + ); + + assert + ( + (actualContext->SegFs & ZWC_SEGMENT_BITS) == + (continueContext.SegFs & ZWC_SEGMENT_BITS) + ); + + assert + ( + (actualContext->SegEs & ZWC_SEGMENT_BITS) == + (continueContext.SegEs & ZWC_SEGMENT_BITS) + ); + + assert + ( + (actualContext->SegDs & ZWC_SEGMENT_BITS) == + (continueContext.SegDs & ZWC_SEGMENT_BITS) + ); + + /* Integer registers */ + assert(actualContext->Edi == continueContext.Edi); + assert(actualContext->Esi == continueContext.Esi); + assert(actualContext->Ebx == continueContext.Ebx); + printf("%s %lX : %lX\n", "Edx", actualContext->Edx, continueContext.Edx); + //assert(actualContext->Edx == continueContext.Edx); + assert(actualContext->Ecx == continueContext.Ecx); + assert(actualContext->Eax == continueContext.Eax); + + /* Control registers and segments */ + assert(actualContext->Ebp == continueContext.Ebp); + assert(actualContext->Eip == continueContext.Eip); + + assert + ( + (actualContext->SegCs & ZWC_SEGMENT_BITS) == + (continueContext.SegCs & ZWC_SEGMENT_BITS) + ); + + assert + ( + (actualContext->EFlags & ZWC_EFLAGS_BITS) == + (continueContext.EFlags & ZWC_EFLAGS_BITS) + ); + + assert(actualContext->Esp == continueContext.Esp); + + assert + ( + (actualContext->SegSs & ZWC_SEGMENT_BITS) == + (continueContext.SegSs & ZWC_SEGMENT_BITS) + ); +#endif + + longjmp(jmpbuf, 1); +} + +int main(void) +{ + initrand(); + + /* First time */ + if(setjmp(jmpbuf) == 0) + { + CONTEXT bogus; + + continueContext.ContextFlags = CONTEXT_FULL; + GetThreadContext(GetCurrentThread(), &continueContext); + +#ifdef _M_IX86 + continueContext.ContextFlags = CONTEXT_FULL; + + /* Fill the integer registers with random values */ + continueContext.Edi = randULONG(); + continueContext.Esi = randULONG(); + continueContext.Ebx = randULONG(); + continueContext.Edx = randULONG(); + continueContext.Ecx = randULONG(); + continueContext.Eax = randULONG(); + continueContext.Ebp = randULONG(); + + /* Randomize all the allowed flags (determined experimentally with WinDbg) */ + continueContext.EFlags = randULONG() & 0x3C0CD5; + + /* Randomize the stack pointer as much as possible */ + continueContext.Esp = + (ULONG)(((ULONG_PTR)&bogus) & 0xFFFFFFFF) + + sizeof(bogus) - + (randULONG() & 0xF) * 4; + + /* continuePoint() is implemented in assembler */ + continueContext.Eip = (ULONG)((ULONG_PTR)continuePoint & 0xFFFFFFF); + + /* Can't do a lot about segments */ +#endif + + ZwContinue(&continueContext, FALSE); + } + /* Second time */ + else + return 0; + + assert(0); + return 1; +}