Having custom controls implemented as window classes, it is convenient to use them directly in resource dialog templates. Visual Studio resource editor allow to add custom control item to dialog. This custom control has a Class property which defines window class name of the control. Should native C++ implementation of window class be registered, it can be used in dialog templates.
CRegisteredWindowT template class turns window class implementation (descendant of ATL’s CWindowImpl) into registerable class. The sample project turns WTL’s CHyperLinkImpl implementation of a hyperlink control into Windows WTL_HypeLinkEx class:
class CHyperLinkEx :
public CRegisteredWindowT >
{
public:
DECLARE_WND_CLASS(_T(“WTL_HyperLinkEx”))
};
Before usage in a dialog template, the registration should take place at least once somewhere in the project, for example in dialog class constructor:
CMainDialog() throw()
{
ATLVERIFY(CHyperLinkEx::Register());
}
The instance of the control class is accessible from the dialog class as follows:
LRESULT OnInitDialog(HWND, LPARAM)
{
CHyperLinkEx* pHyperLinkEx = CHyperLinkEx::FromWindow(GetDlgItem(IDC_HYPERLINK2));
ATLASSERT(pHyperLinkEx);
The sample project illustrate usage of CRegisteredWindowT template class and hyperlink control:
Visual C++.NET 2003 source code can be downloaded here, compiled binary – here.