⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 clipboard_scope.hpp

📁 新版本TR1的stl
💻 HPP
📖 第 1 页 / 共 2 页
字号:
    void    set_data(HBITMAP hBmp) stlsoft_throw_1(clipboard_scope_exception );
    /// \brief Sets the bitmap to the clipboard with CF_HDROP format.
    void    set_data(HDROP hDrop) stlsoft_throw_1(clipboard_scope_exception );
    /// \brief Sets the bitmap to the clipboard with CF_ENHMETAFILE format.
    void    set_data(HENHMETAFILE hEmf) stlsoft_throw_1(clipboard_scope_exception );
    /// \brief Sets the bitmap to the clipboard with CF_PALETTE format.
    void    set_data(HPALETTE hPal) stlsoft_throw_1(clipboard_scope_exception );

    /// \brief Gets the data with the requested format from the clipboard
    HANDLE  get_data(UINT fmt) const stlsoft_throw_1(clipboard_scope_exception );

    /// \brief Gets the clipboard data with the CF_TEXT format.
    void    get_data(char const*& str) const stlsoft_throw_1(clipboard_scope_exception );

    /// \brief Gets the clipboard data with the CF_UNICODETEXT format.
    void    get_data(wchar_t const*& str) const stlsoft_throw_1(clipboard_scope_exception );

    /// \brief Gets the clipboard data with the CF_BITMAP format.
    void    get_data(HBITMAP& hBmp) const stlsoft_throw_1(clipboard_scope_exception );
    /// \brief Gets the clipboard data with the CF_HDROP format.
    void    get_data(HDROP& hDrop) const stlsoft_throw_1(clipboard_scope_exception );
    /// \brief Gets the clipboard data with the CF_ENHMETAFILE format.
    void    get_data(HENHMETAFILE& hEmf) const stlsoft_throw_1(clipboard_scope_exception );
    /// \brief Gets the clipboard data with the CF_PALETTE format.
    void    get_data(HPALETTE& hPal) const stlsoft_throw_1(clipboard_scope_exception );
/// @}

/// \name Members
/// @{
private:
    clipboard_scope(class_type const&);
    class_type& operator =(class_type const&);
/// @}
};

////////////////////////////////////////////////////////////////////////////
// Unit-testing

#ifdef STLSOFT_UNITTEST
# include "./unittest/clipboard_scope_unittest_.h"
#endif /* STLSOFT_UNITTEST */

/* /////////////////////////////////////////////////////////////////////////
 * Shims
 */



/* /////////////////////////////////////////////////////////////////////////
 * Implementation
 */

#ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION

inline clipboard_scope::clipboard_scope(HWND hwndOwner /* = NULL */) stlsoft_throw_1(clipboard_scope_exception )
{
    if(!::OpenClipboard(hwndOwner))
    {
        STLSOFT_THROW_X(clipboard_scope_exception("Cannot open clipboard", ::GetLastError()));
    }
}

inline clipboard_scope::~clipboard_scope() stlsoft_throw_0()
{
    ::CloseClipboard();
}

inline clipboard_scope::allocator_type clipboard_scope::get_allocator() const
{
    allocator_type const& ator = *this;

    return ator;
}

inline void clipboard_scope::clear() stlsoft_throw_1(clipboard_scope_exception )
{
    if(!::EmptyClipboard())
    {
        STLSOFT_THROW_X(clipboard_scope_exception("Cannot empty clipboard", ::GetLastError()));
    }
}

inline HWND clipboard_scope::owner() const
{
    HWND hwnd = ::GetClipboardOwner();

    if( NULL == hwnd &&
        ERROR_SUCCESS != ::GetLastError())
    {
        STLSOFT_THROW_X(clipboard_scope_exception("Cannot get clipboard owner", ::GetLastError()));
    }

    return hwnd;
}

inline ws_bool_t clipboard_scope::is_fmt_available(UINT fmt) const
{
    return BOOL2bool(::IsClipboardFormatAvailable(fmt));
}

inline void clipboard_scope::set_data(UINT fmt, HANDLE hData) stlsoft_throw_1(clipboard_scope_exception )
{
    if(NULL == ::SetClipboardData(fmt, hData))
    {
        STLSOFT_THROW_X(clipboard_scope_exception("Cannot set clipboard data", ::GetLastError()));
    }
}

inline void clipboard_scope::set_data(char const* str) stlsoft_throw_1(clipboard_scope_exception )
{
#ifdef STLSOFT_LF_ALLOCATOR_REBIND_SUPPORT
    allocator_type::rebind<char>::other     ator(*this);
#else /* ? STLSOFT_LF_ALLOCATOR_REBIND_SUPPORT */
    global_allocator<char>                  ator;
#endif /* STLSOFT_LF_ALLOCATOR_REBIND_SUPPORT */

    set_data(CF_TEXT, stlsoft_ns_qual(string_dup)(str, ator));
}

