怎么动态修改模态对话框的标题,MFC
如何动态修改模态对话框的标题,MFC
小弟我在看书的时候,有一个例子是做简单的课程成绩管理程序. 然后书上讲的动态改变模态对话框标题的方法是错的.也就是下面这三句代码.
CDlgInput pInput;
pInput.SetWindowText("ABC");
pInput.DoModal();
然后,小弟我想用一个自定义的消息,参数包括pInput对象的指针,以及标题的内容指针, 发给CDlgInput 类里面去.
然后在CDlgInput类里面加一消息响应函数,以及OnInitial()函数,实现动态改变标题.
但是不行. 请各位大侠,有谁牛点的,帮我看一下这个问题.
CView::OnInputgrade()
{
for(i=0;i<5;i++)
{
CDlgInput pInput;
szCaption.Format("请输入第 %d 位学生的成绩",i+1);
SendMessage(WM_USER+1,(WPARAM)(&pInput),(LPARAM)(&szCaption));
pInput.DoModal();
score[i][0]=pInput.m_Grade1;
score[i][1]=pInput.m_Grade2;
score[i][2]=pInput.m_Grade3;
score[i][3]=pInput.m_Grade4;
}
}
然后,在CDlgInput类里,加上自定义消息响应函数.
void CDlgInput::OnMessage1(WPARAM wParam, LPARAM lParam)
{
szCaption=(CString*)lParam;
pInput1= (CDlgInput*)wParam;
//return 0;
}
以及OnInitial()函数 (其中szCaption被定义成一个CString类的指针变量,pInput1是CDlgInput类的指针变量.)
BOOL CDlgInput::OnInitDialog()
{
CDialog::OnInitDialog();
pInput1->SetWindowText(*szCaption);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
------解决方案--------------------
模态对话框在DoModal之前向其发生消息是无效的,因为这是窗口根本就没有创建。
你应该通过设置变量的方式来操作,例如:
小弟我在看书的时候,有一个例子是做简单的课程成绩管理程序. 然后书上讲的动态改变模态对话框标题的方法是错的.也就是下面这三句代码.
CDlgInput pInput;
pInput.SetWindowText("ABC");
pInput.DoModal();
然后,小弟我想用一个自定义的消息,参数包括pInput对象的指针,以及标题的内容指针, 发给CDlgInput 类里面去.
然后在CDlgInput类里面加一消息响应函数,以及OnInitial()函数,实现动态改变标题.
但是不行. 请各位大侠,有谁牛点的,帮我看一下这个问题.
CView::OnInputgrade()
{
for(i=0;i<5;i++)
{
CDlgInput pInput;
szCaption.Format("请输入第 %d 位学生的成绩",i+1);
SendMessage(WM_USER+1,(WPARAM)(&pInput),(LPARAM)(&szCaption));
pInput.DoModal();
score[i][0]=pInput.m_Grade1;
score[i][1]=pInput.m_Grade2;
score[i][2]=pInput.m_Grade3;
score[i][3]=pInput.m_Grade4;
}
}
然后,在CDlgInput类里,加上自定义消息响应函数.
void CDlgInput::OnMessage1(WPARAM wParam, LPARAM lParam)
{
szCaption=(CString*)lParam;
pInput1= (CDlgInput*)wParam;
//return 0;
}
以及OnInitial()函数 (其中szCaption被定义成一个CString类的指针变量,pInput1是CDlgInput类的指针变量.)
BOOL CDlgInput::OnInitDialog()
{
CDialog::OnInitDialog();
pInput1->SetWindowText(*szCaption);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
------解决方案--------------------
模态对话框在DoModal之前向其发生消息是无效的,因为这是窗口根本就没有创建。
你应该通过设置变量的方式来操作,例如:
- C/C++ code
class CDlgInput : public CDialog { public: .... void SetCaption(LPCTSTR lpszCaption) { m_strCaption = lpszCaption; } private: CString m_strCaption; }; BOOL CDlgInput::OnInitDialog() { CDialog::OnInitDialog(); SetWindowText(m_strCaption); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } CView::OnInputgrade() { CDlgInput dlg; dlg.SetCaption("请输入第 1 位学生的成绩"); dlg.DoModal(); }