Solved

Does SendMessageToDescendants Send Messages to CPropertySheet Windows

Posted on 2008-06-17
14
1,094 Views
Last Modified: 2010-05-18
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
Comment
Question by:david_johns
  • 8
  • 6
14 Comments
 
LVL 49

Expert Comment

by:DanRollins
ID: 21811431
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
 

Author Comment

by:david_johns
ID: 21811508
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
 
LVL 49

Expert Comment

by:DanRollins
ID: 21817539
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
ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

 

Author Comment

by:david_johns
ID: 21817939
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
 

Author Comment

by:david_johns
ID: 21818728
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
 
LVL 49

Expert Comment

by:DanRollins
ID: 21825729
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
 

Author Comment

by:david_johns
ID: 21827674
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
 
LVL 49

Expert Comment

by:DanRollins
ID: 21828207
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
 

Author Comment

by:david_johns
ID: 21829597
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
 
LVL 49

Expert Comment

by:DanRollins
ID: 21835044
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
 

Author Comment

by:david_johns
ID: 21836202
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
 
LVL 49

Expert Comment

by:DanRollins
ID: 21836657
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
 

Author Comment

by:david_johns
ID: 21861363
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
 

Accepted Solution

by:
david_johns earned 0 total points
ID: 23864402
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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question