Introduce basic support for Windows GDI resources
Signed-off-by: Simon Rozman <simon@rozman.si>
This commit is contained in:
parent
51b262b382
commit
b8816476e5
@ -47,6 +47,9 @@
|
|||||||
<ClCompile Include="..\src\WinSock2.cpp">
|
<ClCompile Include="..\src\WinSock2.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\src\GDI.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="..\src\PCH.h">
|
<ClInclude Include="..\src\PCH.h">
|
||||||
@ -100,5 +103,8 @@
|
|||||||
<ClInclude Include="..\include\WinStd\WinSock2.h">
|
<ClInclude Include="..\include\WinStd\WinSock2.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\include\WinStd\GDI.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
@ -47,6 +47,9 @@
|
|||||||
<ClCompile Include="..\src\WinSock2.cpp">
|
<ClCompile Include="..\src\WinSock2.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\src\GDI.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="..\src\PCH.h">
|
<ClInclude Include="..\src\PCH.h">
|
||||||
@ -100,5 +103,8 @@
|
|||||||
<ClInclude Include="..\include\WinStd\WinSock2.h">
|
<ClInclude Include="..\include\WinStd\WinSock2.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\include\WinStd\GDI.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
@ -26,6 +26,7 @@
|
|||||||
<ClCompile Include="..\src\Crypt.cpp" />
|
<ClCompile Include="..\src\Crypt.cpp" />
|
||||||
<ClCompile Include="..\src\EAP.cpp" />
|
<ClCompile Include="..\src\EAP.cpp" />
|
||||||
<ClCompile Include="..\src\ETW.cpp" />
|
<ClCompile Include="..\src\ETW.cpp" />
|
||||||
|
<ClCompile Include="..\src\GDI.cpp" />
|
||||||
<ClCompile Include="..\src\Sec.cpp" />
|
<ClCompile Include="..\src\Sec.cpp" />
|
||||||
<ClCompile Include="..\src\SetupAPI.cpp" />
|
<ClCompile Include="..\src\SetupAPI.cpp" />
|
||||||
<ClCompile Include="..\src\PCH.cpp">
|
<ClCompile Include="..\src\PCH.cpp">
|
||||||
@ -39,11 +40,12 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="..\include\WinStd\Base64.h" />
|
<ClInclude Include="..\include\WinStd\Base64.h" />
|
||||||
<ClInclude Include="..\include\WinStd\COM.h" />
|
<ClInclude Include="..\include\WinStd\COM.h" />
|
||||||
|
<ClInclude Include="..\include\WinStd\Common.h" />
|
||||||
<ClInclude Include="..\include\WinStd\Cred.h" />
|
<ClInclude Include="..\include\WinStd\Cred.h" />
|
||||||
<ClInclude Include="..\include\WinStd\Crypt.h" />
|
<ClInclude Include="..\include\WinStd\Crypt.h" />
|
||||||
<ClInclude Include="..\include\WinStd\EAP.h" />
|
<ClInclude Include="..\include\WinStd\EAP.h" />
|
||||||
<ClInclude Include="..\include\WinStd\Common.h" />
|
|
||||||
<ClInclude Include="..\include\WinStd\ETW.h" />
|
<ClInclude Include="..\include\WinStd\ETW.h" />
|
||||||
|
<ClInclude Include="..\include\WinStd\GDI.h" />
|
||||||
<ClInclude Include="..\include\WinStd\Hex.h" />
|
<ClInclude Include="..\include\WinStd\Hex.h" />
|
||||||
<ClInclude Include="..\include\WinStd\MSI.h" />
|
<ClInclude Include="..\include\WinStd\MSI.h" />
|
||||||
<ClInclude Include="..\include\WinStd\Sec.h" />
|
<ClInclude Include="..\include\WinStd\Sec.h" />
|
||||||
|
199
include/WinStd/GDI.h
Normal file
199
include/WinStd/GDI.h
Normal file
@ -0,0 +1,199 @@
|
|||||||
|
/*
|
||||||
|
Copyright © 1991-2021 Amebis
|
||||||
|
|
||||||
|
This file is part of WinStd.
|
||||||
|
|
||||||
|
Setup is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
Setup is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with Setup. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
///
|
||||||
|
/// \defgroup WinStdGdiAPI GDI API
|
||||||
|
/// Integrates WinStd classes with Microsoft Windows GDI
|
||||||
|
///
|
||||||
|
|
||||||
|
#include "Common.h"
|
||||||
|
|
||||||
|
#include <Windows.h>
|
||||||
|
|
||||||
|
namespace winstd
|
||||||
|
{
|
||||||
|
template<class T> class gdi_handle;
|
||||||
|
class dc;
|
||||||
|
class window_dc;
|
||||||
|
class dc_selector;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
|
||||||
|
namespace winstd
|
||||||
|
{
|
||||||
|
/// \addtogroup WinStdGdiAPI
|
||||||
|
/// @{
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Windows HGDIOBJ wrapper class
|
||||||
|
///
|
||||||
|
template<class T>
|
||||||
|
class gdi_handle : public handle<T, NULL>
|
||||||
|
{
|
||||||
|
HANDLE_IMPL(gdi_handle, NULL)
|
||||||
|
|
||||||
|
public:
|
||||||
|
///
|
||||||
|
/// Closes an open object handle.
|
||||||
|
///
|
||||||
|
/// \sa [DeleteObject function](https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-deleteobject)
|
||||||
|
///
|
||||||
|
virtual ~gdi_handle()
|
||||||
|
{
|
||||||
|
if (m_h != invalid)
|
||||||
|
DeleteObject(m_h);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
///
|
||||||
|
/// Closes an open object handle.
|
||||||
|
///
|
||||||
|
/// \sa [DeleteObject function](https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-deleteobject)
|
||||||
|
///
|
||||||
|
void free_internal() noexcept override
|
||||||
|
{
|
||||||
|
DeleteObject(m_h);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Device context wrapper class
|
||||||
|
///
|
||||||
|
class dc : public handle<HDC, NULL>
|
||||||
|
{
|
||||||
|
HANDLE_IMPL(dc, NULL)
|
||||||
|
|
||||||
|
public:
|
||||||
|
///
|
||||||
|
/// Deletes the specified device context (DC).
|
||||||
|
///
|
||||||
|
/// \sa [DeleteDC function](https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-deletedc)
|
||||||
|
///
|
||||||
|
virtual ~dc();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
///
|
||||||
|
/// Deletes the specified device context (DC).
|
||||||
|
///
|
||||||
|
/// \sa [DeleteDC function](https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-deletedc)
|
||||||
|
///
|
||||||
|
void free_internal() noexcept override;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Device context wrapper class
|
||||||
|
///
|
||||||
|
class window_dc : public handle<HDC, NULL>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
inline window_dc() noexcept :
|
||||||
|
m_hwnd(NULL)
|
||||||
|
{}
|
||||||
|
|
||||||
|
inline window_dc(_In_opt_ handle_type h, _In_opt_ HWND hwnd) noexcept :
|
||||||
|
handle<handle_type, NULL>(h),
|
||||||
|
m_hwnd(hwnd)
|
||||||
|
{}
|
||||||
|
|
||||||
|
inline window_dc(_Inout_ window_dc &&h) noexcept :
|
||||||
|
handle<handle_type, NULL>(std::move(h)),
|
||||||
|
m_hwnd(h.m_hwnd)
|
||||||
|
{}
|
||||||
|
|
||||||
|
inline 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:
|
||||||
|
///
|
||||||
|
/// Releases a device context (DC), freeing it for use by other applications.
|
||||||
|
///
|
||||||
|
/// \sa [ReleaseDC function](https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-releasedc)
|
||||||
|
///
|
||||||
|
virtual ~window_dc();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
///
|
||||||
|
/// Releases a device context (DC), freeing it for use by other applications.
|
||||||
|
///
|
||||||
|
/// \sa [ReleaseDC function](https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-releasedc)
|
||||||
|
///
|
||||||
|
void free_internal() noexcept override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
HWND m_hwnd; ///< Window handle
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Context scope DC object restorer
|
||||||
|
///
|
||||||
|
class dc_selector
|
||||||
|
{
|
||||||
|
WINSTD_NONCOPYABLE(dc_selector)
|
||||||
|
WINSTD_NONMOVABLE(dc_selector)
|
||||||
|
|
||||||
|
public:
|
||||||
|
///
|
||||||
|
/// Selects an object into the specified device context (DC). The new object replaces the previous object of the same type.
|
||||||
|
///
|
||||||
|
/// \sa [SelectObject function](https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-selectobject)
|
||||||
|
///
|
||||||
|
inline dc_selector(_In_ HDC hdc, _In_ HGDIOBJ h) noexcept :
|
||||||
|
m_hdc(hdc),
|
||||||
|
m_orig(SelectObject(hdc, h))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Restores original object.
|
||||||
|
///
|
||||||
|
/// \sa [SelectObject function](https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-selectobject)
|
||||||
|
///
|
||||||
|
virtual ~dc_selector();
|
||||||
|
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Return result of `SelectObject()` call.
|
||||||
|
///
|
||||||
|
/// \sa [SelectObject function](https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-selectobject)
|
||||||
|
///
|
||||||
|
inline HGDIOBJ status() const noexcept
|
||||||
|
{
|
||||||
|
return m_orig;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
HDC m_hdc; ///< A handle to the device context
|
||||||
|
HGDIOBJ m_orig; ///< Original object handle
|
||||||
|
};
|
||||||
|
|
||||||
|
/// @}
|
||||||
|
}
|
66
src/GDI.cpp
Normal file
66
src/GDI.cpp
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
/*
|
||||||
|
Copyright © 1991-2021 Amebis
|
||||||
|
Copyright © 2016 GÉANT
|
||||||
|
|
||||||
|
This file is part of WinStd.
|
||||||
|
|
||||||
|
Setup is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
Setup is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with Setup. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "PCH.h"
|
||||||
|
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
// winstd::dc
|
||||||
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
winstd::dc::~dc()
|
||||||
|
{
|
||||||
|
if (m_h != invalid)
|
||||||
|
DeleteDC(m_h);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void winstd::dc::free_internal() noexcept
|
||||||
|
{
|
||||||
|
DeleteDC(m_h);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
// winstd::window_dc
|
||||||
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
winstd::window_dc::~window_dc()
|
||||||
|
{
|
||||||
|
if (m_h != invalid)
|
||||||
|
ReleaseDC(m_hwnd, m_h);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void winstd::window_dc::free_internal() noexcept
|
||||||
|
{
|
||||||
|
ReleaseDC(m_hwnd, m_h);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
// winstd::dc_selector
|
||||||
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
winstd::dc_selector::~dc_selector()
|
||||||
|
{
|
||||||
|
if (m_orig)
|
||||||
|
SelectObject(m_hdc, m_orig);
|
||||||
|
}
|
@ -30,6 +30,7 @@
|
|||||||
#if _WIN32_WINNT >= _WIN32_WINNT_VISTA
|
#if _WIN32_WINNT >= _WIN32_WINNT_VISTA
|
||||||
#include "../include/WinStd/ETW.h"
|
#include "../include/WinStd/ETW.h"
|
||||||
#endif
|
#endif
|
||||||
|
#include "../include/WinStd/GDI.h"
|
||||||
#include "../include/WinStd/Hex.h"
|
#include "../include/WinStd/Hex.h"
|
||||||
#include "../include/WinStd/MSI.h"
|
#include "../include/WinStd/MSI.h"
|
||||||
#if defined(SECURITY_WIN32) || defined(SECURITY_KERNEL) || defined(SECURITY_MAC)
|
#if defined(SECURITY_WIN32) || defined(SECURITY_KERNEL) || defined(SECURITY_MAC)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user