Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
WinTypes.h
Go to the documentation of this file.
1 //
4 //
5 
6 #ifndef _INC_WinTypes_H
7 #define _INC_WinTypes_H
8 #ifndef NO_PRAGMA_ONCE
9 #pragma once
10 #endif
11 
12 #include "../GrayLibBase.h"
14 #include "GrayCore/include/StrT.h"
15 #include "GrayCore/include/cMem.h"
16 #include "GrayCore/include/cOSProcess.h" // WINHANDLE_NULL
17 
18 #ifdef __linux__
19 
20 // Linux doesn't define this stuff. just dummy this for prototypes.
21 typedef void* HWND; // dummy this
22 typedef void* HDC;
23 typedef void* HBITMAP;
24 typedef void* HRGN;
25 typedef void* HCURSOR;
26 
27 typedef INT_PTR LRESULT;
28 typedef LONG LPARAM;
29 typedef LONG WPARAM;
30 typedef const char* ATOM; // WORD in _WIN32
31 typedef char CHAR;
32 
33 enum WINMSG_t
34 {
37 #define WINMSGDEF(a,b,c) WM_##a = b,
38 #include "WinMsgs.tbl"
39 #undef WINMSGDEF
40 };
41 
42 // Define the basic Windows style geometric structs.
43 
44 typedef struct tagSIZE
45 {
46  LONG cx;
47  LONG cy;
48 } SIZE;
49 
50 typedef struct tagPOINT
51 {
52  LONG x;
53  LONG y;
54 } POINT;
55 
56 typedef struct tagPOINTS
57 {
58  short x;
59  short y;
60 } POINTS;
61 
62 typedef struct tagRECT
63 {
64  LONG left;
65  LONG top;
66  LONG right;
67  LONG bottom;
68 } RECT;
69 
70 typedef struct tagMSG
71 {
72  HWND hwnd;
73  UINT message;
74  WPARAM wParam;
75  LPARAM lParam;
76  DWORD time;
77  POINT pt;
78 #ifdef _MAC
79  DWORD lPrivate;
80 #endif
81 } MSG;
82 
83 #define LF_FACESIZE 32
84 typedef struct tagLOGFONTA
85 {
86  LONG lfHeight;
87  LONG lfWidth;
88  LONG lfEscapement;
89  LONG lfOrientation;
90  LONG lfWeight;
91  BYTE lfItalic;
92  BYTE lfUnderline;
93  BYTE lfStrikeOut;
94  BYTE lfCharSet;
95  BYTE lfOutPrecision;
96  BYTE lfClipPrecision;
97  BYTE lfQuality;
98  BYTE lfPitchAndFamily;
99  CHAR lfFaceName[LF_FACESIZE];
100 } LOGFONTA;
101 // typedef LOGFONTA LOGFONT;
102 
103 struct WINDOWPLACEMENT
104 {
105 };
106 
107 #else // _WIN32
108 
110 
111 typedef UINT WINMSG_t;
112 
114 #ifndef WM_NULL
115 #define WM_NULL 0 // WINMSG_t
116 #endif
117 #ifndef WM_MOUSEWHEEL
118 #define WM_MOUSEWHEEL 0x020A
119 #endif
120 
121 #endif // _WIN32
122 
123 #define MF_GREYED 1
124 
125 namespace GrayLib
126 {
127  class cWinSize : public SIZE
128  {
132 
133  public:
134  cWinSize(LONG _cx = 0, LONG _cy = 0) noexcept
135  {
136  this->cx = _cx;
137  this->cy = _cy;
138  }
139  cWinSize(const SIZE& rsize) noexcept
140  {
141  *static_cast<SIZE*>(this) = rsize;
142  }
143  bool operator == (const SIZE& rsize) const noexcept
144  {
145  return(rsize.cx == this->cx && rsize.cy == this->cy);
146  }
147  bool PtInRect(int x, int y) const noexcept
148  {
149  if (x < 0 || x >= this->cx)
150  return false;
151  if (y < 0 || y >= this->cy)
152  return false;
153  return true;
154  }
155  bool isZero() const noexcept
156  {
157  return(cx == 0 && cy == 0);
158  }
159  void SetZero() noexcept
160  {
161  cx = 0; cy = 0;
162  }
163  float get_AspectRatio() const noexcept;
164  void SetMaxAspect(int maxx, int maxy);
165  };
166 
167  class cWinFontCfg : public _GTN(LOGFONT)
168  {
172 
173  typedef _GTN(LOGFONT) SUPER_t;
174 
175  public:
176  cWinFontCfg() noexcept
177  {
178  InitZero();
179  }
180  cWinFontCfg(const SUPER_t& fontcfg) noexcept
181  {
182  ref_LogFont() = fontcfg;
183  }
184  SUPER_t& ref_LogFont() noexcept
185  {
186  return *static_cast<SUPER_t*>(this);
187  }
188  const SUPER_t& ref_LogFont() const noexcept
189  {
190  return *static_cast<const SUPER_t*>(this);
191  }
192  void InitZero() noexcept
193  {
194  cMem::Zero(static_cast<SUPER_t*>(this), sizeof(SUPER_t));
195  }
196  StrLen_t put_FaceName(const GChar_t* pszFaceName) noexcept
197  {
198  // ASSUME LF_FACESIZE MAX
199  return StrT::CopyLen<GChar_t>(this->lfFaceName, pszFaceName, _countof(this->lfFaceName));
200  }
201  bool IsSameFont(const SUPER_t& rFont) const noexcept
202  {
203  return !::memcmp(static_cast<const SUPER_t*>(this), &rFont, sizeof(SUPER_t));
204  }
205  int get_FontSize() const noexcept
206  {
208  return this->lfHeight;
209  }
210  int get_FontSizeA() const noexcept
211  {
214  if (this->lfHeight == 0) // use default.
215  {
216  return 10;
217  }
218  return ABS(this->lfHeight);
219  }
220  int get_FontWidthA() const noexcept
221  {
223  if (this->lfWidth == 0) // use default.
224  {
225  return 10;
226  }
227  return ABS(this->lfWidth);
228  }
229  };
230 
231  class cWindowPlacement : public ::WINDOWPLACEMENT
232  {
237 
238  typedef ::WINDOWPLACEMENT SUPER_t;
239 
240  public:
241  cWindowPlacement() noexcept
242  {
243  cMem::Zero(static_cast<SUPER_t*>(this), sizeof(SUPER_t));
244  // this->length = 0;
245  this->ptMinPosition.x = -1; // pick some random position.
246  this->ptMinPosition.y = -1;
247  this->ptMaxPosition.x = -1;
248  this->ptMaxPosition.y = -1;
249  }
250 
251 #ifdef _WIN32
252  cWindowPlacement(HWND hWnd)
253  {
254  UpdatePlacement(hWnd);
255  }
256  bool UpdatePlacement(HWND hWnd)
257  {
258  return ::GetWindowPlacement(hWnd, static_cast<SUPER_t*>(this));
259  }
260 #endif
261 
262  void InitPlacement() noexcept
263  {
264  // Make this valid and empty.
265  this->length = sizeof(SUPER_t);
266  }
267  bool isInitPlacement() const noexcept
268  {
270  return this->length == sizeof(SUPER_t);
271  }
272  SHOWWINDOW_t get_ShowWindowwMode() const noexcept
273  {
274  return (SHOWWINDOW_t)(this->showCmd);
275  }
276  bool isShowIconic() const noexcept
277  {
278  return (get_ShowWindowwMode() == SW_SHOWMINIMIZED || get_ShowWindowwMode() == SW_SHOWMINNOACTIVE);
279  }
280 
281  const RECT& get_NormalRect() const noexcept
282  {
284  return this->rcNormalPosition;
285  }
286  };
287 
288 #if defined(_DEBUG) && defined(_WIN32)
289  GRAYLIB_LINK StrLen_t GRAYCALL MakeWinMsgStr(char* pszOut, StrLen_t nCharsMax, WINMSG_t uMsg, WPARAM wParam, LPARAM lParam);
290 #endif
291 }
292 
293 #endif // WinTypes
#define GRAYCALL
declare calling convention for static functions so everyone knows the arg passing scheme....
Definition: GrayCore.h:36
#define GRAYLIB_LINK
Definition: GrayLibBase.h:35
#define _GTN(c)
_WIN32 name has a A or W for UTF8 or UNICODE (like _FNF)
Definition: StrConst.h:28
#define ABS(n)
Definition: SysTypes.h:460
UINT WINMSG_t
Supplement _WIN32 "windows.h".
Definition: WinTypes.h:111
#define _countof(a)
Definition: cKernel.h:35
Definition: WinTypes.h:168
bool IsSameFont(const SUPER_t &rFont) const noexcept
Definition: WinTypes.h:201
int get_FontSize() const noexcept
Definition: WinTypes.h:205
SUPER_t & ref_LogFont() noexcept
Definition: WinTypes.h:184
const SUPER_t & ref_LogFont() const noexcept
Definition: WinTypes.h:188
cWinFontCfg() noexcept
Definition: WinTypes.h:176
cWinFontCfg(const SUPER_t &fontcfg) noexcept
Definition: WinTypes.h:180
void InitZero() noexcept
Definition: WinTypes.h:192
int get_FontWidthA() const noexcept
Definition: WinTypes.h:220
int get_FontSizeA() const noexcept
Definition: WinTypes.h:210
StrLen_t put_FaceName(const GChar_t *pszFaceName) noexcept
Definition: WinTypes.h:196
Definition: WinTypes.h:128
float get_AspectRatio() const noexcept
Definition: WinTypes.cpp:12
cWinSize(LONG _cx=0, LONG _cy=0) noexcept
Definition: WinTypes.h:134
void SetMaxAspect(int maxx, int maxy)
Definition: WinTypes.cpp:19
cWinSize(const SIZE &rsize) noexcept
Definition: WinTypes.h:139
bool isZero() const noexcept
Definition: WinTypes.h:155
void SetZero() noexcept
Definition: WinTypes.h:159
bool operator==(const SIZE &rsize) const noexcept
Definition: WinTypes.h:143
bool PtInRect(int x, int y) const noexcept
Definition: WinTypes.h:147
Definition: WinTypes.h:232
SHOWWINDOW_t get_ShowWindowwMode() const noexcept
Definition: WinTypes.h:272
void InitPlacement() noexcept
Definition: WinTypes.h:262
const RECT & get_NormalRect() const noexcept
Definition: WinTypes.h:281
bool isShowIconic() const noexcept
Definition: WinTypes.h:276
bool isInitPlacement() const noexcept
Definition: WinTypes.h:267
cWindowPlacement() noexcept
Definition: WinTypes.h:241
Definition: cMesh.h:22
int StrLen_t
the length of a string in chars (bytes for UTF8, wchar_t for UNICODE). or offset in characters....
Definition: StrConst.h:32
char GChar_t
My version of TCHAR, _TCHAR.
Definition: StrConst.h:26
static void Zero(void *pData, size_t nSizeBlock) noexcept
Definition: cMem.h:100