-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAppConfig.cpp
More file actions
108 lines (90 loc) · 2.37 KB
/
Copy pathAppConfig.cpp
File metadata and controls
108 lines (90 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#include <tchar.h>
#include <Windows.h>
#include "AppConfig.h"
#include "misc.h"
ApplicationConfig::ApplicationConfig()
{
this->LocalRegistry = nullptr;
}
ApplicationConfig::ApplicationConfig(const TCHAR * const FileName)
{
LONG LResult;
LResult = ::RegLoadAppKey(FileName, &this->LocalRegistry, KEY_READ | KEY_WRITE, 0, 0);
if(LResult != ERROR_SUCCESS)
{
::Debug(TEXT("RegLoadAppKey(%s) failed with %u.\n"), LResult);
this->LocalRegistry = nullptr;
}
}
ApplicationConfig::~ApplicationConfig()
{
if(this->LocalRegistry != nullptr)
{
::RegCloseKey(this->LocalRegistry);
}
}
void ApplicationConfig::GetWindowPosition(POINT * const Coord)
{
DWORD Value;
if(this->Read32(CONFIG_COORD_LEFT, &Value))
{
Coord->x = (LONG)Value;
}
if(this->Read32(CONFIG_COORD_TOP, &Value))
{
Coord->y = (LONG)Value;
}
}
void ApplicationConfig::SetWindowPosition(const POINT * const Coord)
{
this->Write32(CONFIG_COORD_LEFT, Coord->x);
this->Write32(CONFIG_COORD_TOP, Coord->y);
}
void ApplicationConfig::GetWindowSize(SIZE * const Metric)
{
DWORD Value;
if(this->Read32(CONFIG_SIZE_WIDTH, &Value))
{
Metric->cx = (LONG)Value;
}
if(this->Read32(CONFIG_SIZE_HEIGHT, &Value))
{
Metric->cy = (LONG)Value;
}
}
void ApplicationConfig::SetWindowSize(const SIZE * const Metric)
{
this->Write32(CONFIG_SIZE_WIDTH, Metric->cx);
this->Write32(CONFIG_SIZE_HEIGHT, Metric->cy);
}
bool ApplicationConfig::Read32(const TCHAR * const Name, unsigned long * const Value)
{
LONG LResult;
unsigned long ValueType;
unsigned long ValueSize;
unsigned long ValueDWORD;
if(this->LocalRegistry == nullptr)
{
return false;
}
ValueSize = sizeof(unsigned long);
LResult = ::RegQueryValueEx(this->LocalRegistry, Name, nullptr, &ValueType, reinterpret_cast<LPBYTE>(&ValueDWORD), &ValueSize);
if(LResult == ERROR_SUCCESS)
{
*Value = ValueDWORD;
}
return (LResult == ERROR_SUCCESS);
}
void ApplicationConfig::Write32(const TCHAR * const Name, const unsigned long Value)
{
LONG LResult;
if(this->LocalRegistry == nullptr)
{
return;
}
LResult = ::RegSetValueEx(this->LocalRegistry, Name, 0, REG_DWORD, reinterpret_cast<const BYTE *>(&Value), sizeof(unsigned long));
if(LResult != ERROR_SUCCESS)
{
::Debug(TEXT("Can not store value at %s with %u (%u).\n"), Name, Value, LResult);
}
}