It doesn't work because, before calling DoModal, the dialog window is not yet created (the CDialog-derived object has not yet attached a window). One solution is to add a public member to your CDialog-derived class (e.g. CString m_strCaption), set its value before calling DoModal, then call SetWindowText in the WM_INITDIALOG message handler (OnInitDialog). Example:
class CMyDialog : public CDialog
{
// ...
public:
CString m_strCaption;
// ...
};
// ...
BOOL CMyDialog::OnInitDialog()
{
// ...
SetWindowText(m_strCaption);
// ...
}
// ...
// ... CMyDialog dlgOper; // ...
dlgOper.m_strCaption = _T("Baba Safta is programming");
dlgOper.DoModal();
// ...
// ...
|