CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 1999
    Posts
    16

    Accessing CDucument from CDialogBar



    I have made a class derived from CDialogBar.

    The DialogBar itself is created in the OnCreate

    method of the CFrameWnd class.

    The dialogbar includes several buttons and edit-boxes.

    Now I wanted to pass a integer-value from the DialogBar

    to the Document-class like this:


    CMyDoc *m_doc = (CMyDoc *)GetParent();

    m_doc->value_in_document_class= 10;


    With this pointer to the document class it is possible to

    call methods of it, but if a value should be passed the

    following assertion-error occurs in "barcore.cpp"


    ASSERT(m_nCount == 0 || m_pData != NULL);


    In my case the m_pData value is NULL.


    Does anyone know a sollution for this problem.








  2. #2
    Join Date
    Apr 1999
    Posts
    191

    Invalid casting



    CWnd::GetParent() returns a CWnd*. You can't cast this to a CDocument*, because CDocument and CWnd aren't related. Assuming that you're creating the dialog from your view class, you could create a new constructor for the dialog that allows you to pass a CDocument* into it. Then you could construct your dialog thus:


    CMyDialog dlg(GetDocument());

  3. #3
    Join Date
    Mar 1999
    Posts
    22

    Re: CDocumant is not a parent of CDialogBar, it is ReBar.



    Hi.

    You misunderstand the relationship between CDcoument and CDialogBar.

    Use SPY++ to figure it out.

    One time I also check this. If I didn't forget, the parent of CDialogBar

    is ReBar if you use App Wizard by generating CDialogBar.

    By the way, if you want to bring the varaible to CDocument class, there must

    be a couple of ways. If you can understand how apply button on Property page

    works, you will solve this problem.

    Basically, we brings CWnd of CDialogBar to CDocumet.

    For cxample,

    //CMyDocument class

    public:

    void GetOfWnd(CMyDialogBar *);

    // its cpp

    void CMyDocument::GetOfWnd(CMyDialogBar* m_Wnd)

    {

    p_nWnd = m_Wnd);

    }

    //CMyDialogBar class

    CMyDialogBar::OnInitDialog()

    {

    ......

    ((CMyDocument*)AfxGetMainWnd())->GetOfWnd(this);

    }

    //After this, CMyDocument class

    p_nWnd->variable //From CMyDialogBar public member.

    After I check the class wizard, I can't find CDialogBar class if I generate

    CDialgBar itself. So you use the base class CDialog?

    Because CDialogBar exists, it derived from CControlbar class. Therefore,

    we can't use OnInitdialog function? In this case, the situation will be

    changed.


    Hope for help.

    -Masaaki Onishi-


















Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured