WinStd
Windows Win32 API using Standard C++
Loading...
Searching...
No Matches
GDI.h
1/*
2 ​SPDX-License-Identifier: MIT
3 Copyright © 1991-2024 Amebis
4*/
5
7
8#pragma once
9
10#include "Common.h"
11
12namespace winstd
13{
16
20 template<class T>
21 class gdi_handle : public handle<T, NULL>
22 {
24
25 public:
31 virtual ~gdi_handle()
32 {
33 if (m_h != invalid)
35 }
36
37 protected:
43 void free_internal() noexcept override
44 {
45 DeleteObject(m_h);
46 }
47 };
48
52 class icon : public handle<HICON, NULL>
53 {
54 WINSTD_HANDLE_IMPL(icon, HICON, NULL)
55
56 public:
62 virtual ~icon()
63 {
64 if (m_h != invalid)
66 }
67
68 protected:
74 void free_internal() noexcept override
75 {
76 DestroyIcon(m_h);
77 }
78 };
79
83 class dc : public handle<HDC, NULL>
84 {
85 WINSTD_HANDLE_IMPL(dc, HDC, NULL)
86
87 public:
93 virtual ~dc()
94 {
95 if (m_h != invalid)
97 }
98
99 protected:
105 void free_internal() noexcept override
106 {
107 DeleteDC(m_h);
108 }
109 };
110
114 class window_dc : public handle<HDC, NULL>
115 {
116 public:
120 window_dc() noexcept :
121 m_hwnd(NULL)
122 {}
123
127 window_dc(_In_opt_ handle_type h, _In_opt_ HWND hwnd) noexcept :
129 m_hwnd(hwnd)
130 {}
131
135 window_dc(_Inout_ window_dc &&h) noexcept :
136 handle<handle_type, NULL>(std::move(h)),
137 m_hwnd(h.m_hwnd)
138 {}
139
143 window_dc& operator=(_Inout_ window_dc &&h) noexcept
144 {
146 m_hwnd = h.m_hwnd;
147 return *this;
148 }
149
151
152 public:
158 virtual ~window_dc()
159 {
160 if (m_h != invalid)
162 }
163
164 protected:
170 void free_internal() noexcept override
171 {
172 ReleaseDC(m_hwnd, m_h);
173 }
174
175 protected:
176 HWND m_hwnd;
177 };
178
183 {
186
187 public:
193 dc_selector(_In_ HDC hdc, _In_ HGDIOBJ h) noexcept :
194 m_hdc(hdc),
195 m_orig(SelectObject(hdc, h))
196 {}
197
203 virtual ~dc_selector()
204 {
205 if (m_orig)
206 SelectObject(m_hdc, m_orig);
207 }
208
214 HGDIOBJ status() const noexcept
215 {
216 return m_orig;
217 }
218
219 protected:
220 HDC m_hdc;
221 HGDIOBJ m_orig;
222 };
223
225}
Context scope DC object restorer.
Definition GDI.h:183
dc_selector(HDC hdc, HGDIOBJ h) noexcept
Selects an object into the specified device context (DC). The new object replaces the previous object...
Definition GDI.h:193
virtual ~dc_selector()
Restores original object.
Definition GDI.h:203
HGDIOBJ m_orig
Original object handle.
Definition GDI.h:221
HGDIOBJ status() const noexcept
Return result of SelectObject() call.
Definition GDI.h:214
HDC m_hdc
A handle to the device context.
Definition GDI.h:220
Device context wrapper class.
Definition GDI.h:84
void free_internal() noexcept override
Deletes the specified device context (DC).
Definition GDI.h:105
virtual ~dc()
Deletes the specified device context (DC).
Definition GDI.h:93
Windows HGDIOBJ wrapper class.
Definition GDI.h:22
void free_internal() noexcept override
Closes an open object handle.
Definition GDI.h:43
virtual ~gdi_handle()
Closes an open object handle.
Definition GDI.h:31
Base abstract template class to support generic object handle keeping.
Definition Common.h:1024
handle() noexcept
Definition Common.h:1039
handle_type m_h
Definition Common.h:1276
HDC handle_type
Definition Common.h:1029
Windows HICON wrapper class.
Definition GDI.h:53
void free_internal() noexcept override
Closes an open object handle.
Definition GDI.h:74
virtual ~icon()
Closes an open object handle.
Definition GDI.h:62
Device context wrapper class.
Definition GDI.h:115
HWND m_hwnd
Window handle.
Definition GDI.h:176
window_dc(handle_type h, HWND hwnd) noexcept
Initializes a device context from existing data.
Definition GDI.h:127
void free_internal() noexcept override
Releases a device context (DC), freeing it for use by other applications.
Definition GDI.h:170
virtual ~window_dc()
Releases a device context (DC), freeing it for use by other applications.
Definition GDI.h:158
window_dc() noexcept
Initializes an empty device context.
Definition GDI.h:120
window_dc & operator=(window_dc &&h) noexcept
Copy an existing device context.
Definition GDI.h:143
window_dc(window_dc &&h) noexcept
Move an existing device context.
Definition GDI.h:135
#define WINSTD_NONCOPYABLE(C)
Declares a class as non-copyable.
Definition Common.h:67
#define WINSTD_NONMOVABLE(C)
Declares a class as non-movable.
Definition Common.h:75
#define WINSTD_HANDLE_IMPL(C, T, INVAL)
Implements default constructors and operators to prevent their auto-generation by compiler.
Definition Common.h:164
static const T invalid
Definition Common.h:1034