如何访问父对话框的成员变量? [英] How to access member variable of parent dialog?

查看:79
本文介绍了如何访问父对话框的成员变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在父对话框中有一个成员变量

I have a member variable

NOTIFYICONDATA niData;

来显示系统托盘。



And我有一个孩子对话框学生,我有一个AddStudent按钮



我想在我的AddStudent点击事件中使用niData显示bollon即

新学生补充......



我该怎么做?



我尝试过:



in my parent dialog to display system tray.

And I have a child dialog Student on that I have one AddStudent button

I wanted to use niData in my click event of AddStudent to display bollon i.e.
" New Student added..."

How do I do that?

What I have tried:

void CStudent::SaveData()
{
	Student s1;
	CString sname,id,sclass,m;
	m_txtStudentName.GetWindowTextW(sname);
	m_txtStudentId.GetWindowTextW(id);
	m_txtClass.GetWindowTextW(sclass);

	sprintf(s1.sname,"%S",sname);
	sprintf(s1.id,"%S",id);
	sprintf(s1.sclass,"%S",sclass);
	
	bool flag=ValidateData(s1,&m);

	if(flag)
	{
		CFile write(L"student.txt",CFile::modeCreate|CFile::modeReadWrite|CFile::modeNoTruncate);
		write.SeekToEnd();
		write.Write(&s1,sizeof(s1));
		write.Close();
		LoadDataToList();
		ClearFields();
		//Here I wanted to access niData which is declared in parent dialog to show system tray bollon that "New Student added"

	}
	ShowMessage(m);
	
}


void CStudent::OnBnClickedAdd()
{
	// TODO: Add your control notification handler code here
	SaveData();
	
}

推荐答案

不要这样做 - 它限制孩子只能使用特定的父级,这是非常糟糕的设计和非常糟糕的OOP。

相反,在父级可以处理的子对话框中添加一个事件。孩子举起学生添加事件,父母用信息做了他们想要的事。
Don't do it that way - it restricts the child to only work with a specific parent, and that's very bad design, and very bad OOPs.
Instead, add an event to your child dialog that the parent can handle. The child raises the event "Student added" and the parent does what it wants with the information.


从保存数据中我传递给父母对话消息

From the save data I passed message to the parent Dialog
GetParent()->SendMessage(WM_USER + 558);





在父对话框中我抓到了这条消息处理





And in parent Dialog I caught that message and handle that

ON_MESSAGE(WM_USER+558, OnStudentAdd)







LRESULT CDialogControlDlg::OnStudentAdd(WPARAM wparam, LPARAM lparam)
{
	_tcscpy(niData.szInfoTitle,L"New Record Inserted!");
	_tcscpy(niData.szInfo,L"New Student Added.....");
	niData.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP |NIF_INFO;
	niData.uTimeout=500;
	Shell_NotifyIcon(NIM_MODIFY, &niData);
	return 0;
}


这篇关于如何访问父对话框的成员变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