Communications between dialogs
-
I have 7 child dialogs, & a parent dialog. From parent dialog, I call 1st child, on the child dlg's buttons child sends message to the parent. Among that one message is to update the object in parent which is working fine. The second message is to hide that child and show another child dialog. I have added method for the message : afx_msg LRESULT DataEntryDialog::OnSHOW_NEXT_VIEW(WPARAM wparam, LPARAM lparam) { } In child1 : in .h the events are declared as
enum
{
BASE /* not used */ = WM_USER,
CHANGED_DS, SHOW_NEXT_VIEW,
};void CPage1Dlg::TellParent()
{
// Update deptStock obj with the parent
this->CRHPostMessageToParent(CHANGED_DS, (int)&deptStock);
this->ShowWindow(false);
CRHPostMessageToParent(SHOW_NEXT_VIEW, 2);
}In parent: Childs are created as below in OnInitDialog():
CRect rect(4, 2, 5,2); CPoint point(0, 10); childPage1.CRHCreateGenericChildDialog(this, &rect,0, NULL); childPage1.SetDeptStock(deptStock); rect += point; childPage2.CRHCreateGenericChildDialog(this, &rect, 1, NULL); childPage2.ShowWindow(false); childVisible = 1;
afx_msg LRESULT DataEntryDialog::OnCHANGED_DS(WPARAM wparam, LPARAM lparam)
// handles message sent up from child dialog
{
deptStock = (DeptStock&)lparam;
AfxMessageBox(_T("Dept Stock Updated"));
return 0;
}afx_msg LRESULT DataEntryDialog::OnSHOW_NEXT_VIEW(WPARAM wparam, LPARAM lparam) {
int childView = (int)lparam; AfxMessageBox(childView); if (childView ==2) { childPage2.SetDeptStock(deptStock); childPage2.ShowWindow(true); childVisible = 2; } return 0;
}
Any guidance on the above is highly appreciated.
Thanks Terry
-
I have 7 child dialogs, & a parent dialog. From parent dialog, I call 1st child, on the child dlg's buttons child sends message to the parent. Among that one message is to update the object in parent which is working fine. The second message is to hide that child and show another child dialog. I have added method for the message : afx_msg LRESULT DataEntryDialog::OnSHOW_NEXT_VIEW(WPARAM wparam, LPARAM lparam) { } In child1 : in .h the events are declared as
enum
{
BASE /* not used */ = WM_USER,
CHANGED_DS, SHOW_NEXT_VIEW,
};void CPage1Dlg::TellParent()
{
// Update deptStock obj with the parent
this->CRHPostMessageToParent(CHANGED_DS, (int)&deptStock);
this->ShowWindow(false);
CRHPostMessageToParent(SHOW_NEXT_VIEW, 2);
}In parent: Childs are created as below in OnInitDialog():
CRect rect(4, 2, 5,2); CPoint point(0, 10); childPage1.CRHCreateGenericChildDialog(this, &rect,0, NULL); childPage1.SetDeptStock(deptStock); rect += point; childPage2.CRHCreateGenericChildDialog(this, &rect, 1, NULL); childPage2.ShowWindow(false); childVisible = 1;
afx_msg LRESULT DataEntryDialog::OnCHANGED_DS(WPARAM wparam, LPARAM lparam)
// handles message sent up from child dialog
{
deptStock = (DeptStock&)lparam;
AfxMessageBox(_T("Dept Stock Updated"));
return 0;
}afx_msg LRESULT DataEntryDialog::OnSHOW_NEXT_VIEW(WPARAM wparam, LPARAM lparam) {
int childView = (int)lparam; AfxMessageBox(childView); if (childView ==2) { childPage2.SetDeptStock(deptStock); childPage2.ShowWindow(true); childVisible = 2; } return 0;
}
Any guidance on the above is highly appreciated.
Thanks Terry
A lot of dialogs opened in one program is bad style and is confusing the programer and user so you should avoid it. :-O For communication is messaging between windows and dialogs suitable. Do it via PostMessage to avoid blocking. For the data you better use one global object so everywhere is the same data. Then you only need to post the message to every open window/dialog that data is changed. Please believe me: make a array of HWND!!!
Greetings from Germany
-
A lot of dialogs opened in one program is bad style and is confusing the programer and user so you should avoid it. :-O For communication is messaging between windows and dialogs suitable. Do it via PostMessage to avoid blocking. For the data you better use one global object so everywhere is the same data. Then you only need to post the message to every open window/dialog that data is changed. Please believe me: make a array of HWND!!!
Greetings from Germany
Thanks KarstenK,
KarstenK wrote:
Please believe me: make a array of HWND!!!
I am gonna make an array of CDialog & place each child dialog in it. Currectly, I am just checking it with 2 dialogs. Can you give some helpline of how to do with PostMessage. The
this->CRHPostMessageToParent(CHANGED_DS, (int)&deptStock);
in return calls PostMessage by passing the childDialogId as WPAram
void CRHGenericChildDialog::CRHPostMessageToParent(UINT message, LPARAM lParam)
{
CRHpParent->PostMessage(message, CRHId, lParam);
}Thanks Terry
-
I have 7 child dialogs, & a parent dialog. From parent dialog, I call 1st child, on the child dlg's buttons child sends message to the parent. Among that one message is to update the object in parent which is working fine. The second message is to hide that child and show another child dialog. I have added method for the message : afx_msg LRESULT DataEntryDialog::OnSHOW_NEXT_VIEW(WPARAM wparam, LPARAM lparam) { } In child1 : in .h the events are declared as
enum
{
BASE /* not used */ = WM_USER,
CHANGED_DS, SHOW_NEXT_VIEW,
};void CPage1Dlg::TellParent()
{
// Update deptStock obj with the parent
this->CRHPostMessageToParent(CHANGED_DS, (int)&deptStock);
this->ShowWindow(false);
CRHPostMessageToParent(SHOW_NEXT_VIEW, 2);
}In parent: Childs are created as below in OnInitDialog():
CRect rect(4, 2, 5,2); CPoint point(0, 10); childPage1.CRHCreateGenericChildDialog(this, &rect,0, NULL); childPage1.SetDeptStock(deptStock); rect += point; childPage2.CRHCreateGenericChildDialog(this, &rect, 1, NULL); childPage2.ShowWindow(false); childVisible = 1;
afx_msg LRESULT DataEntryDialog::OnCHANGED_DS(WPARAM wparam, LPARAM lparam)
// handles message sent up from child dialog
{
deptStock = (DeptStock&)lparam;
AfxMessageBox(_T("Dept Stock Updated"));
return 0;
}afx_msg LRESULT DataEntryDialog::OnSHOW_NEXT_VIEW(WPARAM wparam, LPARAM lparam) {
int childView = (int)lparam; AfxMessageBox(childView); if (childView ==2) { childPage2.SetDeptStock(deptStock); childPage2.ShowWindow(true); childVisible = 2; } return 0;
}
Any guidance on the above is highly appreciated.
Thanks Terry
Trupti Mehta wrote:
I have 7 child dialogs, & a parent dialog. From parent dialog, I call 1st child, on the child dlg's buttons child sends message to the parent. Among that one message is to update the object in parent which is working fine. The second message is to hide that child and show another child dialog.
Sounds like you need a property sheet wizard.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
-
I have 7 child dialogs, & a parent dialog. From parent dialog, I call 1st child, on the child dlg's buttons child sends message to the parent. Among that one message is to update the object in parent which is working fine. The second message is to hide that child and show another child dialog. I have added method for the message : afx_msg LRESULT DataEntryDialog::OnSHOW_NEXT_VIEW(WPARAM wparam, LPARAM lparam) { } In child1 : in .h the events are declared as
enum
{
BASE /* not used */ = WM_USER,
CHANGED_DS, SHOW_NEXT_VIEW,
};void CPage1Dlg::TellParent()
{
// Update deptStock obj with the parent
this->CRHPostMessageToParent(CHANGED_DS, (int)&deptStock);
this->ShowWindow(false);
CRHPostMessageToParent(SHOW_NEXT_VIEW, 2);
}In parent: Childs are created as below in OnInitDialog():
CRect rect(4, 2, 5,2); CPoint point(0, 10); childPage1.CRHCreateGenericChildDialog(this, &rect,0, NULL); childPage1.SetDeptStock(deptStock); rect += point; childPage2.CRHCreateGenericChildDialog(this, &rect, 1, NULL); childPage2.ShowWindow(false); childVisible = 1;
afx_msg LRESULT DataEntryDialog::OnCHANGED_DS(WPARAM wparam, LPARAM lparam)
// handles message sent up from child dialog
{
deptStock = (DeptStock&)lparam;
AfxMessageBox(_T("Dept Stock Updated"));
return 0;
}afx_msg LRESULT DataEntryDialog::OnSHOW_NEXT_VIEW(WPARAM wparam, LPARAM lparam) {
int childView = (int)lparam; AfxMessageBox(childView); if (childView ==2) { childPage2.SetDeptStock(deptStock); childPage2.ShowWindow(true); childVisible = 2; } return 0;
}
Any guidance on the above is highly appreciated.
Thanks Terry
Terry, So you have one parent dialog and 7 child dialogs. At first one of your child dialog will be displayed and if you click one button in child dialog, that child should be closed and next child dialog should be shown until all child dialog finishes. Is that your requirement? Regards, Jijo.
_____________________________________________________ http://weseetips.com[^] Visual C++ tips and tricks. Updated daily.
-
Terry, So you have one parent dialog and 7 child dialogs. At first one of your child dialog will be displayed and if you click one button in child dialog, that child should be closed and next child dialog should be shown until all child dialog finishes. Is that your requirement? Regards, Jijo.
_____________________________________________________ http://weseetips.com[^] Visual C++ tips and tricks. Updated daily.
Yes, want to hide 1 child and show other child. But I want this to be controlled programmatically as the child dialogs need not be in series. I mean after child3, on some basis child5, or child7 or child3 should come respectively. I work on WinCE5 for a specific device and it doesn't support Property Sheets. WinCe supports, but that device's SDK doesn't support. So, I got to work out manually only.
Thanks Terry
-
Yes, want to hide 1 child and show other child. But I want this to be controlled programmatically as the child dialogs need not be in series. I mean after child3, on some basis child5, or child7 or child3 should come respectively. I work on WinCE5 for a specific device and it doesn't support Property Sheets. WinCe supports, but that device's SDK doesn't support. So, I got to work out manually only.
Thanks Terry
Terry, I hope in your parent dialog, you're creating instance of child dialog and shows it by calling
DoModel()
. Instead of child dialog sending message to parent, just close the child dialog by callingEndDialog()
function. In theEndDialog()
you can give a parameter which will be returned by theDoModel()
function. So by checking the return code ofChildDialog.DoModel()
, you can show next dialog. For instance,void CParentDialog::ShowChildDialog()
{
CDialogDlg ChildDialog;
if( SHOW_NEXT_DIALOG == ChildDialog.DoModal())
{
// Show your next child dialog.
}
}// In child dialog
void ChildDialog::OnNextDialog()
{
// The SHOW_NEXT_DIALOG will be returned by the DoModel() call.
EndDialog( SHOW_NEXT_DIALOG );
}Here in the e.g. if the DoModel() returns SHOW_NEXT_DIALOG, then its the request to show next dialog. Just try this. Just let me know if you've more issues. Regards, Jijo.
_____________________________________________________ http://weseetips.com[^] Visual C++ tips and tricks. Updated daily.
-
Terry, I hope in your parent dialog, you're creating instance of child dialog and shows it by calling
DoModel()
. Instead of child dialog sending message to parent, just close the child dialog by callingEndDialog()
function. In theEndDialog()
you can give a parameter which will be returned by theDoModel()
function. So by checking the return code ofChildDialog.DoModel()
, you can show next dialog. For instance,void CParentDialog::ShowChildDialog()
{
CDialogDlg ChildDialog;
if( SHOW_NEXT_DIALOG == ChildDialog.DoModal())
{
// Show your next child dialog.
}
}// In child dialog
void ChildDialog::OnNextDialog()
{
// The SHOW_NEXT_DIALOG will be returned by the DoModel() call.
EndDialog( SHOW_NEXT_DIALOG );
}Here in the e.g. if the DoModel() returns SHOW_NEXT_DIALOG, then its the request to show next dialog. Just try this. Just let me know if you've more issues. Regards, Jijo.
_____________________________________________________ http://weseetips.com[^] Visual C++ tips and tricks. Updated daily.
Thanks Jijo, As the dialogs are not in series & can call previous dialog also. So I call messages SHOW_NEXT_DIALOG with the child dialog # to be shown & it works perfectly. I figured out to work as expected. Thanks jijo for the efforts. Jijo, I can't add an int, float to CString. Like I want to add up "Name " + int + float in a CString. How do I achieve it. I tried many ways, but gives error or warnings only. Help me if you can.
Thanks Terry
-
Thanks Jijo, As the dialogs are not in series & can call previous dialog also. So I call messages SHOW_NEXT_DIALOG with the child dialog # to be shown & it works perfectly. I figured out to work as expected. Thanks jijo for the efforts. Jijo, I can't add an int, float to CString. Like I want to add up "Name " + int + float in a CString. How do I achieve it. I tried many ways, but gives error or warnings only. Help me if you can.
Thanks Terry
Trupti Mehta wrote:
Jijo, I can't add an int, float to CString. Like I want to add up "Name " + int + float in a CString. How do I achieve it. I tried many ways, but gives error or warnings only. Help me if you can.
CString csMessage;
int nInteger = 10;
float fFloat = 20.0f;// Format the message.
csMessage.Format( _T("%s %d %f"), // Format String.
_T("Name :"),
nInteger,
fFloat );
// if you want to format the float precision, just use %0.2f in format string.
// So only two decimal digits will be shown.Hope the code snippet explains everything you asked. :) Regards, Jijo.
_____________________________________________________ http://weseetips.com[^] Visual C++ tips and tricks. Updated daily.