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