tharstern
asked on
Child messages not being recieved by parent
I have a CDialog based class that creates more CDialog based classes. Like this:-
BOOL CCarriageCostsDlg::OnInitD ialog()
{
CDialog::OnInitDialog();
m_Tab.InsertItem(0, THAR_LANG_SINGLE_ITEM(_T(" Details")) );
m_Tab.InsertItem(1, THAR_LANG_SINGLE_ITEM(_T(" Prices"))) ;
m_pDetailsTab = new CCarriageCostsDetailsDlg(m _Zones, m_WeightBands, m_Services, this);
m_pDetailsTab->Create(IDD_ CARRIAGECO STSDETAILS TAB, this);
m_pPricesTab = new CCarriageCostsPricesDlg;
m_pPricesTab->Create(IDD_C ARRIAGECOS TSPRICESTA B, this);
...
}
The problem is I want to handle the BN_CLICKED of a button on CCarriageCostsDetailsDlg in CCarriageCostsDlg. Like this:-
ON_NOTIFY(BN_CLICKED, IDC_BUTTON_APPLY, OnClickedButtonApply)
ON_NOTIFY(BN_CLICKED, IDC_BUTTON_EDIT, OnClickedButtonEdit)
But these events are not recieved. I know I can use a pointer within CCarriageCostsDetailsDlg and call a public method within CCarriageCostsDlg or Post/Send a custom message but that is very bad and ugly code so would like to do this the 'correct' way.
Is there something wrong with my ON_NOTIFY? according to MSDN this should work.
To Quote MSDN:-
"If, in your parent window class, you supply a handler for a specific WM_NOTIFY message or a range of WM_NOTIFY messages, your handler will be called only if the child control sending those messages does not have a reflected message handler through ON_NOTIFY_REFLECT()."
It does not have a ON_NOTIFY_REFLECT().
BOOL CCarriageCostsDlg::OnInitD
{
CDialog::OnInitDialog();
m_Tab.InsertItem(0, THAR_LANG_SINGLE_ITEM(_T("
m_Tab.InsertItem(1, THAR_LANG_SINGLE_ITEM(_T("
m_pDetailsTab = new CCarriageCostsDetailsDlg(m
m_pDetailsTab->Create(IDD_
m_pPricesTab = new CCarriageCostsPricesDlg;
m_pPricesTab->Create(IDD_C
...
}
The problem is I want to handle the BN_CLICKED of a button on CCarriageCostsDetailsDlg in CCarriageCostsDlg. Like this:-
ON_NOTIFY(BN_CLICKED, IDC_BUTTON_APPLY, OnClickedButtonApply)
ON_NOTIFY(BN_CLICKED, IDC_BUTTON_EDIT, OnClickedButtonEdit)
But these events are not recieved. I know I can use a pointer within CCarriageCostsDetailsDlg and call a public method within CCarriageCostsDlg or Post/Send a custom message but that is very bad and ugly code so would like to do this the 'correct' way.
Is there something wrong with my ON_NOTIFY? according to MSDN this should work.
To Quote MSDN:-
"If, in your parent window class, you supply a handler for a specific WM_NOTIFY message or a range of WM_NOTIFY messages, your handler will be called only if the child control sending those messages does not have a reflected message handler through ON_NOTIFY_REFLECT()."
It does not have a ON_NOTIFY_REFLECT().
The parent window of the child control sending the message is your child dialog, not the dialog owning the child dialog.
Always you can redirect a message manually at PreTranslateMessage() function. You can use either SendMessage or PostMessage inside it.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
@alb66
Thx, absolutely spot on :)
Thx, absolutely spot on :)
ASKER
Thanks a lot.