stl template for ATL::CWindow
I'd like to be able to use stl strings to do functions like
GetWindowText(), SetWindowText(), etc... So, I thought it would be
handy to use a template that could be applied to ATL::CWindow derived
object. e.g.
STLWnd<CEdit> m_edit;
Ideally, I'd like to be able to do something simple like:
#ifdef UNICODE
#define TSTRING std::wstring
#else
#define TSTRING std::string
#endif
template <class TBase>
class STLWnd :
public TBase
{
public:
STLWnd(void) :
TBase()
{ };
TSTRING GetWindowText()
{
ATLASSERT(::IsWindow(m_hWnd));
int len = ::GetWindowTextLength(m_hWnd);
std::auto_ptr<TCHAR> txt(new TCHAR[len + 1]);
::GetWindowText(m_hWnd, txt.get(), len + 1);
return TSTRING(txt.get());
};
void SetWindowText(const TSTRING& str)
{
::SetWindowText(m_hWnd, str.c_str());
};
};
But, I'm having some trouble getting everything working.
The compiler complains that I don't have an = operator overloaded. But,
that way lies insanity as I end up re-implementing the entire
ATL::CWindow class. (Perhaps I'm just implementing it wrong...Is there
a right way to override the = operator?)
Can anybody offer any suggestions on getting this to work?
Thanks,
PaulH