inline void clipboard_scope::set_data(char const* str, ws_size_t n) stlsoft_throw_1(clipboard_scope_exception )
{
#ifdef STLSOFT_LF_ALLOCATOR_REBIND_SUPPORT
    allocator_type::rebind<char>::other     ator(*this);
#else /* ? STLSOFT_LF_ALLOCATOR_REBIND_SUPPORT */
    global_allocator<char>                  ator;
#endif /* STLSOFT_LF_ALLOCATOR_REBIND_SUPPORT */

    set_data(CF_TEXT, stlsoft_ns_qual(string_dup)(str, n, ator));
}

inline void clipboard_scope::set_data(wchar_t const* str) stlsoft_throw_1(clipboard_scope_exception )
{
#ifdef STLSOFT_LF_ALLOCATOR_REBIND_SUPPORT
    allocator_type::rebind<wchar_t>::other  ator(*this);
#else /* ? STLSOFT_LF_ALLOCATOR_REBIND_SUPPORT */
    global_allocator<wchar_t>               ator;
#endif /* STLSOFT_LF_ALLOCATOR_REBIND_SUPPORT */

    set_data(CF_UNICODETEXT, stlsoft_ns_qual(string_dup)(str, ator));
}

inline void clipboard_scope::set_data(wchar_t const* str, ws_size_t n) stlsoft_throw_1(clipboard_scope_exception )
{
#ifdef STLSOFT_LF_ALLOCATOR_REBIND_SUPPORT
    allocator_type::rebind<wchar_t>::other  ator(*this);
#else /* ? STLSOFT_LF_ALLOCATOR_REBIND_SUPPORT */
    global_allocator<wchar_t>               ator;
#endif /* STLSOFT_LF_ALLOCATOR_REBIND_SUPPORT */

    set_data(CF_UNICODETEXT, stlsoft_ns_qual(string_dup)(str, n, ator));
}

inline void clipboard_scope::set_data(HBITMAP hBmp) stlsoft_throw_1(clipboard_scope_exception )
{
    set_data(CF_BITMAP, hBmp);
}

inline void clipboard_scope::set_data(HDROP hDrop) stlsoft_throw_1(clipboard_scope_exception )
{
    set_data(CF_HDROP, hDrop);
}

inline void clipboard_scope::set_data(HENHMETAFILE hEmf) stlsoft_throw_1(clipboard_scope_exception )
{
    set_data(CF_ENHMETAFILE, hEmf);
}

inline void clipboard_scope::set_data(HPALETTE hPal) stlsoft_throw_1(clipboard_scope_exception )
{
    set_data(CF_PALETTE, hPal);
}

inline HANDLE clipboard_scope::get_data(UINT fmt) const stlsoft_throw_1(clipboard_scope_exception )
{
    HANDLE hData = ::GetClipboardData(fmt);

    if( NULL == hData &&
        ERROR_SUCCESS != ::GetLastError())
    {
        STLSOFT_THROW_X(clipboard_scope_exception("Cannot get clipboard data", ::GetLastError()));
    }

    return hData;
}

inline void clipboard_scope::get_data(char const*& str) const stlsoft_throw_1(clipboard_scope_exception )
{
    str = static_cast<char const*>(get_data(CF_TEXT));
}

inline void clipboard_scope::get_data(wchar_t const*& str) const stlsoft_throw_1(clipboard_scope_exception )
{
    str = static_cast<wchar_t const*>(get_data(CF_UNICODETEXT));
}

inline void clipboard_scope::get_data(HBITMAP& hBmp) const stlsoft_throw_1(clipboard_scope_exception )
{
    hBmp = static_cast<HBITMAP>(get_data(CF_BITMAP));
}

inline void clipboard_scope::get_data(HDROP& hDrop) const stlsoft_throw_1(clipboard_scope_exception )
{
    hDrop = static_cast<HDROP>(get_data(CF_HDROP));
}

inline void clipboard_scope::get_data(HENHMETAFILE& hEmf) const stlsoft_throw_1(clipboard_scope_exception )
{
    hEmf = static_cast<HENHMETAFILE>(get_data(CF_ENHMETAFILE));
}

inline void clipboard_scope::get_data(HPALETTE& hPal) const stlsoft_throw_1(clipboard_scope_exception )
{
    hPal = static_cast<HPALETTE>(get_data(CF_PALETTE));
}

#endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */

/* /////////////////////////////////////////////////////////////////////////
 * Namespace
 */

#ifndef _WINSTL_NO_NAMESPACE
# if defined(_STLSOFT_NO_NAMESPACE) || \
     defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
} // namespace winstl
# else
} // namespace winstl_project
} // namespace stlsoft
# endif /* _STLSOFT_NO_NAMESPACE */

#endif /* !_WINSTL_NO_NAMESPACE */

/* ////////////////////////////////////////////////////////////////////// */

#endif /* WINSTL_INCL_WINSTL_CLIPBOARD_HPP_CLIPBOARD_SCOPE */

/* ////////////////////////////////////////////////////////////////////// */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -