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

📄 hwnd.hpp

📁 新版本TR1的stl
💻 HPP
📖 第 1 页 / 共 2 页
字号:
// Implementation
private:
    ws_size_t get_window_text(HWND h, char_type* buffer, ws_size_t cchBuffer);

// Members
private:
    char_type   *m_buffer;

// Not to be implemented
private:
    void operator =(class_type const& rhs);
};

#ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION

STLSOFT_TEMPLATE_SPECIALISATION
inline ws_size_t c_str_ptr_null_HWND_proxy<ws_char_a_t>::get_window_text(HWND h, ws_char_a_t *buffer, ws_size_t cchBuffer)
{
    return GetWindowTextA__(h, buffer, cchBuffer);
}

STLSOFT_TEMPLATE_SPECIALISATION
inline ws_size_t c_str_ptr_null_HWND_proxy<ws_char_w_t>::get_window_text(HWND h, ws_char_w_t *buffer, ws_size_t cchBuffer)
{
    return GetWindowTextW__(h, buffer, cchBuffer);
}

#endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */

/** \brief This class provides an intermediary object that may be returned by the
 * c_str_ptr() function, such that the window text of a given window may be
 * accessed as a null-terminated string.
 *
 * \ingroup group__concept__shim__string_access
 *
 */
template <ss_typename_param_k C>
class c_str_ptr_HWND_proxy
{
    typedef cstring_maker<C>                            string_maker_type;
public:
    typedef C                                           char_type;
    typedef c_str_ptr_HWND_proxy<C>                     class_type;

// Construction
public:
    /// Constructs an instance of the proxy from the given HWND
    ///
    /// \param h The HWND from which the text will be retrieved
    ss_explicit_k c_str_ptr_HWND_proxy(HWND h)
    {
        ws_size_t length  =   WindowTextLength_traits<C>::get_length(h);

        m_buffer = string_maker_type::alloc(length);

        if(NULL != m_buffer)
        {
            get_window_text(h, m_buffer, length + 1);
        }
    }

#ifdef STLSOFT_CF_MOVE_CONSTRUCTOR_SUPPORT
    /// Move constructor
    ///
    /// This <a href = "http://synesis.com.au/resources/articles/cpp/movectors.pdf">move constructor</a>
    /// is for circumstances when the compiler does not, or cannot, apply the
    /// return value optimisation. It causes the contents of \c rhs to be
    /// transferred into the constructing instance. This is completely safe
    /// because the \c rhs instance will never be accessed in its own right, so
    /// does not need to maintain ownership of its contents.
    c_str_ptr_HWND_proxy(class_type& rhs)
        : m_buffer(rhs.m_buffer)
    {
        move_lhs_from_rhs(rhs).m_buffer = NULL;
    }
#else /* ? STLSOFT_CF_MOVE_CONSTRUCTOR_SUPPORT */
    // Copy constructor
    c_str_ptr_HWND_proxy(class_type const& rhs)
        : m_buffer(string_maker_type::dup_null(rhs.m_buffer))
    {}
#endif /* STLSOFT_CF_MOVE_CONSTRUCTOR_SUPPORT */

    /// Releases any storage aquired by the proxy
    ~c_str_ptr_HWND_proxy() stlsoft_throw_0()
    {
        string_maker_type::free(m_buffer);
    }

// Accessors
public:
    /// Returns a null-terminated string representing the window contents, or
    /// the empty string "" if the window contains no text.
    operator char_type const* () const
    {
        static char_type    s_ch[1] = { '\0' };

        return (NULL == m_buffer) ? s_ch : m_buffer;
    }

// Implementation
private:
    ws_size_t get_window_text(HWND h, char_type* buffer, ws_size_t cchBuffer);

// Members
private:
    char_type   *m_buffer;

// Not to be implemented
private:
    void operator =(class_type const& rhs);
};

#ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION

STLSOFT_TEMPLATE_SPECIALISATION
inline ws_size_t c_str_ptr_HWND_proxy<ws_char_a_t>::get_window_text(HWND h, ws_char_a_t *buffer, ws_size_t cchBuffer)
{
    return GetWindowTextA__(h, buffer, cchBuffer);
}

STLSOFT_TEMPLATE_SPECIALISATION
inline ws_size_t c_str_ptr_HWND_proxy<ws_char_w_t>::get_window_text(HWND h, ws_char_w_t *buffer, ws_size_t cchBuffer)
{
    return GetWindowTextW__(h, buffer, cchBuffer);
}

#endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */


/* /////////////////////////////////////////////////////////////////////////
 * IOStream compatibility
 */

template<   ss_typename_param_k C
        ,   ss_typename_param_k S
        >
inline S& operator <<(S& s, c_str_ptr_null_HWND_proxy<C> const& shim)
{
    s << static_cast<C const*>(shim);

    return s;
}

template<   ss_typename_param_k C
        ,   ss_typename_param_k S
        >
inline S& operator <<(S& s, c_str_ptr_HWND_proxy<C> const& shim)
{
    s << static_cast<C const*>(shim);

    return s;
}

