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 l, long t, long r, long b)
33 {
34 left = l;
35 top = t;
36 right = r;
37 bottom = b;
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
160
161enum class ButtonType {
164 INFO = 3,
167 WARN = 6,
168 GRAY = 7,
170 BLUE = 9,
172 TEAL = 11,
173 CYAN = 12,
174 PINK = 13,
175 INDIGO = 14,
176 ORANGE = 15,
177 BROWN = 16,
178 SILVER = 17,
179 RED = 18,
180 WINDOW = 19,
182};
183
184enum class ChartType {
185 BAR = 1,
186 PIE = 2,
187 DONUT = 3,
188 AREA = 4,
189 LINE = 5,
191 RADAR = 7,
194};
195
197{
198public:
199
200 KeyValue(const wstring& key, const wstring& value)
201 {
202 _key = key;
203 _value = value;
204 }
205 wstring _key;
206 wstring _value;
207};
208
210{
211public:
212 __int64 _value1;
213 __int64 _value2;
214 __int64 _value3;
215 __int64 _value4;
216 __int64 _value5;
217 __int64 _value6;
218 __int64 _value7;
219 __int64 _value8;
220 __int64 _value9;
221 __int64 _value10;
222};
223
225{
226public:
227
228 static wstring strToWStr(const char* input);
229 static string wStrToStr(const wchar_t* input);
230
231 static RECT SRectToRECT(const Bounds& rect);
232
233public:
234
235 static BOOL getExeName(wstring& filePath, BOOL returnFileNameOnly);
236 static BOOL getExeFolder(wstring& exeDir);
237
238public:
239
240 static BOOL copyFile(const wstring& srcFilePath, const wstring& destFilePath, BOOL failIfExists = TRUE, BOOL createDirectoryIfNotExists = TRUE);
241 static BOOL getFileSize(const wstring& filePath, DWORD& fileSize);
242 static BOOL getDirFromPath(const wstring& filePath, wstring& directory);
243 static BOOL getPathComponents(const wstring& filePath, wstring& directory, wstring& fileName, wstring& fileExtension);
244 static BOOL createDirectory(const wstring& directory);
245
246 static BOOL readFile(FILE* fp, void* buffer, size_t size, DWORD atOffset);
247 static BOOL writeFile(FILE* fp, void* buffer, size_t size, DWORD atOffset);
248
249public:
250
251 static BOOL createShortcut(const wchar_t* targetPath);
252
253 static BOOL addRegistryEntry(const wchar_t* valueName, const wchar_t* valueData, const wchar_t* subKeyPath, HKEY hSection = HKEY_CURRENT_USER);
254 static BOOL executeSystemCommand(const wchar_t* command, const wchar_t* parameters, const wchar_t* workingDirectory, BOOL waitForCompletion = FALSE);
255
256public:
257
258 static BOOL isDigit(wchar_t ch);
259 static BOOL isAlpha(wchar_t ch);
260 static BOOL isDigitOrAlpha(wchar_t ch);
261
262 static wstring systemTimeToStrYYYYMMDD(const SYSTEMTIME& sysTime);
263 static SYSTEMTIME strYYYYMMDDToSystemTime(const wstring& strYYYYMMDD);
264};
265
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:184
@ RADAR
Definition Common.h:191
@ LINE
Definition Common.h:189
@ SCATTER
Definition Common.h:192
@ DONUT
Definition Common.h:187
@ BAR
Definition Common.h:185
@ AREA
Definition Common.h:188
@ HEATMAP
Definition Common.h:193
@ PIE
Definition Common.h:186
@ FUNNEL
Definition Common.h:190
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
@ BUTTON
Definition Common.h:158
@ 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
@ ACTIONICON
Definition Common.h:157
ButtonType
Definition Common.h:161
@ LIGHTGRAY
Definition Common.h:169
@ SILVER
Definition Common.h:178
@ BLUE
Definition Common.h:170
@ PINK
Definition Common.h:174
@ WARN
Definition Common.h:167
@ CYAN
Definition Common.h:173
@ PRIMARY
Definition Common.h:163
@ GRAY
Definition Common.h:168
@ BROWN
Definition Common.h:177
@ INFO
Definition Common.h:164
@ DEFAULT
Definition Common.h:162
@ ORANGE
Definition Common.h:176
@ DANGER
Definition Common.h:165
@ WINDOW
Definition Common.h:180
@ CUSTOM
Definition Common.h:181
@ TEAL
Definition Common.h:172
@ LIGHTBLUE
Definition Common.h:171
@ RED
Definition Common.h:179
@ SUCCESS
Definition Common.h:166
@ INDIGO
Definition Common.h:175
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 l, long t, long r, long b)
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:225
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:205
KeyValue(const wstring &key, const wstring &value)
Definition Common.h:200
wstring _value
Definition Common.h:206
Definition Common.h:210
__int64 _value4
Definition Common.h:215
__int64 _value5
Definition Common.h:216
__int64 _value3
Definition Common.h:214
__int64 _value1
Definition Common.h:212
__int64 _value6
Definition Common.h:217
__int64 _value9
Definition Common.h:220
__int64 _value7
Definition Common.h:218
__int64 _value10
Definition Common.h:221
__int64 _value8
Definition Common.h:219
__int64 _value2
Definition Common.h:213