Something went wrong. Try again.
A simple, small calculator placed discreetly near the Windows Taskbar or anywhere on the screen taskbar-calculator.marcomaroni.it
Something went wrong. Try again.
taskbar-calculator Settings.cpp
1.8 kB · 57 lines
C++
at main
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758#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); }}