我需要設置對話框表單標題。我試圖創建CString變量,可能綁定到類嚮導的標題。但在選擇菜單中沒有主窗體控件。這樣做的方式是什麼?設置MFC對話框表單標題
這是我的對話形式:
#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;
}
這是創建對話框代碼:
BOOL CPreparationApp::InitInstance()
{
MyDlg Dlg;
//how to tell Dlg to have form caption "BLABLABLA"?
Dlg.DoModal();
return TRUE;
}
類似於Dlg.SetWindowText(「BLABLABLA」); ?此代碼引發異常 – vico
您必須在確定您的窗口存在時執行此操作。正如@ ScottMcP-MVP所建議的,你可以把它放在OnInitDialog中。如果你事先知道你的標題是什麼,請使用一個CString成員變量和一個Set方法來填充它,調用MyDlg dlg之間的方法;和dlg.DoModal();並且在你的OnInitDialog中你可以調用SetWindowText(m_yourMemberVariable); – IssamTP