Solved

Does SendMessageToDescendants Send Messages to CPropertySheet Windows

Posted on 2008-06-17
14
1,074 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
 

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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

757 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now