
Originally Posted by
Igor Vartanov
No. In OnClose() handler I believe. Of course you add ON_WM_CLOSE() to message map and send WM_CLOSE on OK or Cancel.
You just add to your dialog class this virtual member function:
Code:
void PostNcDestroy()
{
delete this;
}
MSDN provides lots of simple sample projects.

I tried your proposition as I understood it. Unfortunately nothing changed.
Here is declaration of Dialog Class:
Code:
#pragma once
// CPixie3_DLG1 dialog
class CPixie3_DLG1 : public CDialog
{
DECLARE_DYNAMIC(CPixie3_DLG1)
public:
CPixie3_DLG1(CWnd* pParent = NULL); // standard constructor
virtual ~CPixie3_DLG1();
// Dialog Data
enum { IDD = IDD_DIALOG };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
void PostNcDestroy()
{
delete this;
}
DECLARE_MESSAGE_MAP()
public:
afx_msg void OnClose();
afx_msg void OnBnClickedOk();
};
and here is its implementation:
Code:
// Pixie3_DLG1.cpp : implementation file
//
#include "stdafx.h"
#include "Pixie3_GUI.h"
#include "Pixie3_DLG1.h"
#include "afxdialogex.h"
#include "vpi_user.h"
// CPixie3_DLG1 dialog
IMPLEMENT_DYNAMIC(CPixie3_DLG1, CDialog)
CPixie3_DLG1::CPixie3_DLG1(CWnd* pParent /*=NULL*/)
: CDialog(CPixie3_DLG1::IDD, pParent)
{
vpi_printf("Inside of CPixie3_DLG1 consructor\n");
}
CPixie3_DLG1::~CPixie3_DLG1()
{
}
void CPixie3_DLG1::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CPixie3_DLG1, CDialog)
ON_WM_CLOSE()
ON_BN_CLICKED(IDOK, &CPixie3_DLG1::OnBnClickedOk)
END_MESSAGE_MAP()
// CPixie3_DLG1 message handlers
void CPixie3_DLG1::OnClose()
{
// TODO: Add your message handler code here and/or call default
CDialog::OnClose();
}
void CPixie3_DLG1::OnBnClickedOk()
{
OnClose();
CDialog::OnOK();
}
I also tried the second option:
Code:
vpi_printf("Initialization starts ...\n");
CWinApp::InitInstance();
CPixie3_DLG1 dlg;
dlg.DoModal();
vpi_printf("Initialization finishes ...\n");
return FALSE;
Unfortunately it doesn't work at all. I think DoModal function cannot be used in my case, where there is no parent window.
Here is CAD tool output window (with vpi_printf function messages):
Pixie3_GUI_displaying2.JPG
As you can constate, the dialog constructor didn't accomplish his job (message "Initialization finishes ...\n" didn't appear.
Best Regards,
Pavel.