Вопрос

I have the following code in trying to set the text in a Cedit text box:

class CMetaDlg : public CDialogEx
{
public:
CMetaDlg();

// Dialog Data
enum { IDD = IDD_META };

protected:
virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support

// Implementation
protected:
DECLARE_MESSAGE_MAP()
public:
CEdit m_author;
CEdit m_sources;
afx_msg void OnBnClickedOk();
};

CMetaDlg::CMetaDlg() : CDialogEx(CMetaDlg::IDD)
{
}

void CMetaDlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
DDX_Control(pDX, IDC_AUTHOR, m_author);
DDX_Control(pDX, IDC_SOURCES, m_sources);
}

BEGIN_MESSAGE_MAP(CMetaDlg, CDialogEx)
ON_BN_CLICKED(IDOK, &CMetaDlg::OnBnClickedOk)
END_MESSAGE_MAP()

void CEmergenceApp::OnFileMeta()
{


CMetaDlg md;    
md.DoModal();
md.m_author.SetWindowTextW(CEmergenceView::GetDoc()->author);
md.m_sources.SetWindowTextW(CEmergenceView::GetDoc()->sources);
}

This gives me a debug assertion error. I am assuming the problem lies in the lines:

md.m_author.SetWindowTextW(CEmergenceView::GetDoc()->author);
md.m_sources.SetWindowTextW(CEmergenceView::GetDoc()->sources);

As commenting them out, everything works fine.

Это было полезно?

Решение

When you call DoModal the dialog is created, the edit controls are created and then when the user clicks OK or Cancel the edit controls and dialog window are destroyed. Then DoModal returns. I do not understand what you are trying to do by trying to set the edit control's text after the dialog box closes.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top