SavvyUI C++ UI Library
Loading...
Searching...
No Matches
Common.h
Go to the documentation of this file.
1#pragma once
2
3#include <Windows.h>
4#include <windowsx.h>
5#include <commdlg.h>
6#include <ole2.h>
7#include <stdio.h>
8#include <gdiplus.h>
9#include <string>
10#include <vector>
11#include <map>
12using namespace std;
13
14#define PI 3.14159265358979323846
15
16typedef HWND WinHandle;
17typedef HDC DCHandle;
18typedef HMENU MenuHandle;
19
20class Bounds
21{
22public:
23
25 {
26 left = 0;
27 top = 0;
28 right = 0;
29 bottom = 0;
30 }
31
32 Bounds(long x, long y, long x2, long y2)
33 {
34 left = x;
35 top = y;
36 right = x2;
37 bottom = y2;
38 }
39
40 void setWidth(long w)
41 {
42 right = left + w - 1;
43 }
44
45 void setHeight(long h)
46 {
47 bottom = top + h - 1;
48 }
49
50 void deflateRect(long numPixels)
51 {
52 long xPixels = numPixels;
53 while (xPixels > 0)
54 {
55 if (left >= right)
56 break;
57 left++;
58
59 if (right > left)
60 right--;
61 xPixels--;
62 }
63 long yPixels = numPixels;
64 while (yPixels > 0)
65 {
66 if (top >= bottom)
67 break;
68 top++;
69
70 if (bottom > top)
71 bottom--;
72 yPixels--;
73 }
74 }
75
76 void inflateRect(long numPixels)
77 {
78 long xPixels = numPixels;
79 while (xPixels > 0)
80 {
81 if (left > 0)
82 left--;
83 else
84 break;
85
86 right++;
87 xPixels--;
88 }
89 long yPixels = numPixels;
90 while (yPixels > 0)
91 {
92 if (top > 0)
93 top--;
94 else
95 break;
96
97 bottom++;
98 yPixels--;
99 }
100 }
101
102 long width() const
103 {
104 return right - left;
105 }
106
107 long height() const
108 {
109 return bottom - top;
110 }
111
112 BOOL contains(long x, long y)
113 {
114 if (right > left && bottom > top)
115 return (x >= left && x <= right && y >= top && y <= bottom);
116 return FALSE;
117 }
118
120};
121
122enum class Direction {
123 LEFT = 1,
124 TOP = 2,
125 RIGHT = 3,
127};
128
140
141enum class ImageType {
142 PNG = 1,
143 GIF = 2,
144 JPG = 3
145};
146
158
159enum class ButtonType {
162 INFO = 3,
165 WARN = 6,
166 GRAY = 7,
168 BLUE = 9,
170 TEAL = 11,
171 CYAN = 12,
172 PINK = 13,
173 INDIGO = 14,
174 ORANGE = 15,
175 BROWN = 16,
176 SILVER = 17,
177 RED = 18,
178 WINDOW = 19,
180};
181
182enum class ChartType {
183 BAR = 1,
184 PIE = 2,
185 DONUT = 3,
186 AREA = 4,
187 LINE = 5,
189 RADAR = 7,
192};
193
195{
196public:
197
198 KeyValue(const wstring& key, const wstring& value)
199 {
200 _key = key;
201 _value = value;
202 }
203 wstring _key;
204 wstring _value;
205};
206
208{
209public:
210 __int64 _value1;
211 __int64 _value2;
212 __int64 _value3;
213 __int64 _value4;
214 __int64 _value5;
215 __int64 _value6;
216 __int64 _value7;
217 __int64 _value8;
218 __int64 _value9;
219 __int64 _value10;
220};
221
223{
224public:
225
226 static wstring strToWStr(const char* input);
227 static string wStrToStr(const wchar_t* input);
228
229 static RECT SRectToRECT(const Bounds& rect);
230
231public:
232
233 static BOOL getExeName(wstring& filePath, BOOL returnFileNameOnly);
234 static BOOL getExeFolder(wstring& exeDir);
235
236public:
237
238 static BOOL copyFile(const wstring& srcFilePath, const wstring& destFilePath, BOOL failIfExists = TRUE, BOOL createDirectoryIfNotExists = TRUE);
239 static BOOL getFileSize(const wstring& filePath, DWORD& fileSize);
240 static BOOL getDirFromPath(const wstring& filePath, wstring& directory);
241 static BOOL getPathComponents(const wstring& filePath, wstring& directory, wstring& fileName, wstring& fileExtension);
242 static BOOL createDirectory(const wstring& directory);
243
244 static BOOL readFile(FILE* fp, void* buffer, size_t size, DWORD atOffset);
245 static BOOL writeFile(FILE* fp, void* buffer, size_t size, DWORD atOffset);
246
247public:
248
249 static BOOL createShortcut(const wchar_t* targetPath);
250
251 static BOOL addRegistryEntry(const wchar_t* valueName, const wchar_t* valueData, const wchar_t* subKeyPath, HKEY hSection = HKEY_CURRENT_USER);
252 static BOOL executeSystemCommand(const wchar_t* command, const wchar_t* parameters, const wchar_t* workingDirectory, BOOL waitForCompletion = FALSE);
253
254public:
255
256 static BOOL isDigit(wchar_t ch);
257 static BOOL isAlpha(wchar_t ch);
258 static BOOL isDigitOrAlpha(wchar_t ch);
259
260 static wstring systemTimeToStrYYYYMMDD(const SYSTEMTIME& sysTime);
261 static SYSTEMTIME strYYYYMMDDToSystemTime(const wstring& strYYYYMMDD);
262};
263
Direction
Definition Common.h:122
@ BOTTOM
Definition Common.h:126
@ RIGHT
Definition Common.h:125
@ TOP
Definition Common.h:124
@ LEFT
Definition Common.h:123
ImageType
Definition Common.h:141
@ PNG
Definition Common.h:142
@ JPG
Definition Common.h:144
@ GIF
Definition Common.h:143
HWND WinHandle
Definition Common.h:16
ChartType
Definition Common.h:182
@ RADAR
Definition Common.h:189
@ LINE
Definition Common.h:187
@ SCATTER
Definition Common.h:190
@ DONUT
Definition Common.h:185
@ BAR
Definition Common.h:183
@ AREA
Definition Common.h:186
@ HEATMAP
Definition Common.h:191
@ PIE
Definition Common.h:184
@ FUNNEL
Definition Common.h:188
HDC DCHandle
Definition Common.h:17
ImageAlignment
Definition Common.h:129
@ BOTTOMCENTER
Definition Common.h:137
@ MIDDLERIGHT
Definition Common.h:135
@ TOPRIGHT
Definition Common.h:132
@ MIDDLECENTER
Definition Common.h:134
@ BOTTOMLEFT
Definition Common.h:136
@ BOTTOMRIGHT
Definition Common.h:138
@ MIDDLELEFT
Definition Common.h:133
@ TOPCENTER
Definition Common.h:131
@ TOPLEFT
Definition Common.h:130
HMENU MenuHandle
Definition Common.h:18
EditType
Definition Common.h:147
@ NUMBERFIELD
Definition Common.h:150
@ TEXTAREAFIELD
Definition Common.h:154
@ TEXTFIELD
Definition Common.h:148
@ COMBOBOXFIELD
Definition Common.h:153
@ COMPUTED
Definition Common.h:156
@ DATETIMEFIELD
Definition Common.h:152
@ DATEFIELD
Definition Common.h:151
@ BOOLFIELD
Definition Common.h:155
@ MASKEDFIELD
Definition Common.h:149
ButtonType
Definition Common.h:159
@ LIGHTGRAY
Definition Common.h:167
@ SILVER
Definition Common.h:176
@ BLUE
Definition Common.h:168
@ PINK
Definition Common.h:172
@ WARN
Definition Common.h:165
@ CYAN
Definition Common.h:171
@ PRIMARY
Definition Common.h:161
@ GRAY
Definition Common.h:166
@ BROWN
Definition Common.h:175
@ INFO
Definition Common.h:162
@ DEFAULT
Definition Common.h:160
@ ORANGE
Definition Common.h:174
@ DANGER
Definition Common.h:163
@ WINDOW
Definition Common.h:178
@ CUSTOM
Definition Common.h:179
@ TEAL
Definition Common.h:170
@ LIGHTBLUE
Definition Common.h:169
@ RED
Definition Common.h:177
@ SUCCESS
Definition Common.h:164
@ INDIGO
Definition Common.h:173
Definition Common.h:21
long left
Definition Common.h:119
void deflateRect(long numPixels)
Definition Common.h:50
Bounds()
Definition Common.h:24
void setWidth(long w)
Definition Common.h:40
void inflateRect(long numPixels)
Definition Common.h:76
void setHeight(long h)
Definition Common.h:45
long height() const
Definition Common.h:107
long top
Definition Common.h:119
Bounds(long x, long y, long x2, long y2)
Definition Common.h:32
long right
Definition Common.h:119
BOOL contains(long x, long y)
Definition Common.h:112
long width() const
Definition Common.h:102
long bottom
Definition Common.h:119
Definition Common.h:223
static RECT SRectToRECT(const Bounds &rect)
static string wStrToStr(const wchar_t *input)
static BOOL copyFile(const wstring &srcFilePath, const wstring &destFilePath, BOOL failIfExists=TRUE, BOOL createDirectoryIfNotExists=TRUE)
static BOOL writeFile(FILE *fp, void *buffer, size_t size, DWORD atOffset)
static BOOL readFile(FILE *fp, void *buffer, size_t size, DWORD atOffset)
static BOOL getFileSize(const wstring &filePath, DWORD &fileSize)
static BOOL executeSystemCommand(const wchar_t *command, const wchar_t *parameters, const wchar_t *workingDirectory, BOOL waitForCompletion=FALSE)
static BOOL createShortcut(const wchar_t *targetPath)
static SYSTEMTIME strYYYYMMDDToSystemTime(const wstring &strYYYYMMDD)
static BOOL getExeFolder(wstring &exeDir)
static BOOL getDirFromPath(const wstring &filePath, wstring &directory)
static BOOL isDigitOrAlpha(wchar_t ch)
static BOOL addRegistryEntry(const wchar_t *valueName, const wchar_t *valueData, const wchar_t *subKeyPath, HKEY hSection=HKEY_CURRENT_USER)
static BOOL createDirectory(const wstring &directory)
static wstring strToWStr(const char *input)
static wstring systemTimeToStrYYYYMMDD(const SYSTEMTIME &sysTime)
static BOOL getPathComponents(const wstring &filePath, wstring &directory, wstring &fileName, wstring &fileExtension)
static BOOL isAlpha(wchar_t ch)
static BOOL isDigit(wchar_t ch)
static BOOL getExeName(wstring &filePath, BOOL returnFileNameOnly)
wstring _key
Definition Common.h:203
KeyValue(const wstring &key, const wstring &value)
Definition Common.h:198
wstring _value
Definition Common.h:204
Definition Common.h:208
__int64 _value4
Definition Common.h:213
__int64 _value5
Definition Common.h:214
__int64 _value3
Definition Common.h:212
__int64 _value1
Definition Common.h:210
__int64 _value6
Definition Common.h:215
__int64 _value9
Definition Common.h:218
__int64 _value7
Definition Common.h:216
__int64 _value10
Definition Common.h:219
__int64 _value8
Definition Common.h:217
__int64 _value2
Definition Common.h:211