Doc/View in CDialog
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10

Thread: Doc/View in CDialog

  1. #1
    Join Date
    Jul 2001
    Posts
    293

    Doc/View in CDialog

    Hello,

    I have a app with doc/view architekture.
    Is it possible to show/edit a doc of this type also in a CDialog within this app?
    How can I do that?

  2. #2
    Join Date
    Jan 2009
    Posts
    64

    Re: Doc/View in CDialog

    If I understand, you have a CDialog, where you can show/edit your CDocument ... you can get a pointer to CDocument, visible from anywhere, and based on this pointer, obviously, you can show/edit the content of CDocument into your CDialog ...

    http://support.microsoft.com/kb/108587

    Hope it helps.

  3. #3
    Join Date
    Jan 2012
    Location
    India
    Posts
    146

    Re: Doc/View in CDialog

    In view , in a function call where u need to pass document pointer ...
    u can use following method

    Code:
     void XYZView ::OnFunctionMyDialog
    {
    	// TODO: Add your command handler code here
    
    	
    	CXYZDoc* pDoc = GetDocument();
    	ASSERT_VALID(pDoc);
    
    	Here u get document pointer
    
    }
    In your dialog , .h and .cpp files , overwrite the default constructor

    pass document pointer to that ..

    for eg

    Code:
    #include "XYZDoc.h"  .... u will need this declaration
    
    class CXYZDoc ;
    
    
    // CMyDialog.h : header file
    //
    
    
    /////////////////////////////////////////////////////////////////////////////
    // CMyDialog dialog
    
    
    class CMyDialog : public CDialog
    {
    // Construction
    
    public:
    
    	CMyDialog(CWnd* pParent ,CXYZDoc * pd);   // standard constructor
    	
    	CXYZDoc * pDoc;
    
    }
    In Dialog.cpp , modify the default constructor code


    Code:
    CMyDialog::CMyDialog(CWnd* pParent , CXYZDoc * pd )
    	: CDialog(CResultDialog::IDD, pParent)
    {
    	//{{AFX_DATA_INIT(CResultDialog)
    
    	// dialog variables
    
    	pParent = NULL;
    	pDoc = pd; // here pass value to pointer
    
    	//}}AFX_DATA_INIT
    }
    Now u can use any variable from document via pDoc->.


    In your view cpp ..


    use code


    Code:
     void XYZView ::OnFunctionMyDialog
    {
    	// TODO: Add your command handler code here
    
    	
    	CXYZDoc* pDoc = GetDocument();
    	ASSERT_VALID(pDoc);
    
    	Here u get document pointer
    
    	now pass it to dialog
    
    	CMyDialog * md;
    
    	md = new CMyDialog (NULL,pDoc);
    
           ( if u r using dialog from document .. the code will be
    	md = new CMyDialog(NULL,this);
    	this  .. is doc ptr
    	)
    
    	md->DoModal();
    	delete(md);
    
    
    }
    Last edited by new_2012; May 13th, 2014 at 02:42 AM.

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,605

    Re: Doc/View in CDialog

    Quote Originally Posted by Ralf Schneider View Post
    Hello,

    I have a app with doc/view architekture.
    Is it possible to show/edit a doc of this type also in a CDialog within this app?
    How can I do that?
    Do you mean you'd like a View looking like a dialog (with controls)?
    Then use CFormView derived class as a View.
    Victor Nijegorodov

  5. #5
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,605

    Re: Doc/View in CDialog

    Quote Originally Posted by new_2012 View Post
    In view , in a function call where u need to pass document pointer ...
    u can use following method
    Please, edit your post to correct Code tags: the closing tags use a slash, not a backslash.
    Victor Nijegorodov

  6. #6
    Join Date
    Jan 2012
    Location
    India
    Posts
    146

    Re: Doc/View in CDialog

    Sorry VictorN sir .. I have edited the code tags .. I will keep this in mind

  7. #7
    Join Date
    Jul 2001
    Posts
    293

    Re: Doc/View in CDialog

    Hello,

    thanks for your answers.
    But I think, I am completely misunderstood.

    I try it again:
    My app shows data during his doc/view architecture(classe CmyView/CmyDoc), normally.

    But in a special case I want to open and show the some data also in a CDialog within this app.
    How can I use my CmyView- and CmyDoc-classes also in this CDialog?
    I need also the same behaviour and parts of my use interface in the CDialog.

  8. #8
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,605

    Re: Doc/View in CDialog

    Quote Originally Posted by Ralf Schneider View Post
    ...
    I try it again:
    My app shows data during his doc/view architecture(classe CmyView/CmyDoc), normally.

    But in a special case I want to open and show the some data also in a CDialog within this app.
    How can I use my CmyView- and CmyDoc-classes also in this CDialog?
    I need also the same behaviour and parts of my use interface in the CDialog.
    Well, you wrote nothing new comparing with your OP.
    Thus I can only repeat my answer in the post#4: use CFormView derived class.
    Victor Nijegorodov

  9. #9
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,228

    Re: Doc/View in CDialog


  10. #10
    Join Date
    Jul 2001
    Posts
    293

    Re: Doc/View in CDialog

    Quote Originally Posted by GCDEF View Post
    this goes in the right direction.
    I will have a look on it tomorrow. Thank you.

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center