CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Modelless

  1. #1
    Join Date
    Jun 2001
    Posts
    126

    Modelless

    Alright, I am using a Modelless dialog in my dialog project. I have made the instance of the modelless dialog a member variable of the main dialog so as to try to stop memory leaks. However, if I create, show, and exit the modelless dialog, and then try to create and show it again, I get an Assertion error. Is there a way to get around this?


  2. #2
    Join Date
    Dec 2000
    Location
    Canada
    Posts
    732

    Re: Modelless

    Is your member variable a pointer? If so, make sure you're deleting it when exiting the dialog (OnDestroy). Then set the pointer to NULL.


  3. #3
    Join Date
    May 2000
    Location
    NJ
    Posts
    640

    Re: Modelless

    If your putting it on the Heap (new), make sure you delete off the heap.



    // WaitDlg.cpp : implementation file
    //

    #include "stdafx.h"
    #include "cdi.h"
    #include "WaitDlg.h"

    #ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #endif

    /////////////////////////////////////////////////////////////////////////////
    // CWaitDlg dialog


    CWaitDlg::CWaitDlg(CWnd* pParent /*=NULL*/)
    : CDialog(CWaitDlg::IDD, pParent)
    {
    //{{AFX_DATA_INIT(CWaitDlg)
    m_clstrWait = _T("");
    //}}AFX_DATA_INIT
    }


    void CWaitDlg:oDataExchange(CDataExchange* pDX)
    {
    CDialog:oDataExchange(pDX);
    //{{AFX_DATA_MAP(CWaitDlg)
    DDX_Text(pDX, IDC_STATIC_WAIT, m_clstrWait);
    DDV_MaxChars(pDX, m_clstrWait, 100);
    //}}AFX_DATA_MAP
    }


    BEGIN_MESSAGE_MAP(CWaitDlg, CDialog)
    //{{AFX_MSG_MAP(CWaitDlg)
    //}}AFX_MSG_MAP
    END_MESSAGE_MAP()

    /////////////////////////////////////////////////////////////////////////////
    // CWaitDlg message handlers

    BOOL CWaitDlg::OnInitDialog()
    {
    CDialog::OnInitDialog();

    m_clstrWait = "";
    //SetDlgItemText(IDC_STATIC_WAIT, m_clstrWait);

    return TRUE; // return TRUE unless you set the focus to a control
    // EXCEPTION: OCX Property Pages should return FALSE
    }

    void CWaitDlg::OnDestroyDlg()
    {
    DestroyWindow();
    }

    void CWaitDlg::SetWaitText(CString sztext)
    {
    UpdateData(TRUE);
    m_clstrWait = sztext;
    SetDlgItemText(IDC_STATIC_WAIT, m_clstrWait);
    }


    void CWaitDlg::PostNcDestroy()
    {
    CDialog::PostNcDestroy();
    delete this;
    }

    ////////////////////
    // Header File
    #if !defined(AFX_WAITDLG_H__BB9EBE31_1618_11D4_980E_00C0F028520E__INCLUDED_)
    #define AFX_WAITDLG_H__BB9EBE31_1618_11D4_980E_00C0F028520E__INCLUDED_

    #if _MSC_VER > 1000
    #pragma once
    #endif // _MSC_VER > 1000
    // WaitDlg.h : header file
    //

    /////////////////////////////////////////////////////////////////////////////
    // CWaitDlg dialog

    class CWaitDlg : public CDialog
    {
    // Construction
    public:
    CWaitDlg(CWnd* pParent = NULL); // standard constructor
    void OnDestroyDlg();
    void SetWaitText(CString sztext);
    // Dialog Data
    //{{AFX_DATA(CWaitDlg)
    enum { IDD = IDD_DIALOG_WAIT };
    CString m_clstrWait;
    //}}AFX_DATA


    // Overrides
    // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CWaitDlg)
    protected:
    virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
    virtual void PostNcDestroy();
    //}}AFX_VIRTUAL

    // Implementation
    protected:

    // Generated message map functions
    //{{AFX_MSG(CWaitDlg)
    virtual BOOL OnInitDialog();
    //}}AFX_MSG
    DECLARE_MESSAGE_MAP()
    };

    //{{AFX_INSERT_LOCATION}}
    // Microsoft Visual C++ will insert additional declarations immediately before the previous line.

    #endif // !defined(AFX_WAITDLG_H__BB9EBE31_1618_11D4_980E_00C0F028520E__INCLUDED_)



    /////////////////////////
    ///// Call it from somewhere in your application

    CWaitDlg* m_pwaitdlg;
    m_pwaitdlg = new CWaitDlg;

    int hStatusWnd; // Handle of Status modaless dlg

    // Create Modaless Dialog
    hStatusWnd = m_pwaitdlg->Create(IDD_DIALOG_WAIT);



    if(!hStatusWnd)
    {
    return;
    }

    m_pwaitdlg->CenterWindow(NULL);
    m_pwaitdlg->ShowWindow(SW_SHOW);
    m_pwaitdlg->SetWaitText("Updating Devices in Group");
    m_pwaitdlg->UpdateWindow();



    // When Finished with it destroy and delete it
    m_pwaitdlg->OnDestroyDlg();






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