# WinStd: include/WinStd/GDI.h Source File

Loading...
Searching...
No Matches
GDI.h
/*
​SPDX-License-Identifier: MIT
Copyright © 1991-2024 Amebis
*/
#pragma once
#include "Common.h"
namespace winstd
{
template<class T>
class gdi_handle : public handle<T, NULL>
{
WINSTD_HANDLE_IMPL(gdi_handle, T, NULL)
public:
virtual ~gdi_handle()
{
if (m_h != invalid)
free_internal();
}
protected:
void free_internal() noexcept override
{
DeleteObject(m_h);
}
};
class icon : public handle<HICON, NULL>
{
WINSTD_HANDLE_IMPL(icon, HICON, NULL)
public:
virtual ~icon()
{
if (m_h != invalid)
free_internal();
}
protected:
void free_internal() noexcept override
{
DestroyIcon(m_h);
}
};
class dc : public handle<HDC, NULL>
{
WINSTD_HANDLE_IMPL(dc, HDC, NULL)
public:
virtual ~dc()
{
if (m_h != invalid)
free_internal();
}
protected:
void free_internal() noexcept override
{
DeleteDC(m_h);
}
};
class window_dc : public handle<HDC, NULL>
{
public:
window_dc() noexcept :
m_hwnd(NULL)
{}
window_dc(_In_opt_ handle_type h, _In_opt_ HWND hwnd) noexcept :
handle<handle_type, NULL>(h),
m_hwnd(hwnd)
{}
window_dc(_Inout_ window_dc &&h) noexcept :
handle<handle_type, NULL>(std::move(h)),
m_hwnd(h.m_hwnd)
{}
window_dc& operator=(_Inout_ window_dc &&h) noexcept
{
handle<handle_type, NULL>::operator=(std::move(h));
m_hwnd = h.m_hwnd;
return *this;
}
WINSTD_NONCOPYABLE(window_dc)
public:
virtual ~window_dc()
{
if (m_h != invalid)
free_internal();
}
protected:
void free_internal() noexcept override
{
ReleaseDC(m_hwnd, m_h);
}
protected:
HWND m_hwnd;
};
class dc_selector
{
WINSTD_NONCOPYABLE(dc_selector)
WINSTD_NONMOVABLE(dc_selector)
public:
dc_selector(_In_ HDC hdc, _In_ HGDIOBJ h) noexcept :
m_hdc(hdc),
m_orig(SelectObject(hdc, h))
{}
virtual ~dc_selector()
{
if (m_orig)
SelectObject(m_hdc, m_orig);
}
HGDIOBJ status() const noexcept
{
return m_orig;
}
protected:
HDC m_hdc;
HGDIOBJ m_orig;
};
}
winstd::dc_selector
Context scope DC object restorer.
Definition GDI.h:183
winstd::dc_selector::dc_selector
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
winstd::dc_selector::~dc_selector
virtual ~dc_selector()
Restores original object.
Definition GDI.h:203
winstd::dc_selector::m_orig
HGDIOBJ m_orig
Original object handle.
Definition GDI.h:221
winstd::dc_selector::status
HGDIOBJ status() const noexcept
Return result of SelectObject() call.
Definition GDI.h:214
winstd::dc_selector::m_hdc
HDC m_hdc
A handle to the device context.
Definition GDI.h:220
winstd::dc
Device context wrapper class.
Definition GDI.h:84
winstd::dc::free_internal
void free_internal() noexcept override
Deletes the specified device context (DC).
Definition GDI.h:105
winstd::dc::~dc
virtual ~dc()
Deletes the specified device context (DC).
Definition GDI.h:93
winstd::gdi_handle
Windows HGDIOBJ wrapper class.
Definition GDI.h:22
winstd::gdi_handle::free_internal
void free_internal() noexcept override
Closes an open object handle.
Definition GDI.h:43
winstd::gdi_handle::~gdi_handle
virtual ~gdi_handle()
Closes an open object handle.
Definition GDI.h:31
winstd::handle
Base abstract template class to support generic object handle keeping.
Definition Common.h:874
winstd::handle< HDC, NULL >::handle
handle() noexcept
Definition Common.h:889
winstd::handle< T, NULL >::m_h
handle_type m_h
Definition Common.h:1126
winstd::handle< HDC, NULL >::handle_type
HDC handle_type
Definition Common.h:879
winstd::icon
Windows HICON wrapper class.
Definition GDI.h:53
winstd::icon::free_internal
void free_internal() noexcept override
Closes an open object handle.
Definition GDI.h:74
winstd::icon::~icon
virtual ~icon()
Closes an open object handle.
Definition GDI.h:62
winstd::window_dc
Device context wrapper class.
Definition GDI.h:115
winstd::window_dc::m_hwnd
HWND m_hwnd
Window handle.
Definition GDI.h:176
winstd::window_dc::window_dc
window_dc(handle_type h, HWND hwnd) noexcept
Initializes a device context from existing data.
Definition GDI.h:127
winstd::window_dc::free_internal
void free_internal() noexcept override
Releases a device context (DC), freeing it for use by other applications.
Definition GDI.h:170
winstd::window_dc::~window_dc
virtual ~window_dc()
Releases a device context (DC), freeing it for use by other applications.
Definition GDI.h:158
winstd::window_dc::window_dc
window_dc() noexcept
Initializes an empty device context.
Definition GDI.h:120
winstd::window_dc::operator=
window_dc & operator=(window_dc &&h) noexcept
Copy an existing device context.
Definition GDI.h:143
winstd::window_dc::window_dc
window_dc(window_dc &&h) noexcept
Move an existing device context.
Definition GDI.h:135
WINSTD_NONCOPYABLE
#define WINSTD_NONCOPYABLE(C)
Declares a class as non-copyable.
Definition Common.h:67
WINSTD_NONMOVABLE
#define WINSTD_NONMOVABLE(C)
Declares a class as non-movable.
Definition Common.h:75
WINSTD_HANDLE_IMPL
#define WINSTD_HANDLE_IMPL(C, T, INVAL)
Implements default constructors and operators to prevent their auto-generation by compiler.
Definition Common.h:164
winstd::handle< T, NULL >::invalid
static const T invalid
Definition Common.h:884