/* /////////////////////////////////////////////////////////////////////////
 * c_str_data
 *
 * This can be applied to an expression, and the return value is either a
 * pointer to the character string or to an empty string.
 */

#ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION

inline c_str_ptr_HWND_proxy<ws_char_a_t> c_str_data_a(HWND h)
{
    return c_str_ptr_HWND_proxy<ws_char_a_t>(h);
}
inline c_str_ptr_HWND_proxy<ws_char_w_t> c_str_data_w(HWND h)
{
    return c_str_ptr_HWND_proxy<ws_char_w_t>(h);
}

#endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */

/** \brief \ref group__concept__shim__string_access__c_str_data for HWND
 *
 * \ingroup group__concept__shim__string_access
 *
 */
inline c_str_ptr_HWND_proxy<TCHAR> c_str_data(HWND h)
{
    return c_str_ptr_HWND_proxy<TCHAR>(h);
}

/* /////////////////////////////////////////////////////////////////////////
 * c_str_len
 *
 * This can be applied to an expression, and the return value is the number of
 * characters in the character string in the expression.
 */

/* HWND */

#ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION

inline ws_size_t c_str_len_a(HWND h)
{
    return GetWindowTextLength__A(h);
}
inline ws_size_t c_str_len_w(HWND h)
{
    return GetWindowTextLength__W(h);
}

#endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */

/** \brief \ref group__concept__shim__string_access__c_str_len for HWND
 *
 * \ingroup group__concept__shim__string_access
 *
 */
inline ws_size_t c_str_len(HWND h)
{
    return GetWindowTextLength__(h);
}

/* /////////////////////////////////////////////////////////////////////////
 * c_str_ptr
 *
 * This can be applied to an expression, and the return value is either a
 * pointer to the character string or to an empty string.
 */

/* HWND */

#ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION

inline c_str_ptr_HWND_proxy<ws_char_a_t> c_str_ptr_a(HWND h)
{
    return c_str_ptr_HWND_proxy<ws_char_a_t>(h);
}
inline c_str_ptr_HWND_proxy<ws_char_w_t> c_str_ptr_w(HWND h)
{
    return c_str_ptr_HWND_proxy<ws_char_w_t>(h);
}

#endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */

/** \brief \ref group__concept__shim__string_access__c_str_ptr for HWND
 *
 * \ingroup group__concept__shim__string_access
 *
 */
inline c_str_ptr_HWND_proxy<TCHAR> c_str_ptr(HWND h)
{
    return c_str_ptr_HWND_proxy<TCHAR>(h);
}

/* /////////////////////////////////////////////////////////////////////////
 * c_str_ptr_null
 *
 * This can be applied to an expression, and the return value is either a
 * pointer to the character string or NULL.
 */

/* HWND */

#ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION

inline c_str_ptr_null_HWND_proxy<ws_char_a_t> c_str_ptr_null_a(HWND h)
{
    return c_str_ptr_null_HWND_proxy<ws_char_a_t>(h);
}
inline c_str_ptr_null_HWND_proxy<ws_char_w_t> c_str_ptr_null_w(HWND h)
{
    return c_str_ptr_null_HWND_proxy<ws_char_w_t>(h);
}

#endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */

/** \brief \ref group__concept__shim__string_access__c_str_ptr_null for HWND
 *
 * \ingroup group__concept__shim__string_access
 *
 */
inline c_str_ptr_null_HWND_proxy<TCHAR> c_str_ptr_null(HWND h)
{
    return c_str_ptr_null_HWND_proxy<TCHAR>(h);
}

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

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

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

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

/* /////////////////////////////////////////////////////////////////////////
 * Namespace
 *
 * The string access shims exist either in the stlsoft namespace, or in the
 * global namespace. This is required by the lookup rules.
 *
 */

#ifndef _WINSTL_NO_NAMESPACE
# if !defined(_STLSOFT_NO_NAMESPACE) && \
     !defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
namespace stlsoft
{
# else /* ? _STLSOFT_NO_NAMESPACE */
/* There is no stlsoft namespace, so must define in the global namespace */
# endif /* !_STLSOFT_NO_NAMESPACE */

using ::winstl::c_str_data;
using ::winstl::c_str_data_a;
using ::winstl::c_str_data_w;

using ::winstl::c_str_len;
using ::winstl::c_str_len_a;
using ::winstl::c_str_len_w;

using ::winstl::c_str_ptr;
using ::winstl::c_str_ptr_a;
using ::winstl::c_str_ptr_w;

using ::winstl::c_str_ptr_null;
using ::winstl::c_str_ptr_null_a;
using ::winstl::c_str_ptr_null_w;

# if !defined(_STLSOFT_NO_NAMESPACE) && \
     !defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
} // namespace stlsoft
# else /* ? _STLSOFT_NO_NAMESPACE */
/* There is no stlsoft namespace, so must define in the global namespace */
# endif /* !_STLSOFT_NO_NAMESPACE */
#endif /* !_WINSTL_NO_NAMESPACE */

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

#endif /* !WINSTL_INCL_WINSTL_SHIMS_ACCESS_STRING_HPP_HWND */

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

⌨️ 快捷键说明

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