Переделай код по структуре программы.
Действия программы зависят от пользователя:
-человек запускает пк
-Программа сразу должна выдать окно с вводом пароля заранее придуманным им
-Программа проверяет верный он или нет (дальше по исходу событий)
-Пароль введён вверно значит программа закрывается и человек работает дальше.



#include <windows.h>
#include <string>
#include <shlobj.h>
#include <iostream>

LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	static std::string password;
	static bool hasEnteredPassword = false;

	switch (uMsg)
	{
	case WM_CREATE:
	{
		HWND hEdit = CreateWindowEx(0, TEXT("edit"), TEXT(""), WS_CHILD | WS_VISIBLE | WS_BORDER | ES_PASSWORD, 10, 10, 200, 25, hwnd, nullptr, nullptr, nullptr);
		HWND hButton = CreateWindowEx(0, TEXT("button"), TEXT("Ввести"), WS_CHILD | WS_VISIBLE, 10, 40, 100, 25, hwnd, reinterpret_cast<HMENU>(1), nullptr, nullptr);
		break;
	}
	case WM_COMMAND:
	{
		if (LOWORD(wParam) == 1)
		{
			HWND hEdit = GetDlgItem(hwnd, 0);
			int length = GetWindowTextLength(hEdit);
			password.assign(length, ‘\0’);
			GetWindowTextA(hEdit, &password[0], length + 1);

			MessageBox(hwnd, TEXT("Пароль сохранен."), TEXT("Вход запрещен"), MB_OK | MB_ICONINFORMATION);

			hasEnteredPassword = true;
			ShowWindow(hwnd, SW_HIDE);
			break;
		}
		break;
	}
	case WM_CLOSE:
	{
		if (hasEnteredPassword)
		{
			DestroyWindow(hwnd);
		}
		else
		{
			MessageBox(hwnd, TEXT("Введите пароль."), TEXT("Ошибка"), MB_OK | MB_ICONERROR);
		}
		break;
	}
	case WM_DESTROY:
	{
		PostQuitMessage(0);
		break;
	}
	default:
		return DefWindowProc(hwnd, uMsg, wParam, lParam);
	}
	return 0;
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
	WNDCLASS wc = {};
	wc.lpfnWndProc = WindowProc;
	wc.hInstance = hInstance;
	wc.lpszClassName = TEXT("PasswordWindowClass");
	RegisterClass(&wc);

	HWND hwnd = CreateWindowEx(0, wc.lpszClassName, TEXT("Ввод пароля"), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 300, 150, nullptr, nullptr, hInstance, nullptr);
	if (hwnd == nullptr)
	{
		return 0;
	}

	ShowWindow(hwnd, nCmdShow);

	// Создание службы Windows
	SC_HANDLE hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_CREATE_SERVICE);
	if (hSCManager == NULL)
	{
		return 0;
	}

	SC_HANDLE hService = CreateService(
		hSCManager,
		TEXT("MyService"),
		TEXT("MyService"),
		SERVICE_ALL_ACCESS,
		SERVICE_WIN32_OWN_PROCESS,
		SERVICE_DEMAND_START,
		SERVICE_ERROR_NORMAL,
		TEXT("path\to\your\application.exe"),
		NULL,
		NULL,
		NULL,
		NULL,
		NULL
	);
	if (hService == NULL)
	{
		CloseServiceHandle(hSCManager);
		return 0;
	}

	CloseServiceHandle(hService);
	CloseServiceHandle(hSCManager);

	// Создание задачи планировщика
	ITaskScheduler* pITaskScheduler;
	HRESULT hr = CoCreateInstance(CLSID_CTaskScheduler, NULL, CLSCTX_INPROC_SERVER, IID_ITaskScheduler, (void**)&pITaskScheduler);
	if (FAILED(hr))
	{
		return 0;
	}

	ITask* pITask;
	hr = pITaskScheduler->NewWorkItem(TEXT("MyTask"), CLSID_CTask, IID_ITask, (IUnknown**)&pITask);
	if (FAILED(hr))
	{
		pITaskScheduler->Release();
		return 0;
	}

	hr = pITask->SetApplicationName(TEXT("path\to\your\application.exe"));
	if (FAILED(hr))
	{
		pITask->Release();
		pITaskScheduler->Release();
		return 0;
	}

	WORD triggerIndex;
	hr = pITask->CreateTrigger(&triggerIndex, NULL);
	if (FAILED(hr))
	{
		pITask->Release();
		pITaskScheduler->Release();
		return 0;
	}

	hr = pITask->SetTriggerString(triggerIndex, L"START_AT_LOGON");
	if (FAILED(hr))
	{
		pITask->Release();
		pITaskScheduler->Release();
		return 0;
	}

	pITask->Release();
	pITaskScheduler->Release();

	MSG msg = {};
	while (GetMessage(&msg, nullptr, 0, 0))
	{
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}

	return static_cast<int>(msg.wParam);
}