#include "stdafx.h" #include "Settings.h" namespace { const wchar_t* kKey = L"Software\\TaskbarCalculator"; bool ReadDword(const wchar_t* name, DWORD& out) { HKEY h; if (RegOpenKeyExW(HKEY_CURRENT_USER, kKey, 0, KEY_QUERY_VALUE, &h) != ERROR_SUCCESS) return false; DWORD type = 0, val = 0, size = sizeof(val); LONG r = RegQueryValueExW(h, name, nullptr, &type, (LPBYTE)&val, &size); RegCloseKey(h); if (r != ERROR_SUCCESS || type != REG_DWORD) return false; out = val; return true; } void WriteDword(const wchar_t* name, DWORD val) { HKEY h; if (RegCreateKeyExW(HKEY_CURRENT_USER, kKey, 0, nullptr, 0, KEY_SET_VALUE, nullptr, &h, nullptr) != ERROR_SUCCESS) return; RegSetValueExW(h, name, 0, REG_DWORD, (const BYTE*)&val, sizeof(val)); RegCloseKey(h); } } namespace Settings { bool LoadWindowPos(POINT& pt) { DWORD x, y; if (ReadDword(L"PosX", x) && ReadDword(L"PosY", y)) { pt.x = (LONG)(INT)x; pt.y = (LONG)(INT)y; return true; } return false; } void SaveWindowPos(POINT pt) { WriteDword(L"PosX", (DWORD)pt.x); WriteDword(L"PosY", (DWORD)pt.y); } bool LoadVisible(bool def) { DWORD v; return ReadDword(L"Visible", v) ? (v != 0) : def; } void SaveVisible(bool visible) { WriteDword(L"Visible", visible ? 1 : 0); } bool LoadWindowWidth(DWORD& out) { DWORD w; if (ReadDword(L"Width96", w) && w > 0) { out = w; return true; } return false; } void SaveWindowWidth(DWORD width96) { WriteDword(L"Width96", width96); } }