diff options
author | jbzdarkid <jbzdarkid@gmail.com> | 2018-10-29 19:57:02 -0700 |
---|---|---|
committer | jbzdarkid <jbzdarkid@gmail.com> | 2018-10-29 19:57:02 -0700 |
commit | 0d728e66b7bde350a6e5d9f0a467bba7a3433f16 (patch) | |
tree | 39856a87d48466aab7652f228f5729b43196abf7 /Source/Main.cpp | |
parent | a5d9a2eb991e387909281949c2b1f3395a7740ff (diff) | |
download | witness-tutorializer-0d728e66b7bde350a6e5d9f0a467bba7a3433f16.tar.gz witness-tutorializer-0d728e66b7bde350a6e5d9f0a467bba7a3433f16.tar.bz2 witness-tutorializer-0d728e66b7bde350a6e5d9f0a467bba7a3433f16.zip |
should be working
Diffstat (limited to 'Source/Main.cpp')
-rw-r--r-- | Source/Main.cpp | 187 |
1 files changed, 79 insertions, 108 deletions
diff --git a/Source/Main.cpp b/Source/Main.cpp index 86a784b..b227e3d 100644 --- a/Source/Main.cpp +++ b/Source/Main.cpp | |||
@@ -1,49 +1,73 @@ | |||
1 | // Source.cpp : Defines the entry point for the application. | 1 | // Source.cpp : Defines the entry point for the application. |
2 | // | 2 | // |
3 | 3 | ||
4 | #include "stdafx.h" | ||
5 | #include "resource.h" | 4 | #include "resource.h" |
6 | #include "tchar.h" | ||
7 | #include "Randomizer.h" | ||
8 | #include <Richedit.h> | 5 | #include <Richedit.h> |
9 | #include <iostream> | ||
10 | #include <ctime> | 6 | #include <ctime> |
11 | #include <string> | 7 | #include <string> |
8 | #include "Randomizer.h" | ||
9 | #include "windows.h" | ||
12 | 10 | ||
13 | #define MAX_LOADSTRING 100 | 11 | #define IDC_RANDOMIZE 0x401 |
14 | #define IDC_RANDOMIZE 0x464 | 12 | #define IDC_TOGGLESPEED 0x402 |
15 | |||
16 | HINSTANCE hInst; | ||
17 | WCHAR szWindowClass[MAX_LOADSTRING]; | ||
18 | HWND hwndSeed, hwndRandomize; | ||
19 | 13 | ||
20 | // Forward declares | 14 | HWND hwndSeed, hwndRandomize, hwndSpeedSetting; |
21 | ATOM MyRegisterClass(HINSTANCE hInstance); | ||
22 | BOOL InitInstance(HINSTANCE, int); | ||
23 | LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); | ||
24 | INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM); | ||
25 | 15 | ||
26 | int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow) | 16 | LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) |
27 | { | 17 | { |
28 | LoadStringW(hInstance, IDC_SOURCE, szWindowClass, MAX_LOADSTRING); | 18 | static bool wasSeedRandomlyGenerated; |
29 | MyRegisterClass(hInstance); | ||
30 | if (!InitInstance(hInstance, nCmdShow)) { | ||
31 | return FALSE; | ||
32 | } | ||
33 | |||
34 | MSG msg; | ||
35 | while (!GetMessage(&msg, nullptr, 0, 0) == 0) | ||
36 | { | ||
37 | TranslateMessage(&msg); | ||
38 | DispatchMessage(&msg); | ||
39 | } | ||
40 | 19 | ||
41 | return (int) msg.wParam; | 20 | if (message == WM_DESTROY) { |
21 | PostQuitMessage(0); | ||
22 | } else if (message == WM_COMMAND) { | ||
23 | switch (LOWORD(wParam)) { | ||
24 | // Speed checkbox | ||
25 | case IDC_TOGGLESPEED: | ||
26 | if (IsDlgButtonChecked(hwndSpeedSetting, 1)) { | ||
27 | CheckDlgButton(hwndSpeedSetting, 1, BST_UNCHECKED); | ||
28 | } else { | ||
29 | CheckDlgButton(hwndSpeedSetting, 1, BST_CHECKED); | ||
30 | } | ||
31 | break; | ||
32 | |||
33 | // Randomize button | ||
34 | case IDC_RANDOMIZE: | ||
35 | { | ||
36 | std::wstring text(100, '\0'); | ||
37 | GetWindowText(hwndSeed, &text[0], 100); | ||
38 | int seed = 0; | ||
39 | if (wasSeedRandomlyGenerated || wcslen(text.c_str()) == 0) { | ||
40 | srand(static_cast<unsigned int>(time(nullptr))); // Seed from the time in milliseconds | ||
41 | rand(); // Increment RNG so that RNG isn't still using the time | ||
42 | seed = rand() % 100000; | ||
43 | std::wstring seedString = std::to_wstring(seed); | ||
44 | SetWindowText(hwndSeed, seedString.c_str()); | ||
45 | wasSeedRandomlyGenerated = true; | ||
46 | } else { | ||
47 | seed = _wtoi(text.c_str()); | ||
48 | wasSeedRandomlyGenerated = false; | ||
49 | } | ||
50 | srand(seed); | ||
51 | Randomizer randomizer; | ||
52 | randomizer.Randomize(); | ||
53 | if (IsDlgButtonChecked(hwndSpeedSetting, 1)) { | ||
54 | randomizer.AdjustSpeed(); | ||
55 | } | ||
56 | SetWindowText(hwndRandomize, L"Randomized!"); | ||
57 | break; | ||
58 | } | ||
59 | } | ||
60 | } | ||
61 | return DefWindowProc(hwnd, message, wParam, lParam); | ||
42 | } | 62 | } |
43 | 63 | ||
44 | ATOM MyRegisterClass(HINSTANCE hInstance) | 64 | int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow) |
45 | { | 65 | { |
46 | WNDCLASSEXW wcex = { | 66 | #define MAX_LOADSTRING 100 |
67 | WCHAR szWindowClass[MAX_LOADSTRING]; | ||
68 | LoadStringW(hInstance, IDC_SOURCE, szWindowClass, MAX_LOADSTRING); | ||
69 | |||
70 | WNDCLASSEXW wcex = { | ||
47 | sizeof(WNDCLASSEX), | 71 | sizeof(WNDCLASSEX), |
48 | CS_HREDRAW | CS_VREDRAW, | 72 | CS_HREDRAW | CS_VREDRAW, |
49 | WndProc, | 73 | WndProc, |
@@ -57,95 +81,42 @@ ATOM MyRegisterClass(HINSTANCE hInstance) | |||
57 | szWindowClass, | 81 | szWindowClass, |
58 | LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL)), | 82 | LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL)), |
59 | }; | 83 | }; |
60 | 84 | RegisterClassExW(&wcex); | |
61 | return RegisterClassExW(&wcex); | ||
62 | } | ||
63 | |||
64 | BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) | ||
65 | { | ||
66 | hInst = hInstance; // Store instance handle in our global variable | ||
67 | 85 | ||
68 | WCHAR szTitle[MAX_LOADSTRING]; | 86 | WCHAR szTitle[MAX_LOADSTRING]; |
69 | LoadStringW(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); | 87 | LoadStringW(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); |
70 | HWND hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW, | 88 | HWND hwnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW, |
71 | 400, 200, 500, 500, nullptr, nullptr, hInstance, nullptr); | 89 | 400, 200, 500, 500, nullptr, nullptr, hInstance, nullptr); |
72 | 90 | ||
73 | if (!hWnd) return FALSE; | ||
74 | |||
75 | LoadLibrary(L"Msftedit.dll"); | 91 | LoadLibrary(L"Msftedit.dll"); |
76 | HWND label = CreateWindow(L"STATIC", L"Enter a seed:", | ||
77 | WS_TABSTOP | WS_VISIBLE | WS_CHILD | SS_LEFT, | ||
78 | 10, 15, 90, 16, hWnd, NULL, hInst, NULL); | ||
79 | 92 | ||
80 | hwndSeed = CreateWindowEx(0, MSFTEDIT_CLASS, L"", | ||
81 | WS_TABSTOP | WS_VISIBLE | WS_CHILD | WS_BORDER, | ||
82 | 100, 10, 50, 26, hWnd, NULL, hInst, NULL); | ||
83 | 93 | ||
94 | CreateWindow(L"STATIC", L"Enter a seed:", | ||
95 | WS_TABSTOP | WS_VISIBLE | WS_CHILD | SS_LEFT, | ||
96 | 10, 15, 90, 16, hwnd, NULL, hInstance, NULL); | ||
97 | hwndSeed = CreateWindow(MSFTEDIT_CLASS, L"", | ||
98 | WS_TABSTOP | WS_VISIBLE | WS_CHILD | WS_BORDER, | ||
99 | 100, 10, 50, 26, hwnd, NULL, hInstance, NULL); | ||
84 | hwndRandomize = CreateWindow(L"BUTTON", L"Randomize", | 100 | hwndRandomize = CreateWindow(L"BUTTON", L"Randomize", |
85 | WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, | 101 | WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, |
86 | 160, 10, 100, 26, hWnd, (HMENU)IDC_RANDOMIZE, hInst, NULL); | 102 | 160, 10, 100, 26, hwnd, (HMENU)IDC_RANDOMIZE, hInstance, NULL); |
87 | |||
88 | HDC hdc = GetDC(hWnd); | ||
89 | RECT rect; | ||
90 | GetClientRect(hWnd, &rect); | ||
91 | LPCWSTR text = L"this Window cannot be used"; | ||
92 | DrawText(hdc, text, static_cast<int>(wcslen(text)), &rect, DT_CENTER | DT_VCENTER); | ||
93 | ReleaseDC(hWnd, hdc); | ||
94 | |||
95 | ShowWindow(hWnd, nCmdShow); | ||
96 | UpdateWindow(hWnd); | ||
97 | return TRUE; | ||
98 | } | ||
99 | 103 | ||
100 | LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) | 104 | hwndSpeedSetting = CreateWindow(L"BUTTON", L"", |
101 | { | 105 | WS_VISIBLE | WS_CHILD | BS_CHECKBOX, |
102 | if (message == WM_DESTROY) { | 106 | 10, 52, 12, 12, hwnd, (HMENU)IDC_TOGGLESPEED, hInstance, NULL); |
103 | PostQuitMessage(0); | 107 | CreateWindow(L"STATIC", L"Speed up various autoscrollers", |
104 | } else if (message == WM_COMMAND) { | 108 | WS_TABSTOP | WS_VISIBLE | WS_CHILD | SS_LEFT, |
105 | int wmId = LOWORD(wParam); | 109 | 27, 50, 205, 16, hwnd, NULL, hInstance, NULL); |
106 | // Parse the menu selections: | ||
107 | if (wmId == IDC_RANDOMIZE) { | ||
108 | std::wstring text(100, '\0'); | ||
109 | GetWindowText(hwndSeed, &text[0], 100); | ||
110 | int seed = 0; | ||
111 | if (wcslen(text.c_str()) == 0) { | ||
112 | srand(static_cast<unsigned int>(time(nullptr))); // Seed from the time in milliseconds | ||
113 | rand(); | ||
114 | seed = rand() % 100000; | ||
115 | std::wstring seedString = std::to_wstring(seed); | ||
116 | SetWindowText(hwndSeed, seedString.c_str()); | ||
117 | } else { | ||
118 | seed = _wtoi(text.c_str()); | ||
119 | } | ||
120 | srand(seed); | ||
121 | Randomizer randomizer; | ||
122 | randomizer.Randomize(); | ||
123 | /* | ||
124 | if (adjustSpeed.isChecked()) { | ||
125 | randomizer.AdjustSpeed(); | ||
126 | } | ||
127 | */ | ||
128 | SetWindowText(hwndRandomize, L"Randomized!"); | ||
129 | } | ||
130 | } | ||
131 | return DefWindowProc(hWnd, message, wParam, lParam); | ||
132 | } | ||
133 | 110 | ||
134 | INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) | 111 | ShowWindow(hwnd, nCmdShow); |
135 | { | 112 | UpdateWindow(hwnd); |
136 | UNREFERENCED_PARAMETER(lParam); | 113 | |
137 | switch (message) | 114 | MSG msg; |
115 | while (!GetMessage(&msg, nullptr, 0, 0) == 0) | ||
138 | { | 116 | { |
139 | case WM_INITDIALOG: | 117 | TranslateMessage(&msg); |
140 | return TRUE; | 118 | DispatchMessage(&msg); |
141 | |||
142 | case WM_COMMAND: | ||
143 | if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) | ||
144 | { | ||
145 | EndDialog(hDlg, LOWORD(wParam)); | ||
146 | return TRUE; | ||
147 | } | ||
148 | break; | ||
149 | } | 119 | } |
150 | return FALSE; | 120 | |
121 | return (int) msg.wParam; | ||
151 | } | 122 | } |