Click here to Skip to main content
14,692,359 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a member variable
NOTIFYICONDATA niData;
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();
	
}
Posted
Updated 17-Feb-17 23:06pm

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.
   
Comments
Premnath Mali 18-Feb-17 4:01am
   
Thanks !!!
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;
}
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900