How to set the parent dialog??
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: How to set the parent dialog??

  1. #1
    Join Date
    Dec 2005
    Posts
    445

    How to set the parent dialog??

    Hi all,

    Iíve created a modeless dialog from my main dialog as follows:

    Code:
    m_pContainerDlg = new CDlgContainer(NULL, this);
    m_pContainerDlg->Create(CDlgContainer::IDD, GetDesktopWindow());
    m_pContainerDlg ->ShowWindow(SW_SHOW);
    This container dialog creates a child dialog which I show inside the container

    Code:
    BOOL CDlgContainer::OnInitDialog()
    {
        // Create the child dialog and show it 
        m_pChildDlg = new CChildDlg(this);
        m_pChildDlg->Create(IDD_DIRECTORY_DIALOG, this);
    
        return FALSE;
    }
    From my child dialog I then create a modal dialog when a user clicks on a button

    Code:
    CChildDlg:: CChildDlg (CWnd* pParent /*=NULL*/)  : 
    	m_pParent((CDlgContainer*)pParent),
    {
    }
    
    void CChildDlg::OnBnClickedBtn()
    {
        CMyDlg MyDlg;
        INT_PTR iResult = MyDlg.DoModal(pParent);
    }
    My problem is that the CMyDlg is modal but to the main dialog and not to the container or the child dialog.

    Can anyone please advise??

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

    Re: How to set the parent dialog??

    Quote Originally Posted by Salvadoravi View Post
    From my child dialog I then create a modal dialog when a user clicks on a button

    Code:
    void CChildDlg::OnBnClickedBtn()
    {
        CMyDlg MyDlg;
        INT_PTR iResult = MyDlg.DoModal(pParent);
    }
    My problem is that the CMyDlg is modal but to the main dialog and not to the container or the child dialog.
    Does this code compile?
    AFAIK CDialog::DoModal has no parameters at all:
    http://msdn.microsoft.com/en-us/libr...v=vs.100).aspx
    Victor Nijegorodov

  3. #3
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Posts
    12,069

    Re: How to set the parent dialog??

    "My problem is that the CMyDlg is modal but to the main dialog and not to the container or the child dialog."

    I'm not even sure what that means. Modality isn't constrained or affected by a parent/child relationship.

  4. #4
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    5,962

    Re: How to set the parent dialog??

    Quote Originally Posted by Salvadoravi View Post
    My problem is that the CMyDlg is modal but to the main dialog and not to the container or the child dialog.
    Pointer to parent must be passed via constructor parameter, and your CMyDlg must have the corresponding constructor.

    Code:
    
    class CMyDlg: public CDialog
    {
    . . .
        CMyDlg(CWnd* pParent = NULL): CDialog(IDD, pParent) {. . .}
    };
    
    
    CChildDlg:: CChildDlg (CWnd* pParent /*=NULL*/)  : 
        m_pParent((CDlgContainer*)pParent),
    {
    }
    
    void CChildDlg::OnBnClickedBtn()
    {
        CMyDlg MyDlg(this);
        INT_PTR iResult = MyDlg.DoModal();
    }
    Best regards,
    Igor

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center