Set MFC dialog form caption

mfcvisual c++

I need to set dialog form caption. I was trying to create CString variable that might be binded to caption with Class Wizard. But there is no main form control in selection menu. What is the way of doing that?

This is my dialog form:

#include "stdafx.h"
#include "MyDlg.h"
#include "afxdialogex.h"


// MyDlg dialog

IMPLEMENT_DYNAMIC(MyDlg, CDialog)

MyDlg::MyDlg(CWnd* pParent /*=NULL*/)
    : CDialog(MyDlg::IDD, pParent)
    , m_edit(_T(""))
{

}

MyDlg::~MyDlg()
{
}

void MyDlg::DoDataExchange(CDataExchange* pDX)
{
    CDialog::DoDataExchange(pDX);
    DDX_Text(pDX, IDC_EDIT1, m_edit);
}


BEGIN_MESSAGE_MAP(MyDlg, CDialog)
    ON_BN_CLICKED(IDOK, &MyDlg::OnBnClickedOk)
END_MESSAGE_MAP()


// MyDlg message handlers


void MyDlg::OnBnClickedOk()
{

    // TODO: Add your control notification handler code here
    CDialog::OnOK();
    txt=m_edit;
}

This is code that creates dialog:

BOOL CPreparationApp::InitInstance()
{

    MyDlg Dlg;
//how to tell Dlg to have form caption "BLABLABLA"?
    Dlg.DoModal();


        return TRUE;
}

Best Answer

Hoping I've understood your question in the right way:

// MyDlg.h
class MyDlg
{
 public:    // private is fine too if you're OOP nazi but you have to provide a SetDlgCaption method then.
    CString m_strDlgCaption;
};

// MyDlg.cpp
BOOL MyDlg::OnInitDialog( )
{
    SetWindowText( m_strDlgCaption );
}


BOOL CPreparationApp::InitInstance()
{

    MyDlg Dlg;

    Dlg.m_strDlgCaption = _T("A fancy caption for your dialog");
    Dlg.DoModal();
}
Related Topic