Depends on what you mean by "encapsulation". If you think of the property sheet as
embodying the functionality, it is no business of the external interface how you choose to
arrange the functionality into individual pages. You just SendMessage to the sheet, and
it worries about dispatching; I usually just do a SendMessageToDescendants from the
property sheet. Alternatively, I'll encapsulate the send-to logic in a function that does
a SendMessageToDescendants tot he sheet itself.
Nobody outside the property sheet needs to know how the pages are arranged, what controls
they use to implement the concepts, etc. That sounds like a REALLY clean interface to
The sheet should not access the pages directly; the sheet must neither know nor care what
a page implements, or how it implements it. That's why I use registered messages and
Outside the sheet, nobody knows there is even a page. The concept is invisible. It is
just a window that processes messages, nothing more.
It seems that the ProertySHEET is modeless because I use PropSheet.Create().
OK, but if I call pPropSHEET->DoSomethingToAPage() from my main dialog,
aren't I then violating the rules of encapsulation and data hiding? Shouldn't
then a Windows message be sent to the PropSHEET? Then the call would be
I do recall Joe mentioning working through the PropertySHEET using the
PropertyPAGE as a sort of view. I can see that. In this scenario, there is
not much modularity between the PAGE's and SHEET. I don't guess any messaging
would have to be sent between the PAGE's and SHEET. True?
I just figured if there was something on the PAGE that didn't involve
anything else, I would message the PAGE to deal with it.
I guess it just gets down to how much should be modular. The primary dialog
should never be manipulating data in the PAGE or calling member functions of
the PAGE unless there's a very compelling reason. I get that now (from
At what point should the SHEET be allowed to access the PAGE directly? These
seem, from my conversations here, more inherently coupled.
How much of the SHEET should the dialog be able to access? Should as much as
possible be messaging? That is now how my thought process has shifted. Nearly
everything should be messaging if it can.
If I don't message the PAGE directly, then I will message the SHEET.
It's just nebulous as to where these lines should be drawn.
"AliR (VC++ MVP)" wrote:
I remember your origianl thread!
I have a question? Is this Property sheet modeless or modal?
If we are talking about the modeless propertysheet
You don't need to send a message from the parent to the PropertyPage. You
can provide a method in your CPropertySheet derived class which will endup
calling the CPropertyPage derived classes method. (I think this came up in
your original post).
class CMyPropertySheet : public CPropertySheet
class CMyDialog2 : public CPropertyPage
Now from you main window after you have created your propertysheet class you
can call DoSomethingToAPage.
Now if this is a model dialog, you can't do the above, or SendMessages from
the main window.
wrote in message news:DF84642E-A7B7-4A66-83A8-72C3FD44EF98@microsoft.com...
In a previous post a while back, Joe pointed out that my structure was
incorrect on my app (in fact, I believe the quote was, paraphrased, "that
kind of code sets my teeth on edge").
I was, and still am, sending messages to the parent dialog. I can send a
message to the parent dialog from the Property Pages but have not had any
luck with the reverse.
I am trying to move it in the right direction by sending messages to the
Property Page from the parent.
To send a message to the parent I use:
AfxGetMainWnd()->PostMessage(WM_CLOSE, 0, 0);
LRESULT Rslt = ::SendMessage(m_pMainWnd->m_hWnd ,UWM_INIT_PG1, 0, 0);
I have also seen:
GetParent()->SendMessage(WM_COMMAND, MAKEWPARAM(Something(), 1000),
Of course, I add the appropriate message map and afx_msg entries. I
the same format to send a message to Property Page, but no luck.
Here is the program structure:
The program is a small program structured as follows:
Dialog bases app.
App creates primary dialog (done by VS2005)
Primary dialog creates Property Sheet
Property Sheet creates 4 property pages
Joseph M. Newcomer [MVP]