CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 17 of 17
  1. #16
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: Hide ahd Show Dialog

    Quote Originally Posted by ajbharani View Post
    Something like this
    Code:
    void CDialog1::OnButton1() 
    {
        CDialog2 *dia2 = new CDialog2();    
        dia2->Create(IDD_DIALOG2);
        dia2->ShowWindow(SW_SHOW);
    }
    No, not like that, if you don't want to leak memory. Make the pointer to the dialog a member of the class.
    Code:
    class CDialog1
    {
      CDialog2 *m_dia2;
    };
    
    CDialog1::CDialog1()
    {
       m_dia2 = NULL;
    }
    
    void CDialog1::OnButton1() 
    {
        if(m_dia2 == NULL) 
            m_dia2 = new CDialog2();
    
        if(!m_dia2->Create(IDD_DIALOG2))
        {
            delete m_dia2;
            m_dia2 = NULL;
    
            // show error
        }
    
        m_dia2->ShowWindow(SW_SHOW); // or perhaps first call SW_SHOW and second call SW_HIDE
    }
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  2. #17
    Join Date
    Jan 2008
    Location
    India
    Posts
    408

    Re: Hide ahd Show Dialog

    Quote Originally Posted by cilu View Post
    No, not like that, if you don't want to leak memory. Make the pointer to the dialog a member of the class.
    Code:
    class CDialog1
    {
      CDialog2 *m_dia2;
    };
    
    CDialog1::CDialog1()
    {
       m_dia2 = NULL;
    }
    
    void CDialog1::OnButton1() 
    {
        if(m_dia2 == NULL) 
            m_dia2 = new CDialog2();
    
        if(!m_dia2->Create(IDD_DIALOG2))
        {
            delete m_dia2;
            m_dia2 = NULL;
    
            // show error
        }
    
        m_dia2->ShowWindow(SW_SHOW); // or perhaps first call SW_SHOW and second call SW_HIDE
    }
    Ok. Nice piece of information. Thnks
    Rate the posts which you find useful

Page 2 of 2 FirstFirst 12

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