📄 applet_module.hpp
字号:
/// \brief Begins the iteration
///
/// \return An iterator representing the start of the sequence
iterator begin();
/// \brief Ends the iteration
///
/// \return An iterator representing the end of the sequence
iterator end();
/// \brief Begins the iteration
///
/// \return An iterator representing the start of the sequence
const_iterator begin() const;
/// \brief Ends the iteration
///
/// \return An iterator representing the end of the sequence
const_iterator end() const;
/// @}
/// \name Implementation
/// @{
private:
void init_(int flags, HWND hwndParent);
/// @}
/// \name Members
/// @{
private:
const string_type m_path;
module m_module;
applets_type_ m_applets;
error_translator m_errorTranslator;
/// @}
/// \name Not to be implemented
/// @{
private:
applet_module(class_type const&);
class_type& operator =(class_type const&);
/// @}
};
/* /////////////////////////////////////////////////////////////////////////
* Implementation
*/
#ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
// applet
inline applet::applet(applet_module_base *module, applet::index_type index)
: m_module(module)
, m_index(index)
, m_icon(NULL)
, m_name()
, m_description()
, m_data(0)
{
WINSTL_ASSERT(NULL != module);
WINSTL_ASSERT(0 == index || index < control_panel_get_count(m_module->m_pfn, m_module->m_hwnd));
::SetLastError(0);
if( !control_panel_init(m_module->m_pfn, m_module->m_hwnd) &&
0 == (m_module->m_flags & applet_module::dontExpectNonZeroInit))
{
#ifdef STLSOFT_CF_EXCEPTION_SUPPORT
STLSOFT_THROW_X(control_panel_exception("Applet initialisation failed", ::GetLastError()));
#else /* ? STLSOFT_CF_EXCEPTION_SUPPORT */
::SetLastError(ERROR_DLL_INIT_FAILED);
m_module = NULL;
#endif /* STLSOFT_CF_EXCEPTION_SUPPORT */
}
else
{
#ifdef STLSOFT_CF_EXCEPTION_SUPPORT
try
{
#endif /* STLSOFT_CF_EXCEPTION_SUPPORT */
CPLINFO info = { CPL_DYNAMIC_RES, CPL_DYNAMIC_RES, CPL_DYNAMIC_RES, 0 };
control_panel_inquire(m_module->m_pfn, m_module->m_hwnd, m_index, &info);
if(CPL_DYNAMIC_RES != info.idIcon)
{
m_icon = ::LoadIcon(m_module->m_hinst, MAKEINTRESOURCE(info.idIcon));
if( NULL == m_icon &&
applet_module::ignoreIconLoadFailures == (m_module->m_flags & applet_module::ignoreIconLoadFailures))
{
#ifdef STLSOFT_CF_EXCEPTION_SUPPORT
STLSOFT_THROW_X(resource_exception("Could not load the applet icon", ::GetLastError(), MAKEINTRESOURCE(info.idIcon), RT_ICON));
#endif /* STLSOFT_CF_EXCEPTION_SUPPORT */
}
}
if(CPL_DYNAMIC_RES != info.idName)
{
m_name = resource_string_type_(m_module->m_hinst, info.idName);
}
if(CPL_DYNAMIC_RES != info.idInfo)
{
m_description = resource_string_type_(m_module->m_hinst, info.idInfo);
}
m_data = info.lData;
#ifdef STLSOFT_CF_EXCEPTION_SUPPORT
}
catch(...)
{
control_panel_uninit(m_module->m_pfn, m_module->m_hwnd);
throw;
}
#endif /* STLSOFT_CF_EXCEPTION_SUPPORT */
}
}
inline applet::~applet() stlsoft_throw_0()
{
#ifdef STLSOFT_CF_EXCEPTION_SUPPORT
WINSTL_ASSERT(NULL != m_module);
#else /* ? STLSOFT_CF_EXCEPTION_SUPPORT */
if(NULL != NULL)
#endif /* STLSOFT_CF_EXCEPTION_SUPPORT */
{
control_panel_uninit(m_module->m_pfn, m_module->m_hwnd);
}
}
inline void applet::open(HWND hwnd)
{
#ifdef STLSOFT_CF_EXCEPTION_SUPPORT
WINSTL_ASSERT(NULL != m_module);
#else /* ? STLSOFT_CF_EXCEPTION_SUPPORT */
if(NULL != NULL)
#endif /* STLSOFT_CF_EXCEPTION_SUPPORT */
{
if(NULL == hwnd)
{
hwnd = m_module->m_hwnd;
}
control_panel_run(m_module->m_pfn, hwnd, m_index, m_data);
}
}
inline void applet::open(HWND hwnd, TCHAR const* arguments)
{
#ifdef STLSOFT_CF_EXCEPTION_SUPPORT
WINSTL_ASSERT(NULL != m_module);
#else /* ? STLSOFT_CF_EXCEPTION_SUPPORT */
if(NULL != NULL)
#endif /* STLSOFT_CF_EXCEPTION_SUPPORT */
{
if( NULL == arguments ||
'\0' == *arguments)
{
this->open(hwnd);
}
else
{
if(NULL == hwnd)
{
hwnd = m_module->m_hwnd;
}
control_panel_run(m_module->m_pfn, hwnd, m_index, arguments);
}
}
}
inline applet::index_type applet::get_index() const
{
#ifdef STLSOFT_CF_EXCEPTION_SUPPORT
WINSTL_ASSERT(NULL != m_module);
#else /* ? STLSOFT_CF_EXCEPTION_SUPPORT */
if(NULL == m_module)
{
return ~index_type(0);
}
#endif /* STLSOFT_CF_EXCEPTION_SUPPORT */
return m_index;
}
inline applet::string_type applet::get_name() const
{
#ifdef STLSOFT_CF_EXCEPTION_SUPPORT
WINSTL_ASSERT(NULL != m_module);
#else /* ? STLSOFT_CF_EXCEPTION_SUPPORT */
if(NULL == m_module)
{
return m_name;
}
#endif /* STLSOFT_CF_EXCEPTION_SUPPORT */
if(m_name.empty())
{
NEWCPLINFO info = { sizeof(info), 0, 0, 0, NULL, { '\0' }, { '\0' }, { '\0' } };
control_panel_newinquire(m_module->m_pfn, m_module->m_hwnd, m_index, &info);
return info.szName;
}
return m_name;
}
inline applet::string_type applet::get_description() const
{
#ifdef STLSOFT_CF_EXCEPTION_SUPPORT
WINSTL_ASSERT(NULL != m_module);
#else /* ? STLSOFT_CF_EXCEPTION_SUPPORT */
if(NULL == m_module)
{
return m_description;
}
#endif /* STLSOFT_CF_EXCEPTION_SUPPORT */
if(m_description.empty())
{
NEWCPLINFO info = { sizeof(info), 0, 0, 0, NULL, { '\0' }, { '\0' }, { '\0' } };
control_panel_newinquire(m_module->m_pfn, m_module->m_hwnd, m_index, &info);
return info.szInfo;
}
return m_description;
}
inline HICON applet::get_icon() const
{
#ifdef STLSOFT_CF_EXCEPTION_SUPPORT
WINSTL_ASSERT(NULL != m_module);
#else /* ? STLSOFT_CF_EXCEPTION_SUPPORT */
if(NULL == m_module)
{
return NULL;
}
#endif /* STLSOFT_CF_EXCEPTION_SUPPORT */
if(NULL == m_icon)
{
NEWCPLINFO info = { sizeof(info), 0, 0, 0, NULL, { '\0' }, { '\0' }, { '\0' } };
control_panel_newinquire(m_module->m_pfn, m_module->m_hwnd, m_index, &info);
return info.hIcon;
}
return m_icon;
}
inline LONG applet::get_data() const
{
return m_data;
}
// applet_module::error_translator
inline applet_module::error_translator::error_translator()
: cc(STLSOFT_CDECL_VALUE)
{
pfnC = on_failure;
}
inline applet_module::error_translator::error_translator(applet_module::onFailureC pfn)
: cc(STLSOFT_CDECL_VALUE)
{
pfnC = pfn;
}
inline applet_module::error_translator::error_translator(applet_module::onFailureS pfn)
: cc(STLSOFT_STDCALL_VALUE)
{
pfnS = pfn;
}
inline /* static */ void STLSOFT_CDECL applet_module::error_translator::on_failure(TCHAR const* /* path */)
{}
// applet_module
inline void applet_module::init_(int flags, HWND hwndParent)
{
WINSTL_ASSERT(NULL == m_hwnd);
WINSTL_ASSERT(NULL == m_pfn);
::SetLastError(0);
if(NULL == m_module.get_symbol("CPlApplet", m_pfn))
{
#ifdef STLSOFT_CF_EXCEPTION_SUPPORT
STLSOFT_THROW_X(control_panel_exception("Control panel entry point not found", ::GetLastError()));
#endif /* STLSOFT_CF_EXCEPTION_SUPPORT */
}
else
{
m_flags = flags;
m_hwnd = hwndParent;
m_hinst = m_module.get_module_handle();
size_type numApplets = control_panel_get_count(m_pfn, m_hwnd);
if( 0 == numApplets &&
assumeOneAppletIfNone == (m_flags & assumeOneAppletIfNone))
{
numApplets = 1;
}
{ for(size_type index = 0; index < numApplets; ++index)
{
m_applets.push_back(applet(this, index));
}}
}
}
inline applet_module::applet_module(TCHAR const* path, int flags /* = ignoreIconLoadFailures */, HWND hwndParent /* = NULL */)
: m_path(path)
, m_module(path)
, m_applets()
, m_errorTranslator()
{
init_(flags, hwndParent);
}
inline applet_module::applet_module(TCHAR const* path, applet_module::onFailureC pfn, int flags /* = ignoreIconLoadFailures */, HWND hwndParent /* = NULL */)
: m_path(path)
, m_module(path)
, m_applets()
, m_errorTranslator(pfn)
{
init_(flags, hwndParent);
}
inline applet_module::applet_module(TCHAR const* path, applet_module::onFailureS pfn, int flags /* = ignoreIconLoadFailures */, HWND hwndParent /* = NULL */)
: m_path(path)
, m_module(path)
, m_applets()
, m_errorTranslator(pfn)
{
init_(flags, hwndParent);
}
inline applet_module::string_type const& applet_module::get_path() const
{
return m_path;
}
inline applet_module::size_type applet_module::size() const
{
return m_applets.size();
}
inline applet_module::value_type &applet_module::operator [](index_type index)
{
WINSTL_MESSAGE_ASSERT("Invalid index", index < size());
return m_applets[index];
}
inline applet_module::value_type const& applet_module::operator [](index_type index) const
{
WINSTL_MESSAGE_ASSERT("Invalid index", index < size());
return m_applets[index];
}
inline applet_module::iterator applet_module::begin()
{
return m_applets.begin();
}
inline applet_module::iterator applet_module::end()
{
return m_applets.end();
}
inline applet_module::const_iterator applet_module::begin() const
{
return m_applets.begin();
}
inline applet_module::const_iterator applet_module::end() const
{
return m_applets.end();
}
#endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
/* /////////////////////////////////////////////////////////////////////////
* Unit-testing
*/
#ifdef STLSOFT_UNITTEST
# include "./unittest/applet_module_unittest_.h"
#endif /* STLSOFT_UNITTEST */
/* ////////////////////////////////////////////////////////////////////// */
#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_CONTROL_PANEL_HPP_APPLET_MODULE */
/* ////////////////////////////////////////////////////////////////////// */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -