+void start_notepad() {\r
+ ZeroMemory(&si, sizeof(si));\r
+ si.cb = sizeof(si);\r
+ ZeroMemory(&pi, sizeof(pi));\r
+\r
+ if (!CreateProcessA(NULL, // No module name (use command line)\r
+ "notepad.exe lvl/0.txt", // Command line\r
+ NULL, // Process handle not inheritable\r
+ NULL, // Thread handle not inheritable\r
+ FALSE, // Set handle inheritance to FALSE\r
+ 0, // No creation flags\r
+ NULL, // Use parent's environment block\r
+ NULL, // Use parent's starting directory\r
+ &si, // Pointer to STARTUPINFO structure\r
+ &pi) // Pointer to PROCESS_INFORMATION structure\r
+ ) {\r
+ printf("CreateProcess failed (%d).\n", GetLastError());\r
+ }\r
+ Sleep(1000);\r
+ EnumWindows([](HWND hwnd, LPARAM lp)->BOOL{\r
+ if (check_class(hwnd, "Notepad")) {\r
+ *(HWND*)lp = hwnd;\r
+ return false;\r
+ }\r
+ return true;\r
+ }, (LPARAM)&hwnd_notepad);\r
+ EnumChildWindows(hwnd_notepad, [](HWND hwnd, LPARAM lp)->BOOL{\r
+ printf("looking at %p\n", hwnd);\r
+ if (check_class(hwnd, "NotepadTextBox")) {\r
+ EnumChildWindows(hwnd, [](HWND hwnd, LPARAM lp)->BOOL{\r
+ printf(" looking at %p\n", hwnd);\r
+ const size_t size = (WIDTH+4)*(HEIGHT+2);\r
+ char b[size];\r
+ DWORD_PTR dwResult;\r
+ b[0] = 0;\r
+ SendMessageTimeoutA(hwnd, WM_GETTEXT, size, (LPARAM)b,\r
+ SMTO_ABORTIFHUNG, 100, &dwResult);\r
+ if (b[0] == '+') {\r
+ // TODO: check lvl\r
+ printf("%.*s.\n", size, b);\r
+ *(HWND*)lp = hwnd;\r
+ return false;\r
+ }\r
+ return true;\r
+ }, lp);\r
+ if (lp) return false;\r
+ }\r
+ return true;\r
+ }, (LPARAM)&hwnd_edit);\r
+ SendMessage(hwnd_edit, EM_SETREADONLY, TRUE, NULL);\r
+}\r
+void close_notepad() {\r
+ SendMessage(hwnd_edit, EM_SETREADONLY, FALSE, NULL);\r
+ //TerminateProcess(pi.hProcess, 0);\r
+ //CloseHandle(pi.hProcess);\r
+ //CloseHandle(pi.hThread);\r