subclassing controls in dynamically biult dialog box 
Author Message
 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?



Mon, 26 Jan 2004 01:37:36 GMT  
 subclassing controls in dynamically biult dialog box

Quote:
>...
>This produces an assert from within CWnd::Attach(HWND hWndNew):

Are you already creating the edit window by calling the CEditDouble
Create function?

Dave
--
MVP VC++ FAQ: http://www.mvps.org/vcfaq
My address is altered to discourage junk mail.
Please post responses to the newsgroup thread,
there's no need for follow-up email copies.



Mon, 26 Jan 2004 04:22:18 GMT  
 subclassing controls in dynamically biult dialog box

Quote:
> >This produces an assert from within CWnd::Attach(HWND hWndNew):

> Are you already creating the edit window by calling the CEditDouble
> Create function?

I wasn't, so I tried that too, this gave an assert in the Attach method of
the CEditDouble.

The good news is that I started looking at the create method and rethinking
the problem. I managed to get the functionality I wanted by simply
creat(Ex)ing the CEditDouble in the InitDialog handler. This seems to create
a new control of the correct class. The bad news is that I still haven't
solved the "how to subclass" problem.

Thanks for your time so far,

martin



Mon, 26 Jan 2004 23:52:36 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Problems with List box in dynamically created dialog box

2. Problems with List box in dynamically created dialog box

3. Subclassing dialog boxes

4. Modeless dialog boxes in dynamically linked dll

5. Strange behavior when subclassing a static control in modal dialog

6. How do I change the caption on an MFC Dialog box (dynamically)

7. dynamically build dialog box

8. Change title for dialog box dynamically

9. change title for dialog box dynamically

10. Add a button dynamically on the creation of a Dialog Box

11. Dynamically alter size of Dialog Box

12. Dynamically changing text of a menu in a Dialog box

 

 
Powered by phpBB® Forum Software