Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
cWindow.h
Go to the documentation of this file.
1 //
6 
7 #ifndef _INC_cWindow_H
8 #define _INC_cWindow_H
9 #ifndef NO_PRAGMA_ONCE
10 #pragma once
11 #endif
12 
13 #include "cWndHandle.h"
14 #include "../WinAPI/cWinAtom.h"
16 
17 namespace GrayLib
18 {
20 
21 #ifdef _WIN32
22 
23  class GRAYLIB_LINK cWinMsg
24  {
28 
29  public:
30  WINMSG_t m_uMsg;
31  WPARAM m_wParam;
32  LPARAM m_lParam;
33 
34  public:
35  cWinMsg(WINMSG_t uMsg, WPARAM wParam = 0, LPARAM lParam = 0) noexcept
36  : m_uMsg(uMsg), m_wParam(wParam), m_lParam(lParam)
37  {
38  }
39  cWinMsg(WINMSG_t uMsg, WPARAM wParam, const void* lParam) noexcept
40  : m_uMsg(uMsg), m_wParam(wParam), m_lParam((LPARAM)lParam)
41  {
42  }
43  cWinMsg(WINMSG_t uMsg, WPARAM wParam, WPARAM a, WPARAM b) noexcept
44  : m_uMsg(uMsg), m_wParam(wParam), m_lParam(MAKELPARAM(a, b))
45  {
46  }
47 
48  // Parse helpers.
49  POINT get_Point() const noexcept
50  {
51  // ASSERT(m_uMsg==sdf); // Only these type messages.
52  POINT pt;
53  pt.x = 0; // TODO !!!!!!!!!????
54  pt.y = 0;
55  return pt;
56  }
57  };
58 
59  class GRAYLIB_LINK cWinClassHandle : public cWinAtomH
60  {
64  public:
65  cWinClassHandle(ATOM a = INVALID_ATOM) noexcept
66  : cWinAtomH(a)
67  {
68  }
69  bool GetInfo(HINSTANCE hInstance, _GTN(WNDCLASS)* pWC) const
70  {
71  return _GTN(::GetClassInfo)(hInstance, get_IntAtom(), pWC);
72  }
73 #ifndef UNDER_CE
74  bool GetInfoEx(HINSTANCE hInstance, _GTN(WNDCLASSEX)* pWC) const
75  {
76  return _GTN(::GetClassInfoEx)(hInstance, get_IntAtom(), pWC);
77  }
78 #endif
79  bool Unregister(HINSTANCE hInstance)
80  {
81  return _GTN(::UnregisterClass)(get_IntAtom(), hInstance);
82  }
83  };
84 
85 #endif
86 
88  {
93 
94  typedef cWndHandle SUPER_t;
95 
96  public:
97  static const GChar_t* const k_pszClassNameDefault;
98 
99 #ifdef _WIN32
100  private:
101  static cWinClassHandle sm_aClassNameDefault;
102 #endif
103 
104  public:
105  cWindow(HWND hWnd = WINHANDLE_NULL) noexcept
106  : cWndHandle(hWnd)
107  {
108  }
109 
110 #ifdef _WIN32
111  virtual ~cWindow()
112  {
114  DestroyWindow();
115  }
116  bool AttachHwnd(HWND hWnd)
117  {
118  if (hWnd == get_Hwnd())
119  return true;
120  DestroyWindow();
121  return SUPER_t::AttachHwnd(hWnd);
122  }
123 
124  static LRESULT WINAPI WndProc(HWND hWnd, WINMSG_t message, WPARAM wParam, LPARAM lParam);
125  virtual LRESULT WindowProc(WINMSG_t message, WPARAM wParam, LPARAM lParam);
126 
127  static ATOM GRAYCALL RegisterClassX(_GTN(WNDCLASS)* pWC);
128  static ATOM GRAYCALL RegisterClassX(const GChar_t* pszClassName, UINT uStyleFlags = CS_DBLCLKS, HICON hIcon = WINHANDLE_NULL, HBRUSH hBrushBack = (HBRUSH)(COLOR_WINDOW + 1));
129  static bool GRAYCALL RegisterClassNameDefault();
130 
131 #if defined(UNDER_CE)
132  static const DWORD k_nStyleDef = WS_VISIBLE;
133 #else
134  static const DWORD k_nStyleDef = WS_OVERLAPPEDWINDOW | WS_VISIBLE;
135 #endif
136  bool CreateWindowDef(const GChar_t* pszTitle = nullptr, DWORD dwStyle = k_nStyleDef, int x = CW_USEDEFAULT, int y = CW_USEDEFAULT, int cx = CW_USEDEFAULT, int cy = CW_USEDEFAULT, HWND hWndParent = WINHANDLE_NULL, HMENU hMenuOrChildId = WINHANDLE_NULL);
137 
138  UNITTEST2_PREDEF(cWindow);
139 #endif
140  };
141 
142 }
143 
144 #endif // _INC_cWindow_H
#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
UINT WINMSG_t
Supplement _WIN32 "windows.h".
Definition: WinTypes.h:111
#define WINHANDLE_NULL
HWND, HPEN, etc are NOT OS Handles. like HWND_DESKTOP. like HANDLEPTR_NULL. This is a WINAPI void* ha...
Definition: cOSHandle.h:23
Definition: cWindow.h:88
static const GChar_t *const k_pszClassNameDefault
Definition: cWindow.h:97
cWindow(HWND hWnd=WINHANDLE_NULL) noexcept
Definition: cWindow.h:105
Definition: cWndHandle.h:26
Definition: cMesh.h:22
UNITTEST2_PREDEF(cQuadtree)
char GChar_t
My version of TCHAR, _TCHAR.
Definition: StrConst.h:26