//----------------------------------------------------------------------------------------------------------------------
/// \file
/// Public C++ ScreenCapture API.
// Copyright (c) Microsoft Corporation. All Rights Reserved.
//----------------------------------------------------------------------------------------------------------------------
#pragma once
#if defined(_WIN32)
#include "Wex.Common.h"
#include
namespace WEX { namespace Common
{
#pragma warning(push)
#pragma warning(disable:26812) // It would be good to switch to enum class, but that would be a breaking change.
///
/// The possible ImageFormats that a ScreenCapture can be saved in.
///
namespace ImageFormats
{
enum Format
{
/// Uses a lossless format.
Lossless = 0,
/// Uses the HDPhoto format.
HDPhoto,
/// Uses the PNG format.
PNG,
/// Uses the BMP format.
BMP,
/// Uses the JPEG format.
JPEG,
/// Will use the lowest image format possible on this system (usually JPEG).
LowQuality,
/// \internal
Unknown
};
}
///
/// The possible settings for capturing the mouse cursor
///
namespace ScreenCaptureOptions
{
enum Options
{
/// No options specified
None = 0,
/// Show the mouse cursor in the screen shot
ShowMouseCursor = 1,
/// \internal
Unknown = 2
};
inline Options& operator|=(Options& lhs, Options rhs) noexcept
{
lhs = static_cast((static_cast(lhs) | static_cast(rhs)));
return lhs;
}
inline Options operator|(Options lhs, Options rhs) noexcept
{
return lhs |= rhs;
}
inline int operator&(Options lhs, Options rhs) noexcept
{
return (static_cast(lhs) & static_cast(rhs));
}
}/* namespace ScreenCaptureOptions */
class NoThrowString;
///
/// Defines a class that provides the ability to save ScreenCaptures.
///
class WEXCOMMON_API ScreenCapture final
{
public:
/// Takes a screen capture of all monitors and saves it to disk without the mouse cursor included, and defaults to ImageFormats::LowQuality.
/// The file to save to.
static HRESULT __stdcall Save(const wchar_t* pszFilePath);
/// Takes a screen capture of all monitors and saves it to disk in the specified ImageFormats::Format; does not capture the mouse cursor in the screenshot.
/// The file to save to.
/// The ImageFormats::Format to save as.
static HRESULT __stdcall Save(const wchar_t* pszFilePath, ImageFormats::Format imageFormat);
/// Takes a screen capture of all monitors and saves it to disk as ImageFormats::LowQuality; captures the mouse cursor in the screenshot if requested.
/// The file to save to.
/// Whether or not to capture the mouse cursor in the screenshot.
static HRESULT __stdcall Save(const wchar_t* pszFilePath, ScreenCaptureOptions::Options captureOptions);
/// Takes a screen capture of all monitors and saves it to disk in the spedified ImageFormats::Format; captures the mouse cursor in the screenshot if requested.
/// The file to save to.
/// The ImageFormats::Format to save as.
/// Whether or not to capture the mouse cursor in the screenshot.
static HRESULT __stdcall Save(const wchar_t* pszFilePath, ImageFormats::Format imageFormat, ScreenCaptureOptions::Options captureOptions);
/// Takes a screen capture of a specific rectangle and saves it to disk without the mouse cursor included, and defaults to ImageFormats::LowQuality.
/// A RECT that defines the region of the Desktop to save - in Desktop co-ordinates.
/// The file to save to.
static HRESULT __stdcall Save(RECT rect, const wchar_t* pszFilePath);
/// Takes a screen capture of a specific rectangle and saves it to disk in the specified ImageFormats::Format; does not capture the mouse cursor in the screenshot.
/// A RECT that defines the region of the Desktop to save - in Desktop co-ordinates.
/// The file to save to.
/// The ImageFormats::Format to save as.
static HRESULT __stdcall Save(RECT rect, const wchar_t* pszFilePath, ImageFormats::Format imageFormat);
/// Takes a screen capture of a specific rectangle and saves it to disk as ImageFormats::LowQuality; captures the mouse cursor in the screenshot if requested.
/// A RECT that defines the region of the Desktop to save - in Desktop co-ordinates.
/// The file to save to.
/// Whether or not to capture the mouse cursor in the screenshot.
static HRESULT __stdcall Save(RECT rect, const wchar_t* pszFilePath, ScreenCaptureOptions::Options captureOptions);
/// Takes a screen capture of a specific rectangle and saves it to disk in the spedified ImageFormats::Format; captures the mouse cursor in the screenshot if requested.
/// A RECT that defines the region of the Desktop to save - in Desktop co-ordinates.
/// The file to save to.
/// The ImageFormats::Format to save as.
/// Whether or not to capture the mouse cursor in the screenshot.
static HRESULT __stdcall Save(RECT rect, const wchar_t* pszFilePath, ImageFormats::Format imageFormat, ScreenCaptureOptions::Options captureOptions);
/// Takes a screen capture of a specific rectangle and saves it to disk without the mouse cursor included, and defaults to ImageFormats::LowQuality.
///
///
///
///
/// The file to save to.
static HRESULT __stdcall Save(int left, int top, int right, int bottom, const wchar_t* pszFilePath);
/// Takes a screen capture of a specific rectangle and saves it to disk in the specified ImageFormats::Format; does not capture the mouse cursor in the screenshot.
///
///
///
///
/// The file to save to.
/// The ImageFormats::Format to save as.
static HRESULT __stdcall Save(int left, int top, int right, int bottom, const wchar_t* pszFilePath,
ImageFormats::Format imageFormat);
/// Takes a screen capture of a specific rectangle and saves it to disk as ImageFormats::LowQuality; captures the mouse cursor in the screenshot if requested.
///
///
///
///
/// The file to save to.
/// Whether or not to capture the mouse cursor in the screenshot.
static HRESULT __stdcall Save(int left, int top, int right, int bottom, const wchar_t* pszFilePath, ScreenCaptureOptions::Options captureOptions);
/// Takes a screen capture of a specific rectangle and saves it to disk in the spedified ImageFormats::Format; captures the mouse cursor in the screenshot if requested.
///
///
///
///
/// The file to save to.
/// The ImageFormats::Format to save as.
/// Whether or not to capture the mouse cursor in the screenshot.
static HRESULT __stdcall Save(int left, int top, int right, int bottom, const wchar_t* pszFilePath, ImageFormats::Format imageFormat, ScreenCaptureOptions::Options captureOptions);
/// Takes a screen capture of all monitors and saves it to disk without the mouse cursor included, and defaults to ImageFormats::LowQuality; also updates filePath if the file extension has been modified
///
static HRESULT __stdcall Save(NoThrowString& filePath);
/// Takes a screen capture of all monitors and saves it to disk in the specified ImageFormats::Format; does not capture the mouse cursor in the screenshot; also updates filePath if the file extension has been modified
///
/// The ImageFormats::Format to save as.
static HRESULT __stdcall Save(NoThrowString& filePath, ImageFormats::Format imageFormat);
/// Takes a screen capture of all monitors and saves it to disk as ImageFormats::LowQuality; captures the mouse cursor in the screenshot if requested; also updates filePath if the file extension has been modified
///
/// Whether or not to capture the mouse cursor in the screenshot.
static HRESULT __stdcall Save(NoThrowString& filePath, ScreenCaptureOptions::Options captureOptions);
/// Takes a screen capture of all monitors and saves it to disk in the spedified ImageFormats::Format; captures the mouse cursor in the screenshot if requested; also updates filePath if the file extension has been modified
///
/// The ImageFormats::Format to save as.
/// Whether or not to capture the mouse cursor in the screenshot.
static HRESULT __stdcall Save(NoThrowString& filePath, ImageFormats::Format imageFormat, ScreenCaptureOptions::Options captureOptions);
/// Takes a screen capture of a specific rectangle and saves it to disk without the mouse cursor included, and defaults to ImageFormats::LowQuality; also updates filePath if the file extension has been modified
/// A RECT that defines the region of the Desktop to save - in Desktop co-ordinates.
///
static HRESULT __stdcall Save(RECT rect, NoThrowString& filePath);
/// Takes a screen capture of a specific rectangle and saves it to disk in the specified ImageFormats::Format; does not capture the mouse cursor in the screenshot; also updates filePath if the file extension has been modified
/// A RECT that defines the region of the Desktop to save - in Desktop co-ordinates.
///
/// The ImageFormats::Format to save as.
static HRESULT __stdcall Save(RECT rect, NoThrowString& filePath, ImageFormats::Format imageFormat);
/// Takes a screen capture of a specific rectangle and saves it to disk as ImageFormats::LowQuality; captures the mouse cursor in the screenshot if requested; also updates filePath if the file extension has been modified
/// A RECT that defines the region of the Desktop to save - in Desktop co-ordinates.
///
/// Whether or not to capture the mouse cursor in the screenshot.
static HRESULT __stdcall Save(RECT rect, NoThrowString& filePath, ScreenCaptureOptions::Options captureOptions);
/// Takes a screen capture of a specific rectangle and saves it to disk in the spedified ImageFormats::Format; captures the mouse cursor in the screenshot if requested; also updates filePath if the file extension has been modified
/// A RECT that defines the region of the Desktop to save - in Desktop co-ordinates.
///
/// Whether or not to capture the mouse cursor in the screenshot.
/// The ImageFormats::Format to save as. Defaults to ImageFormats::LowQuality.
static HRESULT __stdcall Save(RECT rect, NoThrowString& filePath, ImageFormats::Format imageFormat, ScreenCaptureOptions::Options captureOptions);
/// Takes a screen capture of a specific rectangle and saves it to disk without the mouse cursor included, and defaults to ImageFormats::LowQuality; also updates filePath if the file extension has been modified
///
///
///
///
///
static HRESULT __stdcall Save(int left, int top, int right, int bottom, NoThrowString& filePath);
/// Takes a screen capture of a specific rectangle and saves it to disk in the specified ImageFormats::Format; does not capture the mouse cursor in the screenshot; also updates filePath if the file extension has been modified
///
///
///
///
///
/// The ImageFormats::Format to save as.
static HRESULT __stdcall Save(int left, int top, int right, int bottom, NoThrowString& filePath, ImageFormats::Format imageFormat);
/// Takes a screen capture of a specific rectangle and saves it to disk as ImageFormats::LowQuality; captures the mouse cursor in the screenshot if requested; also updates filePath if the file extension has been modified
///
///
///
///
///
/// Whether or not to capture the mouse cursor in the screenshot.
static HRESULT __stdcall Save(int left, int top, int right, int bottom, NoThrowString& filePath, ScreenCaptureOptions::Options captureOptions);
/// Takes a screen capture of a specific rectangle and saves it to disk in the spedified ImageFormats::Format; captures the mouse cursor in the screenshot if requested; also updates filePath if the file extension has been modified
///
///
///
///
///
/// The ImageFormats::Format to save as.
/// Whether or not to capture the mouse cursor in the screenshot.
static HRESULT __stdcall Save(int left, int top, int right, int bottom, NoThrowString& filePath, ImageFormats::Format imageFormat, ScreenCaptureOptions::Options captureOptions);
// unsigned short exports
#if defined(WEXCOMMON_FULL_BUILD)
static HRESULT __stdcall Save(const unsigned short* pszFilePath);
static HRESULT __stdcall Save(const unsigned short* pszFilePath, ImageFormats::Format imageFormat);
static HRESULT __stdcall Save(const unsigned short* pszFilePath, ScreenCaptureOptions::Options captureOptions);
static HRESULT __stdcall Save(const unsigned short* pszFilePath, ImageFormats::Format imageFormat, ScreenCaptureOptions::Options captureOptions);
static HRESULT __stdcall Save(RECT rect, const unsigned short* pszFilePath);
static HRESULT __stdcall Save(RECT rect, const unsigned short* pszFilePath, ImageFormats::Format imageFormat);
static HRESULT __stdcall Save(RECT rect, const unsigned short* pszFilePath, ScreenCaptureOptions::Options captureOptions);
static HRESULT __stdcall Save(RECT rect, const unsigned short* pszFilePath, ImageFormats::Format imageFormat, ScreenCaptureOptions::Options captureOptions);
static HRESULT __stdcall Save(int left, int top, int right, int bottom, const unsigned short* pszFilePath);
static HRESULT __stdcall Save(int left, int top, int right, int bottom, const unsigned short* pszFilePath, ImageFormats::Format imageFormat);
static HRESULT __stdcall Save(int left, int top, int right, int bottom, const unsigned short* pszFilePath, ScreenCaptureOptions::Options captureOptions);
static HRESULT __stdcall Save(int left, int top, int right, int bottom, const unsigned short* pszFilePath, ImageFormats::Format imageFormat, ScreenCaptureOptions::Options captureOptions);
#endif
private:
// Disallow construction of static class
ScreenCapture() = delete;
~ScreenCapture() = delete;
ScreenCapture(const ScreenCapture&) = delete;
ScreenCapture& operator=(const ScreenCapture&) = delete;
};
#pragma warning(pop)
}/* namespace Common */}/* namespace WEX */
#endif // #if defined(_WIN32)