Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1180
  • Last Modified:

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
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();
}

Open in new window

0
david_johns
Asked:
david_johns
  • 8
  • 6
1 Solution
 
DanRollinsCommented:
Check the code that you use to create the CPropertySheet that is the direct parent of the CPropertyPage windows.  If you use the default constructor, then the parent is your app's main window (and not any modal dialog that may be running).

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.
0
 
david_johnsAuthor Commented:
Dan,

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);
}

Open in new window

0
 
DanRollinsCommented:
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.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
david_johnsAuthor Commented:
Dan Rollins,

I have verified that CMyMainDlg::WindowProc is getting called.  I tried overriding CStoreSettingsDlg::WindowProc and it is not getting called, however.

Thanks,
David
0
 
david_johnsAuthor Commented:
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
0
 
DanRollinsCommented:
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).
0
 
david_johnsAuthor Commented:
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
0
 
DanRollinsCommented:
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()->SendMessageToDescendants(.....)

0
 
david_johnsAuthor Commented:
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
0
 
DanRollinsCommented:
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).
0
 
david_johnsAuthor Commented:
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();
}

Open in new window

0
 
DanRollinsCommented:
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.
0
 
david_johnsAuthor Commented:
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.
0
 
david_johnsAuthor Commented:
I was trying to find a way to send a message from one of the CPropertyPage[s] to another.  I ended up just passing the message directly to the parent CPropertySheet, which passes it down to each of the CPropertyPages.  I was never able to get theApp to pass it all the way down.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 8
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now