david_johns
asked on
Does SendMessageToDescendants Send Messages to CPropertySheet Windows
I am forwarding messages to the children of my main window by overridding WindowProc as shown below. It works great for all the children that are "embedded" into part of this main dialog. It doesn't seem to be sending it to a CPropertyPage class that I launch allow the user to set some settings for my application. I have show the method I use to launch the dialog for this class. At first I thought it was just not making it to the CPropertySheets that I attach to the CPropertyPage, but then I tried to overrider the WindowProc function of the CPropertyPage and found that it was never recieving the WM_APP_ messages. Am I doing something that makes the CPropertyPage (and even the CPropertySheets underneath it) not get recognized as a descendants of the main dialog?
Thanks,
David
Thanks,
David
LRESULT CMyMainDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
//Broadcast custom defined messages to all windows
if(message>=WM_APP && message<=0xBFFF){
SendMessageToDescendants(message, wParam, lParam, TRUE, TRUE);
}
return CDialog::WindowProc(message, wParam, lParam);
}
void CMyMainDlg::OnViewStoreSettings()
{
CStoreSettingsDlg storeSettingsDlg("Store Settings", this, 0);
storeSettingsDlg.DoModal();
}
ASKER
Dan,
Here is the constructor that creates the CPropertyPage
Here is the constructor that creates the CPropertyPage
CStoreSettingsDlg::CStoreSettingsDlg(LPCTSTR pszCaption, CWnd* pParentWnd, UINT iSelectPage)
:CPropertySheet(pszCaption, pParentWnd, iSelectPage)
{
AddPage(&m_ProfilePage);
AddPage(&m_LoginPage);
AddPage(&m_EmailPage);
AddPage(&m_EmailTemplatePage);
AddPage(&m_TaxRatesPage);
AddPage(&m_ProcessPage);
AddPage(&m_CustomFieldsPage);
AddPage(&m_AccountsPage);
AddPage(&m_ReportsPage);
}
It sounds like the problem is that while in DoModal(), your WindowProc is not getting messages. To verify that, place a line like:
MessageBox("Sending msg", "to decendants");
into that function. Or just put a breakpoint there.
MessageBox("Sending msg", "to decendants");
into that function. Or just put a breakpoint there.
ASKER
Dan Rollins,
I have verified that CMyMainDlg::WindowProc is getting called. I tried overriding CStoreSettingsDlg::WindowP roc and it is not getting called, however.
Thanks,
David
I have verified that CMyMainDlg::WindowProc is getting called. I tried overriding CStoreSettingsDlg::WindowP
Thanks,
David
ASKER
Dan,
BTW - I tried switching to PreTranslateMessage (as I think I had already tried before) and found that it does not receive WM_APP_ messages apparently. That must be the reason I over-rode WindowProc. Also, I checked and GetParent() does return the main dlg for the CPropertySheet and the CPropertySheet for the CPropertyPage(s). It seems the parent-child relationships are correct. For some reason it is just not sending the messages between the CMyMainDlg and the CPropertySheet.
Thanks,
David
BTW - I tried switching to PreTranslateMessage (as I think I had already tried before) and found that it does not receive WM_APP_ messages apparently. That must be the reason I over-rode WindowProc. Also, I checked and GetParent() does return the main dlg for the CPropertySheet and the CPropertySheet for the CPropertyPage(s). It seems the parent-child relationships are correct. For some reason it is just not sending the messages between the CMyMainDlg and the CPropertySheet.
Thanks,
David
One possibility: Property pages can't receive messages until they are created, and creation is delayed until the user actually clicks a tab.
You might be able to verify that this is the issue by seeing if property page 0 (the one that is initially visible) is getting the message. Or manually clicking a few tabs before doing the broadcast.
You should use Spy++ to monitor the activity when the message is broadcast. It will also indicate the parent/child relationships of existing windows (and reveal which CWnd-derived objects are actual windows).
You might be able to verify that this is the issue by seeing if property page 0 (the one that is initially visible) is getting the message. Or manually clicking a few tabs before doing the broadcast.
You should use Spy++ to monitor the activity when the message is broadcast. It will also indicate the parent/child relationships of existing windows (and reveal which CWnd-derived objects are actual windows).
ASKER
Dan,
In Spy++ the PropertySheet window shows up as a peer to the main window, but it seems that is normal for dialogs that are not attached to the main dialog. Even though the main window is its parent, it seems that only windows like controls that are a part of a dialog or other child windows show up underneath the main dialog. Could it be that only those windows will have the message broadcasted to them?
Also, I have confirmed that the break in the link for passing the message down occurs between the main dlg and the PropertySheet by overriding the WindowProc function of the PropertySheet. It never receives the message and therefore does not pass it down. If I, however, send the message directly to the PropertySheet it does pass it down to the PropertyPage windows it owns. This is what I have implemented as a workaround.
Thanks,
David
In Spy++ the PropertySheet window shows up as a peer to the main window, but it seems that is normal for dialogs that are not attached to the main dialog. Even though the main window is its parent, it seems that only windows like controls that are a part of a dialog or other child windows show up underneath the main dialog. Could it be that only those windows will have the message broadcasted to them?
Also, I have confirmed that the break in the link for passing the message down occurs between the main dlg and the PropertySheet by overriding the WindowProc function of the PropertySheet. It never receives the message and therefore does not pass it down. If I, however, send the message directly to the PropertySheet it does pass it down to the PropertyPage windows it owns. This is what I have implemented as a workaround.
Thanks,
David
The MFC function SendMessageToDescendants will select the current window as the "top" If you want to send to all windows of your app, you should use, for instance,
AfxGetMainWnd()->SendMessa geToDescen dants(.... .)
AfxGetMainWnd()->SendMessa
ASKER
Dan,
That seems to make it only send the message to the PropertySheet window and not back to the other (main) windows of my application.
Thanks,
David
That seems to make it only send the message to the PropertySheet window and not back to the other (main) windows of my application.
Thanks,
David
It would depend on which window is set as the parent. It is possible, even common, to set the desktop as the parent for "floating" windows. Any window created thusly would not be in the parent/child hierarchy of your app (that is, would not be a descendant of your main window).
ASKER
Doesn't the code I attached above showing how I create the PropertySheet window make the MainWnd of the application the parent?
void CMyMainDlg::OnViewStoreSettings()
{
CStoreSettingsDlg storeSettingsDlg("Store Settings", this, 0);
storeSettingsDlg.DoModal();
}
It should make that CMyMainDlg object the parent. I don't know what your main window is.
It also disables that CMyMainDlg object, which might also be an issue.
It also disables that CMyMainDlg object, which might also be an issue.
ASKER
Dan,
I have checked Spy++ on internet explorer and other commercial applications and the about box and options dialogs tend to not be listed under the root application window, similar to the way it appears in my application. I agree that it seems like it should, but it appears that my application in not an anomoly in that regard at least.
I have checked Spy++ on internet explorer and other commercial applications and the about box and options dialogs tend to not be listed under the root application window, similar to the way it appears in my application. I agree that it seems like it should, but it appears that my application in not an anomoly in that regard at least.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Note: It is quite unusual to write a WindowProc for your dialog. To intercept and process messages, you should override the
PreTranslateMessage
http://msdn.microsoft.com/en-us/library/kkbhxcs2(VS.80).aspx
member function of your CDialog-derived class object.