9c7c74d352ba0225e8574e0b390edc63eae52350
[reactos.git] / apps / tests / button / buttontst.c
1 /* Based on Radoslaw Sokol's static control test. */
2 #include <windows.h>
3
4 static LPSTR BUTTON_CLASS   = "BUTTON";
5 static LPSTR TEST_WND_CLASS = "TESTWND";
6
7 #ifdef NDEBUG
8  #define DPRINT(s) (void)0
9 #else
10  #define DPRINT(s) OutputDebugStringA("BUTTONTEST: " s "\n")
11 #endif
12
13 HINSTANCE AppInstance = NULL;
14
15 LRESULT WmCreate(
16    HWND Wnd)
17 {
18    UCHAR i;
19    DPRINT("WM_CREATE (enter).");
20    DPRINT("test 1");
21    CreateWindowEx(0, BUTTON_CLASS, "PushButton", BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE,
22       10, 10, 150, 30, Wnd, NULL, AppInstance, NULL);
23    DPRINT("test 2");
24    CreateWindowEx(0, BUTTON_CLASS, "DefPushButton", BS_DEFPUSHBUTTON | WS_CHILD | WS_VISIBLE,
25       10, 40, 150, 30, Wnd, NULL, AppInstance, NULL);
26    DPRINT("test 3");
27    CreateWindowEx(0, BUTTON_CLASS, "AutoRadioButton", BS_AUTORADIOBUTTON | WS_CHILD | WS_VISIBLE,
28       10, 70, 150, 30, Wnd, NULL, AppInstance, NULL);
29    DPRINT("test 4");
30    CreateWindowEx(0, BUTTON_CLASS, "AutoCheckBox", BS_AUTOCHECKBOX | WS_CHILD | WS_VISIBLE,
31       10, 100, 150, 30, Wnd, NULL, AppInstance, NULL);
32
33    DPRINT("WM_CREATE (leave).");
34    return 0;
35 }
36
37 LRESULT CALLBACK TestWndProc(
38    HWND Wnd,
39    UINT Msg,
40    WPARAM wParam,
41    LPARAM lParam)
42 {
43    switch (Msg) {
44    case WM_CREATE:
45       return WmCreate(Wnd);
46    case WM_DESTROY:
47       PostQuitMessage(0);
48       return 0;
49    default:
50       return DefWindowProc(Wnd, Msg, wParam, lParam);
51    }
52 }
53
54 int STDCALL WinMain(
55     HINSTANCE hInstance,
56     HINSTANCE hPrevInstance,
57     LPSTR lpCmdLine,
58     int nShowCmd)
59 {
60    ATOM Result;
61    MSG Msg;
62    HWND MainWindow;
63    WNDCLASSEX TestWndClass = {0};
64    DPRINT("Application starting up.");
65    // Remember instance handle.
66    AppInstance = GetModuleHandle(NULL);
67    // Register test window class.
68    TestWndClass.cbSize = sizeof(WNDCLASSEX);
69    TestWndClass.lpfnWndProc = &TestWndProc;
70    TestWndClass.hInstance = AppInstance;
71    TestWndClass.hCursor = LoadCursor(0, IDC_ARROW);
72    TestWndClass.hbrBackground = CreateSolidBrush(RGB(255,255,230));
73    TestWndClass.lpszClassName = TEST_WND_CLASS;
74    Result = RegisterClassEx(&TestWndClass);
75    if (Result == 0) {
76       DPRINT("Error registering class.");
77       MessageBox(0, "Error registering test window class.",
78          "Button control test", MB_ICONSTOP | MB_OK);
79       ExitProcess(0);
80    }
81    // Create main window.
82    DPRINT("Creating main window.");
83    MainWindow = CreateWindowEx(WS_EX_APPWINDOW | WS_EX_CLIENTEDGE,
84       TEST_WND_CLASS, "Button test",
85       WS_OVERLAPPEDWINDOW, 50, 50, 180, 365,
86       NULL, NULL, AppInstance, NULL);
87    if (MainWindow == 0) {
88       DPRINT("Error creating main window.");
89       UnregisterClass(TEST_WND_CLASS, AppInstance);
90       MessageBox(0, "Error creating test window.",
91          "Static control test", MB_ICONSTOP | MB_OK);
92       ExitProcess(0);
93    }
94    DPRINT("Showing main window.");
95    ShowWindow(MainWindow, SW_SHOWNORMAL);
96    UpdateWindow(MainWindow);
97    // Run message loop.
98    DPRINT("Entering message loop.");
99    while (GetMessage(&Msg, NULL, 0, 0) > 0) {
100       TranslateMessage(&Msg);
101       DispatchMessage(&Msg);
102    }
103    // Unregister window class.
104    UnregisterClass(TEST_WND_CLASS, AppInstance);
105    DPRINT("Exiting.");
106
107    return Msg.wParam;
108 }