diff --git a/reactos/ChangeLog b/reactos/ChangeLog index 252f24b2f16..360799e0a38 100644 --- a/reactos/ChangeLog +++ b/reactos/ChangeLog @@ -1,3 +1,11 @@ +2003-12-07 Casper S. Hornstrup + + * apps/tests/accelerator: New directory. + * apps/tests/accelerator/accelerator.c: New file. + * apps/tests/accelerator/.cvsignore: Ditto. + * apps/tests/accelerator/Makefile: Ditto. + * apps/tests/Makefile (TEST_APPS): Add accelerator. + 2003-12-07 Casper S. Hornstrup * regtests/Makefile: Generate regression test registrations. diff --git a/reactos/apps/tests/Makefile b/reactos/apps/tests/Makefile index 2b0dab2d90d..a0d845d39e8 100644 --- a/reactos/apps/tests/Makefile +++ b/reactos/apps/tests/Makefile @@ -7,7 +7,7 @@ PATH_TO_TOP = ../.. include $(PATH_TO_TOP)/rules.mak # test_old tests -TEST_APPS = SampleWindow alive apc args atomtest bench bitblt button \ +TEST_APPS = accelerator SampleWindow alive apc args atomtest bench bitblt button \ button2 capclock carets cliarea combo consume copymove count dibtest \ dump_shared_data edit enumwnd event file global_mem hello \ hivetest hotkey icontest isotest lineclip linetest lock lpc messagebox \ diff --git a/reactos/apps/tests/accelerator/.cvsignore b/reactos/apps/tests/accelerator/.cvsignore new file mode 100644 index 00000000000..e24713815a0 --- /dev/null +++ b/reactos/apps/tests/accelerator/.cvsignore @@ -0,0 +1,6 @@ +*.o +*.d +*.exe +*.coff +*.sym +*.map \ No newline at end of file diff --git a/reactos/apps/tests/accelerator/Makefile b/reactos/apps/tests/accelerator/Makefile new file mode 100644 index 00000000000..2ea8d4f1e50 --- /dev/null +++ b/reactos/apps/tests/accelerator/Makefile @@ -0,0 +1,19 @@ +PATH_TO_TOP = ../../.. + +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/reactos/apps/tests/accelerator/accelerator.c b/reactos/apps/tests/accelerator/accelerator.c new file mode 100644 index 00000000000..0b7aca65ef1 --- /dev/null +++ b/reactos/apps/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; +}