
subclassing controls in dynamically biult dialog box
I want to write an "InputBox" that I can reuse many times throughout many
projects. The usage will be something like:
double myVal = GetValidDouble(sPrompt, dDefaultValue)
This function will dynamically construct a dialog box (no templates
involved - too much maintenance and clutter) which has a static text control
for the prompt and an edit box for input. I have managed to construct the
dialog box dynamically OK. The problem I have is that I want to subclass the
edit box to a new class that I've written which validates the input as the
user types. The code goes something like this:
1) Call the function.
2) The function creates a class which builds a new dialog in memory and also
has a member variable(m_edt) corresponding to the CEditDouble derived class.
This variable is a class member. It adds the static and the (standard) edit
box with IDs which I know.
3) in the InitDialog function of the dynamically built dialog class I have
the following code:
m_edt.SubclassDlgItem(IDC_EDTDOUBLE, this);
This produces an assert from within CWnd::Attach(HWND hWndNew):
ASSERT(FromHandlePermanent(hWndNew) == NULL);
I looked in this function and find:
CWnd* Pascal CWnd::FromHandlePermanent(HWND hWnd)
{
CHandleMap* pMap = afxMapHWND();
CWnd* pWnd = NULL;
if (pMap != NULL)
{
// only look in the permanent map - does no allocations
pWnd = (CWnd*)pMap->LookupPermanent(hWnd);
ASSERT(pWnd == NULL || pWnd->m_hWnd == hWnd);
}
return pWnd;
Quote:
}
Going through in debug I notice that the pWnd->m_hWnd==hWnd always seems to
be true and not NULL.
When I try the same code with a dialog box based on a resource template it
works fine. Any clues?