Sign in to follow this  

DDX_Control doesn't get custom control's child windows?

This topic is 4839 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, This may or may not be a simple question. I have a custom control that contains a child window. When DDX_Control is called in DoDataExchange the child window's handle is not exchanged along with the rest of the control's data. Is there something else I need to do (override a function, Message Handler, etc.) to keep everything together? Here's some sample code:
class CChildWnd : public CWnd
{
/* DO STUFF */
}

class CCustomControl : public CWnd
{
/* DO STUFF */

    CChildWnd m_Child;

    void OnCreate( LPCREATESTRUCT lpCreateStruct )
    {
	GetClientRect( cr );
	m_ChildWnd.Create( NULL, "ChildWnd", WS_CHILD | WS_VISIBLE, cr, this, IDC_CHILD_WND );

        // ASSERTION PASSES
        ASSERT( m_ChildWnd.m_hWnd != NULL );

        CWnd::OnCreate();
    }
}

class CMyDialog : public CDialog
{
   CCustomControl m_myControl;

    void DoDataExchange( CDataExchange *pDX )
    {
        CDialog::DoDataExchange( pDX );

        DDX_Control( pDX, IDC_CUSTOM_CONTROL, m_myControl );
    }

   void OnInitDialog()
    {
        CDialog::OnInitDialog();

        // ASSERTION WILL FAIL
        ASSERT( m_myControl.m_Child.m_hWnd != NULL );
    }
}





Anyone have any ideas? Thanks in advance! [Edited by - Enfekted on September 13, 2004 11:50:47 AM]

Share this post


Link to post
Share on other sites
Ok, dont you also have to call CWnd::OnCreate before the m_ChildWnd.Create()? Do you have other member functions in your CChildWnd class calling UpdateData somewhere?

Share this post


Link to post
Share on other sites
no, CChildWnd does not call UpdateData anywhere. CChildWnd doesn't actually do anything yet except draw a red square where it is supposed to be (for layout purposes within the CCustomControl control).

I changed the code in CCustomControl::OnCreate() to show how m_ChildWnd is being created. Maybe that has something to do with it?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I would change the OnCreate to call the base class before anything else:


void OnCreate( LPCREATESTRUCT lpCreateStruct )
{
if( CWnd::OnCreate() == -1 )
return -1;

GetClientRect( cr );
m_ChildWnd.Create( NULL, "ChildWnd", WS_CHILD | WS_VISIBLE, cr, this, IDC_CHILD_WND );

// ASSERTION PASSES
ASSERT( m_ChildWnd.m_hWnd != NULL );
}

Share this post


Link to post
Share on other sites
Nope, that didn't do it.

The window is creating fine and displaying ok. The problem comes when I try to modify the CChildWnd::m_hWnd or call any function that accesses it (like SetWindowPos) after DoDataExchange has been called in CMyDialog. All the data is exchanged in CCustomControl after DDX_Control, but the handle is never attached to m_ChildWnd.

It just seems to me that there should be a function that can be overridden that is called from DDX_Control that will allow me to attach m_hWnd to m_ChildWnd or a settings somewhere to tell DDX_Control to do it for me.

Share this post


Link to post
Share on other sites
The m_Child is the same as the m_ChildWnd right? I hope there is no duplicate definition there.

With the DoDataExchange the custom control is subclassed from the dialog. Now for the window and custom control, if you want to pass the messages to the m_cchildwnd you can use SubclassWindow or SubClassDlgItem.

Share this post


Link to post
Share on other sites

This topic is 4839 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this